fairygui.js 770 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067
  1. if (cc.sys.platform == cc.sys.TAOBAO_MINIGAME) {
  2. //淘宝小游戏全局对象需要调整
  3. globalThis.fgui = {};
  4. globalThis.fairygui = globalThis.fgui;
  5. globalThis.__extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. } else {
  19. window.fgui = {};
  20. window.fairygui = window.fgui;
  21. window.__extends = (this && this.__extends) || (function () {
  22. var extendStatics = function (d, b) {
  23. extendStatics = Object.setPrototypeOf ||
  24. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  25. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  26. return extendStatics(d, b);
  27. };
  28. return function (d, b) {
  29. extendStatics(d, b);
  30. function __() { this.constructor = d; }
  31. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  32. };
  33. })();
  34. }
  35. (function (fgui) {
  36. var AsyncOperation = (function () {
  37. function AsyncOperation() {
  38. }
  39. AsyncOperation.prototype.createObject = function (pkgName, resName) {
  40. if (this._node)
  41. throw 'Already running';
  42. var pkg = fgui.UIPackage.getByName(pkgName);
  43. if (pkg) {
  44. var pi = pkg.getItemByName(resName);
  45. if (!pi)
  46. throw new Error("resource not found: " + resName);
  47. this.internalCreateObject(pi);
  48. }
  49. else
  50. throw new Error("package not found: " + pkgName);
  51. };
  52. AsyncOperation.prototype.createObjectFromURL = function (url) {
  53. if (this._node)
  54. throw 'Already running';
  55. var pi = fgui.UIPackage.getItemByURL(url);
  56. if (pi)
  57. this.internalCreateObject(pi);
  58. else
  59. throw new Error("resource not found: " + url);
  60. };
  61. AsyncOperation.prototype.cancel = function () {
  62. if (this._node) {
  63. this._node.destroy();
  64. this._node = null;
  65. }
  66. };
  67. AsyncOperation.prototype.internalCreateObject = function (item) {
  68. this._node = new cc.Node("[AsyncCreating:" + item.name + "]");
  69. this._node.parent = cc.director.getScene();
  70. this._node.on("#", this.completed, this);
  71. this._node.addComponent(AsyncOperationRunner).init(item);
  72. };
  73. AsyncOperation.prototype.completed = function (result) {
  74. this.cancel();
  75. if (this.callback)
  76. this.callback(result);
  77. };
  78. return AsyncOperation;
  79. }());
  80. fgui.AsyncOperation = AsyncOperation;
  81. var AsyncOperationRunner = (function (_super) {
  82. __extends(AsyncOperationRunner, _super);
  83. function AsyncOperationRunner() {
  84. var _this = _super.call(this) || this;
  85. _this._itemList = new Array();
  86. _this._objectPool = new Array();
  87. return _this;
  88. }
  89. AsyncOperationRunner.prototype.init = function (item) {
  90. this._itemList.length = 0;
  91. this._objectPool.length = 0;
  92. var di = { pi: item, type: item.objectType };
  93. di.childCount = this.collectComponentChildren(item);
  94. this._itemList.push(di);
  95. this._index = 0;
  96. };
  97. AsyncOperationRunner.prototype.onDestroy = function () {
  98. this._itemList.length = 0;
  99. var cnt = this._objectPool.length;
  100. if (cnt > 0) {
  101. for (var i = 0; i < cnt; i++)
  102. this._objectPool[i].dispose();
  103. this._objectPool.length = 0;
  104. }
  105. };
  106. AsyncOperationRunner.prototype.collectComponentChildren = function (item) {
  107. var buffer = item.rawData;
  108. buffer.seek(0, 2);
  109. var di;
  110. var pi;
  111. var i;
  112. var dataLen;
  113. var curPos;
  114. var pkg;
  115. var dcnt = buffer.readShort();
  116. for (i = 0; i < dcnt; i++) {
  117. dataLen = buffer.readShort();
  118. curPos = buffer.position;
  119. buffer.seek(curPos, 0);
  120. var type = buffer.readByte();
  121. var src = buffer.readS();
  122. var pkgId = buffer.readS();
  123. buffer.position = curPos;
  124. if (src != null) {
  125. if (pkgId != null)
  126. pkg = fgui.UIPackage.getById(pkgId);
  127. else
  128. pkg = item.owner;
  129. pi = pkg != null ? pkg.getItemById(src) : null;
  130. di = { pi: pi, type: type };
  131. if (pi && pi.type == fgui.PackageItemType.Component)
  132. di.childCount = this.collectComponentChildren(pi);
  133. }
  134. else {
  135. di = { type: type };
  136. if (type == fgui.ObjectType.List)
  137. di.listItemCount = this.collectListChildren(buffer);
  138. }
  139. this._itemList.push(di);
  140. buffer.position = curPos + dataLen;
  141. }
  142. return dcnt;
  143. };
  144. AsyncOperationRunner.prototype.collectListChildren = function (buffer) {
  145. buffer.seek(buffer.position, 8);
  146. var listItemCount = 0;
  147. var i;
  148. var nextPos;
  149. var url;
  150. var pi;
  151. var di;
  152. var defaultItem = buffer.readS();
  153. var itemCount = buffer.readShort();
  154. for (i = 0; i < itemCount; i++) {
  155. nextPos = buffer.readShort();
  156. nextPos += buffer.position;
  157. url = buffer.readS();
  158. if (url == null)
  159. url = defaultItem;
  160. if (url) {
  161. pi = fgui.UIPackage.getItemByURL(url);
  162. if (pi) {
  163. di = { pi: pi, type: pi.objectType };
  164. if (pi.type == fgui.PackageItemType.Component)
  165. di.childCount = this.collectComponentChildren(pi);
  166. this._itemList.push(di);
  167. listItemCount++;
  168. }
  169. }
  170. buffer.position = nextPos;
  171. }
  172. return listItemCount;
  173. };
  174. AsyncOperationRunner.prototype.update = function () {
  175. var obj;
  176. var di;
  177. var poolStart;
  178. var k;
  179. var t = fgui.ToolSet.getTime();
  180. var frameTime = fgui.UIConfig.frameTimeForAsyncUIConstruction;
  181. var totalItems = this._itemList.length;
  182. while (this._index < totalItems) {
  183. di = this._itemList[this._index];
  184. if (di.pi) {
  185. obj = fgui.UIObjectFactory.newObject(di.pi);
  186. this._objectPool.push(obj);
  187. fgui.UIPackage._constructing++;
  188. if (di.pi.type == fgui.PackageItemType.Component) {
  189. poolStart = this._objectPool.length - di.childCount - 1;
  190. obj.constructFromResource2(this._objectPool, poolStart);
  191. this._objectPool.splice(poolStart, di.childCount);
  192. }
  193. else {
  194. obj.constructFromResource();
  195. }
  196. fgui.UIPackage._constructing--;
  197. }
  198. else {
  199. obj = fgui.UIObjectFactory.newObject(di.type);
  200. this._objectPool.push(obj);
  201. if (di.type == fgui.ObjectType.List && di.listItemCount > 0) {
  202. poolStart = this._objectPool.length - di.listItemCount - 1;
  203. for (k = 0; k < di.listItemCount; k++)
  204. obj.itemPool.returnObject(this._objectPool[k + poolStart]);
  205. this._objectPool.splice(poolStart, di.listItemCount);
  206. }
  207. }
  208. this._index++;
  209. if ((this._index % 5 == 0) && fgui.ToolSet.getTime() - t >= frameTime)
  210. return;
  211. }
  212. var result = this._objectPool[0];
  213. this._itemList.length = 0;
  214. this._objectPool.length = 0;
  215. this.node.emit("#", result);
  216. };
  217. return AsyncOperationRunner;
  218. }(cc.Component));
  219. })(fgui || (fgui = {}));
  220. (function (fgui) {
  221. var _nextPageId = 0;
  222. var Controller = (function (_super) {
  223. __extends(Controller, _super);
  224. function Controller() {
  225. var _this = _super.call(this) || this;
  226. _this._pageIds = [];
  227. _this._pageNames = [];
  228. _this._selectedIndex = -1;
  229. _this._previousIndex = -1;
  230. return _this;
  231. }
  232. Controller.prototype.dispose = function () {
  233. };
  234. Object.defineProperty(Controller.prototype, "selectedIndex", {
  235. get: function () {
  236. return this._selectedIndex;
  237. },
  238. set: function (value) {
  239. if (this._selectedIndex != value) {
  240. if (value > this._pageIds.length - 1)
  241. throw "index out of bounds: " + value;
  242. this.changing = true;
  243. this._previousIndex = this._selectedIndex;
  244. this._selectedIndex = value;
  245. this.parent.applyController(this);
  246. this.emit(fgui.Event.STATUS_CHANGED, this);
  247. this.changing = false;
  248. }
  249. },
  250. enumerable: false,
  251. configurable: true
  252. });
  253. Controller.prototype.onChanged = function (callback, target) {
  254. this.on(fgui.Event.STATUS_CHANGED, callback, target);
  255. };
  256. Controller.prototype.offChanged = function (callback, target) {
  257. this.off(fgui.Event.STATUS_CHANGED, callback, target);
  258. };
  259. Controller.prototype.setSelectedIndex = function (value) {
  260. if (this._selectedIndex != value) {
  261. if (value > this._pageIds.length - 1)
  262. throw "index out of bounds: " + value;
  263. this.changing = true;
  264. this._previousIndex = this._selectedIndex;
  265. this._selectedIndex = value;
  266. this.parent.applyController(this);
  267. this.changing = false;
  268. }
  269. };
  270. Object.defineProperty(Controller.prototype, "previsousIndex", {
  271. get: function () {
  272. return this._previousIndex;
  273. },
  274. enumerable: false,
  275. configurable: true
  276. });
  277. Object.defineProperty(Controller.prototype, "selectedPage", {
  278. get: function () {
  279. if (this._selectedIndex == -1)
  280. return null;
  281. else
  282. return this._pageNames[this._selectedIndex];
  283. },
  284. set: function (val) {
  285. var i = this._pageNames.indexOf(val);
  286. if (i == -1)
  287. i = 0;
  288. this.selectedIndex = i;
  289. },
  290. enumerable: false,
  291. configurable: true
  292. });
  293. Controller.prototype.setSelectedPage = function (value) {
  294. var i = this._pageNames.indexOf(value);
  295. if (i == -1)
  296. i = 0;
  297. this.setSelectedIndex(i);
  298. };
  299. Object.defineProperty(Controller.prototype, "previousPage", {
  300. get: function () {
  301. if (this._previousIndex == -1)
  302. return null;
  303. else
  304. return this._pageNames[this._previousIndex];
  305. },
  306. enumerable: false,
  307. configurable: true
  308. });
  309. Object.defineProperty(Controller.prototype, "pageCount", {
  310. get: function () {
  311. return this._pageIds.length;
  312. },
  313. enumerable: false,
  314. configurable: true
  315. });
  316. Controller.prototype.getPageName = function (index) {
  317. return this._pageNames[index];
  318. };
  319. Controller.prototype.addPage = function (name) {
  320. if (name === void 0) { name = ""; }
  321. this.addPageAt(name, this._pageIds.length);
  322. };
  323. Controller.prototype.addPageAt = function (name, index) {
  324. var nid = "" + (_nextPageId++);
  325. if (index == this._pageIds.length) {
  326. this._pageIds.push(nid);
  327. this._pageNames.push(name);
  328. }
  329. else {
  330. this._pageIds.splice(index, 0, nid);
  331. this._pageNames.splice(index, 0, name);
  332. }
  333. };
  334. Controller.prototype.removePage = function (name) {
  335. var i = this._pageNames.indexOf(name);
  336. if (i != -1) {
  337. this._pageIds.splice(i, 1);
  338. this._pageNames.splice(i, 1);
  339. if (this._selectedIndex >= this._pageIds.length)
  340. this.selectedIndex = this._selectedIndex - 1;
  341. else
  342. this.parent.applyController(this);
  343. }
  344. };
  345. Controller.prototype.removePageAt = function (index) {
  346. this._pageIds.splice(index, 1);
  347. this._pageNames.splice(index, 1);
  348. if (this._selectedIndex >= this._pageIds.length)
  349. this.selectedIndex = this._selectedIndex - 1;
  350. else
  351. this.parent.applyController(this);
  352. };
  353. Controller.prototype.clearPages = function () {
  354. this._pageIds.length = 0;
  355. this._pageNames.length = 0;
  356. if (this._selectedIndex != -1)
  357. this.selectedIndex = -1;
  358. else
  359. this.parent.applyController(this);
  360. };
  361. Controller.prototype.hasPage = function (aName) {
  362. return this._pageNames.indexOf(aName) != -1;
  363. };
  364. Controller.prototype.getPageIndexById = function (aId) {
  365. return this._pageIds.indexOf(aId);
  366. };
  367. Controller.prototype.getPageIdByName = function (aName) {
  368. var i = this._pageNames.indexOf(aName);
  369. if (i != -1)
  370. return this._pageIds[i];
  371. else
  372. return null;
  373. };
  374. Controller.prototype.getPageNameById = function (aId) {
  375. var i = this._pageIds.indexOf(aId);
  376. if (i != -1)
  377. return this._pageNames[i];
  378. else
  379. return null;
  380. };
  381. Controller.prototype.getPageId = function (index) {
  382. return this._pageIds[index];
  383. };
  384. Object.defineProperty(Controller.prototype, "selectedPageId", {
  385. get: function () {
  386. if (this._selectedIndex == -1)
  387. return null;
  388. else
  389. return this._pageIds[this._selectedIndex];
  390. },
  391. set: function (val) {
  392. var i = this._pageIds.indexOf(val);
  393. this.selectedIndex = i;
  394. },
  395. enumerable: false,
  396. configurable: true
  397. });
  398. Object.defineProperty(Controller.prototype, "oppositePageId", {
  399. set: function (val) {
  400. var i = this._pageIds.indexOf(val);
  401. if (i > 0)
  402. this.selectedIndex = 0;
  403. else if (this._pageIds.length > 1)
  404. this.selectedIndex = 1;
  405. },
  406. enumerable: false,
  407. configurable: true
  408. });
  409. Object.defineProperty(Controller.prototype, "previousPageId", {
  410. get: function () {
  411. if (this._previousIndex == -1)
  412. return null;
  413. else
  414. return this._pageIds[this._previousIndex];
  415. },
  416. enumerable: false,
  417. configurable: true
  418. });
  419. Controller.prototype.runActions = function () {
  420. if (this._actions) {
  421. var cnt = this._actions.length;
  422. for (var i = 0; i < cnt; i++)
  423. this._actions[i].run(this, this.previousPageId, this.selectedPageId);
  424. }
  425. };
  426. Controller.prototype.setup = function (buffer) {
  427. var beginPos = buffer.position;
  428. buffer.seek(beginPos, 0);
  429. this.name = buffer.readS();
  430. if (buffer.readBool())
  431. this.autoRadioGroupDepth = true;
  432. buffer.seek(beginPos, 1);
  433. var i;
  434. var nextPos;
  435. var cnt = buffer.readShort();
  436. for (i = 0; i < cnt; i++) {
  437. this._pageIds.push(buffer.readS());
  438. this._pageNames.push(buffer.readS());
  439. }
  440. var homePageIndex = 0;
  441. if (buffer.version >= 2) {
  442. var homePageType = buffer.readByte();
  443. switch (homePageType) {
  444. case 1:
  445. homePageIndex = buffer.readShort();
  446. break;
  447. case 2:
  448. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.branch);
  449. if (homePageIndex == -1)
  450. homePageIndex = 0;
  451. break;
  452. case 3:
  453. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.getVar(buffer.readS()));
  454. if (homePageIndex == -1)
  455. homePageIndex = 0;
  456. break;
  457. }
  458. }
  459. buffer.seek(beginPos, 2);
  460. cnt = buffer.readShort();
  461. if (cnt > 0) {
  462. if (!this._actions)
  463. this._actions = new Array();
  464. for (i = 0; i < cnt; i++) {
  465. nextPos = buffer.readShort();
  466. nextPos += buffer.position;
  467. var action = fgui.ControllerAction.createAction(buffer.readByte());
  468. action.setup(buffer);
  469. this._actions.push(action);
  470. buffer.position = nextPos;
  471. }
  472. }
  473. if (this.parent && this._pageIds.length > 0)
  474. this._selectedIndex = homePageIndex;
  475. else
  476. this._selectedIndex = -1;
  477. };
  478. return Controller;
  479. }(cc.EventTarget));
  480. fgui.Controller = Controller;
  481. })(fgui || (fgui = {}));
  482. (function (fgui) {
  483. var DragDropManager = (function () {
  484. function DragDropManager() {
  485. this._agent = new fgui.GLoader();
  486. this._agent.draggable = true;
  487. this._agent.touchable = false;
  488. this._agent.setSize(100, 100);
  489. this._agent.setPivot(0.5, 0.5, true);
  490. this._agent.align = fgui.AlignType.Center;
  491. this._agent.verticalAlign = fgui.VertAlignType.Middle;
  492. this._agent.sortingOrder = 1000000;
  493. this._agent.on(fgui.Event.DRAG_END, this.onDragEnd, this);
  494. }
  495. Object.defineProperty(DragDropManager, "inst", {
  496. get: function () {
  497. if (!DragDropManager._inst)
  498. DragDropManager._inst = new DragDropManager();
  499. return DragDropManager._inst;
  500. },
  501. enumerable: false,
  502. configurable: true
  503. });
  504. Object.defineProperty(DragDropManager.prototype, "dragAgent", {
  505. get: function () {
  506. return this._agent;
  507. },
  508. enumerable: false,
  509. configurable: true
  510. });
  511. Object.defineProperty(DragDropManager.prototype, "dragging", {
  512. get: function () {
  513. return this._agent.parent != null;
  514. },
  515. enumerable: false,
  516. configurable: true
  517. });
  518. DragDropManager.prototype.startDrag = function (source, icon, sourceData, touchId) {
  519. if (this._agent.parent)
  520. return;
  521. this._sourceData = sourceData;
  522. this._agent.url = icon;
  523. fgui.GRoot.inst.addChild(this._agent);
  524. var pt = fgui.GRoot.inst.getTouchPosition(touchId);
  525. pt = fgui.GRoot.inst.globalToLocal(pt.x, pt.y);
  526. this._agent.setPosition(pt.x, pt.y);
  527. this._agent.startDrag(touchId);
  528. };
  529. DragDropManager.prototype.cancel = function () {
  530. if (this._agent.parent) {
  531. this._agent.stopDrag();
  532. fgui.GRoot.inst.removeChild(this._agent);
  533. this._sourceData = null;
  534. }
  535. };
  536. DragDropManager.prototype.onDragEnd = function () {
  537. if (!this._agent.parent)
  538. return;
  539. fgui.GRoot.inst.removeChild(this._agent);
  540. var sourceData = this._sourceData;
  541. this._sourceData = null;
  542. var obj = fgui.GRoot.inst.touchTarget;
  543. while (obj) {
  544. if (obj.node.hasEventListener(fgui.Event.DROP)) {
  545. obj.requestFocus();
  546. obj.node.emit(fgui.Event.DROP, obj, sourceData);
  547. return;
  548. }
  549. obj = obj.parent;
  550. }
  551. };
  552. return DragDropManager;
  553. }());
  554. fgui.DragDropManager = DragDropManager;
  555. })(fgui || (fgui = {}));
  556. (function (fgui) {
  557. var ButtonMode;
  558. (function (ButtonMode) {
  559. ButtonMode[ButtonMode["Common"] = 0] = "Common";
  560. ButtonMode[ButtonMode["Check"] = 1] = "Check";
  561. ButtonMode[ButtonMode["Radio"] = 2] = "Radio";
  562. })(ButtonMode = fgui.ButtonMode || (fgui.ButtonMode = {}));
  563. var AutoSizeType;
  564. (function (AutoSizeType) {
  565. AutoSizeType[AutoSizeType["None"] = 0] = "None";
  566. AutoSizeType[AutoSizeType["Both"] = 1] = "Both";
  567. AutoSizeType[AutoSizeType["Height"] = 2] = "Height";
  568. AutoSizeType[AutoSizeType["Shrink"] = 3] = "Shrink";
  569. })(AutoSizeType = fgui.AutoSizeType || (fgui.AutoSizeType = {}));
  570. var AlignType;
  571. (function (AlignType) {
  572. AlignType[AlignType["Left"] = 0] = "Left";
  573. AlignType[AlignType["Center"] = 1] = "Center";
  574. AlignType[AlignType["Right"] = 2] = "Right";
  575. })(AlignType = fgui.AlignType || (fgui.AlignType = {}));
  576. var VertAlignType;
  577. (function (VertAlignType) {
  578. VertAlignType[VertAlignType["Top"] = 0] = "Top";
  579. VertAlignType[VertAlignType["Middle"] = 1] = "Middle";
  580. VertAlignType[VertAlignType["Bottom"] = 2] = "Bottom";
  581. })(VertAlignType = fgui.VertAlignType || (fgui.VertAlignType = {}));
  582. var LoaderFillType;
  583. (function (LoaderFillType) {
  584. LoaderFillType[LoaderFillType["None"] = 0] = "None";
  585. LoaderFillType[LoaderFillType["Scale"] = 1] = "Scale";
  586. LoaderFillType[LoaderFillType["ScaleMatchHeight"] = 2] = "ScaleMatchHeight";
  587. LoaderFillType[LoaderFillType["ScaleMatchWidth"] = 3] = "ScaleMatchWidth";
  588. LoaderFillType[LoaderFillType["ScaleFree"] = 4] = "ScaleFree";
  589. LoaderFillType[LoaderFillType["ScaleNoBorder"] = 5] = "ScaleNoBorder";
  590. })(LoaderFillType = fgui.LoaderFillType || (fgui.LoaderFillType = {}));
  591. var ListLayoutType;
  592. (function (ListLayoutType) {
  593. ListLayoutType[ListLayoutType["SingleColumn"] = 0] = "SingleColumn";
  594. ListLayoutType[ListLayoutType["SingleRow"] = 1] = "SingleRow";
  595. ListLayoutType[ListLayoutType["FlowHorizontal"] = 2] = "FlowHorizontal";
  596. ListLayoutType[ListLayoutType["FlowVertical"] = 3] = "FlowVertical";
  597. ListLayoutType[ListLayoutType["Pagination"] = 4] = "Pagination";
  598. })(ListLayoutType = fgui.ListLayoutType || (fgui.ListLayoutType = {}));
  599. var ListSelectionMode;
  600. (function (ListSelectionMode) {
  601. ListSelectionMode[ListSelectionMode["Single"] = 0] = "Single";
  602. ListSelectionMode[ListSelectionMode["Multiple"] = 1] = "Multiple";
  603. ListSelectionMode[ListSelectionMode["Multiple_SingleClick"] = 2] = "Multiple_SingleClick";
  604. ListSelectionMode[ListSelectionMode["None"] = 3] = "None";
  605. })(ListSelectionMode = fgui.ListSelectionMode || (fgui.ListSelectionMode = {}));
  606. var OverflowType;
  607. (function (OverflowType) {
  608. OverflowType[OverflowType["Visible"] = 0] = "Visible";
  609. OverflowType[OverflowType["Hidden"] = 1] = "Hidden";
  610. OverflowType[OverflowType["Scroll"] = 2] = "Scroll";
  611. })(OverflowType = fgui.OverflowType || (fgui.OverflowType = {}));
  612. var PackageItemType;
  613. (function (PackageItemType) {
  614. PackageItemType[PackageItemType["Image"] = 0] = "Image";
  615. PackageItemType[PackageItemType["MovieClip"] = 1] = "MovieClip";
  616. PackageItemType[PackageItemType["Sound"] = 2] = "Sound";
  617. PackageItemType[PackageItemType["Component"] = 3] = "Component";
  618. PackageItemType[PackageItemType["Atlas"] = 4] = "Atlas";
  619. PackageItemType[PackageItemType["Font"] = 5] = "Font";
  620. PackageItemType[PackageItemType["Swf"] = 6] = "Swf";
  621. PackageItemType[PackageItemType["Misc"] = 7] = "Misc";
  622. PackageItemType[PackageItemType["Unknown"] = 8] = "Unknown";
  623. PackageItemType[PackageItemType["Spine"] = 9] = "Spine";
  624. PackageItemType[PackageItemType["DragonBones"] = 10] = "DragonBones";
  625. })(PackageItemType = fgui.PackageItemType || (fgui.PackageItemType = {}));
  626. var ObjectType;
  627. (function (ObjectType) {
  628. ObjectType[ObjectType["Image"] = 0] = "Image";
  629. ObjectType[ObjectType["MovieClip"] = 1] = "MovieClip";
  630. ObjectType[ObjectType["Swf"] = 2] = "Swf";
  631. ObjectType[ObjectType["Graph"] = 3] = "Graph";
  632. ObjectType[ObjectType["Loader"] = 4] = "Loader";
  633. ObjectType[ObjectType["Group"] = 5] = "Group";
  634. ObjectType[ObjectType["Text"] = 6] = "Text";
  635. ObjectType[ObjectType["RichText"] = 7] = "RichText";
  636. ObjectType[ObjectType["InputText"] = 8] = "InputText";
  637. ObjectType[ObjectType["Component"] = 9] = "Component";
  638. ObjectType[ObjectType["List"] = 10] = "List";
  639. ObjectType[ObjectType["Label"] = 11] = "Label";
  640. ObjectType[ObjectType["Button"] = 12] = "Button";
  641. ObjectType[ObjectType["ComboBox"] = 13] = "ComboBox";
  642. ObjectType[ObjectType["ProgressBar"] = 14] = "ProgressBar";
  643. ObjectType[ObjectType["Slider"] = 15] = "Slider";
  644. ObjectType[ObjectType["ScrollBar"] = 16] = "ScrollBar";
  645. ObjectType[ObjectType["Tree"] = 17] = "Tree";
  646. ObjectType[ObjectType["Loader3D"] = 18] = "Loader3D";
  647. })(ObjectType = fgui.ObjectType || (fgui.ObjectType = {}));
  648. var ProgressTitleType;
  649. (function (ProgressTitleType) {
  650. ProgressTitleType[ProgressTitleType["Percent"] = 0] = "Percent";
  651. ProgressTitleType[ProgressTitleType["ValueAndMax"] = 1] = "ValueAndMax";
  652. ProgressTitleType[ProgressTitleType["Value"] = 2] = "Value";
  653. ProgressTitleType[ProgressTitleType["Max"] = 3] = "Max";
  654. })(ProgressTitleType = fgui.ProgressTitleType || (fgui.ProgressTitleType = {}));
  655. var ScrollBarDisplayType;
  656. (function (ScrollBarDisplayType) {
  657. ScrollBarDisplayType[ScrollBarDisplayType["Default"] = 0] = "Default";
  658. ScrollBarDisplayType[ScrollBarDisplayType["Visible"] = 1] = "Visible";
  659. ScrollBarDisplayType[ScrollBarDisplayType["Auto"] = 2] = "Auto";
  660. ScrollBarDisplayType[ScrollBarDisplayType["Hidden"] = 3] = "Hidden";
  661. })(ScrollBarDisplayType = fgui.ScrollBarDisplayType || (fgui.ScrollBarDisplayType = {}));
  662. var ScrollType;
  663. (function (ScrollType) {
  664. ScrollType[ScrollType["Horizontal"] = 0] = "Horizontal";
  665. ScrollType[ScrollType["Vertical"] = 1] = "Vertical";
  666. ScrollType[ScrollType["Both"] = 2] = "Both";
  667. })(ScrollType = fgui.ScrollType || (fgui.ScrollType = {}));
  668. var FlipType;
  669. (function (FlipType) {
  670. FlipType[FlipType["None"] = 0] = "None";
  671. FlipType[FlipType["Horizontal"] = 1] = "Horizontal";
  672. FlipType[FlipType["Vertical"] = 2] = "Vertical";
  673. FlipType[FlipType["Both"] = 3] = "Both";
  674. })(FlipType = fgui.FlipType || (fgui.FlipType = {}));
  675. var ChildrenRenderOrder;
  676. (function (ChildrenRenderOrder) {
  677. ChildrenRenderOrder[ChildrenRenderOrder["Ascent"] = 0] = "Ascent";
  678. ChildrenRenderOrder[ChildrenRenderOrder["Descent"] = 1] = "Descent";
  679. ChildrenRenderOrder[ChildrenRenderOrder["Arch"] = 2] = "Arch";
  680. })(ChildrenRenderOrder = fgui.ChildrenRenderOrder || (fgui.ChildrenRenderOrder = {}));
  681. var GroupLayoutType;
  682. (function (GroupLayoutType) {
  683. GroupLayoutType[GroupLayoutType["None"] = 0] = "None";
  684. GroupLayoutType[GroupLayoutType["Horizontal"] = 1] = "Horizontal";
  685. GroupLayoutType[GroupLayoutType["Vertical"] = 2] = "Vertical";
  686. })(GroupLayoutType = fgui.GroupLayoutType || (fgui.GroupLayoutType = {}));
  687. var PopupDirection;
  688. (function (PopupDirection) {
  689. PopupDirection[PopupDirection["Auto"] = 0] = "Auto";
  690. PopupDirection[PopupDirection["Up"] = 1] = "Up";
  691. PopupDirection[PopupDirection["Down"] = 2] = "Down";
  692. })(PopupDirection = fgui.PopupDirection || (fgui.PopupDirection = {}));
  693. var RelationType;
  694. (function (RelationType) {
  695. RelationType[RelationType["Left_Left"] = 0] = "Left_Left";
  696. RelationType[RelationType["Left_Center"] = 1] = "Left_Center";
  697. RelationType[RelationType["Left_Right"] = 2] = "Left_Right";
  698. RelationType[RelationType["Center_Center"] = 3] = "Center_Center";
  699. RelationType[RelationType["Right_Left"] = 4] = "Right_Left";
  700. RelationType[RelationType["Right_Center"] = 5] = "Right_Center";
  701. RelationType[RelationType["Right_Right"] = 6] = "Right_Right";
  702. RelationType[RelationType["Top_Top"] = 7] = "Top_Top";
  703. RelationType[RelationType["Top_Middle"] = 8] = "Top_Middle";
  704. RelationType[RelationType["Top_Bottom"] = 9] = "Top_Bottom";
  705. RelationType[RelationType["Middle_Middle"] = 10] = "Middle_Middle";
  706. RelationType[RelationType["Bottom_Top"] = 11] = "Bottom_Top";
  707. RelationType[RelationType["Bottom_Middle"] = 12] = "Bottom_Middle";
  708. RelationType[RelationType["Bottom_Bottom"] = 13] = "Bottom_Bottom";
  709. RelationType[RelationType["Width"] = 14] = "Width";
  710. RelationType[RelationType["Height"] = 15] = "Height";
  711. RelationType[RelationType["LeftExt_Left"] = 16] = "LeftExt_Left";
  712. RelationType[RelationType["LeftExt_Right"] = 17] = "LeftExt_Right";
  713. RelationType[RelationType["RightExt_Left"] = 18] = "RightExt_Left";
  714. RelationType[RelationType["RightExt_Right"] = 19] = "RightExt_Right";
  715. RelationType[RelationType["TopExt_Top"] = 20] = "TopExt_Top";
  716. RelationType[RelationType["TopExt_Bottom"] = 21] = "TopExt_Bottom";
  717. RelationType[RelationType["BottomExt_Top"] = 22] = "BottomExt_Top";
  718. RelationType[RelationType["BottomExt_Bottom"] = 23] = "BottomExt_Bottom";
  719. RelationType[RelationType["Size"] = 24] = "Size";
  720. })(RelationType = fgui.RelationType || (fgui.RelationType = {}));
  721. var FillMethod;
  722. (function (FillMethod) {
  723. FillMethod[FillMethod["None"] = 0] = "None";
  724. FillMethod[FillMethod["Horizontal"] = 1] = "Horizontal";
  725. FillMethod[FillMethod["Vertical"] = 2] = "Vertical";
  726. FillMethod[FillMethod["Radial90"] = 3] = "Radial90";
  727. FillMethod[FillMethod["Radial180"] = 4] = "Radial180";
  728. FillMethod[FillMethod["Radial360"] = 5] = "Radial360";
  729. })(FillMethod = fgui.FillMethod || (fgui.FillMethod = {}));
  730. var FillOrigin;
  731. (function (FillOrigin) {
  732. FillOrigin[FillOrigin["Top"] = 0] = "Top";
  733. FillOrigin[FillOrigin["Bottom"] = 1] = "Bottom";
  734. FillOrigin[FillOrigin["Left"] = 2] = "Left";
  735. FillOrigin[FillOrigin["Right"] = 3] = "Right";
  736. })(FillOrigin = fgui.FillOrigin || (fgui.FillOrigin = {}));
  737. var ObjectPropID;
  738. (function (ObjectPropID) {
  739. ObjectPropID[ObjectPropID["Text"] = 0] = "Text";
  740. ObjectPropID[ObjectPropID["Icon"] = 1] = "Icon";
  741. ObjectPropID[ObjectPropID["Color"] = 2] = "Color";
  742. ObjectPropID[ObjectPropID["OutlineColor"] = 3] = "OutlineColor";
  743. ObjectPropID[ObjectPropID["Playing"] = 4] = "Playing";
  744. ObjectPropID[ObjectPropID["Frame"] = 5] = "Frame";
  745. ObjectPropID[ObjectPropID["DeltaTime"] = 6] = "DeltaTime";
  746. ObjectPropID[ObjectPropID["TimeScale"] = 7] = "TimeScale";
  747. ObjectPropID[ObjectPropID["FontSize"] = 8] = "FontSize";
  748. ObjectPropID[ObjectPropID["Selected"] = 9] = "Selected";
  749. })(ObjectPropID = fgui.ObjectPropID || (fgui.ObjectPropID = {}));
  750. })(fgui || (fgui = {}));
  751. (function (fgui) {
  752. var GObject = (function () {
  753. function GObject() {
  754. this._x = 0;
  755. this._y = 0;
  756. this._alpha = 1;
  757. this._visible = true;
  758. this._touchable = true;
  759. this._skewX = 0;
  760. this._skewY = 0;
  761. this._sortingOrder = 0;
  762. this._internalVisible = true;
  763. this.sourceWidth = 0;
  764. this.sourceHeight = 0;
  765. this.initWidth = 0;
  766. this.initHeight = 0;
  767. this.minWidth = 0;
  768. this.minHeight = 0;
  769. this.maxWidth = 0;
  770. this.maxHeight = 0;
  771. this._width = 0;
  772. this._height = 0;
  773. this._rawWidth = 0;
  774. this._rawHeight = 0;
  775. this._sizePercentInGroup = 0;
  776. this._node = new cc.Node();
  777. if (GObject._defaultGroupIndex == -1) {
  778. GObject._defaultGroupIndex = 0;
  779. var groups = cc.game.groupList;
  780. var cnt = groups.length;
  781. for (var i = 0; i < cnt; i++) {
  782. if (groups[i].toLowerCase() == fgui.UIConfig.defaultUIGroup.toLowerCase()) {
  783. GObject._defaultGroupIndex = i;
  784. break;
  785. }
  786. }
  787. }
  788. this._node["$gobj"] = this;
  789. this._node.groupIndex = GObject._defaultGroupIndex;
  790. this._node.setAnchorPoint(0, 1);
  791. this._node.on(cc.Node.EventType.ANCHOR_CHANGED, this.handleAnchorChanged, this);
  792. this._id = this._node.uuid;
  793. this._name = "";
  794. this._relations = new fgui.Relations(this);
  795. this._gears = new Array(10);
  796. this._blendMode = fgui.BlendMode.Normal;
  797. this._partner = this._node.addComponent(GObjectPartner);
  798. }
  799. Object.defineProperty(GObject.prototype, "id", {
  800. get: function () {
  801. return this._id;
  802. },
  803. enumerable: false,
  804. configurable: true
  805. });
  806. Object.defineProperty(GObject.prototype, "name", {
  807. get: function () {
  808. return this._name;
  809. },
  810. set: function (value) {
  811. this._name = value;
  812. },
  813. enumerable: false,
  814. configurable: true
  815. });
  816. Object.defineProperty(GObject.prototype, "x", {
  817. get: function () {
  818. return this._x;
  819. },
  820. set: function (value) {
  821. this.setPosition(value, this._y);
  822. },
  823. enumerable: false,
  824. configurable: true
  825. });
  826. Object.defineProperty(GObject.prototype, "y", {
  827. get: function () {
  828. return this._y;
  829. },
  830. set: function (value) {
  831. this.setPosition(this._x, value);
  832. },
  833. enumerable: false,
  834. configurable: true
  835. });
  836. GObject.prototype.setPosition = function (xv, yv) {
  837. if (this._x != xv || this._y != yv) {
  838. var dx = xv - this._x;
  839. var dy = yv - this._y;
  840. this._x = xv;
  841. this._y = yv;
  842. this.handlePositionChanged();
  843. if (this instanceof fgui.GGroup)
  844. this.moveChildren(dx, dy);
  845. this.updateGear(1);
  846. if (this._parent && !(this._parent instanceof fgui.GList)) {
  847. this._parent.setBoundsChangedFlag();
  848. if (this._group)
  849. this._group.setBoundsChangedFlag(true);
  850. this._node.emit(fgui.Event.XY_CHANGED, this);
  851. }
  852. if (GObject.draggingObject == this && !sUpdateInDragging)
  853. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  854. }
  855. };
  856. Object.defineProperty(GObject.prototype, "xMin", {
  857. get: function () {
  858. return this._pivotAsAnchor ? (this._x - this._width * this.node.anchorX) : this._x;
  859. },
  860. set: function (value) {
  861. if (this._pivotAsAnchor)
  862. this.setPosition(value + this._width * this.node.anchorX, this._y);
  863. else
  864. this.setPosition(value, this._y);
  865. },
  866. enumerable: false,
  867. configurable: true
  868. });
  869. Object.defineProperty(GObject.prototype, "yMin", {
  870. get: function () {
  871. return this._pivotAsAnchor ? (this._y - this._height * (1 - this.node.anchorY)) : this._y;
  872. },
  873. set: function (value) {
  874. if (this._pivotAsAnchor)
  875. this.setPosition(this._x, value + this._height * (1 - this.node.anchorY));
  876. else
  877. this.setPosition(this._x, value);
  878. },
  879. enumerable: false,
  880. configurable: true
  881. });
  882. Object.defineProperty(GObject.prototype, "pixelSnapping", {
  883. get: function () {
  884. return this._pixelSnapping;
  885. },
  886. set: function (value) {
  887. if (this._pixelSnapping != value) {
  888. this._pixelSnapping = value;
  889. this.handlePositionChanged();
  890. }
  891. },
  892. enumerable: false,
  893. configurable: true
  894. });
  895. GObject.prototype.center = function (restraint) {
  896. var r;
  897. if (this._parent)
  898. r = this.parent;
  899. else
  900. r = this.root;
  901. this.setPosition((r.width - this._width) / 2, (r.height - this._height) / 2);
  902. if (restraint) {
  903. this.addRelation(r, fgui.RelationType.Center_Center);
  904. this.addRelation(r, fgui.RelationType.Middle_Middle);
  905. }
  906. };
  907. Object.defineProperty(GObject.prototype, "width", {
  908. get: function () {
  909. this.ensureSizeCorrect();
  910. if (this._relations.sizeDirty)
  911. this._relations.ensureRelationsSizeCorrect();
  912. return this._width;
  913. },
  914. set: function (value) {
  915. this.setSize(value, this._rawHeight);
  916. },
  917. enumerable: false,
  918. configurable: true
  919. });
  920. Object.defineProperty(GObject.prototype, "height", {
  921. get: function () {
  922. this.ensureSizeCorrect();
  923. if (this._relations.sizeDirty)
  924. this._relations.ensureRelationsSizeCorrect();
  925. return this._height;
  926. },
  927. set: function (value) {
  928. this.setSize(this._rawWidth, value);
  929. },
  930. enumerable: false,
  931. configurable: true
  932. });
  933. GObject.prototype.setSize = function (wv, hv, ignorePivot) {
  934. if (this._rawWidth != wv || this._rawHeight != hv) {
  935. this._rawWidth = wv;
  936. this._rawHeight = hv;
  937. if (wv < this.minWidth)
  938. wv = this.minWidth;
  939. if (hv < this.minHeight)
  940. hv = this.minHeight;
  941. if (this.maxWidth > 0 && wv > this.maxWidth)
  942. wv = this.maxWidth;
  943. if (this.maxHeight > 0 && hv > this.maxHeight)
  944. hv = this.maxHeight;
  945. var dWidth = wv - this._width;
  946. var dHeight = hv - this._height;
  947. this._width = wv;
  948. this._height = hv;
  949. this.handleSizeChanged();
  950. if ((this.node.anchorX != 0 || this.node.anchorY != 1) && !this._pivotAsAnchor && !ignorePivot)
  951. this.setPosition(this.x - this.node.anchorX * dWidth, this.y - (1 - this.node.anchorY) * dHeight);
  952. else
  953. this.handlePositionChanged();
  954. if (this instanceof fgui.GGroup)
  955. this.resizeChildren(dWidth, dHeight);
  956. this.updateGear(2);
  957. if (this._parent) {
  958. this._relations.onOwnerSizeChanged(dWidth, dHeight, this._pivotAsAnchor || !ignorePivot);
  959. this._parent.setBoundsChangedFlag();
  960. if (this._group)
  961. this._group.setBoundsChangedFlag();
  962. }
  963. this._node.emit(fgui.Event.SIZE_CHANGED, this);
  964. }
  965. };
  966. GObject.prototype.makeFullScreen = function () {
  967. this.setSize(fgui.GRoot.inst.width, fgui.GRoot.inst.height);
  968. };
  969. GObject.prototype.ensureSizeCorrect = function () {
  970. };
  971. Object.defineProperty(GObject.prototype, "actualWidth", {
  972. get: function () {
  973. return this.width * Math.abs(this._node.scaleX);
  974. },
  975. enumerable: false,
  976. configurable: true
  977. });
  978. Object.defineProperty(GObject.prototype, "actualHeight", {
  979. get: function () {
  980. return this.height * Math.abs(this._node.scaleY);
  981. },
  982. enumerable: false,
  983. configurable: true
  984. });
  985. Object.defineProperty(GObject.prototype, "scaleX", {
  986. get: function () {
  987. return this._node.scaleX;
  988. },
  989. set: function (value) {
  990. this.setScale(value, this._node.scaleY);
  991. },
  992. enumerable: false,
  993. configurable: true
  994. });
  995. Object.defineProperty(GObject.prototype, "scaleY", {
  996. get: function () {
  997. return this._node.scaleY;
  998. },
  999. set: function (value) {
  1000. this.setScale(this._node.scaleX, value);
  1001. },
  1002. enumerable: false,
  1003. configurable: true
  1004. });
  1005. GObject.prototype.setScale = function (sx, sy) {
  1006. if (this._node.scaleX != sx || this._node.scaleY != sy) {
  1007. this._node.setScale(sx, sy);
  1008. this.updateGear(2);
  1009. }
  1010. };
  1011. Object.defineProperty(GObject.prototype, "skewX", {
  1012. get: function () {
  1013. return this._skewX;
  1014. },
  1015. set: function (value) {
  1016. this.setSkew(value, this._skewY);
  1017. },
  1018. enumerable: false,
  1019. configurable: true
  1020. });
  1021. Object.defineProperty(GObject.prototype, "skewY", {
  1022. get: function () {
  1023. return this._skewY;
  1024. },
  1025. set: function (value) {
  1026. this.setSkew(this._skewX, value);
  1027. },
  1028. enumerable: false,
  1029. configurable: true
  1030. });
  1031. GObject.prototype.setSkew = function (xv, yv) {
  1032. if (this._skewX != xv || this._skewY != yv) {
  1033. this._skewX = xv;
  1034. this._skewY = yv;
  1035. this._node.skewX = xv;
  1036. this._node.skewY = yv;
  1037. }
  1038. };
  1039. Object.defineProperty(GObject.prototype, "pivotX", {
  1040. get: function () {
  1041. return this.node.anchorX;
  1042. },
  1043. set: function (value) {
  1044. this.node.anchorX = value;
  1045. },
  1046. enumerable: false,
  1047. configurable: true
  1048. });
  1049. Object.defineProperty(GObject.prototype, "pivotY", {
  1050. get: function () {
  1051. return 1 - this.node.anchorY;
  1052. },
  1053. set: function (value) {
  1054. this.node.anchorY = 1 - value;
  1055. },
  1056. enumerable: false,
  1057. configurable: true
  1058. });
  1059. GObject.prototype.setPivot = function (xv, yv, asAnchor) {
  1060. if (this.node.anchorX != xv || this.node.anchorY != 1 - yv) {
  1061. this._pivotAsAnchor = asAnchor;
  1062. this.node.setAnchorPoint(xv, 1 - yv);
  1063. }
  1064. else if (this._pivotAsAnchor != asAnchor) {
  1065. this._pivotAsAnchor = asAnchor;
  1066. this.handlePositionChanged();
  1067. }
  1068. };
  1069. Object.defineProperty(GObject.prototype, "pivotAsAnchor", {
  1070. get: function () {
  1071. return this._pivotAsAnchor;
  1072. },
  1073. enumerable: false,
  1074. configurable: true
  1075. });
  1076. Object.defineProperty(GObject.prototype, "touchable", {
  1077. get: function () {
  1078. return this._touchable;
  1079. },
  1080. set: function (value) {
  1081. if (this._touchable != value) {
  1082. this._touchable = value;
  1083. this.updateGear(3);
  1084. }
  1085. },
  1086. enumerable: false,
  1087. configurable: true
  1088. });
  1089. Object.defineProperty(GObject.prototype, "grayed", {
  1090. get: function () {
  1091. return this._grayed;
  1092. },
  1093. set: function (value) {
  1094. if (this._grayed != value) {
  1095. this._grayed = value;
  1096. this.handleGrayedChanged();
  1097. this.updateGear(3);
  1098. }
  1099. },
  1100. enumerable: false,
  1101. configurable: true
  1102. });
  1103. Object.defineProperty(GObject.prototype, "enabled", {
  1104. get: function () {
  1105. return !this._grayed && this._touchable;
  1106. },
  1107. set: function (value) {
  1108. this.grayed = !value;
  1109. this.touchable = value;
  1110. },
  1111. enumerable: false,
  1112. configurable: true
  1113. });
  1114. Object.defineProperty(GObject.prototype, "rotation", {
  1115. get: function () {
  1116. return -this._node.angle;
  1117. },
  1118. set: function (value) {
  1119. value = -value;
  1120. if (this._node.angle != value) {
  1121. this._node.angle = value;
  1122. this.updateGear(3);
  1123. }
  1124. },
  1125. enumerable: false,
  1126. configurable: true
  1127. });
  1128. Object.defineProperty(GObject.prototype, "alpha", {
  1129. get: function () {
  1130. return this._alpha;
  1131. },
  1132. set: function (value) {
  1133. if (this._alpha != value) {
  1134. this._alpha = value;
  1135. this._node.opacity = this._alpha * 255;
  1136. if (this instanceof fgui.GGroup)
  1137. this.handleAlphaChanged();
  1138. this.updateGear(3);
  1139. }
  1140. },
  1141. enumerable: false,
  1142. configurable: true
  1143. });
  1144. Object.defineProperty(GObject.prototype, "visible", {
  1145. get: function () {
  1146. return this._visible;
  1147. },
  1148. set: function (value) {
  1149. if (this._visible != value) {
  1150. this._visible = value;
  1151. this.handleVisibleChanged();
  1152. if (this._group && this._group.excludeInvisibles)
  1153. this._group.setBoundsChangedFlag();
  1154. }
  1155. },
  1156. enumerable: false,
  1157. configurable: true
  1158. });
  1159. Object.defineProperty(GObject.prototype, "_finalVisible", {
  1160. get: function () {
  1161. return this._visible && this._internalVisible && (!this._group || this._group._finalVisible);
  1162. },
  1163. enumerable: false,
  1164. configurable: true
  1165. });
  1166. Object.defineProperty(GObject.prototype, "internalVisible3", {
  1167. get: function () {
  1168. return this._visible && this._internalVisible;
  1169. },
  1170. enumerable: false,
  1171. configurable: true
  1172. });
  1173. Object.defineProperty(GObject.prototype, "sortingOrder", {
  1174. get: function () {
  1175. return this._sortingOrder;
  1176. },
  1177. set: function (value) {
  1178. if (value < 0)
  1179. value = 0;
  1180. if (this._sortingOrder != value) {
  1181. var old = this._sortingOrder;
  1182. this._sortingOrder = value;
  1183. if (this._parent)
  1184. this._parent.childSortingOrderChanged(this, old, this._sortingOrder);
  1185. }
  1186. },
  1187. enumerable: false,
  1188. configurable: true
  1189. });
  1190. GObject.prototype.requestFocus = function () {
  1191. };
  1192. Object.defineProperty(GObject.prototype, "tooltips", {
  1193. get: function () {
  1194. return this._tooltips;
  1195. },
  1196. set: function (value) {
  1197. if (this._tooltips) {
  1198. this._node.off(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1199. this._node.off(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1200. }
  1201. this._tooltips = value;
  1202. if (this._tooltips) {
  1203. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1204. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1205. }
  1206. },
  1207. enumerable: false,
  1208. configurable: true
  1209. });
  1210. Object.defineProperty(GObject.prototype, "blendMode", {
  1211. get: function () {
  1212. return this._blendMode;
  1213. },
  1214. set: function (value) {
  1215. if (this._blendMode != value) {
  1216. this._blendMode = value;
  1217. fgui.BlendModeUtils.apply(this._node, value);
  1218. }
  1219. },
  1220. enumerable: false,
  1221. configurable: true
  1222. });
  1223. Object.defineProperty(GObject.prototype, "onStage", {
  1224. get: function () {
  1225. return this._node && this._node.activeInHierarchy;
  1226. },
  1227. enumerable: false,
  1228. configurable: true
  1229. });
  1230. Object.defineProperty(GObject.prototype, "resourceURL", {
  1231. get: function () {
  1232. if (this.packageItem)
  1233. return "ui://" + this.packageItem.owner.id + this.packageItem.id;
  1234. else
  1235. return null;
  1236. },
  1237. enumerable: false,
  1238. configurable: true
  1239. });
  1240. Object.defineProperty(GObject.prototype, "group", {
  1241. get: function () {
  1242. return this._group;
  1243. },
  1244. set: function (value) {
  1245. if (this._group != value) {
  1246. if (this._group)
  1247. this._group.setBoundsChangedFlag();
  1248. this._group = value;
  1249. if (this._group)
  1250. this._group.setBoundsChangedFlag();
  1251. }
  1252. },
  1253. enumerable: false,
  1254. configurable: true
  1255. });
  1256. GObject.prototype.getGear = function (index) {
  1257. var gear = this._gears[index];
  1258. if (!gear)
  1259. this._gears[index] = gear = fgui.GearBase.create(this, index);
  1260. return gear;
  1261. };
  1262. GObject.prototype.updateGear = function (index) {
  1263. if (this._underConstruct || this._gearLocked)
  1264. return;
  1265. var gear = this._gears[index];
  1266. if (gear && gear.controller)
  1267. gear.updateState();
  1268. };
  1269. GObject.prototype.checkGearController = function (index, c) {
  1270. return this._gears[index] && this._gears[index].controller == c;
  1271. };
  1272. GObject.prototype.updateGearFromRelations = function (index, dx, dy) {
  1273. if (this._gears[index])
  1274. this._gears[index].updateFromRelations(dx, dy);
  1275. };
  1276. GObject.prototype.addDisplayLock = function () {
  1277. var gearDisplay = this._gears[0];
  1278. if (gearDisplay && gearDisplay.controller) {
  1279. var ret = gearDisplay.addLock();
  1280. this.checkGearDisplay();
  1281. return ret;
  1282. }
  1283. else
  1284. return 0;
  1285. };
  1286. GObject.prototype.releaseDisplayLock = function (token) {
  1287. var gearDisplay = this._gears[0];
  1288. if (gearDisplay && gearDisplay.controller) {
  1289. gearDisplay.releaseLock(token);
  1290. this.checkGearDisplay();
  1291. }
  1292. };
  1293. GObject.prototype.checkGearDisplay = function () {
  1294. if (this._handlingController)
  1295. return;
  1296. var connected = this._gears[0] == null || this._gears[0].connected;
  1297. if (this._gears[8])
  1298. connected = this._gears[8].evaluate(connected);
  1299. if (connected != this._internalVisible) {
  1300. this._internalVisible = connected;
  1301. this.handleVisibleChanged();
  1302. if (this._group && this._group.excludeInvisibles)
  1303. this._group.setBoundsChangedFlag();
  1304. }
  1305. };
  1306. Object.defineProperty(GObject.prototype, "gearXY", {
  1307. get: function () {
  1308. return this.getGear(1);
  1309. },
  1310. enumerable: false,
  1311. configurable: true
  1312. });
  1313. Object.defineProperty(GObject.prototype, "gearSize", {
  1314. get: function () {
  1315. return this.getGear(2);
  1316. },
  1317. enumerable: false,
  1318. configurable: true
  1319. });
  1320. Object.defineProperty(GObject.prototype, "gearLook", {
  1321. get: function () {
  1322. return this.getGear(3);
  1323. },
  1324. enumerable: false,
  1325. configurable: true
  1326. });
  1327. Object.defineProperty(GObject.prototype, "relations", {
  1328. get: function () {
  1329. return this._relations;
  1330. },
  1331. enumerable: false,
  1332. configurable: true
  1333. });
  1334. GObject.prototype.addRelation = function (target, relationType, usePercent) {
  1335. this._relations.add(target, relationType, usePercent);
  1336. };
  1337. GObject.prototype.removeRelation = function (target, relationType) {
  1338. this._relations.remove(target, relationType);
  1339. };
  1340. Object.defineProperty(GObject.prototype, "node", {
  1341. get: function () {
  1342. return this._node;
  1343. },
  1344. enumerable: false,
  1345. configurable: true
  1346. });
  1347. Object.defineProperty(GObject.prototype, "parent", {
  1348. get: function () {
  1349. return this._parent;
  1350. },
  1351. enumerable: false,
  1352. configurable: true
  1353. });
  1354. GObject.prototype.removeFromParent = function () {
  1355. if (this._parent)
  1356. this._parent.removeChild(this);
  1357. };
  1358. GObject.prototype.findParent = function () {
  1359. if (this._parent)
  1360. return this._parent;
  1361. var pn = this._node.parent;
  1362. while (pn) {
  1363. var gobj = pn["$gobj"];
  1364. if (gobj)
  1365. return gobj;
  1366. pn = pn.parent;
  1367. }
  1368. return null;
  1369. };
  1370. Object.defineProperty(GObject.prototype, "root", {
  1371. get: function () {
  1372. if (this instanceof fgui.GRoot)
  1373. return this;
  1374. var p = this._parent;
  1375. while (p) {
  1376. if (p instanceof fgui.GRoot)
  1377. return p;
  1378. p = p.parent;
  1379. }
  1380. return fgui.GRoot.inst;
  1381. },
  1382. enumerable: false,
  1383. configurable: true
  1384. });
  1385. Object.defineProperty(GObject.prototype, "asCom", {
  1386. get: function () {
  1387. return this;
  1388. },
  1389. enumerable: false,
  1390. configurable: true
  1391. });
  1392. Object.defineProperty(GObject.prototype, "asButton", {
  1393. get: function () {
  1394. return this;
  1395. },
  1396. enumerable: false,
  1397. configurable: true
  1398. });
  1399. Object.defineProperty(GObject.prototype, "asLabel", {
  1400. get: function () {
  1401. return this;
  1402. },
  1403. enumerable: false,
  1404. configurable: true
  1405. });
  1406. Object.defineProperty(GObject.prototype, "asProgress", {
  1407. get: function () {
  1408. return this;
  1409. },
  1410. enumerable: false,
  1411. configurable: true
  1412. });
  1413. Object.defineProperty(GObject.prototype, "asTextField", {
  1414. get: function () {
  1415. return this;
  1416. },
  1417. enumerable: false,
  1418. configurable: true
  1419. });
  1420. Object.defineProperty(GObject.prototype, "asRichTextField", {
  1421. get: function () {
  1422. return this;
  1423. },
  1424. enumerable: false,
  1425. configurable: true
  1426. });
  1427. Object.defineProperty(GObject.prototype, "asTextInput", {
  1428. get: function () {
  1429. return this;
  1430. },
  1431. enumerable: false,
  1432. configurable: true
  1433. });
  1434. Object.defineProperty(GObject.prototype, "asLoader", {
  1435. get: function () {
  1436. return this;
  1437. },
  1438. enumerable: false,
  1439. configurable: true
  1440. });
  1441. Object.defineProperty(GObject.prototype, "asList", {
  1442. get: function () {
  1443. return this;
  1444. },
  1445. enumerable: false,
  1446. configurable: true
  1447. });
  1448. Object.defineProperty(GObject.prototype, "asTree", {
  1449. get: function () {
  1450. return this;
  1451. },
  1452. enumerable: false,
  1453. configurable: true
  1454. });
  1455. Object.defineProperty(GObject.prototype, "asGraph", {
  1456. get: function () {
  1457. return this;
  1458. },
  1459. enumerable: false,
  1460. configurable: true
  1461. });
  1462. Object.defineProperty(GObject.prototype, "asGroup", {
  1463. get: function () {
  1464. return this;
  1465. },
  1466. enumerable: false,
  1467. configurable: true
  1468. });
  1469. Object.defineProperty(GObject.prototype, "asSlider", {
  1470. get: function () {
  1471. return this;
  1472. },
  1473. enumerable: false,
  1474. configurable: true
  1475. });
  1476. Object.defineProperty(GObject.prototype, "asComboBox", {
  1477. get: function () {
  1478. return this;
  1479. },
  1480. enumerable: false,
  1481. configurable: true
  1482. });
  1483. Object.defineProperty(GObject.prototype, "asImage", {
  1484. get: function () {
  1485. return this;
  1486. },
  1487. enumerable: false,
  1488. configurable: true
  1489. });
  1490. Object.defineProperty(GObject.prototype, "asMovieClip", {
  1491. get: function () {
  1492. return this;
  1493. },
  1494. enumerable: false,
  1495. configurable: true
  1496. });
  1497. GObject.cast = function (obj) {
  1498. return obj["$gobj"];
  1499. };
  1500. Object.defineProperty(GObject.prototype, "text", {
  1501. get: function () {
  1502. return null;
  1503. },
  1504. set: function (value) {
  1505. },
  1506. enumerable: false,
  1507. configurable: true
  1508. });
  1509. Object.defineProperty(GObject.prototype, "icon", {
  1510. get: function () {
  1511. return null;
  1512. },
  1513. set: function (value) {
  1514. },
  1515. enumerable: false,
  1516. configurable: true
  1517. });
  1518. Object.defineProperty(GObject.prototype, "treeNode", {
  1519. get: function () {
  1520. return this._treeNode;
  1521. },
  1522. enumerable: false,
  1523. configurable: true
  1524. });
  1525. GObject.prototype.dispose = function () {
  1526. var n = this._node;
  1527. if (!n)
  1528. return;
  1529. this.removeFromParent();
  1530. this._relations.dispose();
  1531. this._node = null;
  1532. n.destroy();
  1533. for (var i = 0; i < 10; i++) {
  1534. var gear = this._gears[i];
  1535. if (gear)
  1536. gear.dispose();
  1537. }
  1538. };
  1539. GObject.prototype.onEnable = function () {
  1540. };
  1541. GObject.prototype.onDisable = function () {
  1542. };
  1543. GObject.prototype.onUpdate = function () {
  1544. };
  1545. GObject.prototype.onDestroy = function () {
  1546. };
  1547. GObject.prototype.onClick = function (listener, target) {
  1548. this._node.on(fgui.Event.CLICK, listener, target);
  1549. };
  1550. GObject.prototype.onceClick = function (listener, target) {
  1551. this._node.once(fgui.Event.CLICK, listener, target);
  1552. };
  1553. GObject.prototype.offClick = function (listener, target) {
  1554. this._node.off(fgui.Event.CLICK, listener, target);
  1555. };
  1556. GObject.prototype.clearClick = function () {
  1557. this._node.off(fgui.Event.CLICK);
  1558. };
  1559. GObject.prototype.hasClickListener = function () {
  1560. return this._node.hasEventListener(fgui.Event.CLICK);
  1561. };
  1562. GObject.prototype.on = function (type, listener, target) {
  1563. if (type == fgui.Event.DISPLAY || type == fgui.Event.UNDISPLAY)
  1564. this._partner._emitDisplayEvents = true;
  1565. this._node.on(type, listener, target);
  1566. };
  1567. GObject.prototype.once = function (type, listener, target) {
  1568. if (type == fgui.Event.DISPLAY || type == fgui.Event.UNDISPLAY)
  1569. this._partner._emitDisplayEvents = true;
  1570. this._node.once(type, listener, target);
  1571. };
  1572. GObject.prototype.off = function (type, listener, target) {
  1573. this._node.off(type, listener, target);
  1574. };
  1575. Object.defineProperty(GObject.prototype, "draggable", {
  1576. get: function () {
  1577. return this._draggable;
  1578. },
  1579. set: function (value) {
  1580. if (this._draggable != value) {
  1581. this._draggable = value;
  1582. this.initDrag();
  1583. }
  1584. },
  1585. enumerable: false,
  1586. configurable: true
  1587. });
  1588. Object.defineProperty(GObject.prototype, "dragBounds", {
  1589. get: function () {
  1590. return this._dragBounds;
  1591. },
  1592. set: function (value) {
  1593. this._dragBounds = value;
  1594. },
  1595. enumerable: false,
  1596. configurable: true
  1597. });
  1598. GObject.prototype.startDrag = function (touchId) {
  1599. if (!this._node.activeInHierarchy)
  1600. return;
  1601. this.dragBegin(touchId);
  1602. };
  1603. GObject.prototype.stopDrag = function () {
  1604. this.dragEnd();
  1605. };
  1606. Object.defineProperty(GObject.prototype, "dragging", {
  1607. get: function () {
  1608. return GObject.draggingObject == this;
  1609. },
  1610. enumerable: false,
  1611. configurable: true
  1612. });
  1613. GObject.prototype.localToGlobal = function (ax, ay, result) {
  1614. ax = ax || 0;
  1615. ay = ay || 0;
  1616. result = result || new cc.Vec2();
  1617. result.x = ax;
  1618. result.y = ay;
  1619. result.y = -result.y;
  1620. if (!this._pivotAsAnchor) {
  1621. result.x -= this.node.anchorX * this._width;
  1622. result.y += (1 - this.node.anchorY) * this._height;
  1623. }
  1624. this._node.convertToWorldSpaceAR(result, result);
  1625. result.y = fgui.GRoot.inst.height - result.y;
  1626. return result;
  1627. };
  1628. GObject.prototype.globalToLocal = function (ax, ay, result) {
  1629. ax = ax || 0;
  1630. ay = ay || 0;
  1631. result = result || new cc.Vec2();
  1632. result.x = ax;
  1633. result.y = fgui.GRoot.inst.height - ay;
  1634. this._node.convertToNodeSpaceAR(result, result);
  1635. if (!this._pivotAsAnchor) {
  1636. result.x += this._node.anchorX * this._width;
  1637. result.y -= (1 - this._node.anchorY) * this._height;
  1638. }
  1639. result.y = -result.y;
  1640. return result;
  1641. };
  1642. GObject.prototype.localToGlobalRect = function (ax, ay, aw, ah, result) {
  1643. ax = ax || 0;
  1644. ay = ay || 0;
  1645. aw = aw || 0;
  1646. ah = ah || 0;
  1647. result = result || new cc.Rect();
  1648. var pt = this.localToGlobal(ax, ay);
  1649. result.x = pt.x;
  1650. result.y = pt.y;
  1651. pt = this.localToGlobal(ax + aw, ay + ah, pt);
  1652. result.xMax = pt.x;
  1653. result.yMax = pt.y;
  1654. return result;
  1655. };
  1656. GObject.prototype.globalToLocalRect = function (ax, ay, aw, ah, result) {
  1657. ax = ax || 0;
  1658. ay = ay || 0;
  1659. aw = aw || 0;
  1660. ah = ah || 0;
  1661. result = result || new cc.Rect();
  1662. var pt = this.globalToLocal(ax, ay);
  1663. result.x = pt.x;
  1664. result.y = pt.y;
  1665. pt = this.globalToLocal(ax + aw, ay + ah, pt);
  1666. result.xMax = pt.x;
  1667. result.yMax = pt.y;
  1668. return result;
  1669. };
  1670. GObject.prototype.handleControllerChanged = function (c) {
  1671. this._handlingController = true;
  1672. for (var i = 0; i < 10; i++) {
  1673. var gear = this._gears[i];
  1674. if (gear && gear.controller == c)
  1675. gear.apply();
  1676. }
  1677. this._handlingController = false;
  1678. this.checkGearDisplay();
  1679. };
  1680. GObject.prototype.handleAnchorChanged = function () {
  1681. this.handlePositionChanged();
  1682. };
  1683. GObject.prototype.handlePositionChanged = function () {
  1684. var xv = this._x;
  1685. var yv = -this._y;
  1686. if (!this._pivotAsAnchor) {
  1687. xv += this.node.anchorX * this._width;
  1688. yv -= (1 - this.node.anchorY) * this._height;
  1689. }
  1690. if (this._pixelSnapping) {
  1691. xv = Math.round(xv);
  1692. yv = Math.round(yv);
  1693. }
  1694. this._node.setPosition(xv, yv);
  1695. };
  1696. GObject.prototype.handleSizeChanged = function () {
  1697. this._node.setContentSize(this._width, this._height);
  1698. };
  1699. GObject.prototype.handleGrayedChanged = function () {
  1700. };
  1701. GObject.prototype.handleVisibleChanged = function () {
  1702. this._node.active = this._finalVisible;
  1703. if (this instanceof fgui.GGroup)
  1704. this.handleVisibleChanged();
  1705. if (this._parent)
  1706. this._parent.setBoundsChangedFlag();
  1707. };
  1708. GObject.prototype.hitTest = function (globalPt, forTouch) {
  1709. if (forTouch == null)
  1710. forTouch = true;
  1711. if (forTouch && (this._touchDisabled || !this._touchable || !this._node.activeInHierarchy))
  1712. return null;
  1713. if (!this._hitTestPt)
  1714. this._hitTestPt = new cc.Vec2();
  1715. this.globalToLocal(globalPt.x, globalPt.y, this._hitTestPt);
  1716. if (this._pivotAsAnchor) {
  1717. this._hitTestPt.x += this.node.anchorX * this._width;
  1718. this._hitTestPt.y += (1 - this.node.anchorY) * this._height;
  1719. }
  1720. return this._hitTest(this._hitTestPt, globalPt);
  1721. };
  1722. GObject.prototype._hitTest = function (pt, globalPt) {
  1723. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  1724. return this;
  1725. else
  1726. return null;
  1727. };
  1728. GObject.prototype.getProp = function (index) {
  1729. switch (index) {
  1730. case fgui.ObjectPropID.Text:
  1731. return this.text;
  1732. case fgui.ObjectPropID.Icon:
  1733. return this.icon;
  1734. case fgui.ObjectPropID.Color:
  1735. return null;
  1736. case fgui.ObjectPropID.OutlineColor:
  1737. return null;
  1738. case fgui.ObjectPropID.Playing:
  1739. return false;
  1740. case fgui.ObjectPropID.Frame:
  1741. return 0;
  1742. case fgui.ObjectPropID.DeltaTime:
  1743. return 0;
  1744. case fgui.ObjectPropID.TimeScale:
  1745. return 1;
  1746. case fgui.ObjectPropID.FontSize:
  1747. return 0;
  1748. case fgui.ObjectPropID.Selected:
  1749. return false;
  1750. default:
  1751. return undefined;
  1752. }
  1753. };
  1754. GObject.prototype.setProp = function (index, value) {
  1755. switch (index) {
  1756. case fgui.ObjectPropID.Text:
  1757. this.text = value;
  1758. break;
  1759. case fgui.ObjectPropID.Icon:
  1760. this.icon = value;
  1761. break;
  1762. }
  1763. };
  1764. GObject.prototype.constructFromResource = function () {
  1765. };
  1766. GObject.prototype.setup_beforeAdd = function (buffer, beginPos) {
  1767. buffer.seek(beginPos, 0);
  1768. buffer.skip(5);
  1769. var f1;
  1770. var f2;
  1771. this._id = buffer.readS();
  1772. this._name = buffer.readS();
  1773. f1 = buffer.readInt();
  1774. f2 = buffer.readInt();
  1775. this.setPosition(f1, f2);
  1776. if (buffer.readBool()) {
  1777. this.initWidth = buffer.readInt();
  1778. this.initHeight = buffer.readInt();
  1779. this.setSize(this.initWidth, this.initHeight, true);
  1780. }
  1781. if (buffer.readBool()) {
  1782. this.minWidth = buffer.readInt();
  1783. this.maxWidth = buffer.readInt();
  1784. this.minHeight = buffer.readInt();
  1785. this.maxHeight = buffer.readInt();
  1786. }
  1787. if (buffer.readBool()) {
  1788. f1 = buffer.readFloat();
  1789. f2 = buffer.readFloat();
  1790. this.setScale(f1, f2);
  1791. }
  1792. if (buffer.readBool()) {
  1793. f1 = buffer.readFloat();
  1794. f2 = buffer.readFloat();
  1795. this.setSkew(f1, f2);
  1796. }
  1797. if (buffer.readBool()) {
  1798. f1 = buffer.readFloat();
  1799. f2 = buffer.readFloat();
  1800. this.setPivot(f1, f2, buffer.readBool());
  1801. }
  1802. f1 = buffer.readFloat();
  1803. if (f1 != 1)
  1804. this.alpha = f1;
  1805. f1 = buffer.readFloat();
  1806. if (f1 != 0)
  1807. this.rotation = f1;
  1808. if (!buffer.readBool())
  1809. this.visible = false;
  1810. if (!buffer.readBool())
  1811. this.touchable = false;
  1812. if (buffer.readBool())
  1813. this.grayed = true;
  1814. this.blendMode = buffer.readByte();
  1815. var filter = buffer.readByte();
  1816. if (filter == 1) {
  1817. }
  1818. var str = buffer.readS();
  1819. if (str != null)
  1820. this.data = str;
  1821. };
  1822. GObject.prototype.setup_afterAdd = function (buffer, beginPos) {
  1823. buffer.seek(beginPos, 1);
  1824. var str = buffer.readS();
  1825. if (str != null)
  1826. this.tooltips = str;
  1827. var groupId = buffer.readShort();
  1828. if (groupId >= 0)
  1829. this.group = this.parent.getChildAt(groupId);
  1830. buffer.seek(beginPos, 2);
  1831. var cnt = buffer.readShort();
  1832. for (var i = 0; i < cnt; i++) {
  1833. var nextPos = buffer.readShort();
  1834. nextPos += buffer.position;
  1835. var gear = this.getGear(buffer.readByte());
  1836. gear.setup(buffer);
  1837. buffer.position = nextPos;
  1838. }
  1839. };
  1840. GObject.prototype.onRollOver = function () {
  1841. this.root.showTooltips(this.tooltips);
  1842. };
  1843. ;
  1844. GObject.prototype.onRollOut = function () {
  1845. this.root.hideTooltips();
  1846. };
  1847. ;
  1848. GObject.prototype.initDrag = function () {
  1849. if (this._draggable) {
  1850. this.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1851. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1852. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1853. }
  1854. else {
  1855. this.off(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1856. this.off(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1857. this.off(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1858. }
  1859. };
  1860. GObject.prototype.dragBegin = function (touchId) {
  1861. if (GObject.draggingObject) {
  1862. var tmp = GObject.draggingObject;
  1863. tmp.stopDrag();
  1864. GObject.draggingObject = null;
  1865. tmp._node.emit(fgui.Event.DRAG_END);
  1866. }
  1867. if (touchId == undefined)
  1868. touchId = fgui.GRoot.inst.inputProcessor.getAllTouches()[0];
  1869. sGlobalDragStart.set(fgui.GRoot.inst.getTouchPosition(touchId));
  1870. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  1871. GObject.draggingObject = this;
  1872. this._dragTesting = true;
  1873. fgui.GRoot.inst.inputProcessor.addTouchMonitor(touchId, this);
  1874. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1875. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1876. };
  1877. GObject.prototype.dragEnd = function () {
  1878. if (GObject.draggingObject == this) {
  1879. this._dragTesting = false;
  1880. GObject.draggingObject = null;
  1881. }
  1882. sDragQuery = false;
  1883. };
  1884. GObject.prototype.onTouchBegin_0 = function (evt) {
  1885. if (this._dragStartPos == null)
  1886. this._dragStartPos = new cc.Vec2();
  1887. this._dragStartPos.set(evt.pos);
  1888. this._dragTesting = true;
  1889. evt.captureTouch();
  1890. };
  1891. GObject.prototype.onTouchMove_0 = function (evt) {
  1892. if (GObject.draggingObject != this && this._draggable && this._dragTesting) {
  1893. var sensitivity = fgui.UIConfig.touchDragSensitivity;
  1894. if (this._dragStartPos
  1895. && Math.abs(this._dragStartPos.x - evt.pos.x) < sensitivity
  1896. && Math.abs(this._dragStartPos.y - evt.pos.y) < sensitivity)
  1897. return;
  1898. this._dragTesting = false;
  1899. sDragQuery = true;
  1900. this._node.emit(fgui.Event.DRAG_START, evt);
  1901. if (sDragQuery)
  1902. this.dragBegin(evt.touchId);
  1903. }
  1904. if (GObject.draggingObject == this) {
  1905. var xx = evt.pos.x - sGlobalDragStart.x + sGlobalRect.x;
  1906. var yy = evt.pos.y - sGlobalDragStart.y + sGlobalRect.y;
  1907. if (this._dragBounds) {
  1908. var rect = fgui.GRoot.inst.localToGlobalRect(this._dragBounds.x, this._dragBounds.y, this._dragBounds.width, this._dragBounds.height, sDragHelperRect);
  1909. if (xx < rect.x)
  1910. xx = rect.x;
  1911. else if (xx + sGlobalRect.width > rect.xMax) {
  1912. xx = rect.xMax - sGlobalRect.width;
  1913. if (xx < rect.x)
  1914. xx = rect.x;
  1915. }
  1916. if (yy < rect.y)
  1917. yy = rect.y;
  1918. else if (yy + sGlobalRect.height > rect.yMax) {
  1919. yy = rect.yMax - sGlobalRect.height;
  1920. if (yy < rect.y)
  1921. yy = rect.y;
  1922. }
  1923. }
  1924. sUpdateInDragging = true;
  1925. var pt = this.parent.globalToLocal(xx, yy, sHelperPoint);
  1926. this.setPosition(Math.round(pt.x), Math.round(pt.y));
  1927. sUpdateInDragging = false;
  1928. this._node.emit(fgui.Event.DRAG_MOVE, evt);
  1929. }
  1930. };
  1931. GObject.prototype.onTouchEnd_0 = function (evt) {
  1932. if (GObject.draggingObject == this) {
  1933. GObject.draggingObject = null;
  1934. this._node.emit(fgui.Event.DRAG_END, evt);
  1935. }
  1936. };
  1937. GObject._defaultGroupIndex = -1;
  1938. return GObject;
  1939. }());
  1940. fgui.GObject = GObject;
  1941. var sGlobalDragStart = new cc.Vec2();
  1942. var sGlobalRect = new cc.Rect();
  1943. var sHelperPoint = new cc.Vec2();
  1944. var sDragHelperRect = new cc.Rect();
  1945. var sUpdateInDragging;
  1946. var sDragQuery = false;
  1947. var GObjectPartner = (function (_super) {
  1948. __extends(GObjectPartner, _super);
  1949. function GObjectPartner() {
  1950. var _this = _super !== null && _super.apply(this, arguments) || this;
  1951. _this._emitDisplayEvents = false;
  1952. return _this;
  1953. }
  1954. GObjectPartner.prototype.callLater = function (callback, delay) {
  1955. if (!cc.director.getScheduler().isScheduled(callback, this))
  1956. this.scheduleOnce(callback, delay);
  1957. };
  1958. GObjectPartner.prototype.onClickLink = function (evt, text) {
  1959. this.node.emit(fgui.Event.LINK, text, evt);
  1960. };
  1961. GObjectPartner.prototype.onEnable = function () {
  1962. this.node["$gobj"].onEnable();
  1963. if (this._emitDisplayEvents)
  1964. this.node.emit(fgui.Event.DISPLAY);
  1965. };
  1966. GObjectPartner.prototype.onDisable = function () {
  1967. this.node["$gobj"].onDisable();
  1968. if (this._emitDisplayEvents)
  1969. this.node.emit(fgui.Event.UNDISPLAY);
  1970. };
  1971. GObjectPartner.prototype.update = function (dt) {
  1972. this.node["$gobj"].onUpdate(dt);
  1973. };
  1974. GObjectPartner.prototype.onDestroy = function () {
  1975. this.node["$gobj"].onDestroy();
  1976. };
  1977. return GObjectPartner;
  1978. }(cc.Component));
  1979. fgui.GObjectPartner = GObjectPartner;
  1980. })(fgui || (fgui = {}));
  1981. (function (fgui) {
  1982. var GComponent = (function (_super) {
  1983. __extends(GComponent, _super);
  1984. function GComponent() {
  1985. var _this = _super.call(this) || this;
  1986. _this._sortingChildCount = 0;
  1987. _this._childrenRenderOrder = fgui.ChildrenRenderOrder.Ascent;
  1988. _this._apexIndex = 0;
  1989. _this._node.name = "GComponent";
  1990. _this._children = new Array();
  1991. _this._controllers = new Array();
  1992. _this._transitions = new Array();
  1993. _this._margin = new fgui.Margin();
  1994. _this._alignOffset = new cc.Vec2();
  1995. _this._container = new cc.Node("Container");
  1996. _this._container.setAnchorPoint(0, 1);
  1997. _this._node.addChild(_this._container);
  1998. return _this;
  1999. }
  2000. GComponent.prototype.dispose = function () {
  2001. var i;
  2002. var cnt;
  2003. cnt = this._transitions.length;
  2004. for (i = 0; i < cnt; ++i) {
  2005. var trans = this._transitions[i];
  2006. trans.dispose();
  2007. }
  2008. cnt = this._controllers.length;
  2009. for (i = 0; i < cnt; ++i) {
  2010. var cc = this._controllers[i];
  2011. cc.dispose();
  2012. }
  2013. if (this._scrollPane)
  2014. this._scrollPane.destroy();
  2015. cnt = this._children.length;
  2016. for (i = cnt - 1; i >= 0; --i) {
  2017. var obj = this._children[i];
  2018. obj._parent = null;
  2019. obj.dispose();
  2020. }
  2021. this._boundsChanged = false;
  2022. _super.prototype.dispose.call(this);
  2023. };
  2024. Object.defineProperty(GComponent.prototype, "displayListContainer", {
  2025. get: function () {
  2026. return this._container;
  2027. },
  2028. enumerable: false,
  2029. configurable: true
  2030. });
  2031. GComponent.prototype.addChild = function (child) {
  2032. this.addChildAt(child, this._children.length);
  2033. return child;
  2034. };
  2035. GComponent.prototype.addChildAt = function (child, index) {
  2036. if (!child)
  2037. throw "child is null";
  2038. var numChildren = this._children.length;
  2039. if (index >= 0 && index <= numChildren) {
  2040. if (child.parent == this) {
  2041. this.setChildIndex(child, index);
  2042. }
  2043. else {
  2044. child.removeFromParent();
  2045. child._parent = this;
  2046. var cnt = this._children.length;
  2047. if (child.sortingOrder != 0) {
  2048. this._sortingChildCount++;
  2049. index = this.getInsertPosForSortingChild(child);
  2050. }
  2051. else if (this._sortingChildCount > 0) {
  2052. if (index > (cnt - this._sortingChildCount))
  2053. index = cnt - this._sortingChildCount;
  2054. }
  2055. if (index == cnt)
  2056. this._children.push(child);
  2057. else
  2058. this._children.splice(index, 0, child);
  2059. this.onChildAdd(child, index);
  2060. this.setBoundsChangedFlag();
  2061. }
  2062. return child;
  2063. }
  2064. else {
  2065. throw "Invalid child index";
  2066. }
  2067. };
  2068. GComponent.prototype.getInsertPosForSortingChild = function (target) {
  2069. var cnt = this._children.length;
  2070. var i = 0;
  2071. for (i = 0; i < cnt; i++) {
  2072. var child = this._children[i];
  2073. if (child == target)
  2074. continue;
  2075. if (target.sortingOrder < child.sortingOrder)
  2076. break;
  2077. }
  2078. return i;
  2079. };
  2080. GComponent.prototype.removeChild = function (child, dispose) {
  2081. var childIndex = this._children.indexOf(child);
  2082. if (childIndex != -1) {
  2083. this.removeChildAt(childIndex, dispose);
  2084. }
  2085. return child;
  2086. };
  2087. GComponent.prototype.removeChildAt = function (index, dispose) {
  2088. if (index >= 0 && index < this.numChildren) {
  2089. var child = this._children[index];
  2090. child._parent = null;
  2091. if (child.sortingOrder != 0)
  2092. this._sortingChildCount--;
  2093. this._children.splice(index, 1);
  2094. child.group = null;
  2095. this._container.removeChild(child.node);
  2096. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2097. this._partner.callLater(this.buildNativeDisplayList);
  2098. if (dispose)
  2099. child.dispose();
  2100. else
  2101. child.node.parent = null;
  2102. this.setBoundsChangedFlag();
  2103. return child;
  2104. }
  2105. else {
  2106. throw "Invalid child index";
  2107. }
  2108. };
  2109. GComponent.prototype.removeChildren = function (beginIndex, endIndex, dispose) {
  2110. if (beginIndex == undefined)
  2111. beginIndex = 0;
  2112. if (endIndex == undefined)
  2113. endIndex = -1;
  2114. if (endIndex < 0 || endIndex >= this.numChildren)
  2115. endIndex = this.numChildren - 1;
  2116. for (var i = beginIndex; i <= endIndex; ++i)
  2117. this.removeChildAt(beginIndex, dispose);
  2118. };
  2119. GComponent.prototype.getChildAt = function (index) {
  2120. if (index >= 0 && index < this.numChildren)
  2121. return this._children[index];
  2122. else
  2123. throw "Invalid child index";
  2124. };
  2125. GComponent.prototype.getChild = function (name) {
  2126. var cnt = this._children.length;
  2127. for (var i = 0; i < cnt; ++i) {
  2128. if (this._children[i].name == name)
  2129. return this._children[i];
  2130. }
  2131. return null;
  2132. };
  2133. GComponent.prototype.getChildByPath = function (path) {
  2134. var arr = path.split(".");
  2135. var cnt = arr.length;
  2136. var gcom = this;
  2137. var obj;
  2138. for (var i = 0; i < cnt; ++i) {
  2139. obj = gcom.getChild(arr[i]);
  2140. if (!obj)
  2141. break;
  2142. if (i != cnt - 1) {
  2143. if (!(obj instanceof GComponent)) {
  2144. obj = null;
  2145. break;
  2146. }
  2147. else
  2148. gcom = obj;
  2149. }
  2150. }
  2151. return obj;
  2152. };
  2153. GComponent.prototype.getVisibleChild = function (name) {
  2154. var cnt = this._children.length;
  2155. for (var i = 0; i < cnt; ++i) {
  2156. var child = this._children[i];
  2157. if (child._finalVisible && child.name == name)
  2158. return child;
  2159. }
  2160. return null;
  2161. };
  2162. GComponent.prototype.getChildInGroup = function (name, group) {
  2163. var cnt = this._children.length;
  2164. for (var i = 0; i < cnt; ++i) {
  2165. var child = this._children[i];
  2166. if (child.group == group && child.name == name)
  2167. return child;
  2168. }
  2169. return null;
  2170. };
  2171. GComponent.prototype.getChildById = function (id) {
  2172. var cnt = this._children.length;
  2173. for (var i = 0; i < cnt; ++i) {
  2174. if (this._children[i]._id == id)
  2175. return this._children[i];
  2176. }
  2177. return null;
  2178. };
  2179. GComponent.prototype.getChildIndex = function (child) {
  2180. return this._children.indexOf(child);
  2181. };
  2182. GComponent.prototype.setChildIndex = function (child, index) {
  2183. var oldIndex = this._children.indexOf(child);
  2184. if (oldIndex == -1)
  2185. throw "Not a child of this container";
  2186. if (child.sortingOrder != 0)
  2187. return;
  2188. var cnt = this._children.length;
  2189. if (this._sortingChildCount > 0) {
  2190. if (index > (cnt - this._sortingChildCount - 1))
  2191. index = cnt - this._sortingChildCount - 1;
  2192. }
  2193. this._setChildIndex(child, oldIndex, index);
  2194. };
  2195. GComponent.prototype.setChildIndexBefore = function (child, index) {
  2196. var oldIndex = this._children.indexOf(child);
  2197. if (oldIndex == -1)
  2198. throw "Not a child of this container";
  2199. if (child.sortingOrder != 0)
  2200. return oldIndex;
  2201. var cnt = this._children.length;
  2202. if (this._sortingChildCount > 0) {
  2203. if (index > (cnt - this._sortingChildCount - 1))
  2204. index = cnt - this._sortingChildCount - 1;
  2205. }
  2206. if (oldIndex < index)
  2207. return this._setChildIndex(child, oldIndex, index - 1);
  2208. else
  2209. return this._setChildIndex(child, oldIndex, index);
  2210. };
  2211. GComponent.prototype._setChildIndex = function (child, oldIndex, index) {
  2212. var cnt = this._children.length;
  2213. if (index > cnt)
  2214. index = cnt;
  2215. if (oldIndex == index)
  2216. return oldIndex;
  2217. this._children.splice(oldIndex, 1);
  2218. this._children.splice(index, 0, child);
  2219. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  2220. child.node.setSiblingIndex(index);
  2221. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  2222. child.node.setSiblingIndex(cnt - index);
  2223. else
  2224. this._partner.callLater(this.buildNativeDisplayList);
  2225. this.setBoundsChangedFlag();
  2226. return index;
  2227. };
  2228. GComponent.prototype.swapChildren = function (child1, child2) {
  2229. var index1 = this._children.indexOf(child1);
  2230. var index2 = this._children.indexOf(child2);
  2231. if (index1 == -1 || index2 == -1)
  2232. throw "Not a child of this container";
  2233. this.swapChildrenAt(index1, index2);
  2234. };
  2235. GComponent.prototype.swapChildrenAt = function (index1, index2) {
  2236. var child1 = this._children[index1];
  2237. var child2 = this._children[index2];
  2238. this.setChildIndex(child1, index2);
  2239. this.setChildIndex(child2, index1);
  2240. };
  2241. Object.defineProperty(GComponent.prototype, "numChildren", {
  2242. get: function () {
  2243. return this._children.length;
  2244. },
  2245. enumerable: false,
  2246. configurable: true
  2247. });
  2248. GComponent.prototype.isAncestorOf = function (child) {
  2249. if (child == null)
  2250. return false;
  2251. var p = child.parent;
  2252. while (p) {
  2253. if (p == this)
  2254. return true;
  2255. p = p.parent;
  2256. }
  2257. return false;
  2258. };
  2259. GComponent.prototype.addController = function (controller) {
  2260. this._controllers.push(controller);
  2261. controller.parent = this;
  2262. this.applyController(controller);
  2263. };
  2264. GComponent.prototype.getControllerAt = function (index) {
  2265. return this._controllers[index];
  2266. };
  2267. GComponent.prototype.getController = function (name) {
  2268. var cnt = this._controllers.length;
  2269. for (var i = 0; i < cnt; ++i) {
  2270. var c = this._controllers[i];
  2271. if (c.name == name)
  2272. return c;
  2273. }
  2274. return null;
  2275. };
  2276. GComponent.prototype.removeController = function (c) {
  2277. var index = this._controllers.indexOf(c);
  2278. if (index == -1)
  2279. throw "controller not exists";
  2280. c.parent = null;
  2281. this._controllers.splice(index, 1);
  2282. var length = this._children.length;
  2283. for (var i = 0; i < length; i++) {
  2284. var child = this._children[i];
  2285. child.handleControllerChanged(c);
  2286. }
  2287. };
  2288. Object.defineProperty(GComponent.prototype, "controllers", {
  2289. get: function () {
  2290. return this._controllers;
  2291. },
  2292. enumerable: false,
  2293. configurable: true
  2294. });
  2295. GComponent.prototype.onChildAdd = function (child, index) {
  2296. child.node.parent = this._container;
  2297. child.node.active = child._finalVisible;
  2298. if (this._buildingDisplayList)
  2299. return;
  2300. var cnt = this._children.length;
  2301. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  2302. child.node.setSiblingIndex(index);
  2303. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  2304. child.node.setSiblingIndex(cnt - index);
  2305. else
  2306. this._partner.callLater(this.buildNativeDisplayList);
  2307. };
  2308. GComponent.prototype.buildNativeDisplayList = function (dt) {
  2309. if (!isNaN(dt)) {
  2310. var _t = (this.node["$gobj"]);
  2311. _t.buildNativeDisplayList();
  2312. return;
  2313. }
  2314. var cnt = this._children.length;
  2315. if (cnt == 0)
  2316. return;
  2317. var child;
  2318. switch (this._childrenRenderOrder) {
  2319. case fgui.ChildrenRenderOrder.Ascent:
  2320. {
  2321. var j = 0;
  2322. for (var i = 0; i < cnt; i++) {
  2323. child = this._children[i];
  2324. child.node.setSiblingIndex(j++);
  2325. }
  2326. }
  2327. break;
  2328. case fgui.ChildrenRenderOrder.Descent:
  2329. {
  2330. var j = 0;
  2331. for (var i = cnt - 1; i >= 0; i--) {
  2332. child = this._children[i];
  2333. child.node.setSiblingIndex(j++);
  2334. }
  2335. }
  2336. break;
  2337. case fgui.ChildrenRenderOrder.Arch:
  2338. {
  2339. var j = 0;
  2340. for (var i = 0; i < this._apexIndex; i++) {
  2341. child = this._children[i];
  2342. child.node.setSiblingIndex(j++);
  2343. }
  2344. for (var i = cnt - 1; i >= this._apexIndex; i--) {
  2345. child = this._children[i];
  2346. child.node.setSiblingIndex(j++);
  2347. }
  2348. }
  2349. break;
  2350. }
  2351. };
  2352. GComponent.prototype.applyController = function (c) {
  2353. this._applyingController = c;
  2354. var child;
  2355. var length = this._children.length;
  2356. for (var i = 0; i < length; i++) {
  2357. child = this._children[i];
  2358. child.handleControllerChanged(c);
  2359. }
  2360. this._applyingController = null;
  2361. c.runActions();
  2362. };
  2363. GComponent.prototype.applyAllControllers = function () {
  2364. var cnt = this._controllers.length;
  2365. for (var i = 0; i < cnt; ++i) {
  2366. this.applyController(this._controllers[i]);
  2367. }
  2368. };
  2369. GComponent.prototype.adjustRadioGroupDepth = function (obj, c) {
  2370. var cnt = this._children.length;
  2371. var i;
  2372. var child;
  2373. var myIndex = -1, maxIndex = -1;
  2374. for (i = 0; i < cnt; i++) {
  2375. child = this._children[i];
  2376. if (child == obj) {
  2377. myIndex = i;
  2378. }
  2379. else if ((child instanceof fgui.GButton) && child.relatedController == c) {
  2380. if (i > maxIndex)
  2381. maxIndex = i;
  2382. }
  2383. }
  2384. if (myIndex < maxIndex) {
  2385. if (this._applyingController)
  2386. this._children[maxIndex].handleControllerChanged(this._applyingController);
  2387. this.swapChildrenAt(myIndex, maxIndex);
  2388. }
  2389. };
  2390. GComponent.prototype.getTransitionAt = function (index) {
  2391. return this._transitions[index];
  2392. };
  2393. GComponent.prototype.getTransition = function (transName) {
  2394. var cnt = this._transitions.length;
  2395. for (var i = 0; i < cnt; ++i) {
  2396. var trans = this._transitions[i];
  2397. if (trans.name == transName)
  2398. return trans;
  2399. }
  2400. return null;
  2401. };
  2402. GComponent.prototype.isChildInView = function (child) {
  2403. if (this._rectMask) {
  2404. return child.x + child.width >= 0 && child.x <= this.width
  2405. && child.y + child.height >= 0 && child.y <= this.height;
  2406. }
  2407. else if (this._scrollPane) {
  2408. return this._scrollPane.isChildInView(child);
  2409. }
  2410. else
  2411. return true;
  2412. };
  2413. GComponent.prototype.getFirstChildInView = function () {
  2414. var cnt = this._children.length;
  2415. for (var i = 0; i < cnt; ++i) {
  2416. var child = this._children[i];
  2417. if (this.isChildInView(child))
  2418. return i;
  2419. }
  2420. return -1;
  2421. };
  2422. Object.defineProperty(GComponent.prototype, "scrollPane", {
  2423. get: function () {
  2424. return this._scrollPane;
  2425. },
  2426. enumerable: false,
  2427. configurable: true
  2428. });
  2429. Object.defineProperty(GComponent.prototype, "opaque", {
  2430. get: function () {
  2431. return this._opaque;
  2432. },
  2433. set: function (value) {
  2434. this._opaque = value;
  2435. },
  2436. enumerable: false,
  2437. configurable: true
  2438. });
  2439. Object.defineProperty(GComponent.prototype, "margin", {
  2440. get: function () {
  2441. return this._margin;
  2442. },
  2443. set: function (value) {
  2444. this._margin.copy(value);
  2445. this.handleSizeChanged();
  2446. },
  2447. enumerable: false,
  2448. configurable: true
  2449. });
  2450. Object.defineProperty(GComponent.prototype, "childrenRenderOrder", {
  2451. get: function () {
  2452. return this._childrenRenderOrder;
  2453. },
  2454. set: function (value) {
  2455. if (this._childrenRenderOrder != value) {
  2456. this._childrenRenderOrder = value;
  2457. this.buildNativeDisplayList();
  2458. }
  2459. },
  2460. enumerable: false,
  2461. configurable: true
  2462. });
  2463. Object.defineProperty(GComponent.prototype, "apexIndex", {
  2464. get: function () {
  2465. return this._apexIndex;
  2466. },
  2467. set: function (value) {
  2468. if (this._apexIndex != value) {
  2469. this._apexIndex = value;
  2470. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2471. this.buildNativeDisplayList();
  2472. }
  2473. },
  2474. enumerable: false,
  2475. configurable: true
  2476. });
  2477. Object.defineProperty(GComponent.prototype, "mask", {
  2478. get: function () {
  2479. return this._maskContent;
  2480. },
  2481. set: function (value) {
  2482. this.setMask(value, false);
  2483. },
  2484. enumerable: false,
  2485. configurable: true
  2486. });
  2487. GComponent.prototype.setMask = function (value, inverted) {
  2488. if (this._maskContent) {
  2489. this._maskContent.node.off(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2490. this._maskContent.node.off(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2491. this._maskContent.node.off(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2492. this._maskContent.node.off(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2493. this._maskContent.visible = true;
  2494. }
  2495. this._maskContent = value;
  2496. if (this._maskContent) {
  2497. if (!(value instanceof fgui.GImage) && !(value instanceof fgui.GGraph))
  2498. return;
  2499. if (!this._customMask) {
  2500. var maskNode = new cc.Node("Mask");
  2501. maskNode.parent = this._node;
  2502. if (this._scrollPane)
  2503. this._container.parent.parent = maskNode;
  2504. else
  2505. this._container.parent = maskNode;
  2506. this._customMask = maskNode.addComponent(cc.Mask);
  2507. }
  2508. value.visible = false;
  2509. value.node.on(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2510. value.node.on(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2511. value.node.on(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2512. value.node.on(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2513. this._customMask.inverted = inverted;
  2514. if (this._node.activeInHierarchy)
  2515. this.onMaskReady();
  2516. else
  2517. this.on(fgui.Event.DISPLAY, this.onMaskReady, this);
  2518. this.onMaskContentChanged();
  2519. if (this._scrollPane)
  2520. this._scrollPane.adjustMaskContainer();
  2521. else
  2522. this._container.setPosition(0, 0);
  2523. }
  2524. else if (this._customMask) {
  2525. if (this._scrollPane)
  2526. this._container.parent.parent = this._node;
  2527. else
  2528. this._container.parent = this._node;
  2529. this._customMask.node.destroy();
  2530. this._customMask = null;
  2531. if (this._scrollPane)
  2532. this._scrollPane.adjustMaskContainer();
  2533. else
  2534. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2535. }
  2536. };
  2537. GComponent.prototype.onMaskReady = function () {
  2538. this.off(fgui.Event.DISPLAY, this.onMaskReady, this);
  2539. if (this._maskContent instanceof fgui.GImage) {
  2540. this._customMask.type = cc.Mask.Type.IMAGE_STENCIL;
  2541. this._customMask.alphaThreshold = 0.0001;
  2542. this._customMask.spriteFrame = this._maskContent._content.spriteFrame;
  2543. }
  2544. else if (this._maskContent instanceof fgui.GGraph) {
  2545. if (this._maskContent.type == 2)
  2546. this._customMask.type = cc.Mask.Type.ELLIPSE;
  2547. else
  2548. this._customMask.type = cc.Mask.Type.RECT;
  2549. }
  2550. };
  2551. GComponent.prototype.onMaskContentChanged = function () {
  2552. var maskNode = this._customMask.node;
  2553. var contentNode = this._maskContent.node;
  2554. var w = contentNode.width * contentNode.scaleX;
  2555. var h = contentNode.height * contentNode.scaleY;
  2556. maskNode.setContentSize(w, h);
  2557. var left = contentNode.x - contentNode.anchorX * w;
  2558. var top = contentNode.y - contentNode.anchorY * h;
  2559. maskNode.setAnchorPoint(-left / maskNode.width, -top / maskNode.height);
  2560. maskNode.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2561. };
  2562. Object.defineProperty(GComponent.prototype, "_pivotCorrectX", {
  2563. get: function () {
  2564. return -this.pivotX * this._width + this._margin.left;
  2565. },
  2566. enumerable: false,
  2567. configurable: true
  2568. });
  2569. Object.defineProperty(GComponent.prototype, "_pivotCorrectY", {
  2570. get: function () {
  2571. return this.pivotY * this._height - this._margin.top;
  2572. },
  2573. enumerable: false,
  2574. configurable: true
  2575. });
  2576. Object.defineProperty(GComponent.prototype, "baseUserData", {
  2577. get: function () {
  2578. var buffer = this.packageItem.rawData;
  2579. buffer.seek(0, 4);
  2580. return buffer.readS();
  2581. },
  2582. enumerable: false,
  2583. configurable: true
  2584. });
  2585. GComponent.prototype.setupScroll = function (buffer) {
  2586. this._scrollPane = this._node.addComponent(fgui.ScrollPane);
  2587. this._scrollPane.setup(buffer);
  2588. };
  2589. GComponent.prototype.setupOverflow = function (overflow) {
  2590. if (overflow == fgui.OverflowType.Hidden)
  2591. this._rectMask = this._container.addComponent(cc.Mask);
  2592. if (!this._margin.isNone)
  2593. this.handleSizeChanged();
  2594. };
  2595. GComponent.prototype.handleAnchorChanged = function () {
  2596. _super.prototype.handleAnchorChanged.call(this);
  2597. if (this._customMask)
  2598. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2599. else if (this._scrollPane)
  2600. this._scrollPane.adjustMaskContainer();
  2601. else
  2602. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  2603. };
  2604. GComponent.prototype.handleSizeChanged = function () {
  2605. _super.prototype.handleSizeChanged.call(this);
  2606. if (this._customMask)
  2607. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2608. else if (!this._scrollPane)
  2609. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2610. if (this._scrollPane)
  2611. this._scrollPane.onOwnerSizeChanged();
  2612. else
  2613. this._container.setContentSize(this.viewWidth, this.viewHeight);
  2614. };
  2615. GComponent.prototype.handleGrayedChanged = function () {
  2616. var c = this.getController("grayed");
  2617. if (c) {
  2618. c.selectedIndex = this.grayed ? 1 : 0;
  2619. return;
  2620. }
  2621. var v = this.grayed;
  2622. var cnt = this._children.length;
  2623. for (var i = 0; i < cnt; ++i) {
  2624. this._children[i].grayed = v;
  2625. }
  2626. };
  2627. GComponent.prototype.handleControllerChanged = function (c) {
  2628. _super.prototype.handleControllerChanged.call(this, c);
  2629. if (this._scrollPane)
  2630. this._scrollPane.handleControllerChanged(c);
  2631. };
  2632. GComponent.prototype._hitTest = function (pt, globalPt) {
  2633. if (this._customMask) {
  2634. s_vec2.set(globalPt);
  2635. s_vec2.y = fgui.GRoot.inst.height - globalPt.y;
  2636. var b = this._customMask["_hitTest"](s_vec2) || false;
  2637. if (!b)
  2638. return null;
  2639. }
  2640. if (this.hitArea) {
  2641. if (!this.hitArea.hitTest(pt, globalPt))
  2642. return null;
  2643. }
  2644. else if (this._rectMask) {
  2645. s_vec2.set(pt);
  2646. s_vec2.x += this._container.x;
  2647. s_vec2.y += this._container.y;
  2648. var clippingSize = this._container.getContentSize();
  2649. if (s_vec2.x < 0 || s_vec2.y < 0 || s_vec2.x >= clippingSize.width || s_vec2.y >= clippingSize.height)
  2650. return null;
  2651. }
  2652. if (this._scrollPane) {
  2653. var target_1 = this._scrollPane.hitTest(pt, globalPt);
  2654. if (!target_1)
  2655. return null;
  2656. if (target_1 != this)
  2657. return target_1;
  2658. }
  2659. var target = null;
  2660. var cnt = this._children.length;
  2661. for (var i = cnt - 1; i >= 0; i--) {
  2662. var child = this._children[i];
  2663. if (this._maskContent == child || child._touchDisabled)
  2664. continue;
  2665. target = child.hitTest(globalPt);
  2666. if (target)
  2667. break;
  2668. }
  2669. if (!target && this._opaque && (this.hitArea || pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height))
  2670. target = this;
  2671. return target;
  2672. };
  2673. GComponent.prototype.setBoundsChangedFlag = function () {
  2674. if (!this._scrollPane && !this._trackBounds)
  2675. return;
  2676. if (!this._boundsChanged) {
  2677. this._boundsChanged = true;
  2678. this._partner.callLater(this.refresh);
  2679. }
  2680. };
  2681. GComponent.prototype.refresh = function (dt) {
  2682. if (!isNaN(dt)) {
  2683. var _t = (this.node["$gobj"]);
  2684. _t.refresh();
  2685. return;
  2686. }
  2687. if (this._boundsChanged) {
  2688. var len = this._children.length;
  2689. if (len > 0) {
  2690. for (var i = 0; i < len; i++) {
  2691. var child = this._children[i];
  2692. child.ensureSizeCorrect();
  2693. }
  2694. }
  2695. this.updateBounds();
  2696. }
  2697. };
  2698. GComponent.prototype.ensureBoundsCorrect = function () {
  2699. var len = this._children.length;
  2700. if (len > 0) {
  2701. for (var i = 0; i < len; i++) {
  2702. var child = this._children[i];
  2703. child.ensureSizeCorrect();
  2704. }
  2705. }
  2706. if (this._boundsChanged)
  2707. this.updateBounds();
  2708. };
  2709. GComponent.prototype.updateBounds = function () {
  2710. var ax = 0, ay = 0, aw = 0, ah = 0;
  2711. var len = this._children.length;
  2712. if (len > 0) {
  2713. ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  2714. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  2715. var tmp = 0;
  2716. var i = 0;
  2717. for (var i = 0; i < len; i++) {
  2718. var child = this._children[i];
  2719. tmp = child.x;
  2720. if (tmp < ax)
  2721. ax = tmp;
  2722. tmp = child.y;
  2723. if (tmp < ay)
  2724. ay = tmp;
  2725. tmp = child.x + child.actualWidth;
  2726. if (tmp > ar)
  2727. ar = tmp;
  2728. tmp = child.y + child.actualHeight;
  2729. if (tmp > ab)
  2730. ab = tmp;
  2731. }
  2732. aw = ar - ax;
  2733. ah = ab - ay;
  2734. }
  2735. this.setBounds(ax, ay, aw, ah);
  2736. };
  2737. GComponent.prototype.setBounds = function (ax, ay, aw, ah) {
  2738. if (ah === void 0) { ah = 0; }
  2739. this._boundsChanged = false;
  2740. if (this._scrollPane)
  2741. this._scrollPane.setContentSize(Math.round(ax + aw), Math.round(ay + ah));
  2742. };
  2743. Object.defineProperty(GComponent.prototype, "viewWidth", {
  2744. get: function () {
  2745. if (this._scrollPane)
  2746. return this._scrollPane.viewWidth;
  2747. else
  2748. return this.width - this._margin.left - this._margin.right;
  2749. },
  2750. set: function (value) {
  2751. if (this._scrollPane)
  2752. this._scrollPane.viewWidth = value;
  2753. else
  2754. this.width = value + this._margin.left + this._margin.right;
  2755. },
  2756. enumerable: false,
  2757. configurable: true
  2758. });
  2759. Object.defineProperty(GComponent.prototype, "viewHeight", {
  2760. get: function () {
  2761. if (this._scrollPane)
  2762. return this._scrollPane.viewHeight;
  2763. else
  2764. return this.height - this._margin.top - this._margin.bottom;
  2765. },
  2766. set: function (value) {
  2767. if (this._scrollPane)
  2768. this._scrollPane.viewHeight = value;
  2769. else
  2770. this.height = value + this._margin.top + this._margin.bottom;
  2771. },
  2772. enumerable: false,
  2773. configurable: true
  2774. });
  2775. GComponent.prototype.getSnappingPosition = function (xValue, yValue, resultPoint) {
  2776. if (!resultPoint)
  2777. resultPoint = new cc.Vec2();
  2778. var cnt = this._children.length;
  2779. if (cnt == 0) {
  2780. resultPoint.x = 0;
  2781. resultPoint.y = 0;
  2782. return resultPoint;
  2783. }
  2784. this.ensureBoundsCorrect();
  2785. var obj = null;
  2786. var prev = null;
  2787. var i = 0;
  2788. if (yValue != 0) {
  2789. for (; i < cnt; i++) {
  2790. obj = this._children[i];
  2791. if (yValue < obj.y) {
  2792. if (i == 0) {
  2793. yValue = 0;
  2794. break;
  2795. }
  2796. else {
  2797. prev = this._children[i - 1];
  2798. if (yValue < prev.y + prev.actualHeight / 2)
  2799. yValue = prev.y;
  2800. else
  2801. yValue = obj.y;
  2802. break;
  2803. }
  2804. }
  2805. }
  2806. if (i == cnt)
  2807. yValue = obj.y;
  2808. }
  2809. if (xValue != 0) {
  2810. if (i > 0)
  2811. i--;
  2812. for (; i < cnt; i++) {
  2813. obj = this._children[i];
  2814. if (xValue < obj.x) {
  2815. if (i == 0) {
  2816. xValue = 0;
  2817. break;
  2818. }
  2819. else {
  2820. prev = this._children[i - 1];
  2821. if (xValue < prev.x + prev.actualWidth / 2)
  2822. xValue = prev.x;
  2823. else
  2824. xValue = obj.x;
  2825. break;
  2826. }
  2827. }
  2828. }
  2829. if (i == cnt)
  2830. xValue = obj.x;
  2831. }
  2832. resultPoint.x = xValue;
  2833. resultPoint.y = yValue;
  2834. return resultPoint;
  2835. };
  2836. GComponent.prototype.childSortingOrderChanged = function (child, oldValue, newValue) {
  2837. if (newValue === void 0) { newValue = 0; }
  2838. if (newValue == 0) {
  2839. this._sortingChildCount--;
  2840. this.setChildIndex(child, this._children.length);
  2841. }
  2842. else {
  2843. if (oldValue == 0)
  2844. this._sortingChildCount++;
  2845. var oldIndex = this._children.indexOf(child);
  2846. var index = this.getInsertPosForSortingChild(child);
  2847. if (oldIndex < index)
  2848. this._setChildIndex(child, oldIndex, index - 1);
  2849. else
  2850. this._setChildIndex(child, oldIndex, index);
  2851. }
  2852. };
  2853. GComponent.prototype.constructFromResource = function () {
  2854. this.constructFromResource2(null, 0);
  2855. };
  2856. GComponent.prototype.constructFromResource2 = function (objectPool, poolIndex) {
  2857. var contentItem = this.packageItem.getBranch();
  2858. if (!contentItem.decoded) {
  2859. contentItem.decoded = true;
  2860. fgui.TranslationHelper.translateComponent(contentItem);
  2861. }
  2862. var i;
  2863. var dataLen;
  2864. var curPos;
  2865. var nextPos;
  2866. var f1;
  2867. var f2;
  2868. var i1;
  2869. var i2;
  2870. var buffer = contentItem.rawData;
  2871. buffer.seek(0, 0);
  2872. this._underConstruct = true;
  2873. this.sourceWidth = buffer.readInt();
  2874. this.sourceHeight = buffer.readInt();
  2875. this.initWidth = this.sourceWidth;
  2876. this.initHeight = this.sourceHeight;
  2877. this.setSize(this.sourceWidth, this.sourceHeight);
  2878. if (buffer.readBool()) {
  2879. this.minWidth = buffer.readInt();
  2880. this.maxWidth = buffer.readInt();
  2881. this.minHeight = buffer.readInt();
  2882. this.maxHeight = buffer.readInt();
  2883. }
  2884. if (buffer.readBool()) {
  2885. f1 = buffer.readFloat();
  2886. f2 = buffer.readFloat();
  2887. this.setPivot(f1, f2, buffer.readBool());
  2888. }
  2889. if (buffer.readBool()) {
  2890. this._margin.top = buffer.readInt();
  2891. this._margin.bottom = buffer.readInt();
  2892. this._margin.left = buffer.readInt();
  2893. this._margin.right = buffer.readInt();
  2894. }
  2895. var overflow = buffer.readByte();
  2896. if (overflow == fgui.OverflowType.Scroll) {
  2897. var savedPos = buffer.position;
  2898. buffer.seek(0, 7);
  2899. this.setupScroll(buffer);
  2900. buffer.position = savedPos;
  2901. }
  2902. else
  2903. this.setupOverflow(overflow);
  2904. if (buffer.readBool())
  2905. buffer.skip(8);
  2906. this._buildingDisplayList = true;
  2907. buffer.seek(0, 1);
  2908. var controllerCount = buffer.readShort();
  2909. for (i = 0; i < controllerCount; i++) {
  2910. nextPos = buffer.readShort();
  2911. nextPos += buffer.position;
  2912. var controller = new fgui.Controller();
  2913. this._controllers.push(controller);
  2914. controller.parent = this;
  2915. controller.setup(buffer);
  2916. buffer.position = nextPos;
  2917. }
  2918. buffer.seek(0, 2);
  2919. var child;
  2920. var childCount = buffer.readShort();
  2921. for (i = 0; i < childCount; i++) {
  2922. dataLen = buffer.readShort();
  2923. curPos = buffer.position;
  2924. if (objectPool)
  2925. child = objectPool[poolIndex + i];
  2926. else {
  2927. buffer.seek(curPos, 0);
  2928. var type = buffer.readByte();
  2929. var src = buffer.readS();
  2930. var pkgId = buffer.readS();
  2931. var pi = null;
  2932. if (src != null) {
  2933. var pkg;
  2934. if (pkgId != null)
  2935. pkg = fgui.UIPackage.getById(pkgId);
  2936. else
  2937. pkg = contentItem.owner;
  2938. pi = pkg ? pkg.getItemById(src) : null;
  2939. }
  2940. if (pi) {
  2941. child = fgui.UIObjectFactory.newObject(pi);
  2942. child.constructFromResource();
  2943. }
  2944. else
  2945. child = fgui.UIObjectFactory.newObject(type);
  2946. }
  2947. child._underConstruct = true;
  2948. child.setup_beforeAdd(buffer, curPos);
  2949. child._parent = this;
  2950. child.node.parent = this._container;
  2951. this._children.push(child);
  2952. buffer.position = curPos + dataLen;
  2953. }
  2954. buffer.seek(0, 3);
  2955. this.relations.setup(buffer, true);
  2956. buffer.seek(0, 2);
  2957. buffer.skip(2);
  2958. for (i = 0; i < childCount; i++) {
  2959. nextPos = buffer.readShort();
  2960. nextPos += buffer.position;
  2961. buffer.seek(buffer.position, 3);
  2962. this._children[i].relations.setup(buffer, false);
  2963. buffer.position = nextPos;
  2964. }
  2965. buffer.seek(0, 2);
  2966. buffer.skip(2);
  2967. for (i = 0; i < childCount; i++) {
  2968. nextPos = buffer.readShort();
  2969. nextPos += buffer.position;
  2970. child = this._children[i];
  2971. child.setup_afterAdd(buffer, buffer.position);
  2972. child._underConstruct = false;
  2973. buffer.position = nextPos;
  2974. }
  2975. buffer.seek(0, 4);
  2976. buffer.skip(2);
  2977. this.opaque = buffer.readBool();
  2978. var maskId = buffer.readShort();
  2979. if (maskId != -1) {
  2980. this.setMask(this.getChildAt(maskId), buffer.readBool());
  2981. }
  2982. var hitTestId = buffer.readS();
  2983. i1 = buffer.readInt();
  2984. i2 = buffer.readInt();
  2985. if (hitTestId != null) {
  2986. pi = contentItem.owner.getItemById(hitTestId);
  2987. if (pi && pi.hitTestData)
  2988. this.hitArea = new fgui.PixelHitTest(pi.hitTestData, i1, i2);
  2989. }
  2990. else if (i1 != 0 && i2 != -1) {
  2991. this.hitArea = new fgui.ChildHitArea(this.getChildAt(i2));
  2992. }
  2993. buffer.seek(0, 5);
  2994. var transitionCount = buffer.readShort();
  2995. for (i = 0; i < transitionCount; i++) {
  2996. nextPos = buffer.readShort();
  2997. nextPos += buffer.position;
  2998. var trans = new fgui.Transition(this);
  2999. trans.setup(buffer);
  3000. this._transitions.push(trans);
  3001. buffer.position = nextPos;
  3002. }
  3003. this.applyAllControllers();
  3004. this._buildingDisplayList = false;
  3005. this._underConstruct = false;
  3006. this.buildNativeDisplayList();
  3007. this.setBoundsChangedFlag();
  3008. if (contentItem.objectType != fgui.ObjectType.Component)
  3009. this.constructExtension(buffer);
  3010. this.onConstruct();
  3011. };
  3012. GComponent.prototype.constructExtension = function (buffer) {
  3013. };
  3014. GComponent.prototype.onConstruct = function () {
  3015. };
  3016. GComponent.prototype.setup_afterAdd = function (buffer, beginPos) {
  3017. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3018. buffer.seek(beginPos, 4);
  3019. var pageController = buffer.readShort();
  3020. if (pageController != -1 && this._scrollPane)
  3021. this._scrollPane.pageController = this._parent.getControllerAt(pageController);
  3022. var cnt = buffer.readShort();
  3023. for (var i = 0; i < cnt; i++) {
  3024. var cc = this.getController(buffer.readS());
  3025. var pageId = buffer.readS();
  3026. if (cc)
  3027. cc.selectedPageId = pageId;
  3028. }
  3029. if (buffer.version >= 2) {
  3030. cnt = buffer.readShort();
  3031. for (i = 0; i < cnt; i++) {
  3032. var target = buffer.readS();
  3033. var propertyId = buffer.readShort();
  3034. var value = buffer.readS();
  3035. var obj = this.getChildByPath(target);
  3036. if (obj)
  3037. obj.setProp(propertyId, value);
  3038. }
  3039. }
  3040. };
  3041. GComponent.prototype.onEnable = function () {
  3042. var cnt = this._transitions.length;
  3043. for (var i = 0; i < cnt; ++i)
  3044. this._transitions[i].onEnable();
  3045. };
  3046. GComponent.prototype.onDisable = function () {
  3047. var cnt = this._transitions.length;
  3048. for (var i = 0; i < cnt; ++i)
  3049. this._transitions[i].onDisable();
  3050. };
  3051. return GComponent;
  3052. }(fgui.GObject));
  3053. fgui.GComponent = GComponent;
  3054. var s_vec2 = new cc.Vec2();
  3055. })(fgui || (fgui = {}));
  3056. (function (fgui) {
  3057. var GButton = (function (_super) {
  3058. __extends(GButton, _super);
  3059. function GButton() {
  3060. var _this = _super.call(this) || this;
  3061. _this._node.name = "GButton";
  3062. _this._mode = fgui.ButtonMode.Common;
  3063. _this._title = "";
  3064. _this._icon = "";
  3065. _this._sound = fgui.UIConfig.buttonSound;
  3066. _this._soundVolumeScale = fgui.UIConfig.buttonSoundVolumeScale;
  3067. _this._changeStateOnClick = true;
  3068. _this._downEffect = 0;
  3069. _this._downEffectValue = 0.8;
  3070. return _this;
  3071. }
  3072. Object.defineProperty(GButton.prototype, "icon", {
  3073. get: function () {
  3074. return this._icon;
  3075. },
  3076. set: function (value) {
  3077. this._icon = value;
  3078. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3079. if (this._iconObject)
  3080. this._iconObject.icon = value;
  3081. this.updateGear(7);
  3082. },
  3083. enumerable: false,
  3084. configurable: true
  3085. });
  3086. Object.defineProperty(GButton.prototype, "selectedIcon", {
  3087. get: function () {
  3088. return this._selectedIcon;
  3089. },
  3090. set: function (value) {
  3091. this._selectedIcon = value;
  3092. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3093. if (this._iconObject)
  3094. this._iconObject.icon = value;
  3095. },
  3096. enumerable: false,
  3097. configurable: true
  3098. });
  3099. Object.defineProperty(GButton.prototype, "title", {
  3100. get: function () {
  3101. return this._title;
  3102. },
  3103. set: function (value) {
  3104. this._title = value;
  3105. if (this._titleObject)
  3106. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3107. this.updateGear(6);
  3108. },
  3109. enumerable: false,
  3110. configurable: true
  3111. });
  3112. Object.defineProperty(GButton.prototype, "text", {
  3113. get: function () {
  3114. return this.title;
  3115. },
  3116. set: function (value) {
  3117. this.title = value;
  3118. },
  3119. enumerable: false,
  3120. configurable: true
  3121. });
  3122. Object.defineProperty(GButton.prototype, "selectedTitle", {
  3123. get: function () {
  3124. return this._selectedTitle;
  3125. },
  3126. set: function (value) {
  3127. this._selectedTitle = value;
  3128. if (this._titleObject)
  3129. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3130. },
  3131. enumerable: false,
  3132. configurable: true
  3133. });
  3134. Object.defineProperty(GButton.prototype, "titleColor", {
  3135. get: function () {
  3136. var tf = this.getTextField();
  3137. if (tf)
  3138. return tf.color;
  3139. else
  3140. return cc.Color.BLACK;
  3141. },
  3142. set: function (value) {
  3143. var tf = this.getTextField();
  3144. if (tf)
  3145. tf.color = value;
  3146. },
  3147. enumerable: false,
  3148. configurable: true
  3149. });
  3150. Object.defineProperty(GButton.prototype, "titleFontSize", {
  3151. get: function () {
  3152. var tf = this.getTextField();
  3153. if (tf)
  3154. return tf.fontSize;
  3155. else
  3156. return 0;
  3157. },
  3158. set: function (value) {
  3159. var tf = this.getTextField();
  3160. if (tf)
  3161. tf.fontSize = value;
  3162. },
  3163. enumerable: false,
  3164. configurable: true
  3165. });
  3166. Object.defineProperty(GButton.prototype, "sound", {
  3167. get: function () {
  3168. return this._sound;
  3169. },
  3170. set: function (val) {
  3171. this._sound = val;
  3172. },
  3173. enumerable: false,
  3174. configurable: true
  3175. });
  3176. Object.defineProperty(GButton.prototype, "soundVolumeScale", {
  3177. get: function () {
  3178. return this._soundVolumeScale;
  3179. },
  3180. set: function (value) {
  3181. this._soundVolumeScale = value;
  3182. },
  3183. enumerable: false,
  3184. configurable: true
  3185. });
  3186. Object.defineProperty(GButton.prototype, "selected", {
  3187. get: function () {
  3188. return this._selected;
  3189. },
  3190. set: function (val) {
  3191. if (this._mode == fgui.ButtonMode.Common)
  3192. return;
  3193. if (this._selected != val) {
  3194. this._selected = val;
  3195. this.setCurrentState();
  3196. if (this._selectedTitle && this._titleObject)
  3197. this._titleObject.text = this._selected ? this._selectedTitle : this._title;
  3198. if (this._selectedIcon) {
  3199. var str = this._selected ? this._selectedIcon : this._icon;
  3200. if (this._iconObject)
  3201. this._iconObject.icon = str;
  3202. }
  3203. if (this._relatedController
  3204. && this._parent
  3205. && !this._parent._buildingDisplayList) {
  3206. if (this._selected) {
  3207. this._relatedController.selectedPageId = this._relatedPageId;
  3208. if (this._relatedController.autoRadioGroupDepth)
  3209. this._parent.adjustRadioGroupDepth(this, this._relatedController);
  3210. }
  3211. else if (this._mode == fgui.ButtonMode.Check && this._relatedController.selectedPageId == this._relatedPageId)
  3212. this._relatedController.oppositePageId = this._relatedPageId;
  3213. }
  3214. }
  3215. },
  3216. enumerable: false,
  3217. configurable: true
  3218. });
  3219. Object.defineProperty(GButton.prototype, "mode", {
  3220. get: function () {
  3221. return this._mode;
  3222. },
  3223. set: function (value) {
  3224. if (this._mode != value) {
  3225. if (value == fgui.ButtonMode.Common)
  3226. this.selected = false;
  3227. this._mode = value;
  3228. }
  3229. },
  3230. enumerable: false,
  3231. configurable: true
  3232. });
  3233. Object.defineProperty(GButton.prototype, "relatedController", {
  3234. get: function () {
  3235. return this._relatedController;
  3236. },
  3237. set: function (val) {
  3238. this._relatedController = val;
  3239. },
  3240. enumerable: false,
  3241. configurable: true
  3242. });
  3243. Object.defineProperty(GButton.prototype, "relatedPageId", {
  3244. get: function () {
  3245. return this._relatedPageId;
  3246. },
  3247. set: function (val) {
  3248. this._relatedPageId = val;
  3249. },
  3250. enumerable: false,
  3251. configurable: true
  3252. });
  3253. Object.defineProperty(GButton.prototype, "changeStateOnClick", {
  3254. get: function () {
  3255. return this._changeStateOnClick;
  3256. },
  3257. set: function (value) {
  3258. this._changeStateOnClick = value;
  3259. },
  3260. enumerable: false,
  3261. configurable: true
  3262. });
  3263. Object.defineProperty(GButton.prototype, "linkedPopup", {
  3264. get: function () {
  3265. return this._linkedPopup;
  3266. },
  3267. set: function (value) {
  3268. this._linkedPopup = value;
  3269. },
  3270. enumerable: false,
  3271. configurable: true
  3272. });
  3273. GButton.prototype.getTextField = function () {
  3274. if (this._titleObject instanceof fgui.GTextField)
  3275. return this._titleObject;
  3276. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof GButton))
  3277. return this._titleObject.getTextField();
  3278. else
  3279. return null;
  3280. };
  3281. GButton.prototype.fireClick = function () {
  3282. fgui.GRoot.inst.inputProcessor.simulateClick(this);
  3283. };
  3284. GButton.prototype.setState = function (val) {
  3285. if (this._buttonController)
  3286. this._buttonController.selectedPage = val;
  3287. if (this._downEffect == 1) {
  3288. var cnt = this.numChildren;
  3289. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3290. if (!this._downColor)
  3291. this._downColor = new cc.Color();
  3292. var r = this._downEffectValue * 255;
  3293. this._downColor.r = this._downColor.g = this._downColor.b = r;
  3294. for (var i = 0; i < cnt; i++) {
  3295. var obj = this.getChildAt(i);
  3296. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  3297. obj.color = this._downColor;
  3298. }
  3299. }
  3300. else {
  3301. for (var i = 0; i < cnt; i++) {
  3302. var obj = this.getChildAt(i);
  3303. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  3304. obj.color = cc.Color.WHITE;
  3305. }
  3306. }
  3307. }
  3308. else if (this._downEffect == 2) {
  3309. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3310. if (!this._downScaled) {
  3311. this._downScaled = true;
  3312. this.setScale(this.scaleX * this._downEffectValue, this.scaleY * this._downEffectValue);
  3313. }
  3314. }
  3315. else {
  3316. if (this._downScaled) {
  3317. this._downScaled = false;
  3318. this.setScale(this.scaleX / this._downEffectValue, this.scaleY / this._downEffectValue);
  3319. }
  3320. }
  3321. }
  3322. };
  3323. GButton.prototype.setCurrentState = function () {
  3324. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3325. if (this._selected)
  3326. this.setState(GButton.SELECTED_DISABLED);
  3327. else
  3328. this.setState(GButton.DISABLED);
  3329. }
  3330. else {
  3331. if (this._selected)
  3332. this.setState(this._over ? GButton.SELECTED_OVER : GButton.DOWN);
  3333. else
  3334. this.setState(this._over ? GButton.OVER : GButton.UP);
  3335. }
  3336. };
  3337. GButton.prototype.handleControllerChanged = function (c) {
  3338. _super.prototype.handleControllerChanged.call(this, c);
  3339. if (this._relatedController == c)
  3340. this.selected = this._relatedPageId == c.selectedPageId;
  3341. };
  3342. GButton.prototype.handleGrayedChanged = function () {
  3343. if (this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3344. if (this.grayed) {
  3345. if (this._selected && this._buttonController.hasPage(GButton.SELECTED_DISABLED))
  3346. this.setState(GButton.SELECTED_DISABLED);
  3347. else
  3348. this.setState(GButton.DISABLED);
  3349. }
  3350. else if (this._selected)
  3351. this.setState(GButton.DOWN);
  3352. else
  3353. this.setState(GButton.UP);
  3354. }
  3355. else
  3356. _super.prototype.handleGrayedChanged.call(this);
  3357. };
  3358. GButton.prototype.getProp = function (index) {
  3359. switch (index) {
  3360. case fgui.ObjectPropID.Color:
  3361. return this.titleColor;
  3362. case fgui.ObjectPropID.OutlineColor:
  3363. {
  3364. var tf = this.getTextField();
  3365. if (tf)
  3366. return tf.strokeColor;
  3367. else
  3368. return 0;
  3369. }
  3370. case fgui.ObjectPropID.FontSize:
  3371. return this.titleFontSize;
  3372. case fgui.ObjectPropID.Selected:
  3373. return this.selected;
  3374. default:
  3375. return _super.prototype.getProp.call(this, index);
  3376. }
  3377. };
  3378. GButton.prototype.setProp = function (index, value) {
  3379. switch (index) {
  3380. case fgui.ObjectPropID.Color:
  3381. this.titleColor = value;
  3382. break;
  3383. case fgui.ObjectPropID.OutlineColor:
  3384. {
  3385. var tf = this.getTextField();
  3386. if (tf)
  3387. tf.strokeColor = value;
  3388. }
  3389. break;
  3390. case fgui.ObjectPropID.FontSize:
  3391. this.titleFontSize = value;
  3392. break;
  3393. case fgui.ObjectPropID.Selected:
  3394. this.selected = value;
  3395. break;
  3396. default:
  3397. _super.prototype.setProp.call(this, index, value);
  3398. break;
  3399. }
  3400. };
  3401. GButton.prototype.constructExtension = function (buffer) {
  3402. buffer.seek(0, 6);
  3403. this._mode = buffer.readByte();
  3404. var str = buffer.readS();
  3405. if (str)
  3406. this._sound = str;
  3407. this._soundVolumeScale = buffer.readFloat();
  3408. this._downEffect = buffer.readByte();
  3409. this._downEffectValue = buffer.readFloat();
  3410. if (this._downEffect == 2)
  3411. this.setPivot(0.5, 0.5, this.pivotAsAnchor);
  3412. this._buttonController = this.getController("button");
  3413. this._titleObject = this.getChild("title");
  3414. this._iconObject = this.getChild("icon");
  3415. if (this._titleObject)
  3416. this._title = this._titleObject.text;
  3417. if (this._iconObject)
  3418. this._icon = this._iconObject.icon;
  3419. if (this._mode == fgui.ButtonMode.Common)
  3420. this.setState(GButton.UP);
  3421. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3422. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3423. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3424. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3425. this._node.on(fgui.Event.CLICK, this.onClick_1, this);
  3426. };
  3427. GButton.prototype.setup_afterAdd = function (buffer, beginPos) {
  3428. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3429. if (!buffer.seek(beginPos, 6))
  3430. return;
  3431. if (buffer.readByte() != this.packageItem.objectType)
  3432. return;
  3433. var str;
  3434. var iv;
  3435. str = buffer.readS();
  3436. if (str != null)
  3437. this.title = str;
  3438. str = buffer.readS();
  3439. if (str != null)
  3440. this.selectedTitle = str;
  3441. str = buffer.readS();
  3442. if (str != null)
  3443. this.icon = str;
  3444. str = buffer.readS();
  3445. if (str != null)
  3446. this.selectedIcon = str;
  3447. if (buffer.readBool())
  3448. this.titleColor = buffer.readColor();
  3449. iv = buffer.readInt();
  3450. if (iv != 0)
  3451. this.titleFontSize = iv;
  3452. iv = buffer.readShort();
  3453. if (iv >= 0)
  3454. this._relatedController = this.parent.getControllerAt(iv);
  3455. this._relatedPageId = buffer.readS();
  3456. str = buffer.readS();
  3457. if (str != null)
  3458. this._sound = str;
  3459. if (buffer.readBool())
  3460. this._soundVolumeScale = buffer.readFloat();
  3461. this.selected = buffer.readBool();
  3462. };
  3463. GButton.prototype.onRollOver_1 = function () {
  3464. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3465. return;
  3466. this._over = true;
  3467. if (this._down)
  3468. return;
  3469. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3470. return;
  3471. this.setState(this._selected ? GButton.SELECTED_OVER : GButton.OVER);
  3472. };
  3473. GButton.prototype.onRollOut_1 = function () {
  3474. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3475. return;
  3476. this._over = false;
  3477. if (this._down)
  3478. return;
  3479. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3480. return;
  3481. this.setState(this._selected ? GButton.DOWN : GButton.UP);
  3482. };
  3483. GButton.prototype.onTouchBegin_1 = function (evt) {
  3484. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3485. return;
  3486. this._down = true;
  3487. evt.captureTouch();
  3488. if (this._mode == fgui.ButtonMode.Common) {
  3489. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3490. this.setState(GButton.SELECTED_DISABLED);
  3491. else
  3492. this.setState(GButton.DOWN);
  3493. }
  3494. if (this._linkedPopup) {
  3495. if (this._linkedPopup instanceof fgui.Window)
  3496. this._linkedPopup.toggleStatus();
  3497. else
  3498. this.root.togglePopup(this._linkedPopup, this);
  3499. }
  3500. };
  3501. GButton.prototype.onTouchEnd_1 = function (evt) {
  3502. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3503. return;
  3504. if (this._down) {
  3505. this._down = false;
  3506. if (this._node == null)
  3507. return;
  3508. if (this._mode == fgui.ButtonMode.Common) {
  3509. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3510. this.setState(GButton.DISABLED);
  3511. else if (this._over)
  3512. this.setState(GButton.OVER);
  3513. else
  3514. this.setState(GButton.UP);
  3515. }
  3516. else {
  3517. if (!this._over
  3518. && this._buttonController != null
  3519. && (this._buttonController.selectedPage == GButton.OVER
  3520. || this._buttonController.selectedPage == GButton.SELECTED_OVER)) {
  3521. this.setCurrentState();
  3522. }
  3523. }
  3524. }
  3525. };
  3526. GButton.prototype.onClick_1 = function () {
  3527. if (this._sound) {
  3528. var pi = fgui.UIPackage.getItemByURL(this._sound);
  3529. if (pi) {
  3530. var sound = pi.owner.getItemAsset(pi);
  3531. if (sound)
  3532. fgui.GRoot.inst.playOneShotSound(sound, this._soundVolumeScale);
  3533. }
  3534. }
  3535. if (this._mode == fgui.ButtonMode.Check) {
  3536. if (this._changeStateOnClick) {
  3537. this.selected = !this._selected;
  3538. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3539. }
  3540. }
  3541. else if (this._mode == fgui.ButtonMode.Radio) {
  3542. if (this._changeStateOnClick && !this._selected) {
  3543. this.selected = true;
  3544. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3545. }
  3546. }
  3547. else {
  3548. if (this._relatedController)
  3549. this._relatedController.selectedPageId = this._relatedPageId;
  3550. }
  3551. };
  3552. GButton.UP = "up";
  3553. GButton.DOWN = "down";
  3554. GButton.OVER = "over";
  3555. GButton.SELECTED_OVER = "selectedOver";
  3556. GButton.DISABLED = "disabled";
  3557. GButton.SELECTED_DISABLED = "selectedDisabled";
  3558. return GButton;
  3559. }(fgui.GComponent));
  3560. fgui.GButton = GButton;
  3561. })(fgui || (fgui = {}));
  3562. (function (fgui) {
  3563. var GComboBox = (function (_super) {
  3564. __extends(GComboBox, _super);
  3565. function GComboBox() {
  3566. var _this = _super.call(this) || this;
  3567. _this._visibleItemCount = 0;
  3568. _this._selectedIndex = 0;
  3569. _this._popupDirection = fgui.PopupDirection.Auto;
  3570. _this._node.name = "GComboBox";
  3571. _this._visibleItemCount = fgui.UIConfig.defaultComboBoxVisibleItemCount;
  3572. _this._itemsUpdated = true;
  3573. _this._selectedIndex = -1;
  3574. _this._items = [];
  3575. _this._values = [];
  3576. return _this;
  3577. }
  3578. Object.defineProperty(GComboBox.prototype, "text", {
  3579. get: function () {
  3580. if (this._titleObject)
  3581. return this._titleObject.text;
  3582. else
  3583. return null;
  3584. },
  3585. set: function (value) {
  3586. if (this._titleObject)
  3587. this._titleObject.text = value;
  3588. this.updateGear(6);
  3589. },
  3590. enumerable: false,
  3591. configurable: true
  3592. });
  3593. Object.defineProperty(GComboBox.prototype, "icon", {
  3594. get: function () {
  3595. if (this._iconObject)
  3596. return this._iconObject.icon;
  3597. else
  3598. return null;
  3599. },
  3600. set: function (value) {
  3601. if (this._iconObject)
  3602. this._iconObject.icon = value;
  3603. this.updateGear(7);
  3604. },
  3605. enumerable: false,
  3606. configurable: true
  3607. });
  3608. Object.defineProperty(GComboBox.prototype, "titleColor", {
  3609. get: function () {
  3610. var tf = this.getTextField();
  3611. if (tf)
  3612. return tf.color;
  3613. else
  3614. return cc.Color.BLACK;
  3615. },
  3616. set: function (value) {
  3617. var tf = this.getTextField();
  3618. if (tf)
  3619. tf.color = value;
  3620. },
  3621. enumerable: false,
  3622. configurable: true
  3623. });
  3624. Object.defineProperty(GComboBox.prototype, "titleFontSize", {
  3625. get: function () {
  3626. var tf = this.getTextField();
  3627. if (tf)
  3628. return tf.fontSize;
  3629. else
  3630. return 0;
  3631. },
  3632. set: function (value) {
  3633. var tf = this.getTextField();
  3634. if (tf)
  3635. tf.fontSize = value;
  3636. },
  3637. enumerable: false,
  3638. configurable: true
  3639. });
  3640. Object.defineProperty(GComboBox.prototype, "visibleItemCount", {
  3641. get: function () {
  3642. return this._visibleItemCount;
  3643. },
  3644. set: function (value) {
  3645. this._visibleItemCount = value;
  3646. },
  3647. enumerable: false,
  3648. configurable: true
  3649. });
  3650. Object.defineProperty(GComboBox.prototype, "popupDirection", {
  3651. get: function () {
  3652. return this._popupDirection;
  3653. },
  3654. set: function (value) {
  3655. this._popupDirection = value;
  3656. },
  3657. enumerable: false,
  3658. configurable: true
  3659. });
  3660. Object.defineProperty(GComboBox.prototype, "items", {
  3661. get: function () {
  3662. return this._items;
  3663. },
  3664. set: function (value) {
  3665. if (!value)
  3666. this._items.length = 0;
  3667. else
  3668. this._items = value.concat();
  3669. if (this._items.length > 0) {
  3670. if (this._selectedIndex >= this._items.length)
  3671. this._selectedIndex = this._items.length - 1;
  3672. else if (this._selectedIndex == -1)
  3673. this._selectedIndex = 0;
  3674. this.text = this._items[this._selectedIndex];
  3675. if (this._icons && this._selectedIndex < this._icons.length)
  3676. this.icon = this._icons[this._selectedIndex];
  3677. }
  3678. else {
  3679. this.text = "";
  3680. if (this._icons)
  3681. this.icon = null;
  3682. this._selectedIndex = -1;
  3683. }
  3684. this._itemsUpdated = true;
  3685. },
  3686. enumerable: false,
  3687. configurable: true
  3688. });
  3689. Object.defineProperty(GComboBox.prototype, "icons", {
  3690. get: function () {
  3691. return this._icons;
  3692. },
  3693. set: function (value) {
  3694. this._icons = value;
  3695. if (this._icons && this._selectedIndex != -1 && this._selectedIndex < this._icons.length)
  3696. this.icon = this._icons[this._selectedIndex];
  3697. },
  3698. enumerable: false,
  3699. configurable: true
  3700. });
  3701. Object.defineProperty(GComboBox.prototype, "values", {
  3702. get: function () {
  3703. return this._values;
  3704. },
  3705. set: function (value) {
  3706. if (!value)
  3707. this._values.length = 0;
  3708. else
  3709. this._values = value.concat();
  3710. },
  3711. enumerable: false,
  3712. configurable: true
  3713. });
  3714. Object.defineProperty(GComboBox.prototype, "selectedIndex", {
  3715. get: function () {
  3716. return this._selectedIndex;
  3717. },
  3718. set: function (val) {
  3719. if (this._selectedIndex == val)
  3720. return;
  3721. this._selectedIndex = val;
  3722. if (this._selectedIndex >= 0 && this._selectedIndex < this._items.length) {
  3723. this.text = this._items[this._selectedIndex];
  3724. if (this._icons && this._selectedIndex < this._icons.length)
  3725. this.icon = this._icons[this._selectedIndex];
  3726. }
  3727. else {
  3728. this.text = "";
  3729. if (this._icons)
  3730. this.icon = null;
  3731. }
  3732. this.updateSelectionController();
  3733. },
  3734. enumerable: false,
  3735. configurable: true
  3736. });
  3737. Object.defineProperty(GComboBox.prototype, "value", {
  3738. get: function () {
  3739. return this._values[this._selectedIndex];
  3740. },
  3741. set: function (val) {
  3742. var index = this._values.indexOf(val);
  3743. if (index == -1 && val == null)
  3744. index = this._values.indexOf("");
  3745. this.selectedIndex = index;
  3746. },
  3747. enumerable: false,
  3748. configurable: true
  3749. });
  3750. Object.defineProperty(GComboBox.prototype, "selectionController", {
  3751. get: function () {
  3752. return this._selectionController;
  3753. },
  3754. set: function (value) {
  3755. this._selectionController = value;
  3756. },
  3757. enumerable: false,
  3758. configurable: true
  3759. });
  3760. GComboBox.prototype.getTextField = function () {
  3761. if (this._titleObject instanceof fgui.GTextField)
  3762. return this._titleObject;
  3763. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof fgui.GButton))
  3764. return this._titleObject.getTextField();
  3765. else
  3766. return null;
  3767. };
  3768. GComboBox.prototype.setState = function (val) {
  3769. if (this._buttonController)
  3770. this._buttonController.selectedPage = val;
  3771. };
  3772. GComboBox.prototype.getProp = function (index) {
  3773. switch (index) {
  3774. case fgui.ObjectPropID.Color:
  3775. return this.titleColor;
  3776. case fgui.ObjectPropID.OutlineColor:
  3777. {
  3778. var tf = this.getTextField();
  3779. if (tf)
  3780. return tf.strokeColor;
  3781. else
  3782. return 0;
  3783. }
  3784. case fgui.ObjectPropID.FontSize:
  3785. {
  3786. tf = this.getTextField();
  3787. if (tf)
  3788. return tf.fontSize;
  3789. else
  3790. return 0;
  3791. }
  3792. default:
  3793. return _super.prototype.getProp.call(this, index);
  3794. }
  3795. };
  3796. GComboBox.prototype.setProp = function (index, value) {
  3797. switch (index) {
  3798. case fgui.ObjectPropID.Color:
  3799. this.titleColor = value;
  3800. break;
  3801. case fgui.ObjectPropID.OutlineColor:
  3802. {
  3803. var tf = this.getTextField();
  3804. if (tf)
  3805. tf.strokeColor = value;
  3806. }
  3807. break;
  3808. case fgui.ObjectPropID.FontSize:
  3809. {
  3810. tf = this.getTextField();
  3811. if (tf)
  3812. tf.fontSize = value;
  3813. }
  3814. break;
  3815. default:
  3816. _super.prototype.setProp.call(this, index, value);
  3817. break;
  3818. }
  3819. };
  3820. GComboBox.prototype.constructExtension = function (buffer) {
  3821. var str;
  3822. this._buttonController = this.getController("button");
  3823. this._titleObject = this.getChild("title");
  3824. this._iconObject = this.getChild("icon");
  3825. str = buffer.readS();
  3826. if (str) {
  3827. var obj = fgui.UIPackage.createObjectFromURL(str);
  3828. if (!(obj instanceof fgui.GComponent)) {
  3829. console.error("下拉框必须为元件");
  3830. return;
  3831. }
  3832. this.dropdown = obj;
  3833. this.dropdown.name = "this.dropdown";
  3834. this._list = this.dropdown.getChild("list");
  3835. if (this._list == null) {
  3836. console.error(this.resourceURL + ": 下拉框的弹出元件里必须包含名为list的列表");
  3837. return;
  3838. }
  3839. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  3840. this._list.addRelation(this.dropdown, fgui.RelationType.Width);
  3841. this._list.removeRelation(this.dropdown, fgui.RelationType.Height);
  3842. this.dropdown.addRelation(this._list, fgui.RelationType.Height);
  3843. this.dropdown.removeRelation(this._list, fgui.RelationType.Width);
  3844. this.dropdown.on(fgui.Event.UNDISPLAY, this.onPopupClosed, this);
  3845. }
  3846. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3847. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3848. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3849. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3850. };
  3851. GComboBox.prototype.handleControllerChanged = function (c) {
  3852. _super.prototype.handleControllerChanged.call(this, c);
  3853. if (this._selectionController == c)
  3854. this.selectedIndex = c.selectedIndex;
  3855. };
  3856. GComboBox.prototype.updateSelectionController = function () {
  3857. if (this._selectionController && !this._selectionController.changing
  3858. && this._selectedIndex < this._selectionController.pageCount) {
  3859. var c = this._selectionController;
  3860. this._selectionController = null;
  3861. c.selectedIndex = this._selectedIndex;
  3862. this._selectionController = c;
  3863. }
  3864. };
  3865. GComboBox.prototype.dispose = function () {
  3866. if (this.dropdown) {
  3867. this.dropdown.dispose();
  3868. this.dropdown = null;
  3869. }
  3870. _super.prototype.dispose.call(this);
  3871. };
  3872. GComboBox.prototype.setup_afterAdd = function (buffer, beginPos) {
  3873. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3874. if (!buffer.seek(beginPos, 6))
  3875. return;
  3876. if (buffer.readByte() != this.packageItem.objectType)
  3877. return;
  3878. var i;
  3879. var iv;
  3880. var nextPos;
  3881. var str;
  3882. var itemCount = buffer.readShort();
  3883. for (i = 0; i < itemCount; i++) {
  3884. nextPos = buffer.readShort();
  3885. nextPos += buffer.position;
  3886. this._items[i] = buffer.readS();
  3887. this._values[i] = buffer.readS();
  3888. str = buffer.readS();
  3889. if (str != null) {
  3890. if (this._icons == null)
  3891. this._icons = new Array();
  3892. this._icons[i] = str;
  3893. }
  3894. buffer.position = nextPos;
  3895. }
  3896. str = buffer.readS();
  3897. if (str != null) {
  3898. this.text = str;
  3899. this._selectedIndex = this._items.indexOf(str);
  3900. }
  3901. else if (this._items.length > 0) {
  3902. this._selectedIndex = 0;
  3903. this.text = this._items[0];
  3904. }
  3905. else
  3906. this._selectedIndex = -1;
  3907. str = buffer.readS();
  3908. if (str != null)
  3909. this.icon = str;
  3910. if (buffer.readBool())
  3911. this.titleColor = buffer.readColor();
  3912. iv = buffer.readInt();
  3913. if (iv > 0)
  3914. this._visibleItemCount = iv;
  3915. this._popupDirection = buffer.readByte();
  3916. iv = buffer.readShort();
  3917. if (iv >= 0)
  3918. this._selectionController = this.parent.getControllerAt(iv);
  3919. };
  3920. GComboBox.prototype.showDropdown = function () {
  3921. if (this._itemsUpdated) {
  3922. this._itemsUpdated = false;
  3923. this._list.removeChildrenToPool();
  3924. var cnt = this._items.length;
  3925. for (var i = 0; i < cnt; i++) {
  3926. var item = this._list.addItemFromPool();
  3927. item.name = i < this._values.length ? this._values[i] : "";
  3928. item.text = this._items[i];
  3929. item.icon = (this._icons && i < this._icons.length) ? this._icons[i] : null;
  3930. }
  3931. this._list.resizeToFit(this._visibleItemCount);
  3932. }
  3933. this._list.selectedIndex = -1;
  3934. this.dropdown.width = this.width;
  3935. this._list.ensureBoundsCorrect();
  3936. this.root.togglePopup(this.dropdown, this, this._popupDirection);
  3937. if (this.dropdown.parent)
  3938. this.setState(fgui.GButton.DOWN);
  3939. };
  3940. GComboBox.prototype.onPopupClosed = function () {
  3941. if (this._over)
  3942. this.setState(fgui.GButton.OVER);
  3943. else
  3944. this.setState(fgui.GButton.UP);
  3945. };
  3946. GComboBox.prototype.onClickItem = function (itemObject) {
  3947. var _t = this;
  3948. var index = this._list.getChildIndex(itemObject);
  3949. this._partner.callLater(function (dt) {
  3950. _t.onClickItem2(index);
  3951. }, 0.1);
  3952. };
  3953. GComboBox.prototype.onClickItem2 = function (index) {
  3954. if (this.dropdown.parent instanceof fgui.GRoot)
  3955. this.dropdown.parent.hidePopup();
  3956. this._selectedIndex = -1;
  3957. this.selectedIndex = index;
  3958. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3959. };
  3960. GComboBox.prototype.onRollOver_1 = function () {
  3961. this._over = true;
  3962. if (this._down || this.dropdown && this.dropdown.parent)
  3963. return;
  3964. this.setState(fgui.GButton.OVER);
  3965. };
  3966. GComboBox.prototype.onRollOut_1 = function () {
  3967. this._over = false;
  3968. if (this._down || this.dropdown && this.dropdown.parent)
  3969. return;
  3970. this.setState(fgui.GButton.UP);
  3971. };
  3972. GComboBox.prototype.onTouchBegin_1 = function (evt) {
  3973. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3974. return;
  3975. if ((evt.initiator instanceof fgui.GTextInput) && evt.initiator.editable)
  3976. return;
  3977. this._down = true;
  3978. evt.captureTouch();
  3979. if (this.dropdown)
  3980. this.showDropdown();
  3981. };
  3982. GComboBox.prototype.onTouchEnd_1 = function (evt) {
  3983. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3984. return;
  3985. if (this._down) {
  3986. this._down = false;
  3987. if (this.dropdown && !this.dropdown.parent) {
  3988. if (this._over)
  3989. this.setState(fgui.GButton.OVER);
  3990. else
  3991. this.setState(fgui.GButton.UP);
  3992. }
  3993. }
  3994. };
  3995. return GComboBox;
  3996. }(fgui.GComponent));
  3997. fgui.GComboBox = GComboBox;
  3998. })(fgui || (fgui = {}));
  3999. (function (fgui) {
  4000. var GGraph = (function (_super) {
  4001. __extends(GGraph, _super);
  4002. function GGraph() {
  4003. var _this = _super.call(this) || this;
  4004. _this._type = 0;
  4005. _this._lineSize = 0;
  4006. _this._node.name = "GGraph";
  4007. _this._lineSize = 1;
  4008. _this._lineColor = new cc.Color();
  4009. _this._fillColor = new cc.Color(255, 255, 255, 255);
  4010. _this._content = _this._node.addComponent(cc.Graphics);
  4011. return _this;
  4012. }
  4013. GGraph.prototype.drawRect = function (lineSize, lineColor, fillColor, corner) {
  4014. this._type = 1;
  4015. this._lineSize = lineSize;
  4016. this._lineColor.set(lineColor);
  4017. this._fillColor.set(fillColor);
  4018. this._cornerRadius = corner;
  4019. this.updateGraph();
  4020. };
  4021. GGraph.prototype.drawEllipse = function (lineSize, lineColor, fillColor) {
  4022. this._type = 2;
  4023. this._lineSize = lineSize;
  4024. this._lineColor.set(lineColor);
  4025. this._fillColor.set(fillColor);
  4026. this.updateGraph();
  4027. };
  4028. GGraph.prototype.drawRegularPolygon = function (lineSize, lineColor, fillColor, sides, startAngle, distances) {
  4029. this._type = 4;
  4030. this._lineSize = lineSize;
  4031. this._lineColor.set(lineColor);
  4032. this._fillColor.set(fillColor);
  4033. this._sides = sides;
  4034. this._startAngle = startAngle || 0;
  4035. this._distances = distances;
  4036. this.updateGraph();
  4037. };
  4038. GGraph.prototype.drawPolygon = function (lineSize, lineColor, fillColor, points) {
  4039. this._type = 3;
  4040. this._lineSize = lineSize;
  4041. this._lineColor.set(lineColor);
  4042. this._fillColor.set(fillColor);
  4043. this._polygonPoints = points;
  4044. this.updateGraph();
  4045. };
  4046. Object.defineProperty(GGraph.prototype, "distances", {
  4047. get: function () {
  4048. return this._distances;
  4049. },
  4050. set: function (value) {
  4051. this._distances = value;
  4052. if (this._type == 3)
  4053. this.updateGraph();
  4054. },
  4055. enumerable: false,
  4056. configurable: true
  4057. });
  4058. GGraph.prototype.clearGraphics = function () {
  4059. this._type = 0;
  4060. if (this._hasContent) {
  4061. this._content.clear();
  4062. this._hasContent = false;
  4063. }
  4064. };
  4065. Object.defineProperty(GGraph.prototype, "type", {
  4066. get: function () {
  4067. return this._type;
  4068. },
  4069. enumerable: false,
  4070. configurable: true
  4071. });
  4072. Object.defineProperty(GGraph.prototype, "color", {
  4073. get: function () {
  4074. return this._fillColor;
  4075. },
  4076. set: function (value) {
  4077. this._fillColor.set(value);
  4078. if (this._type != 0)
  4079. this.updateGraph();
  4080. },
  4081. enumerable: false,
  4082. configurable: true
  4083. });
  4084. GGraph.prototype.updateGraph = function () {
  4085. var ctx = this._content;
  4086. if (this._hasContent) {
  4087. this._hasContent = false;
  4088. ctx.clear();
  4089. }
  4090. var w = this._width;
  4091. var h = this._height;
  4092. if (w == 0 || h == 0)
  4093. return;
  4094. var px = -this.pivotX * this._width;
  4095. var py = this.pivotY * this._height;
  4096. var ls = this._lineSize / 2;
  4097. ctx.lineWidth = this._lineSize;
  4098. ctx.strokeColor = this._lineColor;
  4099. ctx.fillColor = this._fillColor;
  4100. if (this._type == 1) {
  4101. if (this._cornerRadius) {
  4102. ctx.roundRect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize, this._cornerRadius[0]);
  4103. }
  4104. else
  4105. ctx.rect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize);
  4106. }
  4107. else if (this._type == 2) {
  4108. ctx.ellipse(w / 2 + px, -h / 2 + py, w / 2 - ls, h / 2 - ls);
  4109. }
  4110. else if (this._type == 3) {
  4111. this.drawPath(ctx, this._polygonPoints, px, py);
  4112. }
  4113. else if (this._type == 4) {
  4114. if (!this._polygonPoints)
  4115. this._polygonPoints = [];
  4116. var radius = Math.min(w, h) / 2 - ls;
  4117. this._polygonPoints.length = 0;
  4118. var angle = cc.misc.degreesToRadians(this._startAngle);
  4119. var deltaAngle = 2 * Math.PI / this._sides;
  4120. var dist;
  4121. for (var i = 0; i < this._sides; i++) {
  4122. if (this._distances) {
  4123. dist = this._distances[i];
  4124. if (isNaN(dist))
  4125. dist = 1;
  4126. }
  4127. else
  4128. dist = 1;
  4129. var xv = radius + radius * dist * Math.cos(angle);
  4130. var yv = radius + radius * dist * Math.sin(angle);
  4131. this._polygonPoints.push(xv, yv);
  4132. angle += deltaAngle;
  4133. }
  4134. this.drawPath(ctx, this._polygonPoints, px, py);
  4135. }
  4136. if (ls != 0)
  4137. ctx.stroke();
  4138. if (this._fillColor.a != 0)
  4139. ctx.fill();
  4140. this._hasContent = true;
  4141. };
  4142. GGraph.prototype.drawPath = function (ctx, points, px, py) {
  4143. var cnt = points.length;
  4144. ctx.moveTo(points[0] + px, -points[1] + py);
  4145. for (var i = 2; i < cnt; i += 2)
  4146. ctx.lineTo(points[i] + px, -points[i + 1] + py);
  4147. ctx.lineTo(points[0] + px, -points[1] + py);
  4148. };
  4149. GGraph.prototype.handleSizeChanged = function () {
  4150. _super.prototype.handleSizeChanged.call(this);
  4151. if (this._type != 0)
  4152. this.updateGraph();
  4153. };
  4154. GGraph.prototype.handleAnchorChanged = function () {
  4155. _super.prototype.handleAnchorChanged.call(this);
  4156. if (this._type != 0)
  4157. this.updateGraph();
  4158. };
  4159. GGraph.prototype.getProp = function (index) {
  4160. if (index == fgui.ObjectPropID.Color)
  4161. return this.color;
  4162. else
  4163. return _super.prototype.getProp.call(this, index);
  4164. };
  4165. GGraph.prototype.setProp = function (index, value) {
  4166. if (index == fgui.ObjectPropID.Color)
  4167. this.color = value;
  4168. else
  4169. _super.prototype.setProp.call(this, index, value);
  4170. };
  4171. GGraph.prototype._hitTest = function (pt) {
  4172. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height) {
  4173. if (this._type == 3) {
  4174. var points = this._polygonPoints;
  4175. var len = points.length / 2;
  4176. var i = void 0;
  4177. var j = len - 1;
  4178. var oddNodes = false;
  4179. var w = this._width;
  4180. var h = this._height;
  4181. for (i = 0; i < len; ++i) {
  4182. var ix = points[i * 2];
  4183. var iy = points[i * 2 + 1];
  4184. var jx = points[j * 2];
  4185. var jy = points[j * 2 + 1];
  4186. if ((iy < pt.y && jy >= pt.y || jy < pt.y && iy >= pt.y) && (ix <= pt.x || jx <= pt.x)) {
  4187. if (ix + (pt.y - iy) / (jy - iy) * (jx - ix) < pt.x)
  4188. oddNodes = !oddNodes;
  4189. }
  4190. j = i;
  4191. }
  4192. return oddNodes ? this : null;
  4193. }
  4194. else
  4195. return this;
  4196. }
  4197. else
  4198. return null;
  4199. };
  4200. GGraph.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4201. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4202. buffer.seek(beginPos, 5);
  4203. this._type = buffer.readByte();
  4204. if (this._type != 0) {
  4205. var i;
  4206. var cnt;
  4207. this._lineSize = buffer.readInt();
  4208. this._lineColor.set(buffer.readColor(true));
  4209. this._fillColor.set(buffer.readColor(true));
  4210. if (buffer.readBool()) {
  4211. this._cornerRadius = new Array(4);
  4212. for (i = 0; i < 4; i++)
  4213. this._cornerRadius[i] = buffer.readFloat();
  4214. }
  4215. if (this._type == 3) {
  4216. cnt = buffer.readShort();
  4217. this._polygonPoints = [];
  4218. this._polygonPoints.length = cnt;
  4219. for (i = 0; i < cnt; i++)
  4220. this._polygonPoints[i] = buffer.readFloat();
  4221. }
  4222. else if (this._type == 4) {
  4223. this._sides = buffer.readShort();
  4224. this._startAngle = buffer.readFloat();
  4225. cnt = buffer.readShort();
  4226. if (cnt > 0) {
  4227. this._distances = [];
  4228. for (i = 0; i < cnt; i++)
  4229. this._distances[i] = buffer.readFloat();
  4230. }
  4231. }
  4232. this.updateGraph();
  4233. }
  4234. };
  4235. return GGraph;
  4236. }(fgui.GObject));
  4237. fgui.GGraph = GGraph;
  4238. })(fgui || (fgui = {}));
  4239. (function (fgui) {
  4240. var GGroup = (function (_super) {
  4241. __extends(GGroup, _super);
  4242. function GGroup() {
  4243. var _this = _super.call(this) || this;
  4244. _this._layout = 0;
  4245. _this._lineGap = 0;
  4246. _this._columnGap = 0;
  4247. _this._mainGridIndex = -1;
  4248. _this._mainGridMinSize = 50;
  4249. _this._mainChildIndex = -1;
  4250. _this._totalSize = 0;
  4251. _this._numChildren = 0;
  4252. _this._updating = 0;
  4253. _this._node.name = "GGroup";
  4254. _this._touchDisabled = true;
  4255. return _this;
  4256. }
  4257. GGroup.prototype.dispose = function () {
  4258. this._boundsChanged = false;
  4259. _super.prototype.dispose.call(this);
  4260. };
  4261. Object.defineProperty(GGroup.prototype, "layout", {
  4262. get: function () {
  4263. return this._layout;
  4264. },
  4265. set: function (value) {
  4266. if (this._layout != value) {
  4267. this._layout = value;
  4268. this.setBoundsChangedFlag();
  4269. }
  4270. },
  4271. enumerable: false,
  4272. configurable: true
  4273. });
  4274. Object.defineProperty(GGroup.prototype, "lineGap", {
  4275. get: function () {
  4276. return this._lineGap;
  4277. },
  4278. set: function (value) {
  4279. if (this._lineGap != value) {
  4280. this._lineGap = value;
  4281. this.setBoundsChangedFlag(true);
  4282. }
  4283. },
  4284. enumerable: false,
  4285. configurable: true
  4286. });
  4287. Object.defineProperty(GGroup.prototype, "columnGap", {
  4288. get: function () {
  4289. return this._columnGap;
  4290. },
  4291. set: function (value) {
  4292. if (this._columnGap != value) {
  4293. this._columnGap = value;
  4294. this.setBoundsChangedFlag(true);
  4295. }
  4296. },
  4297. enumerable: false,
  4298. configurable: true
  4299. });
  4300. Object.defineProperty(GGroup.prototype, "excludeInvisibles", {
  4301. get: function () {
  4302. return this._excludeInvisibles;
  4303. },
  4304. set: function (value) {
  4305. if (this._excludeInvisibles != value) {
  4306. this._excludeInvisibles = value;
  4307. this.setBoundsChangedFlag();
  4308. }
  4309. },
  4310. enumerable: false,
  4311. configurable: true
  4312. });
  4313. Object.defineProperty(GGroup.prototype, "autoSizeDisabled", {
  4314. get: function () {
  4315. return this._autoSizeDisabled;
  4316. },
  4317. set: function (value) {
  4318. this._autoSizeDisabled = value;
  4319. },
  4320. enumerable: false,
  4321. configurable: true
  4322. });
  4323. Object.defineProperty(GGroup.prototype, "mainGridMinSize", {
  4324. get: function () {
  4325. return this._mainGridMinSize;
  4326. },
  4327. set: function (value) {
  4328. if (this._mainGridMinSize != value) {
  4329. this._mainGridMinSize = value;
  4330. this.setBoundsChangedFlag();
  4331. }
  4332. },
  4333. enumerable: false,
  4334. configurable: true
  4335. });
  4336. Object.defineProperty(GGroup.prototype, "mainGridIndex", {
  4337. get: function () {
  4338. return this._mainGridIndex;
  4339. },
  4340. set: function (value) {
  4341. if (this._mainGridIndex != value) {
  4342. this._mainGridIndex = value;
  4343. this.setBoundsChangedFlag();
  4344. }
  4345. },
  4346. enumerable: false,
  4347. configurable: true
  4348. });
  4349. GGroup.prototype.setBoundsChangedFlag = function (positionChangedOnly) {
  4350. if (positionChangedOnly === void 0) { positionChangedOnly = false; }
  4351. if (this._updating == 0 && this._parent) {
  4352. if (!positionChangedOnly)
  4353. this._percentReady = false;
  4354. if (!this._boundsChanged) {
  4355. this._boundsChanged = true;
  4356. if (this._layout != fgui.GroupLayoutType.None)
  4357. this._partner.callLater(this._ensureBoundsCorrect);
  4358. }
  4359. }
  4360. };
  4361. GGroup.prototype._ensureBoundsCorrect = function () {
  4362. var _t = (this.node["$gobj"]);
  4363. _t.ensureBoundsCorrect();
  4364. };
  4365. GGroup.prototype.ensureSizeCorrect = function () {
  4366. if (this._parent == null || !this._boundsChanged || this._layout == 0)
  4367. return;
  4368. this._boundsChanged = false;
  4369. if (this._autoSizeDisabled)
  4370. this.resizeChildren(0, 0);
  4371. else {
  4372. this.handleLayout();
  4373. this.updateBounds();
  4374. }
  4375. };
  4376. GGroup.prototype.ensureBoundsCorrect = function () {
  4377. if (this._parent == null || !this._boundsChanged)
  4378. return;
  4379. this._boundsChanged = false;
  4380. if (this._layout == 0)
  4381. this.updateBounds();
  4382. else {
  4383. if (this._autoSizeDisabled)
  4384. this.resizeChildren(0, 0);
  4385. else {
  4386. this.handleLayout();
  4387. this.updateBounds();
  4388. }
  4389. }
  4390. };
  4391. GGroup.prototype.updateBounds = function () {
  4392. this._partner.unschedule(this._ensureBoundsCorrect);
  4393. var cnt = this._parent.numChildren;
  4394. var i;
  4395. var child;
  4396. var ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  4397. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  4398. var tmp;
  4399. var empty = true;
  4400. for (i = 0; i < cnt; i++) {
  4401. child = this._parent.getChildAt(i);
  4402. if (child.group != this || this._excludeInvisibles && !child.internalVisible3)
  4403. continue;
  4404. tmp = child.xMin;
  4405. if (tmp < ax)
  4406. ax = tmp;
  4407. tmp = child.yMin;
  4408. if (tmp < ay)
  4409. ay = tmp;
  4410. tmp = child.xMin + child.width;
  4411. if (tmp > ar)
  4412. ar = tmp;
  4413. tmp = child.yMin + child.height;
  4414. if (tmp > ab)
  4415. ab = tmp;
  4416. empty = false;
  4417. }
  4418. var w = 0, h = 0;
  4419. if (!empty) {
  4420. this._updating |= 1;
  4421. this.setPosition(ax, ay);
  4422. this._updating &= 2;
  4423. w = ar - ax;
  4424. h = ab - ay;
  4425. }
  4426. if ((this._updating & 2) == 0) {
  4427. this._updating |= 2;
  4428. this.setSize(w, h);
  4429. this._updating &= 1;
  4430. }
  4431. else {
  4432. this._updating &= 1;
  4433. this.resizeChildren(this._width - w, this._height - h);
  4434. }
  4435. };
  4436. GGroup.prototype.handleLayout = function () {
  4437. this._updating |= 1;
  4438. var child;
  4439. var i;
  4440. var cnt;
  4441. if (this._layout == fgui.GroupLayoutType.Horizontal) {
  4442. var curX = this.x;
  4443. cnt = this._parent.numChildren;
  4444. for (i = 0; i < cnt; i++) {
  4445. child = this._parent.getChildAt(i);
  4446. if (child.group != this)
  4447. continue;
  4448. if (this._excludeInvisibles && !child.internalVisible3)
  4449. continue;
  4450. child.xMin = curX;
  4451. if (child.width != 0)
  4452. curX += child.width + this._columnGap;
  4453. }
  4454. }
  4455. else if (this._layout == fgui.GroupLayoutType.Vertical) {
  4456. var curY = this.y;
  4457. cnt = this._parent.numChildren;
  4458. for (i = 0; i < cnt; i++) {
  4459. child = this._parent.getChildAt(i);
  4460. if (child.group != this)
  4461. continue;
  4462. if (this._excludeInvisibles && !child.internalVisible3)
  4463. continue;
  4464. child.yMin = curY;
  4465. if (child.height != 0)
  4466. curY += child.height + this._lineGap;
  4467. }
  4468. }
  4469. this._updating &= 2;
  4470. };
  4471. GGroup.prototype.moveChildren = function (dx, dy) {
  4472. if ((this._updating & 1) != 0 || this._parent == null)
  4473. return;
  4474. this._updating |= 1;
  4475. var cnt = this._parent.numChildren;
  4476. var i;
  4477. var child;
  4478. for (i = 0; i < cnt; i++) {
  4479. child = this._parent.getChildAt(i);
  4480. if (child.group == this) {
  4481. child.setPosition(child.x + dx, child.y + dy);
  4482. }
  4483. }
  4484. this._updating &= 2;
  4485. };
  4486. GGroup.prototype.resizeChildren = function (dw, dh) {
  4487. if (this._layout == fgui.GroupLayoutType.None || (this._updating & 2) != 0 || this._parent == null)
  4488. return;
  4489. this._updating |= 2;
  4490. if (this._boundsChanged) {
  4491. this._boundsChanged = false;
  4492. if (!this._autoSizeDisabled) {
  4493. this.updateBounds();
  4494. return;
  4495. }
  4496. }
  4497. var cnt = this._parent.numChildren;
  4498. var i;
  4499. var child;
  4500. if (!this._percentReady) {
  4501. this._percentReady = true;
  4502. this._numChildren = 0;
  4503. this._totalSize = 0;
  4504. this._mainChildIndex = -1;
  4505. var j = 0;
  4506. for (i = 0; i < cnt; i++) {
  4507. child = this._parent.getChildAt(i);
  4508. if (child.group != this)
  4509. continue;
  4510. if (!this._excludeInvisibles || child.internalVisible3) {
  4511. if (j == this._mainGridIndex)
  4512. this._mainChildIndex = i;
  4513. this._numChildren++;
  4514. if (this._layout == 1)
  4515. this._totalSize += child.width;
  4516. else
  4517. this._totalSize += child.height;
  4518. }
  4519. j++;
  4520. }
  4521. if (this._mainChildIndex != -1) {
  4522. if (this._layout == 1) {
  4523. child = this._parent.getChildAt(this._mainChildIndex);
  4524. this._totalSize += this._mainGridMinSize - child.width;
  4525. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4526. }
  4527. else {
  4528. child = this._parent.getChildAt(this._mainChildIndex);
  4529. this._totalSize += this._mainGridMinSize - child.height;
  4530. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4531. }
  4532. }
  4533. for (i = 0; i < cnt; i++) {
  4534. child = this._parent.getChildAt(i);
  4535. if (child.group != this)
  4536. continue;
  4537. if (i == this._mainChildIndex)
  4538. continue;
  4539. if (this._totalSize > 0)
  4540. child._sizePercentInGroup = (this._layout == 1 ? child.width : child.height) / this._totalSize;
  4541. else
  4542. child._sizePercentInGroup = 0;
  4543. }
  4544. }
  4545. var remainSize = 0;
  4546. var remainPercent = 1;
  4547. var priorHandled = false;
  4548. if (this._layout == 1) {
  4549. remainSize = this.width - (this._numChildren - 1) * this._columnGap;
  4550. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4551. child = this._parent.getChildAt(this._mainChildIndex);
  4552. child.setSize(remainSize - (this._totalSize - this._mainGridMinSize), child._rawHeight + dh, true);
  4553. remainSize -= child.width;
  4554. remainPercent -= child._sizePercentInGroup;
  4555. priorHandled = true;
  4556. }
  4557. var curX = this.x;
  4558. for (i = 0; i < cnt; i++) {
  4559. child = this._parent.getChildAt(i);
  4560. if (child.group != this)
  4561. continue;
  4562. if (this._excludeInvisibles && !child.internalVisible3) {
  4563. child.setSize(child._rawWidth, child._rawHeight + dh, true);
  4564. continue;
  4565. }
  4566. if (!priorHandled || i != this._mainChildIndex) {
  4567. child.setSize(Math.round(child._sizePercentInGroup / remainPercent * remainSize), child._rawHeight + dh, true);
  4568. remainPercent -= child._sizePercentInGroup;
  4569. remainSize -= child.width;
  4570. }
  4571. child.xMin = curX;
  4572. if (child.width != 0)
  4573. curX += child.width + this._columnGap;
  4574. }
  4575. }
  4576. else {
  4577. remainSize = this.height - (this._numChildren - 1) * this._lineGap;
  4578. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4579. child = this._parent.getChildAt(this._mainChildIndex);
  4580. child.setSize(child._rawWidth + dw, remainSize - (this._totalSize - this._mainGridMinSize), true);
  4581. remainSize -= child.height;
  4582. remainPercent -= child._sizePercentInGroup;
  4583. priorHandled = true;
  4584. }
  4585. var curY = this.y;
  4586. for (i = 0; i < cnt; i++) {
  4587. child = this._parent.getChildAt(i);
  4588. if (child.group != this)
  4589. continue;
  4590. if (this._excludeInvisibles && !child.internalVisible3) {
  4591. child.setSize(child._rawWidth + dw, child._rawHeight, true);
  4592. continue;
  4593. }
  4594. if (!priorHandled || i != this._mainChildIndex) {
  4595. child.setSize(child._rawWidth + dw, Math.round(child._sizePercentInGroup / remainPercent * remainSize), true);
  4596. remainPercent -= child._sizePercentInGroup;
  4597. remainSize -= child.height;
  4598. }
  4599. child.yMin = curY;
  4600. if (child.height != 0)
  4601. curY += child.height + this._lineGap;
  4602. }
  4603. }
  4604. this._updating &= 1;
  4605. };
  4606. GGroup.prototype.handleAlphaChanged = function () {
  4607. if (this._underConstruct)
  4608. return;
  4609. var cnt = this._parent.numChildren;
  4610. for (var i = 0; i < cnt; i++) {
  4611. var child = this._parent.getChildAt(i);
  4612. if (child.group == this)
  4613. child.alpha = this.alpha;
  4614. }
  4615. };
  4616. GGroup.prototype.handleVisibleChanged = function () {
  4617. if (!this._parent)
  4618. return;
  4619. var cnt = this._parent.numChildren;
  4620. for (var i = 0; i < cnt; i++) {
  4621. var child = this._parent.getChildAt(i);
  4622. if (child.group == this)
  4623. child.handleVisibleChanged();
  4624. }
  4625. };
  4626. GGroup.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4627. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4628. buffer.seek(beginPos, 5);
  4629. this._layout = buffer.readByte();
  4630. this._lineGap = buffer.readInt();
  4631. this._columnGap = buffer.readInt();
  4632. if (buffer.version >= 2) {
  4633. this._excludeInvisibles = buffer.readBool();
  4634. this._autoSizeDisabled = buffer.readBool();
  4635. this._mainGridIndex = buffer.readShort();
  4636. }
  4637. };
  4638. GGroup.prototype.setup_afterAdd = function (buffer, beginPos) {
  4639. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  4640. if (!this.visible)
  4641. this.handleVisibleChanged();
  4642. };
  4643. return GGroup;
  4644. }(fgui.GObject));
  4645. fgui.GGroup = GGroup;
  4646. })(fgui || (fgui = {}));
  4647. (function (fgui) {
  4648. var GImage = (function (_super) {
  4649. __extends(GImage, _super);
  4650. function GImage() {
  4651. var _this = _super.call(this) || this;
  4652. _this._node.name = "GImage";
  4653. _this._touchDisabled = true;
  4654. _this._content = _this._node.addComponent(fgui.Image);
  4655. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  4656. _this._content.trim = false;
  4657. return _this;
  4658. }
  4659. Object.defineProperty(GImage.prototype, "color", {
  4660. get: function () {
  4661. return this._node.color;
  4662. },
  4663. set: function (value) {
  4664. this._node.color = value;
  4665. this.updateGear(4);
  4666. },
  4667. enumerable: false,
  4668. configurable: true
  4669. });
  4670. Object.defineProperty(GImage.prototype, "flip", {
  4671. get: function () {
  4672. return this._content.flip;
  4673. },
  4674. set: function (value) {
  4675. this._content.flip = value;
  4676. },
  4677. enumerable: false,
  4678. configurable: true
  4679. });
  4680. Object.defineProperty(GImage.prototype, "fillMethod", {
  4681. get: function () {
  4682. return this._content.fillMethod;
  4683. },
  4684. set: function (value) {
  4685. this._content.fillMethod = value;
  4686. },
  4687. enumerable: false,
  4688. configurable: true
  4689. });
  4690. Object.defineProperty(GImage.prototype, "fillOrigin", {
  4691. get: function () {
  4692. return this._content.fillOrigin;
  4693. },
  4694. set: function (value) {
  4695. this._content.fillOrigin = value;
  4696. },
  4697. enumerable: false,
  4698. configurable: true
  4699. });
  4700. Object.defineProperty(GImage.prototype, "fillClockwise", {
  4701. get: function () {
  4702. return this._content.fillClockwise;
  4703. },
  4704. set: function (value) {
  4705. this._content.fillClockwise = value;
  4706. },
  4707. enumerable: false,
  4708. configurable: true
  4709. });
  4710. Object.defineProperty(GImage.prototype, "fillAmount", {
  4711. get: function () {
  4712. return this._content.fillAmount;
  4713. },
  4714. set: function (value) {
  4715. this._content.fillAmount = value;
  4716. },
  4717. enumerable: false,
  4718. configurable: true
  4719. });
  4720. GImage.prototype.constructFromResource = function () {
  4721. var contentItem = this.packageItem.getBranch();
  4722. this.sourceWidth = contentItem.width;
  4723. this.sourceHeight = contentItem.height;
  4724. this.initWidth = this.sourceWidth;
  4725. this.initHeight = this.sourceHeight;
  4726. this.setSize(this.sourceWidth, this.sourceHeight);
  4727. contentItem = contentItem.getHighResolution();
  4728. contentItem.load();
  4729. if (contentItem.scale9Grid)
  4730. this._content.type = cc.Sprite.Type.SLICED;
  4731. else if (contentItem.scaleByTile)
  4732. this._content.type = cc.Sprite.Type.TILED;
  4733. this._content.spriteFrame = contentItem.asset;
  4734. };
  4735. GImage.prototype.handleGrayedChanged = function () {
  4736. this._content.grayed = this._grayed;
  4737. };
  4738. GImage.prototype.getProp = function (index) {
  4739. if (index == fgui.ObjectPropID.Color)
  4740. return this.color;
  4741. else
  4742. return _super.prototype.getProp.call(this, index);
  4743. };
  4744. GImage.prototype.setProp = function (index, value) {
  4745. if (index == fgui.ObjectPropID.Color)
  4746. this.color = value;
  4747. else
  4748. _super.prototype.setProp.call(this, index, value);
  4749. };
  4750. GImage.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4751. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4752. buffer.seek(beginPos, 5);
  4753. if (buffer.readBool())
  4754. this.color = buffer.readColor();
  4755. this._content.flip = buffer.readByte();
  4756. this._content.fillMethod = buffer.readByte();
  4757. if (this._content.fillMethod != 0) {
  4758. this._content.fillOrigin = buffer.readByte();
  4759. this._content.fillClockwise = buffer.readBool();
  4760. this._content.fillAmount = buffer.readFloat();
  4761. }
  4762. };
  4763. return GImage;
  4764. }(fgui.GObject));
  4765. fgui.GImage = GImage;
  4766. })(fgui || (fgui = {}));
  4767. (function (fgui) {
  4768. var GLabel = (function (_super) {
  4769. __extends(GLabel, _super);
  4770. function GLabel() {
  4771. var _this = _super.call(this) || this;
  4772. _this._node.name = "GLabel";
  4773. return _this;
  4774. }
  4775. Object.defineProperty(GLabel.prototype, "icon", {
  4776. get: function () {
  4777. if (this._iconObject)
  4778. return this._iconObject.icon;
  4779. },
  4780. set: function (value) {
  4781. if (this._iconObject)
  4782. this._iconObject.icon = value;
  4783. this.updateGear(7);
  4784. },
  4785. enumerable: false,
  4786. configurable: true
  4787. });
  4788. Object.defineProperty(GLabel.prototype, "title", {
  4789. get: function () {
  4790. if (this._titleObject)
  4791. return this._titleObject.text;
  4792. else
  4793. return null;
  4794. },
  4795. set: function (value) {
  4796. if (this._titleObject)
  4797. this._titleObject.text = value;
  4798. this.updateGear(6);
  4799. },
  4800. enumerable: false,
  4801. configurable: true
  4802. });
  4803. Object.defineProperty(GLabel.prototype, "text", {
  4804. get: function () {
  4805. return this.title;
  4806. },
  4807. set: function (value) {
  4808. this.title = value;
  4809. },
  4810. enumerable: false,
  4811. configurable: true
  4812. });
  4813. Object.defineProperty(GLabel.prototype, "titleColor", {
  4814. get: function () {
  4815. var tf = this.getTextField();
  4816. if (tf)
  4817. return tf.color;
  4818. else
  4819. return cc.Color.WHITE;
  4820. },
  4821. set: function (value) {
  4822. var tf = this.getTextField();
  4823. if (tf)
  4824. tf.color = value;
  4825. this.updateGear(4);
  4826. },
  4827. enumerable: false,
  4828. configurable: true
  4829. });
  4830. Object.defineProperty(GLabel.prototype, "titleFontSize", {
  4831. get: function () {
  4832. var tf = this.getTextField();
  4833. if (tf)
  4834. return tf.fontSize;
  4835. else
  4836. return 0;
  4837. },
  4838. set: function (value) {
  4839. var tf = this.getTextField();
  4840. if (tf)
  4841. tf.fontSize = value;
  4842. },
  4843. enumerable: false,
  4844. configurable: true
  4845. });
  4846. Object.defineProperty(GLabel.prototype, "editable", {
  4847. get: function () {
  4848. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4849. return this._titleObject.editable;
  4850. else
  4851. return false;
  4852. },
  4853. set: function (val) {
  4854. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4855. this._titleObject.editable = val;
  4856. },
  4857. enumerable: false,
  4858. configurable: true
  4859. });
  4860. GLabel.prototype.getTextField = function () {
  4861. if (this._titleObject instanceof fgui.GTextField)
  4862. return this._titleObject;
  4863. else if ((this._titleObject instanceof GLabel) || (this._titleObject instanceof fgui.GButton))
  4864. return this._titleObject.getTextField();
  4865. else
  4866. return null;
  4867. };
  4868. GLabel.prototype.getProp = function (index) {
  4869. switch (index) {
  4870. case fgui.ObjectPropID.Color:
  4871. return this.titleColor;
  4872. case fgui.ObjectPropID.OutlineColor:
  4873. {
  4874. var tf = this.getTextField();
  4875. if (tf)
  4876. return tf.strokeColor;
  4877. else
  4878. return 0;
  4879. }
  4880. case fgui.ObjectPropID.FontSize:
  4881. return this.titleFontSize;
  4882. default:
  4883. return _super.prototype.getProp.call(this, index);
  4884. }
  4885. };
  4886. GLabel.prototype.setProp = function (index, value) {
  4887. switch (index) {
  4888. case fgui.ObjectPropID.Color:
  4889. this.titleColor = value;
  4890. break;
  4891. case fgui.ObjectPropID.OutlineColor:
  4892. {
  4893. var tf = this.getTextField();
  4894. if (tf)
  4895. tf.strokeColor = value;
  4896. }
  4897. break;
  4898. case fgui.ObjectPropID.FontSize:
  4899. this.titleFontSize = value;
  4900. break;
  4901. default:
  4902. _super.prototype.setProp.call(this, index, value);
  4903. break;
  4904. }
  4905. };
  4906. GLabel.prototype.constructExtension = function (buffer) {
  4907. this._titleObject = this.getChild("title");
  4908. this._iconObject = this.getChild("icon");
  4909. };
  4910. GLabel.prototype.setup_afterAdd = function (buffer, beginPos) {
  4911. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  4912. if (!buffer.seek(beginPos, 6))
  4913. return;
  4914. if (buffer.readByte() != this.packageItem.objectType)
  4915. return;
  4916. var str;
  4917. str = buffer.readS();
  4918. if (str != null)
  4919. this.title = str;
  4920. str = buffer.readS();
  4921. if (str != null)
  4922. this.icon = str;
  4923. if (buffer.readBool())
  4924. this.titleColor = buffer.readColor();
  4925. var iv = buffer.readInt();
  4926. if (iv != 0)
  4927. this.titleFontSize = iv;
  4928. if (buffer.readBool()) {
  4929. var input = this.getTextField();
  4930. if (input instanceof fgui.GTextInput) {
  4931. str = buffer.readS();
  4932. if (str != null)
  4933. input.promptText = str;
  4934. str = buffer.readS();
  4935. if (str != null)
  4936. input.restrict = str;
  4937. iv = buffer.readInt();
  4938. if (iv != 0)
  4939. input.maxLength = iv;
  4940. iv = buffer.readInt();
  4941. if (iv != 0) {
  4942. }
  4943. if (buffer.readBool())
  4944. input.password = true;
  4945. }
  4946. else
  4947. buffer.skip(13);
  4948. }
  4949. };
  4950. return GLabel;
  4951. }(fgui.GComponent));
  4952. fgui.GLabel = GLabel;
  4953. })(fgui || (fgui = {}));
  4954. (function (fgui) {
  4955. var GList = (function (_super) {
  4956. __extends(GList, _super);
  4957. function GList() {
  4958. var _this = _super.call(this) || this;
  4959. _this.scrollItemToViewOnClick = true;
  4960. _this.foldInvisibleItems = false;
  4961. _this._lineCount = 0;
  4962. _this._columnCount = 0;
  4963. _this._lineGap = 0;
  4964. _this._columnGap = 0;
  4965. _this._lastSelectedIndex = 0;
  4966. _this._numItems = 0;
  4967. _this._realNumItems = 0;
  4968. _this._firstIndex = 0;
  4969. _this._curLineItemCount = 0;
  4970. _this._curLineItemCount2 = 0;
  4971. _this._virtualListChanged = 0;
  4972. _this.itemInfoVer = 0;
  4973. _this._node.name = "GList";
  4974. _this._trackBounds = true;
  4975. _this._pool = new fgui.GObjectPool();
  4976. _this._layout = fgui.ListLayoutType.SingleColumn;
  4977. _this._autoResizeItem = true;
  4978. _this._lastSelectedIndex = -1;
  4979. _this._selectionMode = fgui.ListSelectionMode.Single;
  4980. _this.opaque = true;
  4981. _this._align = fgui.AlignType.Left;
  4982. _this._verticalAlign = fgui.VertAlignType.Top;
  4983. return _this;
  4984. }
  4985. GList.prototype.dispose = function () {
  4986. this._partner.unschedule(this._refreshVirtualList);
  4987. this._pool.clear();
  4988. _super.prototype.dispose.call(this);
  4989. };
  4990. Object.defineProperty(GList.prototype, "layout", {
  4991. get: function () {
  4992. return this._layout;
  4993. },
  4994. set: function (value) {
  4995. if (this._layout != value) {
  4996. this._layout = value;
  4997. this.setBoundsChangedFlag();
  4998. if (this._virtual)
  4999. this.setVirtualListChangedFlag(true);
  5000. }
  5001. },
  5002. enumerable: false,
  5003. configurable: true
  5004. });
  5005. Object.defineProperty(GList.prototype, "lineCount", {
  5006. get: function () {
  5007. return this._lineCount;
  5008. },
  5009. set: function (value) {
  5010. if (this._lineCount != value) {
  5011. this._lineCount = value;
  5012. this.setBoundsChangedFlag();
  5013. if (this._virtual)
  5014. this.setVirtualListChangedFlag(true);
  5015. }
  5016. },
  5017. enumerable: false,
  5018. configurable: true
  5019. });
  5020. Object.defineProperty(GList.prototype, "columnCount", {
  5021. get: function () {
  5022. return this._columnCount;
  5023. },
  5024. set: function (value) {
  5025. if (this._columnCount != value) {
  5026. this._columnCount = value;
  5027. this.setBoundsChangedFlag();
  5028. if (this._virtual)
  5029. this.setVirtualListChangedFlag(true);
  5030. }
  5031. },
  5032. enumerable: false,
  5033. configurable: true
  5034. });
  5035. Object.defineProperty(GList.prototype, "lineGap", {
  5036. get: function () {
  5037. return this._lineGap;
  5038. },
  5039. set: function (value) {
  5040. if (this._lineGap != value) {
  5041. this._lineGap = value;
  5042. this.setBoundsChangedFlag();
  5043. if (this._virtual)
  5044. this.setVirtualListChangedFlag(true);
  5045. }
  5046. },
  5047. enumerable: false,
  5048. configurable: true
  5049. });
  5050. Object.defineProperty(GList.prototype, "columnGap", {
  5051. get: function () {
  5052. return this._columnGap;
  5053. },
  5054. set: function (value) {
  5055. if (this._columnGap != value) {
  5056. this._columnGap = value;
  5057. this.setBoundsChangedFlag();
  5058. if (this._virtual)
  5059. this.setVirtualListChangedFlag(true);
  5060. }
  5061. },
  5062. enumerable: false,
  5063. configurable: true
  5064. });
  5065. Object.defineProperty(GList.prototype, "align", {
  5066. get: function () {
  5067. return this._align;
  5068. },
  5069. set: function (value) {
  5070. if (this._align != value) {
  5071. this._align = value;
  5072. this.setBoundsChangedFlag();
  5073. if (this._virtual)
  5074. this.setVirtualListChangedFlag(true);
  5075. }
  5076. },
  5077. enumerable: false,
  5078. configurable: true
  5079. });
  5080. Object.defineProperty(GList.prototype, "verticalAlign", {
  5081. get: function () {
  5082. return this._verticalAlign;
  5083. },
  5084. set: function (value) {
  5085. if (this._verticalAlign != value) {
  5086. this._verticalAlign = value;
  5087. this.setBoundsChangedFlag();
  5088. if (this._virtual)
  5089. this.setVirtualListChangedFlag(true);
  5090. }
  5091. },
  5092. enumerable: false,
  5093. configurable: true
  5094. });
  5095. Object.defineProperty(GList.prototype, "virtualItemSize", {
  5096. get: function () {
  5097. return this._itemSize;
  5098. },
  5099. set: function (value) {
  5100. if (this._virtual) {
  5101. if (this._itemSize == null)
  5102. this._itemSize = new cc.Size(0, 0);
  5103. this._itemSize.width = value.width;
  5104. this._itemSize.height = value.height;
  5105. this.setVirtualListChangedFlag(true);
  5106. }
  5107. },
  5108. enumerable: false,
  5109. configurable: true
  5110. });
  5111. Object.defineProperty(GList.prototype, "defaultItem", {
  5112. get: function () {
  5113. return this._defaultItem;
  5114. },
  5115. set: function (val) {
  5116. this._defaultItem = fgui.UIPackage.normalizeURL(val);
  5117. },
  5118. enumerable: false,
  5119. configurable: true
  5120. });
  5121. Object.defineProperty(GList.prototype, "autoResizeItem", {
  5122. get: function () {
  5123. return this._autoResizeItem;
  5124. },
  5125. set: function (value) {
  5126. if (this._autoResizeItem != value) {
  5127. this._autoResizeItem = value;
  5128. this.setBoundsChangedFlag();
  5129. if (this._virtual)
  5130. this.setVirtualListChangedFlag(true);
  5131. }
  5132. },
  5133. enumerable: false,
  5134. configurable: true
  5135. });
  5136. Object.defineProperty(GList.prototype, "selectionMode", {
  5137. get: function () {
  5138. return this._selectionMode;
  5139. },
  5140. set: function (value) {
  5141. this._selectionMode = value;
  5142. },
  5143. enumerable: false,
  5144. configurable: true
  5145. });
  5146. Object.defineProperty(GList.prototype, "selectionController", {
  5147. get: function () {
  5148. return this._selectionController;
  5149. },
  5150. set: function (value) {
  5151. this._selectionController = value;
  5152. },
  5153. enumerable: false,
  5154. configurable: true
  5155. });
  5156. Object.defineProperty(GList.prototype, "itemPool", {
  5157. get: function () {
  5158. return this._pool;
  5159. },
  5160. enumerable: false,
  5161. configurable: true
  5162. });
  5163. GList.prototype.getFromPool = function (url) {
  5164. if (!url)
  5165. url = this._defaultItem;
  5166. var obj = this._pool.getObject(url);
  5167. if (obj)
  5168. obj.visible = true;
  5169. return obj;
  5170. };
  5171. GList.prototype.returnToPool = function (obj) {
  5172. this._pool.returnObject(obj);
  5173. };
  5174. GList.prototype.addChildAt = function (child, index) {
  5175. _super.prototype.addChildAt.call(this, child, index);
  5176. if (child instanceof fgui.GButton) {
  5177. child.selected = false;
  5178. child.changeStateOnClick = false;
  5179. }
  5180. child.on(fgui.Event.CLICK, this.onClickItem, this);
  5181. return child;
  5182. };
  5183. GList.prototype.addItem = function (url) {
  5184. if (!url)
  5185. url = this._defaultItem;
  5186. return this.addChild(fgui.UIPackage.createObjectFromURL(url));
  5187. };
  5188. GList.prototype.addItemFromPool = function (url) {
  5189. return this.addChild(this.getFromPool(url));
  5190. };
  5191. GList.prototype.removeChildAt = function (index, dispose) {
  5192. var child = _super.prototype.removeChildAt.call(this, index, dispose);
  5193. if (!dispose)
  5194. child.off(fgui.Event.CLICK, this.onClickItem, this);
  5195. return child;
  5196. };
  5197. GList.prototype.removeChildToPoolAt = function (index) {
  5198. var child = _super.prototype.removeChildAt.call(this, index);
  5199. this.returnToPool(child);
  5200. };
  5201. GList.prototype.removeChildToPool = function (child) {
  5202. _super.prototype.removeChild.call(this, child);
  5203. this.returnToPool(child);
  5204. };
  5205. GList.prototype.removeChildrenToPool = function (beginIndex, endIndex) {
  5206. if (beginIndex == undefined)
  5207. beginIndex = 0;
  5208. if (endIndex == undefined)
  5209. endIndex = -1;
  5210. if (endIndex < 0 || endIndex >= this._children.length)
  5211. endIndex = this._children.length - 1;
  5212. for (var i = beginIndex; i <= endIndex; ++i)
  5213. this.removeChildToPoolAt(beginIndex);
  5214. };
  5215. Object.defineProperty(GList.prototype, "selectedIndex", {
  5216. get: function () {
  5217. var i;
  5218. if (this._virtual) {
  5219. for (i = 0; i < this._realNumItems; i++) {
  5220. var ii = this._virtualItems[i];
  5221. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected || !ii.obj && ii.selected) {
  5222. if (this._loop)
  5223. return i % this._numItems;
  5224. else
  5225. return i;
  5226. }
  5227. }
  5228. }
  5229. else {
  5230. var cnt = this._children.length;
  5231. for (i = 0; i < cnt; i++) {
  5232. var obj = this._children[i];
  5233. if ((obj instanceof fgui.GButton) && obj.selected)
  5234. return i;
  5235. }
  5236. }
  5237. return -1;
  5238. },
  5239. set: function (value) {
  5240. if (value >= 0 && value < this.numItems) {
  5241. if (this._selectionMode != fgui.ListSelectionMode.Single)
  5242. this.clearSelection();
  5243. this.addSelection(value);
  5244. }
  5245. else
  5246. this.clearSelection();
  5247. },
  5248. enumerable: false,
  5249. configurable: true
  5250. });
  5251. GList.prototype.getSelection = function (result) {
  5252. if (!result)
  5253. result = new Array();
  5254. var i;
  5255. if (this._virtual) {
  5256. for (i = 0; i < this._realNumItems; i++) {
  5257. var ii = this._virtualItems[i];
  5258. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected || !ii.obj && ii.selected) {
  5259. var j = i;
  5260. if (this._loop) {
  5261. j = i % this._numItems;
  5262. if (result.indexOf(j) != -1)
  5263. continue;
  5264. }
  5265. result.push(j);
  5266. }
  5267. }
  5268. }
  5269. else {
  5270. var cnt = this._children.length;
  5271. for (i = 0; i < cnt; i++) {
  5272. var obj = this._children[i];
  5273. if ((obj instanceof fgui.GButton) && obj.selected)
  5274. result.push(i);
  5275. }
  5276. }
  5277. return result;
  5278. };
  5279. GList.prototype.addSelection = function (index, scrollItToView) {
  5280. if (this._selectionMode == fgui.ListSelectionMode.None)
  5281. return;
  5282. this.checkVirtualList();
  5283. if (this._selectionMode == fgui.ListSelectionMode.Single)
  5284. this.clearSelection();
  5285. if (scrollItToView)
  5286. this.scrollToView(index);
  5287. this._lastSelectedIndex = index;
  5288. var obj;
  5289. if (this._virtual) {
  5290. var ii = this._virtualItems[index];
  5291. if (ii.obj)
  5292. obj = ii.obj;
  5293. ii.selected = true;
  5294. }
  5295. else
  5296. obj = this.getChildAt(index);
  5297. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5298. obj.selected = true;
  5299. this.updateSelectionController(index);
  5300. }
  5301. };
  5302. GList.prototype.removeSelection = function (index) {
  5303. if (this._selectionMode == fgui.ListSelectionMode.None)
  5304. return;
  5305. var obj;
  5306. if (this._virtual) {
  5307. var ii = this._virtualItems[index];
  5308. if (ii.obj)
  5309. obj = ii.obj;
  5310. ii.selected = false;
  5311. }
  5312. else
  5313. obj = this.getChildAt(index);
  5314. if (obj instanceof fgui.GButton)
  5315. obj.selected = false;
  5316. };
  5317. GList.prototype.clearSelection = function () {
  5318. var i;
  5319. if (this._virtual) {
  5320. for (i = 0; i < this._realNumItems; i++) {
  5321. var ii = this._virtualItems[i];
  5322. if (ii.obj instanceof fgui.GButton)
  5323. ii.obj.selected = false;
  5324. ii.selected = false;
  5325. }
  5326. }
  5327. else {
  5328. var cnt = this._children.length;
  5329. for (i = 0; i < cnt; i++) {
  5330. var obj = this._children[i];
  5331. if (obj instanceof fgui.GButton)
  5332. obj.selected = false;
  5333. }
  5334. }
  5335. };
  5336. GList.prototype.clearSelectionExcept = function (g) {
  5337. var i;
  5338. if (this._virtual) {
  5339. for (i = 0; i < this._realNumItems; i++) {
  5340. var ii = this._virtualItems[i];
  5341. if (ii.obj != g) {
  5342. if (ii.obj instanceof fgui.GButton)
  5343. ii.obj.selected = false;
  5344. ii.selected = false;
  5345. }
  5346. }
  5347. }
  5348. else {
  5349. var cnt = this._children.length;
  5350. for (i = 0; i < cnt; i++) {
  5351. var obj = this._children[i];
  5352. if ((obj instanceof fgui.GButton) && obj != g)
  5353. obj.selected = false;
  5354. }
  5355. }
  5356. };
  5357. GList.prototype.selectAll = function () {
  5358. this.checkVirtualList();
  5359. var last = -1;
  5360. var i;
  5361. if (this._virtual) {
  5362. for (i = 0; i < this._realNumItems; i++) {
  5363. var ii = this._virtualItems[i];
  5364. if ((ii.obj instanceof fgui.GButton) && !ii.obj.selected) {
  5365. ii.obj.selected = true;
  5366. last = i;
  5367. }
  5368. ii.selected = true;
  5369. }
  5370. }
  5371. else {
  5372. var cnt = this._children.length;
  5373. for (i = 0; i < cnt; i++) {
  5374. var obj = this._children[i];
  5375. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5376. obj.selected = true;
  5377. last = i;
  5378. }
  5379. }
  5380. }
  5381. if (last != -1)
  5382. this.updateSelectionController(last);
  5383. };
  5384. GList.prototype.selectNone = function () {
  5385. this.clearSelection();
  5386. };
  5387. GList.prototype.selectReverse = function () {
  5388. this.checkVirtualList();
  5389. var last = -1;
  5390. var i;
  5391. if (this._virtual) {
  5392. for (i = 0; i < this._realNumItems; i++) {
  5393. var ii = this._virtualItems[i];
  5394. if (ii.obj instanceof fgui.GButton) {
  5395. ii.obj.selected = !ii.obj.selected;
  5396. if (ii.obj.selected)
  5397. last = i;
  5398. }
  5399. ii.selected = !ii.selected;
  5400. }
  5401. }
  5402. else {
  5403. var cnt = this._children.length;
  5404. for (i = 0; i < cnt; i++) {
  5405. var obj = this._children[i];
  5406. if (obj instanceof fgui.GButton) {
  5407. obj.selected = !obj.selected;
  5408. if (obj.selected)
  5409. last = i;
  5410. }
  5411. }
  5412. }
  5413. if (last != -1)
  5414. this.updateSelectionController(last);
  5415. };
  5416. GList.prototype.handleArrowKey = function (dir) {
  5417. var index = this.selectedIndex;
  5418. if (index == -1)
  5419. return;
  5420. switch (dir) {
  5421. case 1:
  5422. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5423. index--;
  5424. if (index >= 0) {
  5425. this.clearSelection();
  5426. this.addSelection(index, true);
  5427. }
  5428. }
  5429. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5430. var current = this._children[index];
  5431. var k = 0;
  5432. for (var i = index - 1; i >= 0; i--) {
  5433. var obj = this._children[i];
  5434. if (obj.y != current.y) {
  5435. current = obj;
  5436. break;
  5437. }
  5438. k++;
  5439. }
  5440. for (; i >= 0; i--) {
  5441. obj = this._children[i];
  5442. if (obj.y != current.y) {
  5443. this.clearSelection();
  5444. this.addSelection(i + k + 1, true);
  5445. break;
  5446. }
  5447. }
  5448. }
  5449. break;
  5450. case 3:
  5451. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5452. index++;
  5453. if (index < this._children.length) {
  5454. this.clearSelection();
  5455. this.addSelection(index, true);
  5456. }
  5457. }
  5458. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5459. current = this._children[index];
  5460. k = 0;
  5461. var cnt = this._children.length;
  5462. for (i = index + 1; i < cnt; i++) {
  5463. obj = this._children[i];
  5464. if (obj.x != current.x) {
  5465. current = obj;
  5466. break;
  5467. }
  5468. k++;
  5469. }
  5470. for (; i < cnt; i++) {
  5471. obj = this._children[i];
  5472. if (obj.x != current.x) {
  5473. this.clearSelection();
  5474. this.addSelection(i - k - 1, true);
  5475. break;
  5476. }
  5477. }
  5478. }
  5479. break;
  5480. case 5:
  5481. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5482. index++;
  5483. if (index < this._children.length) {
  5484. this.clearSelection();
  5485. this.addSelection(index, true);
  5486. }
  5487. }
  5488. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5489. current = this._children[index];
  5490. k = 0;
  5491. cnt = this._children.length;
  5492. for (i = index + 1; i < cnt; i++) {
  5493. obj = this._children[i];
  5494. if (obj.y != current.y) {
  5495. current = obj;
  5496. break;
  5497. }
  5498. k++;
  5499. }
  5500. for (; i < cnt; i++) {
  5501. obj = this._children[i];
  5502. if (obj.y != current.y) {
  5503. this.clearSelection();
  5504. this.addSelection(i - k - 1, true);
  5505. break;
  5506. }
  5507. }
  5508. }
  5509. break;
  5510. case 7:
  5511. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5512. index--;
  5513. if (index >= 0) {
  5514. this.clearSelection();
  5515. this.addSelection(index, true);
  5516. }
  5517. }
  5518. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5519. current = this._children[index];
  5520. k = 0;
  5521. for (i = index - 1; i >= 0; i--) {
  5522. obj = this._children[i];
  5523. if (obj.x != current.x) {
  5524. current = obj;
  5525. break;
  5526. }
  5527. k++;
  5528. }
  5529. for (; i >= 0; i--) {
  5530. obj = this._children[i];
  5531. if (obj.x != current.x) {
  5532. this.clearSelection();
  5533. this.addSelection(i + k + 1, true);
  5534. break;
  5535. }
  5536. }
  5537. }
  5538. break;
  5539. }
  5540. };
  5541. GList.prototype.onClickItem = function (evt) {
  5542. if (this._scrollPane && this._scrollPane.isDragged)
  5543. return;
  5544. var item = fgui.GObject.cast(evt.currentTarget);
  5545. this.setSelectionOnEvent(item, evt);
  5546. if (this._scrollPane && this.scrollItemToViewOnClick)
  5547. this._scrollPane.scrollToView(item, true);
  5548. this.dispatchItemEvent(item, evt);
  5549. };
  5550. GList.prototype.dispatchItemEvent = function (item, evt) {
  5551. this._node.emit(fgui.Event.CLICK_ITEM, item, evt);
  5552. };
  5553. GList.prototype.setSelectionOnEvent = function (item, evt) {
  5554. if (!(item instanceof fgui.GButton) || this._selectionMode == fgui.ListSelectionMode.None)
  5555. return;
  5556. var dontChangeLastIndex = false;
  5557. var index = this.childIndexToItemIndex(this.getChildIndex(item));
  5558. if (this._selectionMode == fgui.ListSelectionMode.Single) {
  5559. if (!item.selected) {
  5560. this.clearSelectionExcept(item);
  5561. item.selected = true;
  5562. }
  5563. }
  5564. else {
  5565. if (evt.isShiftDown) {
  5566. if (!item.selected) {
  5567. if (this._lastSelectedIndex != -1) {
  5568. var min = Math.min(this._lastSelectedIndex, index);
  5569. var max = Math.max(this._lastSelectedIndex, index);
  5570. max = Math.min(max, this.numItems - 1);
  5571. var i;
  5572. if (this._virtual) {
  5573. for (i = min; i <= max; i++) {
  5574. var ii = this._virtualItems[i];
  5575. if (ii.obj instanceof fgui.GButton)
  5576. ii.obj.selected = true;
  5577. ii.selected = true;
  5578. }
  5579. }
  5580. else {
  5581. for (i = min; i <= max; i++) {
  5582. var obj = this.getChildAt(i);
  5583. if (obj instanceof fgui.GButton)
  5584. obj.selected = true;
  5585. }
  5586. }
  5587. dontChangeLastIndex = true;
  5588. }
  5589. else {
  5590. item.selected = true;
  5591. }
  5592. }
  5593. }
  5594. else if (evt.isCtrlDown || this._selectionMode == fgui.ListSelectionMode.Multiple_SingleClick) {
  5595. item.selected = !item.selected;
  5596. }
  5597. else {
  5598. if (!item.selected) {
  5599. this.clearSelectionExcept(item);
  5600. item.selected = true;
  5601. }
  5602. else
  5603. this.clearSelectionExcept(item);
  5604. }
  5605. }
  5606. if (!dontChangeLastIndex)
  5607. this._lastSelectedIndex = index;
  5608. if (item.selected)
  5609. this.updateSelectionController(index);
  5610. };
  5611. GList.prototype.resizeToFit = function (itemCount, minSize) {
  5612. if (itemCount === void 0) { itemCount = Number.POSITIVE_INFINITY; }
  5613. if (minSize === void 0) { minSize = 0; }
  5614. this.ensureBoundsCorrect();
  5615. var curCount = this.numItems;
  5616. if (itemCount > curCount)
  5617. itemCount = curCount;
  5618. if (this._virtual) {
  5619. var lineCount = Math.ceil(itemCount / this._curLineItemCount);
  5620. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5621. this.viewHeight = lineCount * this._itemSize.height + Math.max(0, lineCount - 1) * this._lineGap;
  5622. else
  5623. this.viewWidth = lineCount * this._itemSize.width + Math.max(0, lineCount - 1) * this._columnGap;
  5624. }
  5625. else if (itemCount == 0) {
  5626. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5627. this.viewHeight = minSize;
  5628. else
  5629. this.viewWidth = minSize;
  5630. }
  5631. else {
  5632. var i = itemCount - 1;
  5633. var obj = null;
  5634. while (i >= 0) {
  5635. obj = this.getChildAt(i);
  5636. if (!this.foldInvisibleItems || obj.visible)
  5637. break;
  5638. i--;
  5639. }
  5640. if (i < 0) {
  5641. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5642. this.viewHeight = minSize;
  5643. else
  5644. this.viewWidth = minSize;
  5645. }
  5646. else {
  5647. var size = 0;
  5648. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5649. size = obj.y + obj.height;
  5650. if (size < minSize)
  5651. size = minSize;
  5652. this.viewHeight = size;
  5653. }
  5654. else {
  5655. size = obj.x + obj.width;
  5656. if (size < minSize)
  5657. size = minSize;
  5658. this.viewWidth = size;
  5659. }
  5660. }
  5661. }
  5662. };
  5663. GList.prototype.getMaxItemWidth = function () {
  5664. var cnt = this._children.length;
  5665. var max = 0;
  5666. for (var i = 0; i < cnt; i++) {
  5667. var child = this.getChildAt(i);
  5668. if (child.width > max)
  5669. max = child.width;
  5670. }
  5671. return max;
  5672. };
  5673. GList.prototype.handleSizeChanged = function () {
  5674. _super.prototype.handleSizeChanged.call(this);
  5675. this.setBoundsChangedFlag();
  5676. if (this._virtual)
  5677. this.setVirtualListChangedFlag(true);
  5678. };
  5679. GList.prototype.handleControllerChanged = function (c) {
  5680. _super.prototype.handleControllerChanged.call(this, c);
  5681. if (this._selectionController == c)
  5682. this.selectedIndex = c.selectedIndex;
  5683. };
  5684. GList.prototype.updateSelectionController = function (index) {
  5685. if (this._selectionController && !this._selectionController.changing
  5686. && index < this._selectionController.pageCount) {
  5687. var c = this._selectionController;
  5688. this._selectionController = null;
  5689. c.selectedIndex = index;
  5690. this._selectionController = c;
  5691. }
  5692. };
  5693. GList.prototype.getSnappingPosition = function (xValue, yValue, resultPoint) {
  5694. if (this._virtual) {
  5695. resultPoint = resultPoint || new cc.Vec2();
  5696. var saved;
  5697. var index;
  5698. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5699. saved = yValue;
  5700. s_n = yValue;
  5701. index = this.getIndexOnPos1(false);
  5702. yValue = s_n;
  5703. if (index < this._virtualItems.length && saved - yValue > this._virtualItems[index].height / 2 && index < this._realNumItems)
  5704. yValue += this._virtualItems[index].height + this._lineGap;
  5705. }
  5706. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5707. saved = xValue;
  5708. s_n = xValue;
  5709. index = this.getIndexOnPos2(false);
  5710. xValue = s_n;
  5711. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5712. xValue += this._virtualItems[index].width + this._columnGap;
  5713. }
  5714. else {
  5715. saved = xValue;
  5716. s_n = xValue;
  5717. index = this.getIndexOnPos3(false);
  5718. xValue = s_n;
  5719. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5720. xValue += this._virtualItems[index].width + this._columnGap;
  5721. }
  5722. resultPoint.x = xValue;
  5723. resultPoint.y = yValue;
  5724. return resultPoint;
  5725. }
  5726. else {
  5727. return _super.prototype.getSnappingPosition.call(this, xValue, yValue, resultPoint);
  5728. }
  5729. };
  5730. GList.prototype.scrollToView = function (index, ani, setFirst) {
  5731. if (this._virtual) {
  5732. if (this._numItems == 0)
  5733. return;
  5734. this.checkVirtualList();
  5735. if (index >= this._virtualItems.length) {
  5736. throw "Invalid child index: " + index + ">" + this._virtualItems.length;
  5737. }
  5738. if (ani) {
  5739. //先静态活动到80%的位置,后续在动态滑动
  5740. this.scrollToView(Math.floor(index * 0.8), false, setFirst)
  5741. }
  5742. if (this._loop)
  5743. index = Math.floor(this._firstIndex / this._numItems) * this._numItems + index;
  5744. var rect;
  5745. var ii = this._virtualItems[index];
  5746. var pos = 0;
  5747. var i;
  5748. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5749. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5750. pos += this._virtualItems[i].height + this._lineGap;
  5751. rect = new cc.Rect(0, pos, this._itemSize.width, ii.height);
  5752. }
  5753. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5754. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5755. pos += this._virtualItems[i].width + this._columnGap;
  5756. rect = new cc.Rect(pos, 0, ii.width, this._itemSize.height);
  5757. }
  5758. else {
  5759. var page = index / (this._curLineItemCount * this._curLineItemCount2);
  5760. 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);
  5761. }
  5762. if (this._scrollPane) {
  5763. this._scrollPane.scrollToView(rect, ani, setFirst);
  5764. }
  5765. }
  5766. else {
  5767. var obj = this.getChildAt(index);
  5768. if (obj) {
  5769. if (this._scrollPane)
  5770. this._scrollPane.scrollToView(obj, ani, setFirst);
  5771. else if (this.parent && this.parent.scrollPane)
  5772. this.parent.scrollPane.scrollToView(obj, ani, setFirst);
  5773. }
  5774. }
  5775. };
  5776. GList.prototype.getFirstChildInView = function () {
  5777. return this.childIndexToItemIndex(_super.prototype.getFirstChildInView.call(this));
  5778. };
  5779. GList.prototype.childIndexToItemIndex = function (index) {
  5780. if (!this._virtual)
  5781. return index;
  5782. if (this._layout == fgui.ListLayoutType.Pagination) {
  5783. for (var i = this._firstIndex; i < this._realNumItems; i++) {
  5784. if (this._virtualItems[i].obj) {
  5785. index--;
  5786. if (index < 0)
  5787. return i;
  5788. }
  5789. }
  5790. return index;
  5791. }
  5792. else {
  5793. index += this._firstIndex;
  5794. if (this._loop && this._numItems > 0)
  5795. index = index % this._numItems;
  5796. return index;
  5797. }
  5798. };
  5799. GList.prototype.itemIndexToChildIndex = function (index) {
  5800. if (!this._virtual)
  5801. return index;
  5802. if (this._layout == fgui.ListLayoutType.Pagination) {
  5803. return this.getChildIndex(this._virtualItems[index].obj);
  5804. }
  5805. else {
  5806. if (this._loop && this._numItems > 0) {
  5807. var j = this._firstIndex % this._numItems;
  5808. if (index >= j)
  5809. index = index - j;
  5810. else
  5811. index = this._numItems - j + index;
  5812. }
  5813. else
  5814. index -= this._firstIndex;
  5815. return index;
  5816. }
  5817. };
  5818. GList.prototype.setVirtual = function () {
  5819. this._setVirtual(false);
  5820. };
  5821. GList.prototype.setVirtualAndLoop = function () {
  5822. this._setVirtual(true);
  5823. };
  5824. GList.prototype._setVirtual = function (loop) {
  5825. if (!this._virtual) {
  5826. if (!this._scrollPane)
  5827. throw "Virtual list must be scrollable!";
  5828. if (loop) {
  5829. if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.FlowVertical)
  5830. throw "Loop list is not supported for FlowHorizontal or FlowVertical layout!";
  5831. this._scrollPane.bouncebackEffect = false;
  5832. }
  5833. this._virtual = true;
  5834. this._loop = loop;
  5835. this._virtualItems = new Array();
  5836. this.removeChildrenToPool();
  5837. if (this._itemSize == null) {
  5838. this._itemSize = new cc.Size(0, 0);
  5839. var obj = this.getFromPool(null);
  5840. if (!obj) {
  5841. throw "Virtual List must have a default list item resource.";
  5842. }
  5843. else {
  5844. this._itemSize.width = obj.width;
  5845. this._itemSize.height = obj.height;
  5846. }
  5847. this.returnToPool(obj);
  5848. }
  5849. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5850. this._scrollPane.scrollStep = this._itemSize.height;
  5851. if (this._loop)
  5852. this._scrollPane._loop = 2;
  5853. }
  5854. else {
  5855. this._scrollPane.scrollStep = this._itemSize.width;
  5856. if (this._loop)
  5857. this._scrollPane._loop = 1;
  5858. }
  5859. this._node.on(fgui.Event.SCROLL, this.__scrolled, this);
  5860. this.setVirtualListChangedFlag(true);
  5861. }
  5862. };
  5863. Object.defineProperty(GList.prototype, "numItems", {
  5864. get: function () {
  5865. if (this._virtual)
  5866. return this._numItems;
  5867. else
  5868. return this._children.length;
  5869. },
  5870. set: function (value) {
  5871. if (this._virtual) {
  5872. if (this.itemRenderer == null)
  5873. throw "Set itemRenderer first!";
  5874. this._numItems = value;
  5875. if (this._loop)
  5876. this._realNumItems = this._numItems * 6;
  5877. else
  5878. this._realNumItems = this._numItems;
  5879. var oldCount = this._virtualItems.length;
  5880. if (this._realNumItems > oldCount) {
  5881. for (i = oldCount; i < this._realNumItems; i++) {
  5882. var ii = {
  5883. width: this._itemSize.width,
  5884. height: this._itemSize.height,
  5885. updateFlag: 0
  5886. };
  5887. this._virtualItems.push(ii);
  5888. }
  5889. }
  5890. else {
  5891. for (i = this._realNumItems; i < oldCount; i++)
  5892. this._virtualItems[i].selected = false;
  5893. }
  5894. if (this._virtualListChanged != 0)
  5895. this._partner.unschedule(this._refreshVirtualList);
  5896. this._refreshVirtualList();
  5897. }
  5898. else {
  5899. var cnt = this._children.length;
  5900. if (value > cnt) {
  5901. for (var i = cnt; i < value; i++) {
  5902. if (this.itemProvider == null)
  5903. this.addItemFromPool();
  5904. else
  5905. this.addItemFromPool(this.itemProvider(i));
  5906. }
  5907. }
  5908. else {
  5909. this.removeChildrenToPool(value, cnt);
  5910. }
  5911. if (this.itemRenderer != null) {
  5912. for (i = 0; i < value; i++)
  5913. this.itemRenderer(i, this.getChildAt(i));
  5914. }
  5915. }
  5916. },
  5917. enumerable: false,
  5918. configurable: true
  5919. });
  5920. GList.prototype.refreshVirtualList = function () {
  5921. this.setVirtualListChangedFlag(false);
  5922. };
  5923. GList.prototype.checkVirtualList = function () {
  5924. if (this._virtualListChanged != 0) {
  5925. this._refreshVirtualList();
  5926. this._partner.unschedule(this._refreshVirtualList);
  5927. }
  5928. };
  5929. GList.prototype.setVirtualListChangedFlag = function (layoutChanged) {
  5930. if (layoutChanged)
  5931. this._virtualListChanged = 2;
  5932. else if (this._virtualListChanged == 0)
  5933. this._virtualListChanged = 1;
  5934. this._partner.callLater(this._refreshVirtualList);
  5935. };
  5936. GList.prototype._refreshVirtualList = function (dt) {
  5937. if (!isNaN(dt)) {
  5938. var _t = (this.node["$gobj"]);
  5939. _t._refreshVirtualList();
  5940. return;
  5941. }
  5942. var layoutChanged = this._virtualListChanged == 2;
  5943. this._virtualListChanged = 0;
  5944. this._eventLocked = true;
  5945. if (layoutChanged) {
  5946. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.SingleRow)
  5947. this._curLineItemCount = 1;
  5948. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5949. if (this._columnCount > 0)
  5950. this._curLineItemCount = this._columnCount;
  5951. else {
  5952. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5953. if (this._curLineItemCount <= 0)
  5954. this._curLineItemCount = 1;
  5955. }
  5956. }
  5957. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5958. if (this._lineCount > 0)
  5959. this._curLineItemCount = this._lineCount;
  5960. else {
  5961. this._curLineItemCount = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5962. if (this._curLineItemCount <= 0)
  5963. this._curLineItemCount = 1;
  5964. }
  5965. }
  5966. else {
  5967. if (this._columnCount > 0)
  5968. this._curLineItemCount = this._columnCount;
  5969. else {
  5970. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5971. if (this._curLineItemCount <= 0)
  5972. this._curLineItemCount = 1;
  5973. }
  5974. if (this._lineCount > 0)
  5975. this._curLineItemCount2 = this._lineCount;
  5976. else {
  5977. this._curLineItemCount2 = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5978. if (this._curLineItemCount2 <= 0)
  5979. this._curLineItemCount2 = 1;
  5980. }
  5981. }
  5982. }
  5983. var ch = 0, cw = 0;
  5984. if (this._realNumItems > 0) {
  5985. var i;
  5986. var len = Math.ceil(this._realNumItems / this._curLineItemCount) * this._curLineItemCount;
  5987. var len2 = Math.min(this._curLineItemCount, this._realNumItems);
  5988. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5989. for (i = 0; i < len; i += this._curLineItemCount)
  5990. ch += this._virtualItems[i].height + this._lineGap;
  5991. if (ch > 0)
  5992. ch -= this._lineGap;
  5993. if (this._autoResizeItem)
  5994. cw = this._scrollPane.viewWidth;
  5995. else {
  5996. for (i = 0; i < len2; i++)
  5997. cw += this._virtualItems[i].width + this._columnGap;
  5998. if (cw > 0)
  5999. cw -= this._columnGap;
  6000. }
  6001. }
  6002. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  6003. for (i = 0; i < len; i += this._curLineItemCount)
  6004. cw += this._virtualItems[i].width + this._columnGap;
  6005. if (cw > 0)
  6006. cw -= this._columnGap;
  6007. if (this._autoResizeItem)
  6008. ch = this._scrollPane.viewHeight;
  6009. else {
  6010. for (i = 0; i < len2; i++)
  6011. ch += this._virtualItems[i].height + this._lineGap;
  6012. if (ch > 0)
  6013. ch -= this._lineGap;
  6014. }
  6015. }
  6016. else {
  6017. var pageCount = Math.ceil(len / (this._curLineItemCount * this._curLineItemCount2));
  6018. cw = pageCount * this.viewWidth;
  6019. ch = this.viewHeight;
  6020. }
  6021. }
  6022. this.handleAlign(cw, ch);
  6023. this._scrollPane.setContentSize(cw, ch);
  6024. this._eventLocked = false;
  6025. this.handleScroll(true);
  6026. };
  6027. GList.prototype.__scrolled = function (evt) {
  6028. this.handleScroll(false);
  6029. };
  6030. GList.prototype.getIndexOnPos1 = function (forceUpdate) {
  6031. if (this._realNumItems < this._curLineItemCount) {
  6032. s_n = 0;
  6033. return 0;
  6034. }
  6035. var i;
  6036. var pos2;
  6037. var pos3;
  6038. if (this.numChildren > 0 && !forceUpdate) {
  6039. pos2 = this.getChildAt(0).y;
  6040. if (pos2 > s_n) {
  6041. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6042. pos2 -= (this._virtualItems[i].height + this._lineGap);
  6043. if (pos2 <= s_n) {
  6044. s_n = pos2;
  6045. return i;
  6046. }
  6047. }
  6048. s_n = 0;
  6049. return 0;
  6050. }
  6051. else {
  6052. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6053. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6054. if (pos3 > s_n) {
  6055. s_n = pos2;
  6056. return i;
  6057. }
  6058. pos2 = pos3;
  6059. }
  6060. s_n = pos2;
  6061. return this._realNumItems - this._curLineItemCount;
  6062. }
  6063. }
  6064. else {
  6065. pos2 = 0;
  6066. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6067. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6068. if (pos3 > s_n) {
  6069. s_n = pos2;
  6070. return i;
  6071. }
  6072. pos2 = pos3;
  6073. }
  6074. s_n = pos2;
  6075. return this._realNumItems - this._curLineItemCount;
  6076. }
  6077. };
  6078. GList.prototype.getIndexOnPos2 = function (forceUpdate) {
  6079. if (this._realNumItems < this._curLineItemCount) {
  6080. s_n = 0;
  6081. return 0;
  6082. }
  6083. var i;
  6084. var pos2;
  6085. var pos3;
  6086. if (this.numChildren > 0 && !forceUpdate) {
  6087. pos2 = this.getChildAt(0).x;
  6088. if (pos2 > s_n) {
  6089. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6090. pos2 -= (this._virtualItems[i].width + this._columnGap);
  6091. if (pos2 <= s_n) {
  6092. s_n = pos2;
  6093. return i;
  6094. }
  6095. }
  6096. s_n = 0;
  6097. return 0;
  6098. }
  6099. else {
  6100. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6101. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6102. if (pos3 > s_n) {
  6103. s_n = pos2;
  6104. return i;
  6105. }
  6106. pos2 = pos3;
  6107. }
  6108. s_n = pos2;
  6109. return this._realNumItems - this._curLineItemCount;
  6110. }
  6111. }
  6112. else {
  6113. pos2 = 0;
  6114. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6115. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6116. if (pos3 > s_n) {
  6117. s_n = pos2;
  6118. return i;
  6119. }
  6120. pos2 = pos3;
  6121. }
  6122. s_n = pos2;
  6123. return this._realNumItems - this._curLineItemCount;
  6124. }
  6125. };
  6126. GList.prototype.getIndexOnPos3 = function (forceUpdate) {
  6127. if (this._realNumItems < this._curLineItemCount) {
  6128. s_n = 0;
  6129. return 0;
  6130. }
  6131. var viewWidth = this.viewWidth;
  6132. var page = Math.floor(s_n / viewWidth);
  6133. var startIndex = page * (this._curLineItemCount * this._curLineItemCount2);
  6134. var pos2 = page * viewWidth;
  6135. var i;
  6136. var pos3;
  6137. for (i = 0; i < this._curLineItemCount; i++) {
  6138. pos3 = pos2 + this._virtualItems[startIndex + i].width + this._columnGap;
  6139. if (pos3 > s_n) {
  6140. s_n = pos2;
  6141. return startIndex + i;
  6142. }
  6143. pos2 = pos3;
  6144. }
  6145. s_n = pos2;
  6146. return startIndex + this._curLineItemCount - 1;
  6147. };
  6148. GList.prototype.handleScroll = function (forceUpdate) {
  6149. if (this._eventLocked)
  6150. return;
  6151. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6152. var enterCounter = 0;
  6153. while (this.handleScroll1(forceUpdate)) {
  6154. enterCounter++;
  6155. forceUpdate = false;
  6156. if (enterCounter > 20) {
  6157. console.log("FairyGUI: list will never be filled as the item renderer function always returns a different size.");
  6158. break;
  6159. }
  6160. }
  6161. this.handleArchOrder1();
  6162. }
  6163. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  6164. enterCounter = 0;
  6165. while (this.handleScroll2(forceUpdate)) {
  6166. enterCounter++;
  6167. forceUpdate = false;
  6168. if (enterCounter > 20) {
  6169. console.log("FairyGUI: list will never be filled as the item renderer function always returns a different size.");
  6170. break;
  6171. }
  6172. }
  6173. this.handleArchOrder2();
  6174. }
  6175. else {
  6176. this.handleScroll3(forceUpdate);
  6177. }
  6178. this._boundsChanged = false;
  6179. };
  6180. GList.prototype.handleScroll1 = function (forceUpdate) {
  6181. var pos = this._scrollPane.scrollingPosY;
  6182. var max = pos + this._scrollPane.viewHeight;
  6183. var end = max == this._scrollPane.contentHeight;
  6184. s_n = pos;
  6185. var newFirstIndex = this.getIndexOnPos1(forceUpdate);
  6186. pos = s_n;
  6187. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  6188. return false;
  6189. }
  6190. var oldFirstIndex = this._firstIndex;
  6191. this._firstIndex = newFirstIndex;
  6192. var curIndex = newFirstIndex;
  6193. var forward = oldFirstIndex > newFirstIndex;
  6194. var childCount = this.numChildren;
  6195. var lastIndex = oldFirstIndex + childCount - 1;
  6196. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6197. var curX = 0, curY = pos;
  6198. var needRender;
  6199. var deltaSize = 0;
  6200. var firstItemDeltaSize = 0;
  6201. var url = this._defaultItem;
  6202. var ii, ii2;
  6203. var i, j;
  6204. var partSize = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6205. this.itemInfoVer++;
  6206. while (curIndex < this._realNumItems && (end || curY < max)) {
  6207. ii = this._virtualItems[curIndex];
  6208. if (!ii.obj || forceUpdate) {
  6209. if (this.itemProvider != null) {
  6210. url = this.itemProvider(curIndex % this._numItems);
  6211. if (url == null)
  6212. url = this._defaultItem;
  6213. url = fgui.UIPackage.normalizeURL(url);
  6214. }
  6215. if (ii.obj && ii.obj.resourceURL != url) {
  6216. if (ii.obj instanceof fgui.GButton)
  6217. ii.selected = ii.obj.selected;
  6218. this.removeChildToPool(ii.obj);
  6219. ii.obj = null;
  6220. }
  6221. }
  6222. if (!ii.obj) {
  6223. if (forward) {
  6224. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6225. ii2 = this._virtualItems[j];
  6226. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6227. if (ii2.obj instanceof fgui.GButton)
  6228. ii2.selected = ii2.obj.selected;
  6229. ii.obj = ii2.obj;
  6230. ii2.obj = null;
  6231. if (j == reuseIndex)
  6232. reuseIndex--;
  6233. break;
  6234. }
  6235. }
  6236. }
  6237. else {
  6238. for (j = reuseIndex; j <= lastIndex; j++) {
  6239. ii2 = this._virtualItems[j];
  6240. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6241. if (ii2.obj instanceof fgui.GButton)
  6242. ii2.selected = ii2.obj.selected;
  6243. ii.obj = ii2.obj;
  6244. ii2.obj = null;
  6245. if (j == reuseIndex)
  6246. reuseIndex++;
  6247. break;
  6248. }
  6249. }
  6250. }
  6251. if (ii.obj) {
  6252. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6253. }
  6254. else {
  6255. ii.obj = this._pool.getObject(url);
  6256. if (forward)
  6257. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6258. else
  6259. this.addChild(ii.obj);
  6260. }
  6261. if (ii.obj instanceof fgui.GButton)
  6262. ii.obj.selected = ii.selected;
  6263. needRender = true;
  6264. }
  6265. else
  6266. needRender = forceUpdate;
  6267. if (needRender) {
  6268. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleColumn || this._columnCount > 0))
  6269. ii.obj.setSize(partSize, ii.obj.height, true);
  6270. this.itemRenderer(curIndex % this._numItems, ii.obj);
  6271. if (curIndex % this._curLineItemCount == 0) {
  6272. deltaSize += Math.ceil(ii.obj.height) - ii.height;
  6273. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6274. firstItemDeltaSize = Math.ceil(ii.obj.height) - ii.height;
  6275. }
  6276. }
  6277. ii.width = Math.ceil(ii.obj.width);
  6278. ii.height = Math.ceil(ii.obj.height);
  6279. }
  6280. ii.updateFlag = this.itemInfoVer;
  6281. ii.obj.setPosition(curX, curY);
  6282. if (curIndex == newFirstIndex)
  6283. max += ii.height;
  6284. curX += ii.width + this._columnGap;
  6285. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6286. curX = 0;
  6287. curY += ii.height + this._lineGap;
  6288. }
  6289. curIndex++;
  6290. }
  6291. for (i = 0; i < childCount; i++) {
  6292. ii = this._virtualItems[oldFirstIndex + i];
  6293. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6294. if (ii.obj instanceof fgui.GButton)
  6295. ii.selected = ii.obj.selected;
  6296. this.removeChildToPool(ii.obj);
  6297. ii.obj = null;
  6298. }
  6299. }
  6300. childCount = this._children.length;
  6301. for (i = 0; i < childCount; i++) {
  6302. var obj = this._virtualItems[newFirstIndex + i].obj;
  6303. if (this._children[i] != obj)
  6304. this.setChildIndex(obj, i);
  6305. }
  6306. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6307. this._scrollPane.changeContentSizeOnScrolling(0, deltaSize, 0, firstItemDeltaSize);
  6308. if (curIndex > 0 && this.numChildren > 0 && this._container.y <= 0 && this.getChildAt(0).y > -this._container.y)
  6309. return true;
  6310. else
  6311. return false;
  6312. };
  6313. GList.prototype.handleScroll2 = function (forceUpdate) {
  6314. var pos = this._scrollPane.scrollingPosX;
  6315. var max = pos + this._scrollPane.viewWidth;
  6316. var end = pos == this._scrollPane.contentWidth;
  6317. s_n = pos;
  6318. var newFirstIndex = this.getIndexOnPos2(forceUpdate);
  6319. pos = s_n;
  6320. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  6321. return false;
  6322. }
  6323. var oldFirstIndex = this._firstIndex;
  6324. this._firstIndex = newFirstIndex;
  6325. var curIndex = newFirstIndex;
  6326. var forward = oldFirstIndex > newFirstIndex;
  6327. var childCount = this.numChildren;
  6328. var lastIndex = oldFirstIndex + childCount - 1;
  6329. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6330. var curX = pos, curY = 0;
  6331. var needRender;
  6332. var deltaSize = 0;
  6333. var firstItemDeltaSize = 0;
  6334. var url = this._defaultItem;
  6335. var ii, ii2;
  6336. var i, j;
  6337. var partSize = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6338. this.itemInfoVer++;
  6339. while (curIndex < this._realNumItems && (end || curX < max)) {
  6340. ii = this._virtualItems[curIndex];
  6341. if (!ii.obj || forceUpdate) {
  6342. if (this.itemProvider != null) {
  6343. url = this.itemProvider(curIndex % this._numItems);
  6344. if (url == null)
  6345. url = this._defaultItem;
  6346. url = fgui.UIPackage.normalizeURL(url);
  6347. }
  6348. if (ii.obj && ii.obj.resourceURL != url) {
  6349. if (ii.obj instanceof fgui.GButton)
  6350. ii.selected = ii.obj.selected;
  6351. this.removeChildToPool(ii.obj);
  6352. ii.obj = null;
  6353. }
  6354. }
  6355. if (!ii.obj) {
  6356. if (forward) {
  6357. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6358. ii2 = this._virtualItems[j];
  6359. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6360. if (ii2.obj instanceof fgui.GButton)
  6361. ii2.selected = ii2.obj.selected;
  6362. ii.obj = ii2.obj;
  6363. ii2.obj = null;
  6364. if (j == reuseIndex)
  6365. reuseIndex--;
  6366. break;
  6367. }
  6368. }
  6369. }
  6370. else {
  6371. for (j = reuseIndex; j <= lastIndex; j++) {
  6372. ii2 = this._virtualItems[j];
  6373. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6374. if (ii2.obj instanceof fgui.GButton)
  6375. ii2.selected = ii2.obj.selected;
  6376. ii.obj = ii2.obj;
  6377. ii2.obj = null;
  6378. if (j == reuseIndex)
  6379. reuseIndex++;
  6380. break;
  6381. }
  6382. }
  6383. }
  6384. if (ii.obj) {
  6385. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6386. }
  6387. else {
  6388. ii.obj = this._pool.getObject(url);
  6389. if (forward)
  6390. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6391. else
  6392. this.addChild(ii.obj);
  6393. }
  6394. if (ii.obj instanceof fgui.GButton)
  6395. ii.obj.selected = ii.selected;
  6396. needRender = true;
  6397. }
  6398. else
  6399. needRender = forceUpdate;
  6400. if (needRender) {
  6401. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleRow || this._lineCount > 0))
  6402. ii.obj.setSize(ii.obj.width, partSize, true);
  6403. this.itemRenderer(curIndex % this._numItems, ii.obj);
  6404. if (curIndex % this._curLineItemCount == 0) {
  6405. deltaSize += Math.ceil(ii.obj.width) - ii.width;
  6406. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6407. firstItemDeltaSize = Math.ceil(ii.obj.width) - ii.width;
  6408. }
  6409. }
  6410. ii.width = Math.ceil(ii.obj.width);
  6411. ii.height = Math.ceil(ii.obj.height);
  6412. }
  6413. ii.updateFlag = this.itemInfoVer;
  6414. ii.obj.setPosition(curX, curY);
  6415. if (curIndex == newFirstIndex)
  6416. max += ii.width;
  6417. curY += ii.height + this._lineGap;
  6418. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6419. curY = 0;
  6420. curX += ii.width + this._columnGap;
  6421. }
  6422. curIndex++;
  6423. }
  6424. for (i = 0; i < childCount; i++) {
  6425. ii = this._virtualItems[oldFirstIndex + i];
  6426. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6427. if (ii.obj instanceof fgui.GButton)
  6428. ii.selected = ii.obj.selected;
  6429. this.removeChildToPool(ii.obj);
  6430. ii.obj = null;
  6431. }
  6432. }
  6433. childCount = this._children.length;
  6434. for (i = 0; i < childCount; i++) {
  6435. var obj = this._virtualItems[newFirstIndex + i].obj;
  6436. if (this._children[i] != obj)
  6437. this.setChildIndex(obj, i);
  6438. }
  6439. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6440. this._scrollPane.changeContentSizeOnScrolling(deltaSize, 0, firstItemDeltaSize, 0);
  6441. if (curIndex > 0 && this.numChildren > 0 && this._container.x <= 0 && this.getChildAt(0).x > -this._container.x)
  6442. return true;
  6443. else
  6444. return false;
  6445. };
  6446. GList.prototype.handleScroll3 = function (forceUpdate) {
  6447. var pos = this._scrollPane.scrollingPosX;
  6448. s_n = pos;
  6449. var newFirstIndex = this.getIndexOnPos3(forceUpdate);
  6450. pos = s_n;
  6451. if (newFirstIndex == this._firstIndex && !forceUpdate)
  6452. return;
  6453. var oldFirstIndex = this._firstIndex;
  6454. this._firstIndex = newFirstIndex;
  6455. var reuseIndex = oldFirstIndex;
  6456. var virtualItemCount = this._virtualItems.length;
  6457. var pageSize = this._curLineItemCount * this._curLineItemCount2;
  6458. var startCol = newFirstIndex % this._curLineItemCount;
  6459. var viewWidth = this.viewWidth;
  6460. var page = Math.floor(newFirstIndex / pageSize);
  6461. var startIndex = page * pageSize;
  6462. var lastIndex = startIndex + pageSize * 2;
  6463. var needRender;
  6464. var i;
  6465. var ii, ii2;
  6466. var col;
  6467. var url = this._defaultItem;
  6468. var partWidth = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6469. var partHeight = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount2 - 1)) / this._curLineItemCount2;
  6470. this.itemInfoVer++;
  6471. for (i = startIndex; i < lastIndex; i++) {
  6472. if (i >= this._realNumItems)
  6473. continue;
  6474. col = i % this._curLineItemCount;
  6475. if (i - startIndex < pageSize) {
  6476. if (col < startCol)
  6477. continue;
  6478. }
  6479. else {
  6480. if (col > startCol)
  6481. continue;
  6482. }
  6483. ii = this._virtualItems[i];
  6484. ii.updateFlag = this.itemInfoVer;
  6485. }
  6486. var lastObj = null;
  6487. var insertIndex = 0;
  6488. for (i = startIndex; i < lastIndex; i++) {
  6489. if (i >= this._realNumItems)
  6490. continue;
  6491. ii = this._virtualItems[i];
  6492. if (ii.updateFlag != this.itemInfoVer)
  6493. continue;
  6494. if (!ii.obj) {
  6495. while (reuseIndex < virtualItemCount) {
  6496. ii2 = this._virtualItems[reuseIndex];
  6497. if (ii2.obj && ii2.updateFlag != this.itemInfoVer) {
  6498. if (ii2.obj instanceof fgui.GButton)
  6499. ii2.selected = ii2.obj.selected;
  6500. ii.obj = ii2.obj;
  6501. ii2.obj = null;
  6502. break;
  6503. }
  6504. reuseIndex++;
  6505. }
  6506. if (insertIndex == -1)
  6507. insertIndex = this.getChildIndex(lastObj) + 1;
  6508. if (!ii.obj) {
  6509. if (this.itemProvider != null) {
  6510. url = this.itemProvider(i % this._numItems);
  6511. if (url == null)
  6512. url = this._defaultItem;
  6513. url = fgui.UIPackage.normalizeURL(url);
  6514. }
  6515. ii.obj = this._pool.getObject(url);
  6516. this.addChildAt(ii.obj, insertIndex);
  6517. }
  6518. else {
  6519. insertIndex = this.setChildIndexBefore(ii.obj, insertIndex);
  6520. }
  6521. insertIndex++;
  6522. if (ii.obj instanceof fgui.GButton)
  6523. ii.obj.selected = ii.selected;
  6524. needRender = true;
  6525. }
  6526. else {
  6527. needRender = forceUpdate;
  6528. insertIndex = -1;
  6529. lastObj = ii.obj;
  6530. }
  6531. if (needRender) {
  6532. if (this._autoResizeItem) {
  6533. if (this._curLineItemCount == this._columnCount && this._curLineItemCount2 == this._lineCount)
  6534. ii.obj.setSize(partWidth, partHeight, true);
  6535. else if (this._curLineItemCount == this._columnCount)
  6536. ii.obj.setSize(partWidth, ii.obj.height, true);
  6537. else if (this._curLineItemCount2 == this._lineCount)
  6538. ii.obj.setSize(ii.obj.width, partHeight, true);
  6539. }
  6540. this.itemRenderer(i % this._numItems, ii.obj);
  6541. ii.width = Math.ceil(ii.obj.width);
  6542. ii.height = Math.ceil(ii.obj.height);
  6543. }
  6544. }
  6545. var borderX = (startIndex / pageSize) * viewWidth;
  6546. var xx = borderX;
  6547. var yy = 0;
  6548. var lineHeight = 0;
  6549. for (i = startIndex; i < lastIndex; i++) {
  6550. if (i >= this._realNumItems)
  6551. continue;
  6552. ii = this._virtualItems[i];
  6553. if (ii.updateFlag == this.itemInfoVer)
  6554. ii.obj.setPosition(xx, yy);
  6555. if (ii.height > lineHeight)
  6556. lineHeight = ii.height;
  6557. if (i % this._curLineItemCount == this._curLineItemCount - 1) {
  6558. xx = borderX;
  6559. yy += lineHeight + this._lineGap;
  6560. lineHeight = 0;
  6561. if (i == startIndex + pageSize - 1) {
  6562. borderX += viewWidth;
  6563. xx = borderX;
  6564. yy = 0;
  6565. }
  6566. }
  6567. else
  6568. xx += ii.width + this._columnGap;
  6569. }
  6570. for (i = reuseIndex; i < virtualItemCount; i++) {
  6571. ii = this._virtualItems[i];
  6572. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6573. if (ii.obj instanceof fgui.GButton)
  6574. ii.selected = ii.obj.selected;
  6575. this.removeChildToPool(ii.obj);
  6576. ii.obj = null;
  6577. }
  6578. }
  6579. };
  6580. GList.prototype.handleArchOrder1 = function () {
  6581. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6582. var mid = this._scrollPane.posY + this.viewHeight / 2;
  6583. var minDist = Number.POSITIVE_INFINITY;
  6584. var dist = 0;
  6585. var apexIndex = 0;
  6586. var cnt = this.numChildren;
  6587. for (var i = 0; i < cnt; i++) {
  6588. var obj = this.getChildAt(i);
  6589. if (!this.foldInvisibleItems || obj.visible) {
  6590. dist = Math.abs(mid - obj.y - obj.height / 2);
  6591. if (dist < minDist) {
  6592. minDist = dist;
  6593. apexIndex = i;
  6594. }
  6595. }
  6596. }
  6597. this.apexIndex = apexIndex;
  6598. }
  6599. };
  6600. GList.prototype.handleArchOrder2 = function () {
  6601. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6602. var mid = this._scrollPane.posX + this.viewWidth / 2;
  6603. var minDist = Number.POSITIVE_INFINITY;
  6604. var dist = 0;
  6605. var apexIndex = 0;
  6606. var cnt = this.numChildren;
  6607. for (var i = 0; i < cnt; i++) {
  6608. var obj = this.getChildAt(i);
  6609. if (!this.foldInvisibleItems || obj.visible) {
  6610. dist = Math.abs(mid - obj.x - obj.width / 2);
  6611. if (dist < minDist) {
  6612. minDist = dist;
  6613. apexIndex = i;
  6614. }
  6615. }
  6616. }
  6617. this.apexIndex = apexIndex;
  6618. }
  6619. };
  6620. GList.prototype.handleAlign = function (contentWidth, contentHeight) {
  6621. var newOffsetX = 0;
  6622. var newOffsetY = 0;
  6623. if (contentHeight < this.viewHeight) {
  6624. if (this._verticalAlign == fgui.VertAlignType.Middle)
  6625. newOffsetY = Math.floor((this.viewHeight - contentHeight) / 2);
  6626. else if (this._verticalAlign == fgui.VertAlignType.Bottom)
  6627. newOffsetY = this.viewHeight - contentHeight;
  6628. }
  6629. if (contentWidth < this.viewWidth) {
  6630. if (this._align == fgui.AlignType.Center)
  6631. newOffsetX = Math.floor((this.viewWidth - contentWidth) / 2);
  6632. else if (this._align == fgui.AlignType.Right)
  6633. newOffsetX = this.viewWidth - contentWidth;
  6634. }
  6635. if (newOffsetX != this._alignOffset.x || newOffsetY != this._alignOffset.y) {
  6636. this._alignOffset.x = newOffsetX;
  6637. this._alignOffset.y = newOffsetY;
  6638. if (this._scrollPane)
  6639. this._scrollPane.adjustMaskContainer();
  6640. else
  6641. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  6642. }
  6643. };
  6644. GList.prototype.updateBounds = function () {
  6645. if (this._virtual)
  6646. return;
  6647. var i;
  6648. var child;
  6649. var curX = 0;
  6650. var curY = 0;
  6651. var maxWidth = 0;
  6652. var maxHeight = 0;
  6653. var cw = 0, ch = 0;
  6654. var j = 0;
  6655. var page = 0;
  6656. var k = 0;
  6657. var cnt = this._children.length;
  6658. var viewWidth = this.viewWidth;
  6659. var viewHeight = this.viewHeight;
  6660. var lineSize = 0;
  6661. var lineStart = 0;
  6662. var ratio = 0;
  6663. if (this._layout == fgui.ListLayoutType.SingleColumn) {
  6664. for (i = 0; i < cnt; i++) {
  6665. child = this.getChildAt(i);
  6666. if (this.foldInvisibleItems && !child.visible)
  6667. continue;
  6668. if (curY != 0)
  6669. curY += this._lineGap;
  6670. child.y = curY;
  6671. if (this._autoResizeItem)
  6672. child.setSize(viewWidth, child.height, true);
  6673. curY += Math.ceil(child.height);
  6674. if (child.width > maxWidth)
  6675. maxWidth = child.width;
  6676. }
  6677. ch = curY;
  6678. if (ch <= viewHeight && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.vtScrollBar) {
  6679. viewWidth += this._scrollPane.vtScrollBar.width;
  6680. for (i = 0; i < cnt; i++) {
  6681. child = this.getChildAt(i);
  6682. if (this.foldInvisibleItems && !child.visible)
  6683. continue;
  6684. child.setSize(viewWidth, child.height, true);
  6685. if (child.width > maxWidth)
  6686. maxWidth = child.width;
  6687. }
  6688. }
  6689. cw = Math.ceil(maxWidth);
  6690. }
  6691. else if (this._layout == fgui.ListLayoutType.SingleRow) {
  6692. for (i = 0; i < cnt; i++) {
  6693. child = this.getChildAt(i);
  6694. if (this.foldInvisibleItems && !child.visible)
  6695. continue;
  6696. if (curX != 0)
  6697. curX += this._columnGap;
  6698. child.x = curX;
  6699. if (this._autoResizeItem)
  6700. child.setSize(child.width, viewHeight, true);
  6701. curX += Math.ceil(child.width);
  6702. if (child.height > maxHeight)
  6703. maxHeight = child.height;
  6704. }
  6705. cw = curX;
  6706. if (cw <= viewWidth && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.hzScrollBar) {
  6707. viewHeight += this._scrollPane.hzScrollBar.height;
  6708. for (i = 0; i < cnt; i++) {
  6709. child = this.getChildAt(i);
  6710. if (this.foldInvisibleItems && !child.visible)
  6711. continue;
  6712. child.setSize(child.width, viewHeight, true);
  6713. if (child.height > maxHeight)
  6714. maxHeight = child.height;
  6715. }
  6716. }
  6717. ch = Math.ceil(maxHeight);
  6718. }
  6719. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6720. if (this._autoResizeItem && this._columnCount > 0) {
  6721. for (i = 0; i < cnt; i++) {
  6722. child = this.getChildAt(i);
  6723. if (this.foldInvisibleItems && !child.visible)
  6724. continue;
  6725. lineSize += child.sourceWidth;
  6726. j++;
  6727. if (j == this._columnCount || i == cnt - 1) {
  6728. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6729. curX = 0;
  6730. for (j = lineStart; j <= i; j++) {
  6731. child = this.getChildAt(j);
  6732. if (this.foldInvisibleItems && !child.visible)
  6733. continue;
  6734. child.setPosition(curX, curY);
  6735. if (j < i) {
  6736. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), child.height, true);
  6737. curX += Math.ceil(child.width) + this._columnGap;
  6738. }
  6739. else {
  6740. child.setSize(viewWidth - curX, child.height, true);
  6741. }
  6742. if (child.height > maxHeight)
  6743. maxHeight = child.height;
  6744. }
  6745. curY += Math.ceil(maxHeight) + this._lineGap;
  6746. maxHeight = 0;
  6747. j = 0;
  6748. lineStart = i + 1;
  6749. lineSize = 0;
  6750. }
  6751. }
  6752. ch = curY + Math.ceil(maxHeight);
  6753. cw = viewWidth;
  6754. }
  6755. else {
  6756. for (i = 0; i < cnt; i++) {
  6757. child = this.getChildAt(i);
  6758. if (this.foldInvisibleItems && !child.visible)
  6759. continue;
  6760. if (curX != 0)
  6761. curX += this._columnGap;
  6762. if (this._columnCount != 0 && j >= this._columnCount
  6763. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  6764. curX = 0;
  6765. curY += Math.ceil(maxHeight) + this._lineGap;
  6766. maxHeight = 0;
  6767. j = 0;
  6768. }
  6769. child.setPosition(curX, curY);
  6770. curX += Math.ceil(child.width);
  6771. if (curX > maxWidth)
  6772. maxWidth = curX;
  6773. if (child.height > maxHeight)
  6774. maxHeight = child.height;
  6775. j++;
  6776. }
  6777. ch = curY + Math.ceil(maxHeight);
  6778. cw = Math.ceil(maxWidth);
  6779. }
  6780. }
  6781. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  6782. if (this._autoResizeItem && this._lineCount > 0) {
  6783. for (i = 0; i < cnt; i++) {
  6784. child = this.getChildAt(i);
  6785. if (this.foldInvisibleItems && !child.visible)
  6786. continue;
  6787. lineSize += child.sourceHeight;
  6788. j++;
  6789. if (j == this._lineCount || i == cnt - 1) {
  6790. ratio = (viewHeight - lineSize - (j - 1) * this._lineGap) / lineSize;
  6791. curY = 0;
  6792. for (j = lineStart; j <= i; j++) {
  6793. child = this.getChildAt(j);
  6794. if (this.foldInvisibleItems && !child.visible)
  6795. continue;
  6796. child.setPosition(curX, curY);
  6797. if (j < i) {
  6798. child.setSize(child.width, child.sourceHeight + Math.round(child.sourceHeight * ratio), true);
  6799. curY += Math.ceil(child.height) + this._lineGap;
  6800. }
  6801. else {
  6802. child.setSize(child.width, viewHeight - curY, true);
  6803. }
  6804. if (child.width > maxWidth)
  6805. maxWidth = child.width;
  6806. }
  6807. curX += Math.ceil(maxWidth) + this._columnGap;
  6808. maxWidth = 0;
  6809. j = 0;
  6810. lineStart = i + 1;
  6811. lineSize = 0;
  6812. }
  6813. }
  6814. cw = curX + Math.ceil(maxWidth);
  6815. ch = viewHeight;
  6816. }
  6817. else {
  6818. for (i = 0; i < cnt; i++) {
  6819. child = this.getChildAt(i);
  6820. if (this.foldInvisibleItems && !child.visible)
  6821. continue;
  6822. if (curY != 0)
  6823. curY += this._lineGap;
  6824. if (this._lineCount != 0 && j >= this._lineCount
  6825. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) {
  6826. curY = 0;
  6827. curX += Math.ceil(maxWidth) + this._columnGap;
  6828. maxWidth = 0;
  6829. j = 0;
  6830. }
  6831. child.setPosition(curX, curY);
  6832. curY += Math.ceil(child.height);
  6833. if (curY > maxHeight)
  6834. maxHeight = curY;
  6835. if (child.width > maxWidth)
  6836. maxWidth = child.width;
  6837. j++;
  6838. }
  6839. cw = curX + Math.ceil(maxWidth);
  6840. ch = Math.ceil(maxHeight);
  6841. }
  6842. }
  6843. else {
  6844. var eachHeight;
  6845. if (this._autoResizeItem && this._lineCount > 0)
  6846. eachHeight = Math.floor((viewHeight - (this._lineCount - 1) * this._lineGap) / this._lineCount);
  6847. if (this._autoResizeItem && this._columnCount > 0) {
  6848. for (i = 0; i < cnt; i++) {
  6849. child = this.getChildAt(i);
  6850. if (this.foldInvisibleItems && !child.visible)
  6851. continue;
  6852. if (j == 0 && (this._lineCount != 0 && k >= this._lineCount
  6853. || this._lineCount == 0 && curY + (this._lineCount > 0 ? eachHeight : child.height) > viewHeight)) {
  6854. page++;
  6855. curY = 0;
  6856. k = 0;
  6857. }
  6858. lineSize += child.sourceWidth;
  6859. j++;
  6860. if (j == this._columnCount || i == cnt - 1) {
  6861. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6862. curX = 0;
  6863. for (j = lineStart; j <= i; j++) {
  6864. child = this.getChildAt(j);
  6865. if (this.foldInvisibleItems && !child.visible)
  6866. continue;
  6867. child.setPosition(page * viewWidth + curX, curY);
  6868. if (j < i) {
  6869. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), this._lineCount > 0 ? eachHeight : child.height, true);
  6870. curX += Math.ceil(child.width) + this._columnGap;
  6871. }
  6872. else {
  6873. child.setSize(viewWidth - curX, this._lineCount > 0 ? eachHeight : child.height, true);
  6874. }
  6875. if (child.height > maxHeight)
  6876. maxHeight = child.height;
  6877. }
  6878. curY += Math.ceil(maxHeight) + this._lineGap;
  6879. maxHeight = 0;
  6880. j = 0;
  6881. lineStart = i + 1;
  6882. lineSize = 0;
  6883. k++;
  6884. }
  6885. }
  6886. }
  6887. else {
  6888. for (i = 0; i < cnt; i++) {
  6889. child = this.getChildAt(i);
  6890. if (this.foldInvisibleItems && !child.visible)
  6891. continue;
  6892. if (curX != 0)
  6893. curX += this._columnGap;
  6894. if (this._autoResizeItem && this._lineCount > 0)
  6895. child.setSize(child.width, eachHeight, true);
  6896. if (this._columnCount != 0 && j >= this._columnCount
  6897. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  6898. curX = 0;
  6899. curY += Math.ceil(maxHeight) + this._lineGap;
  6900. maxHeight = 0;
  6901. j = 0;
  6902. k++;
  6903. if (this._lineCount != 0 && k >= this._lineCount
  6904. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) {
  6905. page++;
  6906. curY = 0;
  6907. k = 0;
  6908. }
  6909. }
  6910. child.setPosition(page * viewWidth + curX, curY);
  6911. curX += Math.ceil(child.width);
  6912. if (curX > maxWidth)
  6913. maxWidth = curX;
  6914. if (child.height > maxHeight)
  6915. maxHeight = child.height;
  6916. j++;
  6917. }
  6918. }
  6919. ch = page > 0 ? viewHeight : curY + Math.ceil(maxHeight);
  6920. cw = (page + 1) * viewWidth;
  6921. }
  6922. this.handleAlign(cw, ch);
  6923. this.setBounds(0, 0, cw, ch);
  6924. };
  6925. GList.prototype.setup_beforeAdd = function (buffer, beginPos) {
  6926. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  6927. buffer.seek(beginPos, 5);
  6928. this._layout = buffer.readByte();
  6929. this._selectionMode = buffer.readByte();
  6930. this._align = buffer.readByte();
  6931. this._verticalAlign = buffer.readByte();
  6932. this._lineGap = buffer.readShort();
  6933. this._columnGap = buffer.readShort();
  6934. this._lineCount = buffer.readShort();
  6935. this._columnCount = buffer.readShort();
  6936. this._autoResizeItem = buffer.readBool();
  6937. this._childrenRenderOrder = buffer.readByte();
  6938. this._apexIndex = buffer.readShort();
  6939. if (buffer.readBool()) {
  6940. this._margin.top = buffer.readInt();
  6941. this._margin.bottom = buffer.readInt();
  6942. this._margin.left = buffer.readInt();
  6943. this._margin.right = buffer.readInt();
  6944. }
  6945. var overflow = buffer.readByte();
  6946. if (overflow == fgui.OverflowType.Scroll) {
  6947. var savedPos = buffer.position;
  6948. buffer.seek(beginPos, 7);
  6949. this.setupScroll(buffer);
  6950. buffer.position = savedPos;
  6951. }
  6952. else
  6953. this.setupOverflow(overflow);
  6954. if (buffer.readBool())
  6955. buffer.skip(8);
  6956. if (buffer.version >= 2) {
  6957. this.scrollItemToViewOnClick = buffer.readBool();
  6958. this.foldInvisibleItems = buffer.readBool();
  6959. }
  6960. buffer.seek(beginPos, 8);
  6961. this._defaultItem = buffer.readS();
  6962. this.readItems(buffer);
  6963. };
  6964. GList.prototype.readItems = function (buffer) {
  6965. var cnt;
  6966. var i;
  6967. var nextPos;
  6968. var str;
  6969. cnt = buffer.readShort();
  6970. for (i = 0; i < cnt; i++) {
  6971. nextPos = buffer.readShort();
  6972. nextPos += buffer.position;
  6973. str = buffer.readS();
  6974. if (str == null) {
  6975. str = this._defaultItem;
  6976. if (!str) {
  6977. buffer.position = nextPos;
  6978. continue;
  6979. }
  6980. }
  6981. var obj = this.getFromPool(str);
  6982. if (obj) {
  6983. this.addChild(obj);
  6984. this.setupItem(buffer, obj);
  6985. }
  6986. buffer.position = nextPos;
  6987. }
  6988. };
  6989. GList.prototype.setupItem = function (buffer, obj) {
  6990. var str;
  6991. str = buffer.readS();
  6992. if (str != null)
  6993. obj.text = str;
  6994. str = buffer.readS();
  6995. if (str != null && (obj instanceof fgui.GButton))
  6996. obj.selectedTitle = str;
  6997. str = buffer.readS();
  6998. if (str != null)
  6999. obj.icon = str;
  7000. str = buffer.readS();
  7001. if (str != null && (obj instanceof fgui.GButton))
  7002. obj.selectedIcon = str;
  7003. str = buffer.readS();
  7004. if (str != null)
  7005. obj.name = str;
  7006. var cnt;
  7007. var i;
  7008. if (obj instanceof fgui.GComponent) {
  7009. cnt = buffer.readShort();
  7010. for (i = 0; i < cnt; i++) {
  7011. var cc = obj.getController(buffer.readS());
  7012. str = buffer.readS();
  7013. if (cc)
  7014. cc.selectedPageId = str;
  7015. }
  7016. if (buffer.version >= 2) {
  7017. cnt = buffer.readShort();
  7018. for (i = 0; i < cnt; i++) {
  7019. var target = buffer.readS();
  7020. var propertyId = buffer.readShort();
  7021. var value = buffer.readS();
  7022. var obj2 = obj.getChildByPath(target);
  7023. if (obj2)
  7024. obj2.setProp(propertyId, value);
  7025. }
  7026. }
  7027. }
  7028. };
  7029. GList.prototype.setup_afterAdd = function (buffer, beginPos) {
  7030. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  7031. buffer.seek(beginPos, 6);
  7032. var i = buffer.readShort();
  7033. if (i != -1)
  7034. this._selectionController = this.parent.getControllerAt(i);
  7035. };
  7036. return GList;
  7037. }(fgui.GComponent));
  7038. fgui.GList = GList;
  7039. var s_n = 0;
  7040. })(fgui || (fgui = {}));
  7041. (function (fgui) {
  7042. var GObjectPool = (function () {
  7043. function GObjectPool() {
  7044. this._count = 0;
  7045. this._pool = {};
  7046. }
  7047. GObjectPool.prototype.clear = function () {
  7048. for (var i1 in this._pool) {
  7049. var arr = this._pool[i1];
  7050. var cnt = arr.length;
  7051. for (var i = 0; i < cnt; i++)
  7052. arr[i].dispose();
  7053. }
  7054. this._pool = {};
  7055. this._count = 0;
  7056. };
  7057. Object.defineProperty(GObjectPool.prototype, "count", {
  7058. get: function () {
  7059. return this._count;
  7060. },
  7061. enumerable: false,
  7062. configurable: true
  7063. });
  7064. GObjectPool.prototype.getObject = function (url) {
  7065. url = fgui.UIPackage.normalizeURL(url);
  7066. if (url == null)
  7067. return null;
  7068. var arr = this._pool[url];
  7069. if (arr && arr.length) {
  7070. this._count--;
  7071. return arr.shift();
  7072. }
  7073. var child = fgui.UIPackage.createObjectFromURL(url);
  7074. return child;
  7075. };
  7076. GObjectPool.prototype.returnObject = function (obj) {
  7077. var url = obj.resourceURL;
  7078. if (!url)
  7079. return;
  7080. var arr = this._pool[url];
  7081. if (arr == null) {
  7082. arr = new Array();
  7083. this._pool[url] = arr;
  7084. }
  7085. this._count++;
  7086. arr.push(obj);
  7087. };
  7088. return GObjectPool;
  7089. }());
  7090. fgui.GObjectPool = GObjectPool;
  7091. })(fgui || (fgui = {}));
  7092. (function (fgui) {
  7093. var GLoader = (function (_super) {
  7094. __extends(GLoader, _super);
  7095. function GLoader() {
  7096. var _this = _super.call(this) || this;
  7097. _this._frame = 0;
  7098. _this._node.name = "GLoader";
  7099. _this._playing = true;
  7100. _this._url = "";
  7101. _this._fill = fgui.LoaderFillType.None;
  7102. _this._align = fgui.AlignType.Left;
  7103. _this._verticalAlign = fgui.VertAlignType.Top;
  7104. _this._showErrorSign = true;
  7105. _this._color = new cc.Color(255, 255, 255, 255);
  7106. _this._container = new cc.Node("Image");
  7107. _this._container.setAnchorPoint(0, 1);
  7108. _this._node.addChild(_this._container);
  7109. _this._content = _this._container.addComponent(fgui.MovieClip);
  7110. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  7111. _this._content.trim = false;
  7112. _this._content.setPlaySettings();
  7113. return _this;
  7114. }
  7115. GLoader.prototype.dispose = function () {
  7116. if (this._contentItem == null) {
  7117. if (this._content.spriteFrame)
  7118. this.freeExternal(this._content.spriteFrame);
  7119. }
  7120. if (this._content2)
  7121. this._content2.dispose();
  7122. _super.prototype.dispose.call(this);
  7123. };
  7124. Object.defineProperty(GLoader.prototype, "url", {
  7125. get: function () {
  7126. return this._url;
  7127. },
  7128. set: function (value) {
  7129. if (this._url == value)
  7130. return;
  7131. this._url = value;
  7132. this.loadContent();
  7133. this.updateGear(7);
  7134. },
  7135. enumerable: false,
  7136. configurable: true
  7137. });
  7138. Object.defineProperty(GLoader.prototype, "icon", {
  7139. get: function () {
  7140. return this._url;
  7141. },
  7142. set: function (value) {
  7143. this.url = value;
  7144. },
  7145. enumerable: false,
  7146. configurable: true
  7147. });
  7148. Object.defineProperty(GLoader.prototype, "align", {
  7149. get: function () {
  7150. return this._align;
  7151. },
  7152. set: function (value) {
  7153. if (this._align != value) {
  7154. this._align = value;
  7155. this.updateLayout();
  7156. }
  7157. },
  7158. enumerable: false,
  7159. configurable: true
  7160. });
  7161. Object.defineProperty(GLoader.prototype, "verticalAlign", {
  7162. get: function () {
  7163. return this._verticalAlign;
  7164. },
  7165. set: function (value) {
  7166. if (this._verticalAlign != value) {
  7167. this._verticalAlign = value;
  7168. this.updateLayout();
  7169. }
  7170. },
  7171. enumerable: false,
  7172. configurable: true
  7173. });
  7174. Object.defineProperty(GLoader.prototype, "fill", {
  7175. get: function () {
  7176. return this._fill;
  7177. },
  7178. set: function (value) {
  7179. if (this._fill != value) {
  7180. this._fill = value;
  7181. this.updateLayout();
  7182. }
  7183. },
  7184. enumerable: false,
  7185. configurable: true
  7186. });
  7187. Object.defineProperty(GLoader.prototype, "shrinkOnly", {
  7188. get: function () {
  7189. return this._shrinkOnly;
  7190. },
  7191. set: function (value) {
  7192. if (this._shrinkOnly != value) {
  7193. this._shrinkOnly = value;
  7194. this.updateLayout();
  7195. }
  7196. },
  7197. enumerable: false,
  7198. configurable: true
  7199. });
  7200. Object.defineProperty(GLoader.prototype, "autoSize", {
  7201. get: function () {
  7202. return this._autoSize;
  7203. },
  7204. set: function (value) {
  7205. if (this._autoSize != value) {
  7206. this._autoSize = value;
  7207. this.updateLayout();
  7208. }
  7209. },
  7210. enumerable: false,
  7211. configurable: true
  7212. });
  7213. Object.defineProperty(GLoader.prototype, "playing", {
  7214. get: function () {
  7215. return this._playing;
  7216. },
  7217. set: function (value) {
  7218. if (this._playing != value) {
  7219. this._playing = value;
  7220. if (this._content instanceof fgui.MovieClip)
  7221. this._content.playing = value;
  7222. this.updateGear(5);
  7223. }
  7224. },
  7225. enumerable: false,
  7226. configurable: true
  7227. });
  7228. Object.defineProperty(GLoader.prototype, "frame", {
  7229. get: function () {
  7230. return this._frame;
  7231. },
  7232. set: function (value) {
  7233. if (this._frame != value) {
  7234. this._frame = value;
  7235. if (this._content instanceof fgui.MovieClip)
  7236. this._content.frame = value;
  7237. this.updateGear(5);
  7238. }
  7239. },
  7240. enumerable: false,
  7241. configurable: true
  7242. });
  7243. Object.defineProperty(GLoader.prototype, "color", {
  7244. get: function () {
  7245. return this._color;
  7246. },
  7247. set: function (value) {
  7248. this._color.set(value);
  7249. this.updateGear(4);
  7250. this._container.color = value;
  7251. },
  7252. enumerable: false,
  7253. configurable: true
  7254. });
  7255. Object.defineProperty(GLoader.prototype, "fillMethod", {
  7256. get: function () {
  7257. return this._content.fillMethod;
  7258. },
  7259. set: function (value) {
  7260. this._content.fillMethod = value;
  7261. },
  7262. enumerable: false,
  7263. configurable: true
  7264. });
  7265. Object.defineProperty(GLoader.prototype, "fillOrigin", {
  7266. get: function () {
  7267. return this._content.fillOrigin;
  7268. },
  7269. set: function (value) {
  7270. this._content.fillOrigin = value;
  7271. },
  7272. enumerable: false,
  7273. configurable: true
  7274. });
  7275. Object.defineProperty(GLoader.prototype, "fillClockwise", {
  7276. get: function () {
  7277. return this._content.fillClockwise;
  7278. },
  7279. set: function (value) {
  7280. this._content.fillClockwise = value;
  7281. },
  7282. enumerable: false,
  7283. configurable: true
  7284. });
  7285. Object.defineProperty(GLoader.prototype, "fillAmount", {
  7286. get: function () {
  7287. return this._content.fillAmount;
  7288. },
  7289. set: function (value) {
  7290. this._content.fillAmount = value;
  7291. },
  7292. enumerable: false,
  7293. configurable: true
  7294. });
  7295. Object.defineProperty(GLoader.prototype, "showErrorSign", {
  7296. get: function () {
  7297. return this._showErrorSign;
  7298. },
  7299. set: function (value) {
  7300. this._showErrorSign = value;
  7301. },
  7302. enumerable: false,
  7303. configurable: true
  7304. });
  7305. Object.defineProperty(GLoader.prototype, "component", {
  7306. get: function () {
  7307. return this._content2;
  7308. },
  7309. enumerable: false,
  7310. configurable: true
  7311. });
  7312. Object.defineProperty(GLoader.prototype, "texture", {
  7313. get: function () {
  7314. return this._content.spriteFrame;
  7315. },
  7316. set: function (value) {
  7317. this.url = null;
  7318. this._content.spriteFrame = value;
  7319. this._content.type = cc.Sprite.Type.SIMPLE;
  7320. if (value != null) {
  7321. this.sourceWidth = value.getRect().width;
  7322. this.sourceHeight = value.getRect().height;
  7323. }
  7324. else {
  7325. this.sourceWidth = this.sourceHeight = 0;
  7326. }
  7327. this.updateLayout();
  7328. },
  7329. enumerable: false,
  7330. configurable: true
  7331. });
  7332. GLoader.prototype.loadContent = function () {
  7333. this.clearContent();
  7334. if (!this._url)
  7335. return;
  7336. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7337. this.loadFromPackage(this._url);
  7338. else
  7339. this.loadExternal();
  7340. };
  7341. GLoader.prototype.loadFromPackage = function (itemURL) {
  7342. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7343. if (this._contentItem) {
  7344. this._contentItem = this._contentItem.getBranch();
  7345. this.sourceWidth = this._contentItem.width;
  7346. this.sourceHeight = this._contentItem.height;
  7347. this._contentItem = this._contentItem.getHighResolution();
  7348. this._contentItem.load();
  7349. if (this._autoSize)
  7350. this.setSize(this.sourceWidth, this.sourceHeight);
  7351. if (this._contentItem.type == fgui.PackageItemType.Image) {
  7352. if (!this._contentItem.asset) {
  7353. this.setErrorState();
  7354. }
  7355. else {
  7356. this._content.spriteFrame = this._contentItem.asset;
  7357. if (this._content.fillMethod == 0) {
  7358. if (this._contentItem.scale9Grid)
  7359. this._content.type = cc.Sprite.Type.SLICED;
  7360. else if (this._contentItem.scaleByTile)
  7361. this._content.type = cc.Sprite.Type.TILED;
  7362. else
  7363. this._content.type = cc.Sprite.Type.SIMPLE;
  7364. }
  7365. this.updateLayout();
  7366. }
  7367. }
  7368. else if (this._contentItem.type == fgui.PackageItemType.MovieClip) {
  7369. this._content.interval = this._contentItem.interval;
  7370. this._content.swing = this._contentItem.swing;
  7371. this._content.repeatDelay = this._contentItem.repeatDelay;
  7372. this._content.frames = this._contentItem.frames;
  7373. this.updateLayout();
  7374. }
  7375. else if (this._contentItem.type == fgui.PackageItemType.Component) {
  7376. var obj = fgui.UIPackage.createObjectFromURL(itemURL);
  7377. if (!obj)
  7378. this.setErrorState();
  7379. else if (!(obj instanceof fgui.GComponent)) {
  7380. obj.dispose();
  7381. this.setErrorState();
  7382. }
  7383. else {
  7384. this._content2 = obj;
  7385. this._container.addChild(this._content2.node);
  7386. this.updateLayout();
  7387. }
  7388. }
  7389. else
  7390. this.setErrorState();
  7391. }
  7392. else
  7393. this.setErrorState();
  7394. };
  7395. GLoader.prototype.loadExternal = function () {
  7396. var _this = this;
  7397. var url = this.url;
  7398. var callback = function (err, asset) {
  7399. if (_this._url != url || !cc.isValid(_this._node))
  7400. return;
  7401. if (err)
  7402. console.warn(err);
  7403. if (asset instanceof cc.SpriteFrame)
  7404. _this.onExternalLoadSuccess(asset);
  7405. else if (asset instanceof cc.Texture2D)
  7406. _this.onExternalLoadSuccess(new cc.SpriteFrame(asset));
  7407. };
  7408. if (fgui.ToolSet.startsWith(this._url, "http://")
  7409. || fgui.ToolSet.startsWith(this._url, "https://")
  7410. || fgui.ToolSet.startsWith(this._url, '/'))
  7411. cc.assetManager.loadRemote(this._url, callback);
  7412. else
  7413. cc.resources.load(this._url, cc.Asset, callback);
  7414. };
  7415. GLoader.prototype.freeExternal = function (texture) {
  7416. };
  7417. GLoader.prototype.onExternalLoadSuccess = function (texture) {
  7418. this._content.spriteFrame = texture;
  7419. this._content.type = cc.Sprite.Type.SIMPLE;
  7420. this.sourceWidth = texture.getRect().width;
  7421. this.sourceHeight = texture.getRect().height;
  7422. if (this._autoSize)
  7423. this.setSize(this.sourceWidth, this.sourceHeight);
  7424. this.updateLayout();
  7425. };
  7426. GLoader.prototype.onExternalLoadFailed = function () {
  7427. this.setErrorState();
  7428. };
  7429. GLoader.prototype.setErrorState = function () {
  7430. if (!this._showErrorSign)
  7431. return;
  7432. if (this._errorSign == null) {
  7433. if (fgui.UIConfig.loaderErrorSign != null) {
  7434. this._errorSign = GLoader._errorSignPool.getObject(fgui.UIConfig.loaderErrorSign);
  7435. }
  7436. }
  7437. if (this._errorSign) {
  7438. this._errorSign.setSize(this.width, this.height);
  7439. this._container.addChild(this._errorSign.node);
  7440. }
  7441. };
  7442. GLoader.prototype.clearErrorState = function () {
  7443. if (this._errorSign) {
  7444. this._container.removeChild(this._errorSign.node);
  7445. GLoader._errorSignPool.returnObject(this._errorSign);
  7446. this._errorSign = null;
  7447. }
  7448. };
  7449. GLoader.prototype.updateLayout = function () {
  7450. if (this._content2 == null && this._content == null) {
  7451. if (this._autoSize) {
  7452. this._updatingLayout = true;
  7453. this.setSize(50, 30);
  7454. this._updatingLayout = false;
  7455. }
  7456. return;
  7457. }
  7458. var cw = this.sourceWidth;
  7459. var ch = this.sourceHeight;
  7460. var pivotCorrectX = -this.pivotX * this._width;
  7461. var pivotCorrectY = this.pivotY * this._height;
  7462. if (this._autoSize) {
  7463. this._updatingLayout = true;
  7464. if (cw == 0)
  7465. cw = 50;
  7466. if (ch == 0)
  7467. ch = 30;
  7468. this.setSize(cw, ch);
  7469. this._updatingLayout = false;
  7470. this._container.setContentSize(this._width, this._height);
  7471. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  7472. if (this._content2) {
  7473. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  7474. this._content2.setScale(1, 1);
  7475. }
  7476. if (cw == this._width && ch == this._height)
  7477. return;
  7478. }
  7479. var sx = 1, sy = 1;
  7480. if (this._fill != fgui.LoaderFillType.None) {
  7481. sx = this.width / this.sourceWidth;
  7482. sy = this.height / this.sourceHeight;
  7483. if (sx != 1 || sy != 1) {
  7484. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7485. sx = sy;
  7486. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7487. sy = sx;
  7488. else if (this._fill == fgui.LoaderFillType.Scale) {
  7489. if (sx > sy)
  7490. sx = sy;
  7491. else
  7492. sy = sx;
  7493. }
  7494. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7495. if (sx > sy)
  7496. sy = sx;
  7497. else
  7498. sx = sy;
  7499. }
  7500. if (this._shrinkOnly) {
  7501. if (sx > 1)
  7502. sx = 1;
  7503. if (sy > 1)
  7504. sy = 1;
  7505. }
  7506. cw = this.sourceWidth * sx;
  7507. ch = this.sourceHeight * sy;
  7508. }
  7509. }
  7510. this._container.setContentSize(cw, ch);
  7511. if (this._content2) {
  7512. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  7513. this._content2.setScale(sx, sy);
  7514. }
  7515. var nx, ny;
  7516. if (this._align == fgui.AlignType.Left)
  7517. nx = 0;
  7518. else if (this._align == fgui.AlignType.Center)
  7519. nx = Math.floor((this._width - cw) / 2);
  7520. else
  7521. nx = this._width - cw;
  7522. if (this._verticalAlign == fgui.VertAlignType.Top)
  7523. ny = 0;
  7524. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  7525. ny = Math.floor((this._height - ch) / 2);
  7526. else
  7527. ny = this._height - ch;
  7528. ny = -ny;
  7529. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  7530. };
  7531. GLoader.prototype.clearContent = function () {
  7532. this.clearErrorState();
  7533. if (!this._contentItem) {
  7534. var texture = this._content.spriteFrame;
  7535. if (texture)
  7536. this.freeExternal(texture);
  7537. }
  7538. if (this._content2) {
  7539. this._container.removeChild(this._content2.node);
  7540. this._content2.dispose();
  7541. this._content2 = null;
  7542. }
  7543. this._content.frames = null;
  7544. this._content.spriteFrame = null;
  7545. this._contentItem = null;
  7546. };
  7547. GLoader.prototype.handleSizeChanged = function () {
  7548. _super.prototype.handleSizeChanged.call(this);
  7549. if (!this._updatingLayout)
  7550. this.updateLayout();
  7551. };
  7552. GLoader.prototype.handleAnchorChanged = function () {
  7553. _super.prototype.handleAnchorChanged.call(this);
  7554. if (!this._updatingLayout)
  7555. this.updateLayout();
  7556. };
  7557. GLoader.prototype.handleGrayedChanged = function () {
  7558. this._content.grayed = this._grayed;
  7559. };
  7560. GLoader.prototype._hitTest = function (pt, globalPt) {
  7561. if (this._content2) {
  7562. var obj = this._content2.hitTest(globalPt);
  7563. if (obj)
  7564. return obj;
  7565. }
  7566. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  7567. return this;
  7568. else
  7569. return null;
  7570. };
  7571. GLoader.prototype.getProp = function (index) {
  7572. switch (index) {
  7573. case fgui.ObjectPropID.Color:
  7574. return this.color;
  7575. case fgui.ObjectPropID.Playing:
  7576. return this.playing;
  7577. case fgui.ObjectPropID.Frame:
  7578. return this.frame;
  7579. case fgui.ObjectPropID.TimeScale:
  7580. return this._content.timeScale;
  7581. default:
  7582. return _super.prototype.getProp.call(this, index);
  7583. }
  7584. };
  7585. GLoader.prototype.setProp = function (index, value) {
  7586. switch (index) {
  7587. case fgui.ObjectPropID.Color:
  7588. this.color = value;
  7589. break;
  7590. case fgui.ObjectPropID.Playing:
  7591. this.playing = value;
  7592. break;
  7593. case fgui.ObjectPropID.Frame:
  7594. this.frame = value;
  7595. break;
  7596. case fgui.ObjectPropID.TimeScale:
  7597. this._content.timeScale = value;
  7598. break;
  7599. case fgui.ObjectPropID.DeltaTime:
  7600. this._content.advance(value);
  7601. break;
  7602. default:
  7603. _super.prototype.setProp.call(this, index, value);
  7604. break;
  7605. }
  7606. };
  7607. GLoader.prototype.setup_beforeAdd = function (buffer, beginPos) {
  7608. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  7609. buffer.seek(beginPos, 5);
  7610. this._url = buffer.readS();
  7611. this._align = buffer.readByte();
  7612. this._verticalAlign = buffer.readByte();
  7613. this._fill = buffer.readByte();
  7614. this._shrinkOnly = buffer.readBool();
  7615. this._autoSize = buffer.readBool();
  7616. this._showErrorSign = buffer.readBool();
  7617. this._playing = buffer.readBool();
  7618. this._frame = buffer.readInt();
  7619. if (buffer.readBool())
  7620. this.color = buffer.readColor();
  7621. this._content.fillMethod = buffer.readByte();
  7622. if (this._content.fillMethod != 0) {
  7623. this._content.fillOrigin = buffer.readByte();
  7624. this._content.fillClockwise = buffer.readBool();
  7625. this._content.fillAmount = buffer.readFloat();
  7626. }
  7627. if (this._url)
  7628. this.loadContent();
  7629. };
  7630. GLoader._errorSignPool = new fgui.GObjectPool();
  7631. return GLoader;
  7632. }(fgui.GObject));
  7633. fgui.GLoader = GLoader;
  7634. })(fgui || (fgui = {}));
  7635. (function (fgui) {
  7636. var GLoader3D = (function (_super) {
  7637. __extends(GLoader3D, _super);
  7638. function GLoader3D() {
  7639. var _this = _super.call(this) || this;
  7640. _this._frame = 0;
  7641. _this._node.name = "GLoader3D";
  7642. _this._playing = true;
  7643. _this._url = "";
  7644. _this._fill = fgui.LoaderFillType.None;
  7645. _this._align = fgui.AlignType.Left;
  7646. _this._verticalAlign = fgui.VertAlignType.Top;
  7647. _this._color = new cc.Color(255, 255, 255, 255);
  7648. _this._container = new cc.Node("Wrapper");
  7649. _this._container.setAnchorPoint(0, 1);
  7650. _this._node.addChild(_this._container);
  7651. return _this;
  7652. }
  7653. GLoader3D.prototype.dispose = function () {
  7654. _super.prototype.dispose.call(this);
  7655. };
  7656. Object.defineProperty(GLoader3D.prototype, "url", {
  7657. get: function () {
  7658. return this._url;
  7659. },
  7660. set: function (value) {
  7661. if (this._url == value)
  7662. return;
  7663. this._url = value;
  7664. this.loadContent();
  7665. this.updateGear(7);
  7666. },
  7667. enumerable: false,
  7668. configurable: true
  7669. });
  7670. Object.defineProperty(GLoader3D.prototype, "icon", {
  7671. get: function () {
  7672. return this._url;
  7673. },
  7674. set: function (value) {
  7675. this.url = value;
  7676. },
  7677. enumerable: false,
  7678. configurable: true
  7679. });
  7680. Object.defineProperty(GLoader3D.prototype, "align", {
  7681. get: function () {
  7682. return this._align;
  7683. },
  7684. set: function (value) {
  7685. if (this._align != value) {
  7686. this._align = value;
  7687. this.updateLayout();
  7688. }
  7689. },
  7690. enumerable: false,
  7691. configurable: true
  7692. });
  7693. Object.defineProperty(GLoader3D.prototype, "verticalAlign", {
  7694. get: function () {
  7695. return this._verticalAlign;
  7696. },
  7697. set: function (value) {
  7698. if (this._verticalAlign != value) {
  7699. this._verticalAlign = value;
  7700. this.updateLayout();
  7701. }
  7702. },
  7703. enumerable: false,
  7704. configurable: true
  7705. });
  7706. Object.defineProperty(GLoader3D.prototype, "fill", {
  7707. get: function () {
  7708. return this._fill;
  7709. },
  7710. set: function (value) {
  7711. if (this._fill != value) {
  7712. this._fill = value;
  7713. this.updateLayout();
  7714. }
  7715. },
  7716. enumerable: false,
  7717. configurable: true
  7718. });
  7719. Object.defineProperty(GLoader3D.prototype, "shrinkOnly", {
  7720. get: function () {
  7721. return this._shrinkOnly;
  7722. },
  7723. set: function (value) {
  7724. if (this._shrinkOnly != value) {
  7725. this._shrinkOnly = value;
  7726. this.updateLayout();
  7727. }
  7728. },
  7729. enumerable: false,
  7730. configurable: true
  7731. });
  7732. Object.defineProperty(GLoader3D.prototype, "autoSize", {
  7733. get: function () {
  7734. return this._autoSize;
  7735. },
  7736. set: function (value) {
  7737. if (this._autoSize != value) {
  7738. this._autoSize = value;
  7739. this.updateLayout();
  7740. }
  7741. },
  7742. enumerable: false,
  7743. configurable: true
  7744. });
  7745. Object.defineProperty(GLoader3D.prototype, "playing", {
  7746. get: function () {
  7747. return this._playing;
  7748. },
  7749. set: function (value) {
  7750. if (this._playing != value) {
  7751. this._playing = value;
  7752. this.updateGear(5);
  7753. this.onChange();
  7754. }
  7755. },
  7756. enumerable: false,
  7757. configurable: true
  7758. });
  7759. Object.defineProperty(GLoader3D.prototype, "frame", {
  7760. get: function () {
  7761. return this._frame;
  7762. },
  7763. set: function (value) {
  7764. if (this._frame != value) {
  7765. this._frame = value;
  7766. this.updateGear(5);
  7767. this.onChange();
  7768. }
  7769. },
  7770. enumerable: false,
  7771. configurable: true
  7772. });
  7773. Object.defineProperty(GLoader3D.prototype, "animationName", {
  7774. get: function () {
  7775. return this._animationName;
  7776. },
  7777. set: function (value) {
  7778. if (this._animationName != value) {
  7779. this._animationName = value;
  7780. this.onChange();
  7781. }
  7782. },
  7783. enumerable: false,
  7784. configurable: true
  7785. });
  7786. Object.defineProperty(GLoader3D.prototype, "skinName", {
  7787. get: function () {
  7788. return this._skinName;
  7789. },
  7790. set: function (value) {
  7791. if (this._skinName != value) {
  7792. this._skinName = value;
  7793. this.onChange();
  7794. }
  7795. },
  7796. enumerable: false,
  7797. configurable: true
  7798. });
  7799. Object.defineProperty(GLoader3D.prototype, "loop", {
  7800. get: function () {
  7801. return this._loop;
  7802. },
  7803. set: function (value) {
  7804. if (this._loop != value) {
  7805. this._loop = value;
  7806. this.onChange();
  7807. }
  7808. },
  7809. enumerable: false,
  7810. configurable: true
  7811. });
  7812. Object.defineProperty(GLoader3D.prototype, "color", {
  7813. get: function () {
  7814. return this._color;
  7815. },
  7816. set: function (value) {
  7817. this._color.set(value);
  7818. this.updateGear(4);
  7819. if (this._content)
  7820. this._content.node.color = value;
  7821. },
  7822. enumerable: false,
  7823. configurable: true
  7824. });
  7825. Object.defineProperty(GLoader3D.prototype, "content", {
  7826. get: function () {
  7827. return this._content;
  7828. },
  7829. enumerable: false,
  7830. configurable: true
  7831. });
  7832. GLoader3D.prototype.loadContent = function () {
  7833. this.clearContent();
  7834. if (!this._url)
  7835. return;
  7836. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7837. this.loadFromPackage(this._url);
  7838. else
  7839. this.loadExternal();
  7840. };
  7841. GLoader3D.prototype.loadFromPackage = function (itemURL) {
  7842. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7843. if (this._contentItem) {
  7844. this._contentItem = this._contentItem.getBranch();
  7845. this.sourceWidth = this._contentItem.width;
  7846. this.sourceHeight = this._contentItem.height;
  7847. this._contentItem = this._contentItem.getHighResolution();
  7848. if (this._autoSize)
  7849. this.setSize(this.sourceWidth, this.sourceHeight);
  7850. if (this._contentItem.type == fgui.PackageItemType.Spine || this._contentItem.type == fgui.PackageItemType.DragonBones)
  7851. this._contentItem.owner.getItemAssetAsync(this._contentItem, this.onLoaded.bind(this));
  7852. }
  7853. };
  7854. GLoader3D.prototype.onLoaded = function (err, item) {
  7855. if (this._contentItem != item)
  7856. return;
  7857. if (err)
  7858. console.warn(err);
  7859. if (!this._contentItem.asset)
  7860. return;
  7861. if (this._contentItem.type == fgui.PackageItemType.Spine)
  7862. this.setSpine(this._contentItem.asset, this._contentItem.skeletonAnchor);
  7863. else if (this._contentItem.type == fgui.PackageItemType.DragonBones)
  7864. this.setDragonBones(this._contentItem.asset, this._contentItem.atlasAsset, this._contentItem.skeletonAnchor);
  7865. };
  7866. GLoader3D.prototype.setSpine = function (asset, anchor, pma) {
  7867. this.url = null;
  7868. this.clearContent();
  7869. var node = new cc.Node();
  7870. node.color = this._color;
  7871. this._container.addChild(node);
  7872. node.setPosition(anchor.x, -anchor.y);
  7873. this._content = node.addComponent(sp.Skeleton);
  7874. this._content.premultipliedAlpha = pma;
  7875. this._content.skeletonData = asset;
  7876. this.onChangeSpine();
  7877. this.updateLayout();
  7878. };
  7879. GLoader3D.prototype.setDragonBones = function (asset, atlasAsset, anchor, pma) {
  7880. this.url = null;
  7881. this.clearContent();
  7882. var node = new cc.Node();
  7883. node.color = this._color;
  7884. this._container.addChild(node);
  7885. node.setPosition(anchor.x, -anchor.y);
  7886. this._content = node.addComponent(dragonBones.ArmatureDisplay);
  7887. this._content.premultipliedAlpha = pma;
  7888. this._content.dragonAsset = asset;
  7889. this._content.dragonAtlasAsset = atlasAsset;
  7890. var armatureKey = asset["init"](dragonBones.CCFactory.getInstance(), atlasAsset["_uuid"]);
  7891. var dragonBonesData = this._content["_factory"].getDragonBonesData(armatureKey);
  7892. this._content.armatureName = dragonBonesData.armatureNames[0];
  7893. this.onChangeDragonBones();
  7894. this.updateLayout();
  7895. };
  7896. GLoader3D.prototype.onChange = function () {
  7897. this.onChangeSpine();
  7898. this.onChangeDragonBones();
  7899. };
  7900. GLoader3D.prototype.onChangeSpine = function () {
  7901. if (!(this._content instanceof sp.Skeleton))
  7902. return;
  7903. if (this._animationName) {
  7904. var trackEntry = this._content.getCurrent(0);
  7905. if (!trackEntry || trackEntry.animation.name != this._animationName || trackEntry.isComplete() && !trackEntry.loop) {
  7906. this._content.defaultAnimation = this._animationName;
  7907. trackEntry = this._content.setAnimation(0, this._animationName, this._loop);
  7908. }
  7909. if (this._playing)
  7910. this._content.paused = false;
  7911. else {
  7912. this._content.paused = true;
  7913. trackEntry.trackTime = fgui.ToolSet.lerp(0, trackEntry.animationEnd - trackEntry.animationStart, this._frame / 100);
  7914. }
  7915. }
  7916. else
  7917. this._content.clearTrack(0);
  7918. var skin = this._skinName || this._content.skeletonData.getRuntimeData().skins[0].name;
  7919. if (this._content["_skeleton"].skin != skin)
  7920. this._content.setSkin(skin);
  7921. };
  7922. GLoader3D.prototype.onChangeDragonBones = function () {
  7923. if (!(this._content instanceof dragonBones.ArmatureDisplay))
  7924. return;
  7925. if (this._animationName) {
  7926. if (this._playing)
  7927. this._content.playAnimation(this._animationName, this._loop ? 0 : 1);
  7928. else
  7929. this._content.armature().animation.gotoAndStopByFrame(this._animationName, this._frame);
  7930. }
  7931. else
  7932. this._content.armature().animation.reset();
  7933. };
  7934. GLoader3D.prototype.loadExternal = function () {
  7935. if (fgui.ToolSet.startsWith(this._url, "http://")
  7936. || fgui.ToolSet.startsWith(this._url, "https://")
  7937. || fgui.ToolSet.startsWith(this._url, '/'))
  7938. cc.assetManager.loadRemote(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7939. else
  7940. cc.resources.load(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7941. };
  7942. GLoader3D.prototype.onLoaded2 = function (err, asset) {
  7943. if (!this._url || !cc.isValid(this._node))
  7944. return;
  7945. if (err)
  7946. console.warn(err);
  7947. };
  7948. GLoader3D.prototype.updateLayout = function () {
  7949. var cw = this.sourceWidth;
  7950. var ch = this.sourceHeight;
  7951. var pivotCorrectX = -this.pivotX * this._width;
  7952. var pivotCorrectY = this.pivotY * this._height;
  7953. if (this._autoSize) {
  7954. this._updatingLayout = true;
  7955. if (cw == 0)
  7956. cw = 50;
  7957. if (ch == 0)
  7958. ch = 30;
  7959. this.setSize(cw, ch);
  7960. this._updatingLayout = false;
  7961. if (cw == this._width && ch == this._height) {
  7962. this._container.setScale(1, 1);
  7963. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  7964. return;
  7965. }
  7966. }
  7967. var sx = 1, sy = 1;
  7968. if (this._fill != fgui.LoaderFillType.None) {
  7969. sx = this.width / this.sourceWidth;
  7970. sy = this.height / this.sourceHeight;
  7971. if (sx != 1 || sy != 1) {
  7972. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7973. sx = sy;
  7974. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7975. sy = sx;
  7976. else if (this._fill == fgui.LoaderFillType.Scale) {
  7977. if (sx > sy)
  7978. sx = sy;
  7979. else
  7980. sy = sx;
  7981. }
  7982. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7983. if (sx > sy)
  7984. sy = sx;
  7985. else
  7986. sx = sy;
  7987. }
  7988. if (this._shrinkOnly) {
  7989. if (sx > 1)
  7990. sx = 1;
  7991. if (sy > 1)
  7992. sy = 1;
  7993. }
  7994. cw = this.sourceWidth * sx;
  7995. ch = this.sourceHeight * sy;
  7996. }
  7997. }
  7998. this._container.setScale(sx, sy);
  7999. var nx, ny;
  8000. if (this._align == fgui.AlignType.Left)
  8001. nx = 0;
  8002. else if (this._align == fgui.AlignType.Center)
  8003. nx = Math.floor((this._width - cw) / 2);
  8004. else
  8005. nx = this._width - cw;
  8006. if (this._verticalAlign == fgui.VertAlignType.Top)
  8007. ny = 0;
  8008. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  8009. ny = Math.floor((this._height - ch) / 2);
  8010. else
  8011. ny = this._height - ch;
  8012. ny = -ny;
  8013. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  8014. };
  8015. GLoader3D.prototype.clearContent = function () {
  8016. this._contentItem = null;
  8017. if (this._content) {
  8018. this._content.node.destroy();
  8019. this._content = null;
  8020. }
  8021. };
  8022. GLoader3D.prototype.handleSizeChanged = function () {
  8023. _super.prototype.handleSizeChanged.call(this);
  8024. if (!this._updatingLayout)
  8025. this.updateLayout();
  8026. };
  8027. GLoader3D.prototype.handleAnchorChanged = function () {
  8028. _super.prototype.handleAnchorChanged.call(this);
  8029. if (!this._updatingLayout)
  8030. this.updateLayout();
  8031. };
  8032. GLoader3D.prototype.handleGrayedChanged = function () {
  8033. };
  8034. GLoader3D.prototype.getProp = function (index) {
  8035. switch (index) {
  8036. case fgui.ObjectPropID.Color:
  8037. return this.color;
  8038. case fgui.ObjectPropID.Playing:
  8039. return this.playing;
  8040. case fgui.ObjectPropID.Frame:
  8041. return this.frame;
  8042. case fgui.ObjectPropID.TimeScale:
  8043. return 1;
  8044. default:
  8045. return _super.prototype.getProp.call(this, index);
  8046. }
  8047. };
  8048. GLoader3D.prototype.setProp = function (index, value) {
  8049. switch (index) {
  8050. case fgui.ObjectPropID.Color:
  8051. this.color = value;
  8052. break;
  8053. case fgui.ObjectPropID.Playing:
  8054. this.playing = value;
  8055. break;
  8056. case fgui.ObjectPropID.Frame:
  8057. this.frame = value;
  8058. break;
  8059. case fgui.ObjectPropID.TimeScale:
  8060. break;
  8061. case fgui.ObjectPropID.DeltaTime:
  8062. break;
  8063. default:
  8064. _super.prototype.setProp.call(this, index, value);
  8065. break;
  8066. }
  8067. };
  8068. GLoader3D.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8069. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8070. buffer.seek(beginPos, 5);
  8071. this._url = buffer.readS();
  8072. this._align = buffer.readByte();
  8073. this._verticalAlign = buffer.readByte();
  8074. this._fill = buffer.readByte();
  8075. this._shrinkOnly = buffer.readBool();
  8076. this._autoSize = buffer.readBool();
  8077. this._animationName = buffer.readS();
  8078. this._skinName = buffer.readS();
  8079. this._playing = buffer.readBool();
  8080. this._frame = buffer.readInt();
  8081. this._loop = buffer.readBool();
  8082. if (buffer.readBool())
  8083. this.color = buffer.readColor();
  8084. if (this._url)
  8085. this.loadContent();
  8086. };
  8087. return GLoader3D;
  8088. }(fgui.GObject));
  8089. fgui.GLoader3D = GLoader3D;
  8090. })(fgui || (fgui = {}));
  8091. (function (fgui) {
  8092. var GMovieClip = (function (_super) {
  8093. __extends(GMovieClip, _super);
  8094. function GMovieClip() {
  8095. var _this = _super.call(this) || this;
  8096. _this._node.name = "GMovieClip";
  8097. _this._touchDisabled = true;
  8098. _this._content = _this._node.addComponent(fgui.MovieClip);
  8099. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  8100. _this._content.trim = false;
  8101. _this._content.setPlaySettings();
  8102. return _this;
  8103. }
  8104. Object.defineProperty(GMovieClip.prototype, "color", {
  8105. get: function () {
  8106. return this._node.color;
  8107. },
  8108. set: function (value) {
  8109. this._node.color = value;
  8110. this.updateGear(4);
  8111. },
  8112. enumerable: false,
  8113. configurable: true
  8114. });
  8115. Object.defineProperty(GMovieClip.prototype, "playing", {
  8116. get: function () {
  8117. return this._content.playing;
  8118. },
  8119. set: function (value) {
  8120. if (this._content.playing != value) {
  8121. this._content.playing = value;
  8122. this.updateGear(5);
  8123. }
  8124. },
  8125. enumerable: false,
  8126. configurable: true
  8127. });
  8128. Object.defineProperty(GMovieClip.prototype, "frame", {
  8129. get: function () {
  8130. return this._content.frame;
  8131. },
  8132. set: function (value) {
  8133. if (this._content.frame != value) {
  8134. this._content.frame = value;
  8135. this.updateGear(5);
  8136. }
  8137. },
  8138. enumerable: false,
  8139. configurable: true
  8140. });
  8141. Object.defineProperty(GMovieClip.prototype, "timeScale", {
  8142. get: function () {
  8143. return this._content.timeScale;
  8144. },
  8145. set: function (value) {
  8146. this._content.timeScale = value;
  8147. },
  8148. enumerable: false,
  8149. configurable: true
  8150. });
  8151. GMovieClip.prototype.rewind = function () {
  8152. this._content.rewind();
  8153. };
  8154. GMovieClip.prototype.syncStatus = function (anotherMc) {
  8155. this._content.syncStatus(anotherMc._content);
  8156. };
  8157. GMovieClip.prototype.advance = function (timeInSeconds) {
  8158. this._content.advance(timeInSeconds);
  8159. };
  8160. GMovieClip.prototype.setPlaySettings = function (start, end, times, endAt, endCallback, callbackObj) {
  8161. this._content.setPlaySettings(start, end, times, endAt, endCallback, callbackObj);
  8162. };
  8163. GMovieClip.prototype.play = function (times, endCallback) {
  8164. this._content.setPlaySettings(null, null, times, null, endCallback, null);
  8165. };
  8166. GMovieClip.prototype.handleGrayedChanged = function () {
  8167. this._content.grayed = this._grayed;
  8168. };
  8169. GMovieClip.prototype.handleSizeChanged = function () {
  8170. _super.prototype.handleSizeChanged.call(this);
  8171. this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  8172. };
  8173. GMovieClip.prototype.getProp = function (index) {
  8174. switch (index) {
  8175. case fgui.ObjectPropID.Color:
  8176. return this.color;
  8177. case fgui.ObjectPropID.Playing:
  8178. return this.playing;
  8179. case fgui.ObjectPropID.Frame:
  8180. return this.frame;
  8181. case fgui.ObjectPropID.TimeScale:
  8182. return this.timeScale;
  8183. default:
  8184. return _super.prototype.getProp.call(this, index);
  8185. }
  8186. };
  8187. GMovieClip.prototype.setProp = function (index, value) {
  8188. switch (index) {
  8189. case fgui.ObjectPropID.Color:
  8190. this.color = value;
  8191. break;
  8192. case fgui.ObjectPropID.Playing:
  8193. this.playing = value;
  8194. break;
  8195. case fgui.ObjectPropID.Frame:
  8196. this.frame = value;
  8197. break;
  8198. case fgui.ObjectPropID.TimeScale:
  8199. this.timeScale = value;
  8200. break;
  8201. case fgui.ObjectPropID.DeltaTime:
  8202. this.advance(value);
  8203. break;
  8204. default:
  8205. _super.prototype.setProp.call(this, index, value);
  8206. break;
  8207. }
  8208. };
  8209. GMovieClip.prototype.constructFromResource = function () {
  8210. var contentItem = this.packageItem.getBranch();
  8211. this.sourceWidth = contentItem.width;
  8212. this.sourceHeight = contentItem.height;
  8213. this.initWidth = this.sourceWidth;
  8214. this.initHeight = this.sourceHeight;
  8215. this.setSize(this.sourceWidth, this.sourceHeight);
  8216. contentItem = contentItem.getHighResolution();
  8217. contentItem.load();
  8218. this._content.interval = contentItem.interval;
  8219. this._content.swing = contentItem.swing;
  8220. this._content.repeatDelay = contentItem.repeatDelay;
  8221. this._content.frames = contentItem.frames;
  8222. this._content.smoothing = contentItem.smoothing;
  8223. };
  8224. GMovieClip.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8225. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8226. buffer.seek(beginPos, 5);
  8227. if (buffer.readBool())
  8228. this.color = buffer.readColor();
  8229. buffer.readByte();
  8230. this._content.frame = buffer.readInt();
  8231. this._content.playing = buffer.readBool();
  8232. };
  8233. return GMovieClip;
  8234. }(fgui.GObject));
  8235. fgui.GMovieClip = GMovieClip;
  8236. })(fgui || (fgui = {}));
  8237. (function (fgui) {
  8238. var GProgressBar = (function (_super) {
  8239. __extends(GProgressBar, _super);
  8240. function GProgressBar() {
  8241. var _this = _super.call(this) || this;
  8242. _this._min = 0;
  8243. _this._max = 0;
  8244. _this._value = 0;
  8245. _this._barMaxWidth = 0;
  8246. _this._barMaxHeight = 0;
  8247. _this._barMaxWidthDelta = 0;
  8248. _this._barMaxHeightDelta = 0;
  8249. _this._barStartX = 0;
  8250. _this._barStartY = 0;
  8251. _this._node.name = "GProgressBar";
  8252. _this._titleType = fgui.ProgressTitleType.Percent;
  8253. _this._value = 50;
  8254. _this._max = 100;
  8255. return _this;
  8256. }
  8257. Object.defineProperty(GProgressBar.prototype, "titleType", {
  8258. get: function () {
  8259. return this._titleType;
  8260. },
  8261. set: function (value) {
  8262. if (this._titleType != value) {
  8263. this._titleType = value;
  8264. this.update(this._value);
  8265. }
  8266. },
  8267. enumerable: false,
  8268. configurable: true
  8269. });
  8270. Object.defineProperty(GProgressBar.prototype, "min", {
  8271. get: function () {
  8272. return this._min;
  8273. },
  8274. set: function (value) {
  8275. if (this._min != value) {
  8276. this._min = value;
  8277. this.update(this._value);
  8278. }
  8279. },
  8280. enumerable: false,
  8281. configurable: true
  8282. });
  8283. Object.defineProperty(GProgressBar.prototype, "max", {
  8284. get: function () {
  8285. return this._max;
  8286. },
  8287. set: function (value) {
  8288. if (this._max != value) {
  8289. this._max = value;
  8290. this.update(this._value);
  8291. }
  8292. },
  8293. enumerable: false,
  8294. configurable: true
  8295. });
  8296. Object.defineProperty(GProgressBar.prototype, "value", {
  8297. get: function () {
  8298. return this._value;
  8299. },
  8300. set: function (value) {
  8301. if (this._value != value) {
  8302. fgui.GTween.kill(this, false, this.update);
  8303. this._value = value;
  8304. this.update(value);
  8305. }
  8306. },
  8307. enumerable: false,
  8308. configurable: true
  8309. });
  8310. GProgressBar.prototype.tweenValue = function (value, duration) {
  8311. var oldValule;
  8312. var tweener = fgui.GTween.getTween(this, this.update);
  8313. if (tweener) {
  8314. oldValule = tweener.value.x;
  8315. tweener.kill();
  8316. }
  8317. else
  8318. oldValule = this._value;
  8319. this._value = value;
  8320. return fgui.GTween.to(oldValule, this._value, duration).setTarget(this, this.update).setEase(fgui.EaseType.Linear);
  8321. };
  8322. GProgressBar.prototype.update = function (newValue) {
  8323. var percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  8324. if (this._titleObject) {
  8325. switch (this._titleType) {
  8326. case fgui.ProgressTitleType.Percent:
  8327. this._titleObject.text = Math.floor(percent * 100) + "%";
  8328. break;
  8329. case fgui.ProgressTitleType.ValueAndMax:
  8330. this._titleObject.text = Math.floor(newValue) + "/" + Math.floor(this._max);
  8331. break;
  8332. case fgui.ProgressTitleType.Value:
  8333. this._titleObject.text = "" + Math.floor(newValue);
  8334. break;
  8335. case fgui.ProgressTitleType.Max:
  8336. this._titleObject.text = "" + Math.floor(this._max);
  8337. break;
  8338. }
  8339. }
  8340. var fullWidth = this.width - this._barMaxWidthDelta;
  8341. var fullHeight = this.height - this._barMaxHeightDelta;
  8342. if (!this._reverse) {
  8343. if (this._barObjectH) {
  8344. if (!this.setFillAmount(this._barObjectH, percent))
  8345. this._barObjectH.width = Math.round(fullWidth * percent);
  8346. }
  8347. if (this._barObjectV) {
  8348. if (!this.setFillAmount(this._barObjectV, percent))
  8349. this._barObjectV.height = Math.round(fullHeight * percent);
  8350. }
  8351. }
  8352. else {
  8353. if (this._barObjectH) {
  8354. if (!this.setFillAmount(this._barObjectH, 1 - percent)) {
  8355. this._barObjectH.width = Math.round(fullWidth * percent);
  8356. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  8357. }
  8358. }
  8359. if (this._barObjectV) {
  8360. if (!this.setFillAmount(this._barObjectV, 1 - percent)) {
  8361. this._barObjectV.height = Math.round(fullHeight * percent);
  8362. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  8363. }
  8364. }
  8365. }
  8366. if (this._aniObject)
  8367. this._aniObject.setProp(fgui.ObjectPropID.Frame, Math.floor(percent * 100));
  8368. };
  8369. GProgressBar.prototype.setFillAmount = function (bar, percent) {
  8370. if (((bar instanceof fgui.GImage) || (bar instanceof fgui.GLoader)) && bar.fillMethod != fgui.FillMethod.None) {
  8371. bar.fillAmount = percent;
  8372. return true;
  8373. }
  8374. else
  8375. return false;
  8376. };
  8377. GProgressBar.prototype.constructExtension = function (buffer) {
  8378. buffer.seek(0, 6);
  8379. this._titleType = buffer.readByte();
  8380. this._reverse = buffer.readBool();
  8381. this._titleObject = (this.getChild("title"));
  8382. this._barObjectH = this.getChild("bar");
  8383. this._barObjectV = this.getChild("bar_v");
  8384. this._aniObject = this.getChild("ani");
  8385. if (this._barObjectH) {
  8386. this._barMaxWidth = this._barObjectH.width;
  8387. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  8388. this._barStartX = this._barObjectH.x;
  8389. }
  8390. if (this._barObjectV) {
  8391. this._barMaxHeight = this._barObjectV.height;
  8392. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  8393. this._barStartY = this._barObjectV.y;
  8394. }
  8395. };
  8396. GProgressBar.prototype.handleSizeChanged = function () {
  8397. _super.prototype.handleSizeChanged.call(this);
  8398. if (this._barObjectH)
  8399. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  8400. if (this._barObjectV)
  8401. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  8402. if (!this._underConstruct)
  8403. this.update(this._value);
  8404. };
  8405. GProgressBar.prototype.setup_afterAdd = function (buffer, beginPos) {
  8406. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  8407. if (!buffer.seek(beginPos, 6)) {
  8408. this.update(this._value);
  8409. return;
  8410. }
  8411. if (buffer.readByte() != this.packageItem.objectType) {
  8412. this.update(this._value);
  8413. return;
  8414. }
  8415. this._value = buffer.readInt();
  8416. this._max = buffer.readInt();
  8417. if (buffer.version >= 2)
  8418. this._min = buffer.readInt();
  8419. this.update(this._value);
  8420. };
  8421. return GProgressBar;
  8422. }(fgui.GComponent));
  8423. fgui.GProgressBar = GProgressBar;
  8424. })(fgui || (fgui = {}));
  8425. (function (fgui) {
  8426. var GTextField = (function (_super) {
  8427. __extends(GTextField, _super);
  8428. function GTextField() {
  8429. var _this = _super.call(this) || this;
  8430. _this._fontSize = 0;
  8431. _this._leading = 0;
  8432. _this._node.name = "GTextField";
  8433. _this._touchDisabled = true;
  8434. _this._text = "";
  8435. _this._color = new cc.Color(255, 255, 255, 255);
  8436. _this.createRenderer();
  8437. _this.fontSize = 12;
  8438. _this.leading = 3;
  8439. _this.singleLine = false;
  8440. _this._sizeDirty = false;
  8441. _this._node.on(cc.Node.EventType.SIZE_CHANGED, _this.onLabelSizeChanged, _this);
  8442. return _this;
  8443. }
  8444. GTextField.prototype.createRenderer = function () {
  8445. // cc.dynamicAtlasManager.reset();
  8446. this._label = this._node.addComponent(cc.Label);
  8447. // this._label.font = fgui.getFontByName("SIMHEI")
  8448. // this._label.cacheMode = cc.Label.CacheMode.BITMAP;
  8449. this.autoSize = fgui.AutoSizeType.Both;
  8450. };
  8451. Object.defineProperty(GTextField.prototype, "text", {
  8452. get: function () {
  8453. return this._text;
  8454. },
  8455. set: function (value) {
  8456. this._text = value;
  8457. if (this._text == null)
  8458. this._text = "";
  8459. this.updateGear(6);
  8460. this.markSizeChanged();
  8461. this.updateText();
  8462. },
  8463. enumerable: false,
  8464. configurable: true
  8465. });
  8466. Object.defineProperty(GTextField.prototype, "font", {
  8467. get: function () {
  8468. return this._font;
  8469. },
  8470. set: function (value) {
  8471. if (this._font != value || !value) {
  8472. this._font = value;
  8473. this.markSizeChanged();
  8474. var newFont = value ? value : fgui.UIConfig.defaultFont;
  8475. if (fgui.ToolSet.startsWith(newFont, "ui://")) {
  8476. var pi = fgui.UIPackage.getItemByURL(newFont);
  8477. if (pi)
  8478. newFont = pi.owner.getItemAsset(pi);
  8479. else
  8480. newFont = fgui.UIConfig.defaultFont;
  8481. }
  8482. this._realFont = newFont;
  8483. this.updateFont();
  8484. }
  8485. },
  8486. enumerable: false,
  8487. configurable: true
  8488. });
  8489. Object.defineProperty(GTextField.prototype, "fontSize", {
  8490. get: function () {
  8491. return this._fontSize;
  8492. },
  8493. set: function (value) {
  8494. if (value < 0)
  8495. return;
  8496. if (this._fontSize != value) {
  8497. this._fontSize = value;
  8498. this.markSizeChanged();
  8499. this.updateFontSize();
  8500. }
  8501. },
  8502. enumerable: false,
  8503. configurable: true
  8504. });
  8505. Object.defineProperty(GTextField.prototype, "color", {
  8506. get: function () {
  8507. return this._color;
  8508. },
  8509. set: function (value) {
  8510. this._color.set(value);
  8511. this.updateGear(4);
  8512. this.updateFontColor();
  8513. },
  8514. enumerable: false,
  8515. configurable: true
  8516. });
  8517. Object.defineProperty(GTextField.prototype, "align", {
  8518. get: function () {
  8519. return this._label ? this._label.horizontalAlign : 0;
  8520. },
  8521. set: function (value) {
  8522. if (this._label)
  8523. this._label.horizontalAlign = value;
  8524. },
  8525. enumerable: false,
  8526. configurable: true
  8527. });
  8528. Object.defineProperty(GTextField.prototype, "verticalAlign", {
  8529. get: function () {
  8530. return this._label ? this._label.verticalAlign : 0;
  8531. },
  8532. set: function (value) {
  8533. if (this._label)
  8534. this._label.verticalAlign = value;
  8535. },
  8536. enumerable: false,
  8537. configurable: true
  8538. });
  8539. Object.defineProperty(GTextField.prototype, "leading", {
  8540. get: function () {
  8541. return this._leading;
  8542. },
  8543. set: function (value) {
  8544. if (this._leading != value) {
  8545. this._leading = value;
  8546. this.markSizeChanged();
  8547. this.updateFontSize();
  8548. }
  8549. },
  8550. enumerable: false,
  8551. configurable: true
  8552. });
  8553. Object.defineProperty(GTextField.prototype, "letterSpacing", {
  8554. get: function () {
  8555. return this._label ? this._label.spacingX : 0;
  8556. },
  8557. set: function (value) {
  8558. if (this._label && this._label.spacingX != value) {
  8559. this.markSizeChanged();
  8560. this._label.spacingX = value;
  8561. }
  8562. },
  8563. enumerable: false,
  8564. configurable: true
  8565. });
  8566. Object.defineProperty(GTextField.prototype, "underline", {
  8567. get: function () {
  8568. return this._label ? this._label.enableUnderline : false;
  8569. },
  8570. set: function (value) {
  8571. if (this._label)
  8572. this._label.enableUnderline = value;
  8573. },
  8574. enumerable: false,
  8575. configurable: true
  8576. });
  8577. Object.defineProperty(GTextField.prototype, "bold", {
  8578. get: function () {
  8579. return this._label ? this._label.enableBold : false;
  8580. },
  8581. set: function (value) {
  8582. if (this._label)
  8583. this._label.enableBold = value;
  8584. },
  8585. enumerable: false,
  8586. configurable: true
  8587. });
  8588. Object.defineProperty(GTextField.prototype, "italic", {
  8589. get: function () {
  8590. return this._label ? this._label.enableItalic : false;
  8591. },
  8592. set: function (value) {
  8593. if (this._label)
  8594. this._label.enableItalic = value;
  8595. },
  8596. enumerable: false,
  8597. configurable: true
  8598. });
  8599. Object.defineProperty(GTextField.prototype, "singleLine", {
  8600. get: function () {
  8601. return this._label ? !this._label.enableWrapText : false;
  8602. },
  8603. set: function (value) {
  8604. if (this._label)
  8605. this._label.enableWrapText = !value;
  8606. },
  8607. enumerable: false,
  8608. configurable: true
  8609. });
  8610. Object.defineProperty(GTextField.prototype, "stroke", {
  8611. get: function () {
  8612. return (this._outline && this._outline.enabled) ? this._outline.width : 0;
  8613. },
  8614. set: function (value) {
  8615. if (value == 0) {
  8616. if (this._outline)
  8617. this._outline.enabled = false;
  8618. }
  8619. else {
  8620. if (!this._outline) {
  8621. this._outline = this._node.addComponent(cc.LabelOutline);
  8622. this.updateStrokeColor();
  8623. }
  8624. else
  8625. this._outline.enabled = true;
  8626. this._outline.width = value;
  8627. }
  8628. },
  8629. enumerable: false,
  8630. configurable: true
  8631. });
  8632. Object.defineProperty(GTextField.prototype, "strokeColor", {
  8633. get: function () {
  8634. return this._strokeColor;
  8635. },
  8636. set: function (value) {
  8637. if (!this._strokeColor)
  8638. this._strokeColor = new cc.Color();
  8639. this._strokeColor.set(value);
  8640. this.updateGear(4);
  8641. this.updateStrokeColor();
  8642. },
  8643. enumerable: false,
  8644. configurable: true
  8645. });
  8646. Object.defineProperty(GTextField.prototype, "shadowOffset", {
  8647. get: function () {
  8648. return this._shadowOffset;
  8649. },
  8650. set: function (value) {
  8651. if (!this._shadowOffset)
  8652. this._shadowOffset = new cc.Vec2();
  8653. this._shadowOffset.set(value);
  8654. if (this._shadowOffset.x != 0 || this._shadowOffset.y != 0) {
  8655. if (!this._shadow) {
  8656. this._shadow = this._node.addComponent(cc.LabelShadow);
  8657. this.updateShadowColor();
  8658. }
  8659. else
  8660. this._shadow.enabled = true;
  8661. this._shadow.offset.x = value.x;
  8662. this._shadow.offset.y = -value.y;
  8663. }
  8664. else if (this._shadow)
  8665. this._shadow.enabled = false;
  8666. },
  8667. enumerable: false,
  8668. configurable: true
  8669. });
  8670. Object.defineProperty(GTextField.prototype, "shadowColor", {
  8671. get: function () {
  8672. return this._shadowColor;
  8673. },
  8674. set: function (value) {
  8675. if (!this._shadowColor)
  8676. this._shadowColor = new cc.Color();
  8677. this._shadowColor.set(value);
  8678. this.updateShadowColor();
  8679. },
  8680. enumerable: false,
  8681. configurable: true
  8682. });
  8683. Object.defineProperty(GTextField.prototype, "ubbEnabled", {
  8684. get: function () {
  8685. return this._ubbEnabled;
  8686. },
  8687. set: function (value) {
  8688. if (this._ubbEnabled != value) {
  8689. this._ubbEnabled = value;
  8690. this.markSizeChanged();
  8691. this.updateText();
  8692. }
  8693. },
  8694. enumerable: false,
  8695. configurable: true
  8696. });
  8697. Object.defineProperty(GTextField.prototype, "autoSize", {
  8698. get: function () {
  8699. return this._autoSize;
  8700. },
  8701. set: function (value) {
  8702. if (this._autoSize != value) {
  8703. this._autoSize = value;
  8704. this.markSizeChanged();
  8705. this.updateOverflow();
  8706. }
  8707. },
  8708. enumerable: false,
  8709. configurable: true
  8710. });
  8711. GTextField.prototype.parseTemplate = function (template) {
  8712. var pos1 = 0, pos2, pos3;
  8713. var tag;
  8714. var value;
  8715. var result = "";
  8716. while ((pos2 = template.indexOf("{", pos1)) != -1) {
  8717. if (pos2 > 0 && template.charCodeAt(pos2 - 1) == 92) {
  8718. result += template.substring(pos1, pos2 - 1);
  8719. result += "{";
  8720. pos1 = pos2 + 1;
  8721. continue;
  8722. }
  8723. result += template.substring(pos1, pos2);
  8724. pos1 = pos2;
  8725. pos2 = template.indexOf("}", pos1);
  8726. if (pos2 == -1)
  8727. break;
  8728. if (pos2 == pos1 + 1) {
  8729. result += template.substr(pos1, 2);
  8730. pos1 = pos2 + 1;
  8731. continue;
  8732. }
  8733. tag = template.substring(pos1 + 1, pos2);
  8734. pos3 = tag.indexOf("=");
  8735. if (pos3 != -1) {
  8736. value = this._templateVars[tag.substring(0, pos3)];
  8737. if (value == null)
  8738. result += tag.substring(pos3 + 1);
  8739. else
  8740. result += value;
  8741. }
  8742. else {
  8743. value = this._templateVars[tag];
  8744. if (value != null)
  8745. result += value;
  8746. }
  8747. pos1 = pos2 + 1;
  8748. }
  8749. if (pos1 < template.length)
  8750. result += template.substr(pos1);
  8751. return result;
  8752. };
  8753. Object.defineProperty(GTextField.prototype, "templateVars", {
  8754. get: function () {
  8755. return this._templateVars;
  8756. },
  8757. set: function (value) {
  8758. if (this._templateVars == null && value == null)
  8759. return;
  8760. this._templateVars = value;
  8761. this.flushVars();
  8762. },
  8763. enumerable: false,
  8764. configurable: true
  8765. });
  8766. GTextField.prototype.setVar = function (name, value) {
  8767. if (!this._templateVars)
  8768. this._templateVars = {};
  8769. this._templateVars[name] = value;
  8770. return this;
  8771. };
  8772. GTextField.prototype.flushVars = function () {
  8773. this.markSizeChanged();
  8774. this.updateText();
  8775. };
  8776. Object.defineProperty(GTextField.prototype, "textWidth", {
  8777. get: function () {
  8778. this.ensureSizeCorrect();
  8779. return this._node.width;
  8780. },
  8781. enumerable: false,
  8782. configurable: true
  8783. });
  8784. GTextField.prototype.ensureSizeCorrect = function () {
  8785. if (this._sizeDirty) {
  8786. if (this._label["_forceUpdateRenderData"])
  8787. this._label["_forceUpdateRenderData"]();
  8788. else
  8789. this._label["_updateRenderData"](true);
  8790. this._sizeDirty = false;
  8791. }
  8792. };
  8793. GTextField.prototype.updateText = function () {
  8794. var text2 = this._text;
  8795. if (this._templateVars)
  8796. text2 = this.parseTemplate(text2);
  8797. if (this._ubbEnabled)
  8798. text2 = fgui.UBBParser.inst.parse(text2, true);
  8799. this._label.string = text2;
  8800. // cc.dynamicAtlasManager.insertSpriteFrame(this._label["_frame"]);
  8801. // this._label['_forceUpdateRenderData']();
  8802. };
  8803. GTextField.prototype.assignFont = function (label, value) {
  8804. if (value instanceof cc.Font)
  8805. label.font = value;
  8806. else {
  8807. var font = fgui.getFontByName(value);
  8808. if (!font) {
  8809. label.fontFamily = value;
  8810. label.useSystemFont = true;
  8811. }
  8812. else
  8813. label.font = font;
  8814. }
  8815. };
  8816. GTextField.prototype.assignFontColor = function (label, value) {
  8817. var font = label.font;
  8818. if ((font instanceof cc.BitmapFont) && !(font._fntConfig.canTint))
  8819. value = cc.Color.WHITE;
  8820. if (this._grayed)
  8821. value = fgui.ToolSet.toGrayed(value);
  8822. label.node.color = value;
  8823. };
  8824. GTextField.prototype.updateFont = function () {
  8825. this.assignFont(this._label, this._realFont);
  8826. };
  8827. GTextField.prototype.updateFontColor = function () {
  8828. this.assignFontColor(this._label, this._color);
  8829. };
  8830. GTextField.prototype.updateStrokeColor = function () {
  8831. if (!this._outline)
  8832. return;
  8833. if (!this._strokeColor)
  8834. this._strokeColor = new cc.Color();
  8835. if (this._grayed)
  8836. this._outline.color = fgui.ToolSet.toGrayed(this._strokeColor);
  8837. else
  8838. this._outline.color = this._strokeColor;
  8839. };
  8840. GTextField.prototype.updateShadowColor = function () {
  8841. if (!this._shadow)
  8842. return;
  8843. if (!this._shadowColor)
  8844. this._shadowColor = new cc.Color();
  8845. if (this._grayed)
  8846. this._shadow.color = fgui.ToolSet.toGrayed(this._shadowColor);
  8847. else
  8848. this._shadow.color = this._shadowColor;
  8849. };
  8850. GTextField.prototype.updateFontSize = function () {
  8851. var font = this._label.font;
  8852. if (font instanceof cc.BitmapFont) {
  8853. var fntConfig = font._fntConfig;
  8854. if (fntConfig.resizable)
  8855. this._label.fontSize = this._fontSize;
  8856. else
  8857. this._label.fontSize = fntConfig.fontSize;
  8858. this._label.lineHeight = fntConfig.fontSize + (this._leading + 4) * fntConfig.fontSize / this._label.fontSize;
  8859. }
  8860. else {
  8861. this._label.fontSize = this._fontSize;
  8862. this._label.lineHeight = this._fontSize + this._leading;
  8863. }
  8864. };
  8865. GTextField.prototype.updateOverflow = function () {
  8866. if (this._autoSize == fgui.AutoSizeType.Both)
  8867. this._label.overflow = cc.Label.Overflow.NONE;
  8868. else if (this._autoSize == fgui.AutoSizeType.Height) {
  8869. this._label.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
  8870. this._node.width = this._width;
  8871. }
  8872. else if (this._autoSize == fgui.AutoSizeType.Shrink) {
  8873. this._label.overflow = cc.Label.Overflow.SHRINK;
  8874. this._node.setContentSize(this._width, this._height);
  8875. }
  8876. else {
  8877. this._label.overflow = cc.Label.Overflow.CLAMP;
  8878. this._node.setContentSize(this._width, this._height);
  8879. }
  8880. };
  8881. GTextField.prototype.markSizeChanged = function () {
  8882. if (this._underConstruct)
  8883. return;
  8884. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8885. if (!this._sizeDirty) {
  8886. this._node.emit(fgui.Event.SIZE_DELAY_CHANGE, this);
  8887. this._sizeDirty = true;
  8888. }
  8889. }
  8890. };
  8891. GTextField.prototype.onLabelSizeChanged = function () {
  8892. this._sizeDirty = false;
  8893. if (this._underConstruct)
  8894. return;
  8895. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8896. this._updatingSize = true;
  8897. this.setSize(this._node.width, this._node.height);
  8898. this._updatingSize = false;
  8899. }
  8900. };
  8901. GTextField.prototype.handleSizeChanged = function () {
  8902. if (this._updatingSize)
  8903. return;
  8904. if (this._autoSize == fgui.AutoSizeType.None || this._autoSize == fgui.AutoSizeType.Shrink) {
  8905. this._node.setContentSize(this._width, this._height);
  8906. }
  8907. else if (this._autoSize == fgui.AutoSizeType.Height)
  8908. this._node.width = this._width;
  8909. };
  8910. GTextField.prototype.handleGrayedChanged = function () {
  8911. this.updateFontColor();
  8912. this.updateStrokeColor();
  8913. };
  8914. GTextField.prototype.getProp = function (index) {
  8915. switch (index) {
  8916. case fgui.ObjectPropID.Color:
  8917. return this.color;
  8918. case fgui.ObjectPropID.OutlineColor:
  8919. return this.strokeColor;
  8920. case fgui.ObjectPropID.FontSize:
  8921. return this.fontSize;
  8922. default:
  8923. return _super.prototype.getProp.call(this, index);
  8924. }
  8925. };
  8926. GTextField.prototype.setProp = function (index, value) {
  8927. switch (index) {
  8928. case fgui.ObjectPropID.Color:
  8929. this.color = value;
  8930. break;
  8931. case fgui.ObjectPropID.OutlineColor:
  8932. this.strokeColor = value;
  8933. break;
  8934. case fgui.ObjectPropID.FontSize:
  8935. this.fontSize = value;
  8936. break;
  8937. default:
  8938. _super.prototype.setProp.call(this, index, value);
  8939. break;
  8940. }
  8941. };
  8942. GTextField.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8943. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8944. buffer.seek(beginPos, 5);
  8945. this.font = buffer.readS();
  8946. this.fontSize = buffer.readShort();
  8947. this.color = buffer.readColor();
  8948. this.align = buffer.readByte();
  8949. this.verticalAlign = buffer.readByte();
  8950. this.leading = buffer.readShort();
  8951. this.letterSpacing = buffer.readShort();
  8952. this._ubbEnabled = buffer.readBool();
  8953. this.autoSize = buffer.readByte();
  8954. this.underline = buffer.readBool();
  8955. this.italic = buffer.readBool();
  8956. this.bold = buffer.readBool();
  8957. this.singleLine = buffer.readBool();
  8958. if (buffer.readBool()) {
  8959. this.strokeColor = buffer.readColor();
  8960. this.stroke = buffer.readFloat();
  8961. }
  8962. if (buffer.readBool()) {
  8963. this.shadowColor = buffer.readColor();
  8964. var f1 = buffer.readFloat();
  8965. var f2 = buffer.readFloat();
  8966. this.shadowOffset = new cc.Vec2(f1, f2);
  8967. }
  8968. if (buffer.readBool())
  8969. this._templateVars = {};
  8970. };
  8971. GTextField.prototype.setup_afterAdd = function (buffer, beginPos) {
  8972. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  8973. buffer.seek(beginPos, 6);
  8974. var str = buffer.readS();
  8975. if (str != null)
  8976. this.text = str;
  8977. };
  8978. return GTextField;
  8979. }(fgui.GObject));
  8980. fgui.GTextField = GTextField;
  8981. })(fgui || (fgui = {}));
  8982. (function (fgui) {
  8983. var RichTextImageAtlas = (function (_super) {
  8984. __extends(RichTextImageAtlas, _super);
  8985. function RichTextImageAtlas() {
  8986. return _super !== null && _super.apply(this, arguments) || this;
  8987. }
  8988. RichTextImageAtlas.prototype.getSpriteFrame = function (key) {
  8989. var pi = fgui.UIPackage.getItemByURL(key);
  8990. if (pi) {
  8991. pi.load();
  8992. if (pi.type == fgui.PackageItemType.Image)
  8993. return pi.asset;
  8994. else if (pi.type == fgui.PackageItemType.MovieClip)
  8995. return pi.frames[0].texture;
  8996. }
  8997. return _super.prototype.getSpriteFrame.call(this, key);
  8998. };
  8999. return RichTextImageAtlas;
  9000. }(cc.SpriteAtlas));
  9001. fgui.RichTextImageAtlas = RichTextImageAtlas;
  9002. var imageAtlas = new RichTextImageAtlas();
  9003. var GRichTextField = (function (_super) {
  9004. __extends(GRichTextField, _super);
  9005. function GRichTextField() {
  9006. var _this = _super.call(this) || this;
  9007. _this._node.name = "GRichTextField";
  9008. _this._touchDisabled = false;
  9009. _this.linkUnderline = fgui.UIConfig.linkUnderline;
  9010. return _this;
  9011. }
  9012. GRichTextField.prototype.createRenderer = function () {
  9013. this._richText = this._node.addComponent(cc.RichText);
  9014. // this._richText.font = fgui.getFontByName("SIMHEI")
  9015. // this._richText.cacheMode = cc.Label.CacheMode.CHAR;
  9016. this._richText.handleTouchEvent = false;
  9017. this.autoSize = fgui.AutoSizeType.None;
  9018. this._richText.imageAtlas = imageAtlas;
  9019. };
  9020. Object.defineProperty(GRichTextField.prototype, "align", {
  9021. get: function () {
  9022. return this._richText.horizontalAlign;
  9023. },
  9024. set: function (value) {
  9025. this._richText.horizontalAlign = value;
  9026. },
  9027. enumerable: false,
  9028. configurable: true
  9029. });
  9030. Object.defineProperty(GRichTextField.prototype, "underline", {
  9031. get: function () {
  9032. return this._underline;
  9033. },
  9034. set: function (value) {
  9035. if (this._underline != value) {
  9036. this._underline = value;
  9037. this.updateText();
  9038. }
  9039. },
  9040. enumerable: false,
  9041. configurable: true
  9042. });
  9043. Object.defineProperty(GRichTextField.prototype, "bold", {
  9044. get: function () {
  9045. return this._bold;
  9046. },
  9047. set: function (value) {
  9048. if (this._bold != value) {
  9049. this._bold = value;
  9050. this.updateText();
  9051. }
  9052. },
  9053. enumerable: false,
  9054. configurable: true
  9055. });
  9056. Object.defineProperty(GRichTextField.prototype, "italic", {
  9057. get: function () {
  9058. return this._italics;
  9059. },
  9060. set: function (value) {
  9061. if (this._italics != value) {
  9062. this._italics = value;
  9063. this.updateText();
  9064. }
  9065. },
  9066. enumerable: false,
  9067. configurable: true
  9068. });
  9069. GRichTextField.prototype.markSizeChanged = function () {
  9070. };
  9071. GRichTextField.prototype.updateText = function () {
  9072. var text2 = this._text;
  9073. if (this._templateVars)
  9074. text2 = this.parseTemplate(text2);
  9075. if (this._ubbEnabled) {
  9076. fgui.UBBParser.inst.linkUnderline = this.linkUnderline;
  9077. fgui.UBBParser.inst.linkColor = this.linkColor;
  9078. text2 = fgui.UBBParser.inst.parse(text2);
  9079. }
  9080. if (this._bold)
  9081. text2 = "<b>" + text2 + "</b>";
  9082. if (this._italics)
  9083. text2 = "<i>" + text2 + "</i>";
  9084. if (this._underline)
  9085. text2 = "<u>" + text2 + "</u>";
  9086. var c = this._color;
  9087. if (this._grayed)
  9088. c = fgui.ToolSet.toGrayed(c);
  9089. text2 = "<color=" + c.toHEX("#rrggbb") + ">" + text2 + "</color>";
  9090. if (this._autoSize == fgui.AutoSizeType.Both) {
  9091. if (this._richText.maxWidth != 0)
  9092. this._richText.maxWidth = 0;
  9093. this._richText.string = text2;
  9094. if (this.maxWidth != 0 && this._node.width > this.maxWidth)
  9095. this._richText.maxWidth = this.maxWidth;
  9096. }
  9097. else
  9098. this._richText.string = text2;
  9099. };
  9100. GRichTextField.prototype.updateFont = function () {
  9101. this.assignFont(this._richText, this._realFont);
  9102. };
  9103. GRichTextField.prototype.updateFontColor = function () {
  9104. this.assignFontColor(this._richText, this._color);
  9105. };
  9106. GRichTextField.prototype.updateFontSize = function () {
  9107. var fontSize = this._fontSize;
  9108. var font = this._richText.font;
  9109. if (font instanceof cc.BitmapFont) {
  9110. if (!font._fntConfig.resizable)
  9111. fontSize = font._fntConfig.fontSize;
  9112. }
  9113. this._richText.fontSize = fontSize;
  9114. this._richText.lineHeight = fontSize + this._leading * 2;
  9115. };
  9116. GRichTextField.prototype.updateOverflow = function () {
  9117. if (this._autoSize == fgui.AutoSizeType.Both)
  9118. this._richText.maxWidth = 0;
  9119. else
  9120. this._richText.maxWidth = this._width;
  9121. };
  9122. GRichTextField.prototype.handleSizeChanged = function () {
  9123. if (this._updatingSize)
  9124. return;
  9125. if (this._autoSize != fgui.AutoSizeType.Both)
  9126. this._richText.maxWidth = this._width;
  9127. };
  9128. return GRichTextField;
  9129. }(fgui.GTextField));
  9130. fgui.GRichTextField = GRichTextField;
  9131. })(fgui || (fgui = {}));
  9132. (function (fgui) {
  9133. var GRoot = (function (_super) {
  9134. __extends(GRoot, _super);
  9135. function GRoot() {
  9136. var _this = _super.call(this) || this;
  9137. _this._node.name = "GRoot";
  9138. _this.opaque = false;
  9139. _this._volumeScale = 1;
  9140. _this._popupStack = new Array();
  9141. _this._justClosedPopups = new Array();
  9142. _this._modalLayer = new fgui.GGraph();
  9143. _this._modalLayer.setSize(_this.width, _this.height);
  9144. _this._modalLayer.drawRect(0, cc.Color.TRANSPARENT, fgui.UIConfig.modalLayerColor);
  9145. _this._modalLayer.addRelation(_this, fgui.RelationType.Size);
  9146. _this._thisOnResized = _this.onWinResize.bind(_this);
  9147. _this._inputProcessor = _this.node.addComponent(fgui.InputProcessor);
  9148. _this._inputProcessor._captureCallback = _this.onTouchBegin_1;
  9149. if (cc.sys.platform != cc.sys.TAOBAO_MINIGAME && CC_EDITOR) {
  9150. cc.engine.on('design-resolution-changed', _this._thisOnResized);
  9151. }
  9152. else {
  9153. cc.view.on('canvas-resize', _this._thisOnResized);
  9154. }
  9155. _this.onWinResize();
  9156. return _this;
  9157. }
  9158. Object.defineProperty(GRoot, "inst", {
  9159. get: function () {
  9160. if (!GRoot._inst)
  9161. throw 'Call GRoot.create first!';
  9162. return GRoot._inst;
  9163. },
  9164. enumerable: false,
  9165. configurable: true
  9166. });
  9167. GRoot.create = function () {
  9168. GRoot._inst = new GRoot();
  9169. GRoot._inst.node.parent = cc.director.getScene();
  9170. return GRoot._inst;
  9171. };
  9172. GRoot.prototype.onDestroy = function () {
  9173. if (CC_EDITOR) {
  9174. cc.engine.off('design-resolution-changed', this._thisOnResized);
  9175. }
  9176. else {
  9177. cc.view.off('canvas-resize', this._thisOnResized);
  9178. }
  9179. if (this == GRoot._inst)
  9180. GRoot._inst = null;
  9181. };
  9182. GRoot.prototype.getTouchPosition = function (touchId) {
  9183. return this._inputProcessor.getTouchPosition(touchId);
  9184. };
  9185. Object.defineProperty(GRoot.prototype, "touchTarget", {
  9186. get: function () {
  9187. return this._inputProcessor.getTouchTarget();
  9188. },
  9189. enumerable: false,
  9190. configurable: true
  9191. });
  9192. Object.defineProperty(GRoot.prototype, "inputProcessor", {
  9193. get: function () {
  9194. return this._inputProcessor;
  9195. },
  9196. enumerable: false,
  9197. configurable: true
  9198. });
  9199. GRoot.prototype.showWindow = function (win) {
  9200. this.addChild(win);
  9201. win.requestFocus();
  9202. if (win.x > this.width)
  9203. win.x = this.width - win.width;
  9204. else if (win.x + win.width < 0)
  9205. win.x = 0;
  9206. if (win.y > this.height)
  9207. win.y = this.height - win.height;
  9208. else if (win.y + win.height < 0)
  9209. win.y = 0;
  9210. this.adjustModalLayer();
  9211. };
  9212. GRoot.prototype.hideWindow = function (win) {
  9213. win.hide();
  9214. };
  9215. GRoot.prototype.hideWindowImmediately = function (win) {
  9216. if (win.parent == this)
  9217. this.removeChild(win);
  9218. this.adjustModalLayer();
  9219. };
  9220. GRoot.prototype.bringToFront = function (win) {
  9221. var cnt = this.numChildren;
  9222. var i;
  9223. if (this._modalLayer.parent && !win.modal)
  9224. i = this.getChildIndex(this._modalLayer) - 1;
  9225. else
  9226. i = cnt - 1;
  9227. for (; i >= 0; i--) {
  9228. var g = this.getChildAt(i);
  9229. if (g == win)
  9230. return;
  9231. if (g instanceof fgui.Window)
  9232. break;
  9233. }
  9234. if (i >= 0)
  9235. this.setChildIndex(win, i);
  9236. };
  9237. GRoot.prototype.showModalWait = function (msg) {
  9238. if (fgui.UIConfig.globalModalWaiting != null) {
  9239. if (this._modalWaitPane == null)
  9240. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.globalModalWaiting);
  9241. this._modalWaitPane.setSize(this.width, this.height);
  9242. this._modalWaitPane.addRelation(this, fgui.RelationType.Size);
  9243. this.addChild(this._modalWaitPane);
  9244. this._modalWaitPane.text = msg;
  9245. }
  9246. };
  9247. GRoot.prototype.closeModalWait = function () {
  9248. if (this._modalWaitPane && this._modalWaitPane.parent)
  9249. this.removeChild(this._modalWaitPane);
  9250. };
  9251. GRoot.prototype.closeAllExceptModals = function () {
  9252. var arr = this._children.slice();
  9253. var cnt = arr.length;
  9254. for (var i = 0; i < cnt; i++) {
  9255. var g = arr[i];
  9256. if ((g instanceof fgui.Window) && !g.modal)
  9257. g.hide();
  9258. }
  9259. };
  9260. GRoot.prototype.closeAllWindows = function () {
  9261. var arr = this._children.slice();
  9262. var cnt = arr.length;
  9263. for (var i = 0; i < cnt; i++) {
  9264. var g = arr[i];
  9265. if (g instanceof fgui.Window)
  9266. g.hide();
  9267. }
  9268. };
  9269. GRoot.prototype.getTopWindow = function () {
  9270. var cnt = this.numChildren;
  9271. for (var i = cnt - 1; i >= 0; i--) {
  9272. var g = this.getChildAt(i);
  9273. if (g instanceof fgui.Window) {
  9274. return g;
  9275. }
  9276. }
  9277. return null;
  9278. };
  9279. Object.defineProperty(GRoot.prototype, "modalLayer", {
  9280. get: function () {
  9281. return this._modalLayer;
  9282. },
  9283. enumerable: false,
  9284. configurable: true
  9285. });
  9286. Object.defineProperty(GRoot.prototype, "hasModalWindow", {
  9287. get: function () {
  9288. return this._modalLayer.parent != null;
  9289. },
  9290. enumerable: false,
  9291. configurable: true
  9292. });
  9293. Object.defineProperty(GRoot.prototype, "modalWaiting", {
  9294. get: function () {
  9295. return this._modalWaitPane && this._modalWaitPane.node.activeInHierarchy;
  9296. },
  9297. enumerable: false,
  9298. configurable: true
  9299. });
  9300. GRoot.prototype.getPopupPosition = function (popup, target, dir, result) {
  9301. var pos = result || new cc.Vec2();
  9302. var sizeW = 0, sizeH = 0;
  9303. if (target) {
  9304. pos = target.localToGlobal();
  9305. var pos2 = target.localToGlobal(target.width, target.height);
  9306. sizeW = pos2.x - pos.x;
  9307. sizeH = pos2.y - pos.y;
  9308. }
  9309. else {
  9310. pos = this.getTouchPosition();
  9311. pos = this.globalToLocal(pos.x, pos.y);
  9312. }
  9313. if (pos.x + popup.width > this.width)
  9314. pos.x = pos.x + sizeW - popup.width;
  9315. pos.y += sizeH;
  9316. if (((dir === undefined || dir === fgui.PopupDirection.Auto) && pos.y + popup.height > this.height)
  9317. || dir === false || dir === fgui.PopupDirection.Up) {
  9318. pos.y = pos.y - sizeH - popup.height - 1;
  9319. if (pos.y < 0) {
  9320. pos.y = 0;
  9321. pos.x += sizeW / 2;
  9322. }
  9323. }
  9324. return pos;
  9325. };
  9326. GRoot.prototype.showPopup = function (popup, target, dir) {
  9327. if (this._popupStack.length > 0) {
  9328. var k = this._popupStack.indexOf(popup);
  9329. if (k != -1) {
  9330. for (var i = this._popupStack.length - 1; i >= k; i--)
  9331. this.removeChild(this._popupStack.pop());
  9332. }
  9333. }
  9334. this._popupStack.push(popup);
  9335. if (target) {
  9336. var p = target;
  9337. while (p) {
  9338. if (p.parent == this) {
  9339. if (popup.sortingOrder < p.sortingOrder) {
  9340. popup.sortingOrder = p.sortingOrder;
  9341. }
  9342. break;
  9343. }
  9344. p = p.parent;
  9345. }
  9346. }
  9347. this.addChild(popup);
  9348. this.adjustModalLayer();
  9349. var pt = this.getPopupPosition(popup, target, dir);
  9350. popup.setPosition(pt.x, pt.y);
  9351. };
  9352. GRoot.prototype.togglePopup = function (popup, target, dir) {
  9353. if (this._justClosedPopups.indexOf(popup) != -1)
  9354. return;
  9355. this.showPopup(popup, target, dir);
  9356. };
  9357. GRoot.prototype.hidePopup = function (popup) {
  9358. if (popup) {
  9359. var k = this._popupStack.indexOf(popup);
  9360. if (k != -1) {
  9361. for (var i = this._popupStack.length - 1; i >= k; i--)
  9362. this.closePopup(this._popupStack.pop());
  9363. }
  9364. }
  9365. else {
  9366. var cnt = this._popupStack.length;
  9367. for (i = cnt - 1; i >= 0; i--)
  9368. this.closePopup(this._popupStack[i]);
  9369. this._popupStack.length = 0;
  9370. }
  9371. };
  9372. Object.defineProperty(GRoot.prototype, "hasAnyPopup", {
  9373. get: function () {
  9374. return this._popupStack.length != 0;
  9375. },
  9376. enumerable: false,
  9377. configurable: true
  9378. });
  9379. GRoot.prototype.closePopup = function (target) {
  9380. if (target.parent) {
  9381. if (target instanceof fgui.Window)
  9382. target.hide();
  9383. else
  9384. this.removeChild(target);
  9385. }
  9386. };
  9387. GRoot.prototype.showTooltips = function (msg) {
  9388. if (this._defaultTooltipWin == null) {
  9389. var resourceURL = fgui.UIConfig.tooltipsWin;
  9390. if (!resourceURL) {
  9391. console.error("UIConfig.tooltipsWin not defined");
  9392. return;
  9393. }
  9394. this._defaultTooltipWin = fgui.UIPackage.createObjectFromURL(resourceURL);
  9395. }
  9396. this._defaultTooltipWin.text = msg;
  9397. this.showTooltipsWin(this._defaultTooltipWin);
  9398. };
  9399. GRoot.prototype.showTooltipsWin = function (tooltipWin) {
  9400. this.hideTooltips();
  9401. this._tooltipWin = tooltipWin;
  9402. var pt = this.getTouchPosition();
  9403. pt.x += 10;
  9404. pt.y += 20;
  9405. this.globalToLocal(pt.x, pt.y, pt);
  9406. if (pt.x + this._tooltipWin.width > this.width) {
  9407. pt.x = pt.x - this._tooltipWin.width - 1;
  9408. if (pt.x < 0)
  9409. pt.x = 10;
  9410. }
  9411. if (pt.y + this._tooltipWin.height > this.height) {
  9412. pt.y = pt.y - this._tooltipWin.height - 1;
  9413. if (pt.y < 0)
  9414. pt.y = 10;
  9415. }
  9416. this._tooltipWin.setPosition(pt.x, pt.y);
  9417. this.addChild(this._tooltipWin);
  9418. };
  9419. GRoot.prototype.hideTooltips = function () {
  9420. if (this._tooltipWin) {
  9421. if (this._tooltipWin.parent)
  9422. this.removeChild(this._tooltipWin);
  9423. this._tooltipWin = null;
  9424. }
  9425. };
  9426. Object.defineProperty(GRoot.prototype, "volumeScale", {
  9427. get: function () {
  9428. return this._volumeScale;
  9429. },
  9430. set: function (value) {
  9431. this._volumeScale = value;
  9432. },
  9433. enumerable: false,
  9434. configurable: true
  9435. });
  9436. GRoot.prototype.playOneShotSound = function (clip, volumeScale) {
  9437. if (volumeScale === undefined)
  9438. volumeScale = 1;
  9439. cc.audioEngine.play(clip, false, this._volumeScale * volumeScale);
  9440. };
  9441. GRoot.prototype.adjustModalLayer = function () {
  9442. var cnt = this.numChildren;
  9443. if (this._modalWaitPane && this._modalWaitPane.parent)
  9444. this.setChildIndex(this._modalWaitPane, cnt - 1);
  9445. for (var i = cnt - 1; i >= 0; i--) {
  9446. var g = this.getChildAt(i);
  9447. if ((g instanceof fgui.Window) && g.modal) {
  9448. if (this._modalLayer.parent == null)
  9449. this.addChildAt(this._modalLayer, i);
  9450. else
  9451. this.setChildIndexBefore(this._modalLayer, i);
  9452. return;
  9453. }
  9454. }
  9455. if (this._modalLayer.parent)
  9456. this.removeChild(this._modalLayer);
  9457. };
  9458. GRoot.prototype.onTouchBegin_1 = function (evt) {
  9459. if (this._tooltipWin)
  9460. this.hideTooltips();
  9461. this._justClosedPopups.length = 0;
  9462. if (this._popupStack.length > 0) {
  9463. var mc = evt.initiator;
  9464. while (mc && mc != this) {
  9465. var pindex = this._popupStack.indexOf(mc);
  9466. if (pindex != -1) {
  9467. for (var i = this._popupStack.length - 1; i > pindex; i--) {
  9468. var popup = this._popupStack.pop();
  9469. this.closePopup(popup);
  9470. this._justClosedPopups.push(popup);
  9471. }
  9472. return;
  9473. }
  9474. mc = mc.findParent();
  9475. }
  9476. var cnt = this._popupStack.length;
  9477. for (var i = cnt - 1; i >= 0; i--) {
  9478. popup = this._popupStack[i];
  9479. this.closePopup(popup);
  9480. this._justClosedPopups.push(popup);
  9481. }
  9482. this._popupStack.length = 0;
  9483. }
  9484. };
  9485. GRoot.prototype.onWinResize = function () {
  9486. var size = cc.view.getCanvasSize();
  9487. size.width /= cc.view.getScaleX();
  9488. size.height /= cc.view.getScaleY();
  9489. var pos = cc.view.getViewportRect().origin;
  9490. pos.x = pos.x / cc.view.getScaleX();
  9491. pos.y = pos.y / cc.view.getScaleY();
  9492. this.setSize(size.width, size.height);
  9493. this._node.setPosition(-pos.x, this._height - pos.y);
  9494. this.updateContentScaleLevel();
  9495. };
  9496. GRoot.prototype.handlePositionChanged = function () {
  9497. };
  9498. GRoot.prototype.updateContentScaleLevel = function () {
  9499. var ss = Math.max(cc.view.getScaleX(), cc.view.getScaleY());
  9500. if (ss >= 3.5)
  9501. GRoot.contentScaleLevel = 3;
  9502. else if (ss >= 2.5)
  9503. GRoot.contentScaleLevel = 2;
  9504. else if (ss >= 1.5)
  9505. GRoot.contentScaleLevel = 1;
  9506. else
  9507. GRoot.contentScaleLevel = 0;
  9508. };
  9509. GRoot.contentScaleLevel = 0;
  9510. return GRoot;
  9511. }(fgui.GComponent));
  9512. fgui.GRoot = GRoot;
  9513. })(fgui || (fgui = {}));
  9514. (function (fgui) {
  9515. var GScrollBar = (function (_super) {
  9516. __extends(GScrollBar, _super);
  9517. function GScrollBar() {
  9518. var _this = _super.call(this) || this;
  9519. _this._node.name = "GScrollBar";
  9520. _this._dragOffset = new cc.Vec2();
  9521. _this._scrollPerc = 0;
  9522. return _this;
  9523. }
  9524. GScrollBar.prototype.setScrollPane = function (target, vertical) {
  9525. this._target = target;
  9526. this._vertical = vertical;
  9527. };
  9528. GScrollBar.prototype.setDisplayPerc = function (value) {
  9529. if (this._vertical) {
  9530. if (!this._fixedGripSize)
  9531. this._grip.height = Math.floor(value * this._bar.height);
  9532. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  9533. }
  9534. else {
  9535. if (!this._fixedGripSize)
  9536. this._grip.width = Math.floor(value * this._bar.width);
  9537. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  9538. }
  9539. this._grip.visible = value != 0 && value != 1;
  9540. };
  9541. GScrollBar.prototype.setScrollPerc = function (val) {
  9542. this._scrollPerc = val;
  9543. if (this._vertical)
  9544. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  9545. else
  9546. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  9547. };
  9548. Object.defineProperty(GScrollBar.prototype, "minSize", {
  9549. get: function () {
  9550. if (this._vertical)
  9551. return (this._arrowButton1 ? this._arrowButton1.height : 0) + (this._arrowButton2 ? this._arrowButton2.height : 0);
  9552. else
  9553. return (this._arrowButton1 ? this._arrowButton1.width : 0) + (this._arrowButton2 ? this._arrowButton2.width : 0);
  9554. },
  9555. enumerable: false,
  9556. configurable: true
  9557. });
  9558. Object.defineProperty(GScrollBar.prototype, "gripDragging", {
  9559. get: function () {
  9560. return this._gripDragging;
  9561. },
  9562. enumerable: false,
  9563. configurable: true
  9564. });
  9565. GScrollBar.prototype.constructExtension = function (buffer) {
  9566. buffer.seek(0, 6);
  9567. this._fixedGripSize = buffer.readBool();
  9568. this._grip = this.getChild("grip");
  9569. if (!this._grip) {
  9570. console.error("需要定义grip");
  9571. return;
  9572. }
  9573. this._bar = this.getChild("bar");
  9574. if (!this._bar) {
  9575. console.error("需要定义bar");
  9576. return;
  9577. }
  9578. this._arrowButton1 = this.getChild("arrow1");
  9579. this._arrowButton2 = this.getChild("arrow2");
  9580. this._grip.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchDown, this);
  9581. this._grip.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  9582. this._grip.on(fgui.Event.TOUCH_END, this.onGripTouchEnd, this);
  9583. if (this._arrowButton1)
  9584. this._arrowButton1.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow1, this);
  9585. if (this._arrowButton2)
  9586. this._arrowButton2.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow2, this);
  9587. this.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  9588. };
  9589. GScrollBar.prototype.onGripTouchDown = function (evt) {
  9590. evt.stopPropagation();
  9591. evt.captureTouch();
  9592. this._gripDragging = true;
  9593. this._target.updateScrollBarVisible();
  9594. this.globalToLocal(evt.pos.x, evt.pos.y, this._dragOffset);
  9595. this._dragOffset.x -= this._grip.x;
  9596. this._dragOffset.y -= this._grip.y;
  9597. };
  9598. GScrollBar.prototype.onGripTouchMove = function (evt) {
  9599. if (!this.onStage)
  9600. return;
  9601. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9602. if (this._vertical) {
  9603. var curY = pt.y - this._dragOffset.y;
  9604. this._target.setPercY((curY - this._bar.y) / (this._bar.height - this._grip.height), false);
  9605. }
  9606. else {
  9607. var curX = pt.x - this._dragOffset.x;
  9608. this._target.setPercX((curX - this._bar.x) / (this._bar.width - this._grip.width), false);
  9609. }
  9610. };
  9611. GScrollBar.prototype.onGripTouchEnd = function (evt) {
  9612. if (!this.onStage)
  9613. return;
  9614. this._gripDragging = false;
  9615. this._target.updateScrollBarVisible();
  9616. };
  9617. GScrollBar.prototype.onClickArrow1 = function (evt) {
  9618. evt.stopPropagation();
  9619. if (this._vertical)
  9620. this._target.scrollUp();
  9621. else
  9622. this._target.scrollLeft();
  9623. };
  9624. GScrollBar.prototype.onClickArrow2 = function (evt) {
  9625. evt.stopPropagation();
  9626. if (this._vertical)
  9627. this._target.scrollDown();
  9628. else
  9629. this._target.scrollRight();
  9630. };
  9631. GScrollBar.prototype.onBarTouchBegin = function (evt) {
  9632. var pt = this._grip.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9633. if (this._vertical) {
  9634. if (pt.y < 0)
  9635. this._target.scrollUp(4);
  9636. else
  9637. this._target.scrollDown(4);
  9638. }
  9639. else {
  9640. if (pt.x < 0)
  9641. this._target.scrollLeft(4);
  9642. else
  9643. this._target.scrollRight(4);
  9644. }
  9645. };
  9646. return GScrollBar;
  9647. }(fgui.GComponent));
  9648. fgui.GScrollBar = GScrollBar;
  9649. var s_vec2 = new cc.Vec2();
  9650. })(fgui || (fgui = {}));
  9651. (function (fgui) {
  9652. var GSlider = (function (_super) {
  9653. __extends(GSlider, _super);
  9654. function GSlider() {
  9655. var _this = _super.call(this) || this;
  9656. _this._min = 0;
  9657. _this._max = 0;
  9658. _this._value = 0;
  9659. _this._barMaxWidth = 0;
  9660. _this._barMaxHeight = 0;
  9661. _this._barMaxWidthDelta = 0;
  9662. _this._barMaxHeightDelta = 0;
  9663. _this._clickPercent = 0;
  9664. _this._barStartX = 0;
  9665. _this._barStartY = 0;
  9666. _this.changeOnClick = true;
  9667. _this.canDrag = true;
  9668. _this._node.name = "GSlider";
  9669. _this._titleType = fgui.ProgressTitleType.Percent;
  9670. _this._value = 50;
  9671. _this._max = 100;
  9672. _this._clickPos = new cc.Vec2();
  9673. return _this;
  9674. }
  9675. Object.defineProperty(GSlider.prototype, "titleType", {
  9676. get: function () {
  9677. return this._titleType;
  9678. },
  9679. set: function (value) {
  9680. this._titleType = value;
  9681. },
  9682. enumerable: false,
  9683. configurable: true
  9684. });
  9685. Object.defineProperty(GSlider.prototype, "wholeNumbers", {
  9686. get: function () {
  9687. return this._wholeNumbers;
  9688. },
  9689. set: function (value) {
  9690. if (this._wholeNumbers != value) {
  9691. this._wholeNumbers = value;
  9692. this.update();
  9693. }
  9694. },
  9695. enumerable: false,
  9696. configurable: true
  9697. });
  9698. Object.defineProperty(GSlider.prototype, "min", {
  9699. get: function () {
  9700. return this._min;
  9701. },
  9702. set: function (value) {
  9703. if (this._min != value) {
  9704. this._min = value;
  9705. this.update();
  9706. }
  9707. },
  9708. enumerable: false,
  9709. configurable: true
  9710. });
  9711. Object.defineProperty(GSlider.prototype, "max", {
  9712. get: function () {
  9713. return this._max;
  9714. },
  9715. set: function (value) {
  9716. if (this._max != value) {
  9717. this._max = value;
  9718. this.update();
  9719. }
  9720. },
  9721. enumerable: false,
  9722. configurable: true
  9723. });
  9724. Object.defineProperty(GSlider.prototype, "value", {
  9725. get: function () {
  9726. return this._value;
  9727. },
  9728. set: function (value) {
  9729. if (this._value != value && this._value >= this._min) {
  9730. this._value = value;
  9731. this.update();
  9732. }
  9733. },
  9734. enumerable: false,
  9735. configurable: true
  9736. });
  9737. GSlider.prototype.update = function () {
  9738. this.updateWithPercent((this._value - this._min) / (this._max - this._min));
  9739. };
  9740. GSlider.prototype.updateWithPercent = function (percent, manual) {
  9741. percent = fgui.ToolSet.clamp01(percent);
  9742. if (manual) {
  9743. var newValue = fgui.ToolSet.clamp(this._min + (this._max - this._min) * percent, this._min, this._max);
  9744. if (this._wholeNumbers) {
  9745. newValue = Math.round(newValue);
  9746. percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  9747. }
  9748. if (newValue != this._value) {
  9749. this._value = newValue;
  9750. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  9751. }
  9752. }
  9753. if (this._titleObject) {
  9754. switch (this._titleType) {
  9755. case fgui.ProgressTitleType.Percent:
  9756. this._titleObject.text = Math.floor(percent * 100) + "%";
  9757. break;
  9758. case fgui.ProgressTitleType.ValueAndMax:
  9759. this._titleObject.text = this._value + "/" + this._max;
  9760. break;
  9761. case fgui.ProgressTitleType.Value:
  9762. this._titleObject.text = "" + this._value;
  9763. break;
  9764. case fgui.ProgressTitleType.Max:
  9765. this._titleObject.text = "" + this._max;
  9766. break;
  9767. }
  9768. }
  9769. var fullWidth = this.width - this._barMaxWidthDelta;
  9770. var fullHeight = this.height - this._barMaxHeightDelta;
  9771. if (!this._reverse) {
  9772. if (this._barObjectH)
  9773. this._barObjectH.width = Math.round(fullWidth * percent);
  9774. if (this._barObjectV)
  9775. this._barObjectV.height = Math.round(fullHeight * percent);
  9776. }
  9777. else {
  9778. if (this._barObjectH) {
  9779. this._barObjectH.width = Math.round(fullWidth * percent);
  9780. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  9781. }
  9782. if (this._barObjectV) {
  9783. this._barObjectV.height = Math.round(fullHeight * percent);
  9784. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  9785. }
  9786. }
  9787. };
  9788. GSlider.prototype.constructExtension = function (buffer) {
  9789. buffer.seek(0, 6);
  9790. this._titleType = buffer.readByte();
  9791. this._reverse = buffer.readBool();
  9792. if (buffer.version >= 2) {
  9793. this._wholeNumbers = buffer.readBool();
  9794. this.changeOnClick = buffer.readBool();
  9795. }
  9796. this._titleObject = (this.getChild("title"));
  9797. this._barObjectH = this.getChild("bar");
  9798. this._barObjectV = this.getChild("bar_v");
  9799. this._gripObject = this.getChild("grip");
  9800. if (this._barObjectH) {
  9801. this._barMaxWidth = this._barObjectH.width;
  9802. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  9803. this._barStartX = this._barObjectH.x;
  9804. }
  9805. if (this._barObjectV) {
  9806. this._barMaxHeight = this._barObjectV.height;
  9807. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  9808. this._barStartY = this._barObjectV.y;
  9809. }
  9810. if (this._gripObject) {
  9811. this._gripObject.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchBegin, this);
  9812. this._gripObject.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  9813. }
  9814. this._node.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  9815. };
  9816. GSlider.prototype.handleSizeChanged = function () {
  9817. _super.prototype.handleSizeChanged.call(this);
  9818. if (this._barObjectH)
  9819. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  9820. if (this._barObjectV)
  9821. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  9822. if (!this._underConstruct)
  9823. this.update();
  9824. };
  9825. GSlider.prototype.setup_afterAdd = function (buffer, beginPos) {
  9826. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  9827. if (!buffer.seek(beginPos, 6)) {
  9828. this.update();
  9829. return;
  9830. }
  9831. if (buffer.readByte() != this.packageItem.objectType) {
  9832. this.update();
  9833. return;
  9834. }
  9835. this._value = buffer.readInt();
  9836. this._max = buffer.readInt();
  9837. if (buffer.version >= 2)
  9838. this._min = buffer.readInt();
  9839. this.update();
  9840. };
  9841. GSlider.prototype.onGripTouchBegin = function (evt) {
  9842. this.canDrag = true;
  9843. evt.stopPropagation();
  9844. evt.captureTouch();
  9845. this._clickPos = this.globalToLocal(evt.pos.x, evt.pos.y);
  9846. this._clickPercent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9847. };
  9848. GSlider.prototype.onGripTouchMove = function (evt) {
  9849. if (!this.canDrag) {
  9850. return;
  9851. }
  9852. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9853. var deltaX = pt.x - this._clickPos.x;
  9854. var deltaY = pt.y - this._clickPos.y;
  9855. if (this._reverse) {
  9856. deltaX = -deltaX;
  9857. deltaY = -deltaY;
  9858. }
  9859. var percent;
  9860. if (this._barObjectH)
  9861. percent = this._clickPercent + deltaX / this._barMaxWidth;
  9862. else
  9863. percent = this._clickPercent + deltaY / this._barMaxHeight;
  9864. this.updateWithPercent(percent, true);
  9865. };
  9866. GSlider.prototype.onBarTouchBegin = function (evt) {
  9867. if (!this.changeOnClick)
  9868. return;
  9869. var pt = this._gripObject.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9870. var percent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9871. var delta = 0;
  9872. if (this._barObjectH != null)
  9873. delta = (pt.x - this._gripObject.width / 2) / this._barMaxWidth;
  9874. if (this._barObjectV != null)
  9875. delta = (pt.y - this._gripObject.height / 2) / this._barMaxHeight;
  9876. if (this._reverse)
  9877. percent -= delta;
  9878. else
  9879. percent += delta;
  9880. this.updateWithPercent(percent, true);
  9881. };
  9882. return GSlider;
  9883. }(fgui.GComponent));
  9884. fgui.GSlider = GSlider;
  9885. var s_vec2 = new cc.Vec2();
  9886. })(fgui || (fgui = {}));
  9887. (function (fgui) {
  9888. var GTextInput = (function (_super) {
  9889. __extends(GTextInput, _super);
  9890. function GTextInput() {
  9891. var _this = _super.call(this) || this;
  9892. _this._node.name = "GTextInput";
  9893. _this._touchDisabled = false;
  9894. return _this;
  9895. }
  9896. GTextInput.prototype.createRenderer = function () {
  9897. this._editBox = this._node.addComponent(MyEditBox);
  9898. this._editBox.maxLength = -1;
  9899. this._editBox["_updateTextLabel"]();
  9900. this._node.on('text-changed', this.onTextChanged, this);
  9901. this.on(fgui.Event.TOUCH_END, this.onTouchEnd1, this);
  9902. this.autoSize = fgui.AutoSizeType.None;
  9903. };
  9904. Object.defineProperty(GTextInput.prototype, "editable", {
  9905. get: function () {
  9906. return this._editBox.enabled;
  9907. },
  9908. set: function (val) {
  9909. this._editBox.enabled = val;
  9910. },
  9911. enumerable: false,
  9912. configurable: true
  9913. });
  9914. Object.defineProperty(GTextInput.prototype, "maxLength", {
  9915. get: function () {
  9916. return this._editBox.maxLength;
  9917. },
  9918. set: function (val) {
  9919. if (val == 0)
  9920. val = -1;
  9921. this._editBox.maxLength = val;
  9922. },
  9923. enumerable: false,
  9924. configurable: true
  9925. });
  9926. Object.defineProperty(GTextInput.prototype, "promptText", {
  9927. get: function () {
  9928. return this._promptText;
  9929. },
  9930. set: function (val) {
  9931. this._promptText = val;
  9932. var newCreate = !this._editBox.placeholderLabel;
  9933. this._editBox["_updatePlaceholderLabel"]();
  9934. if (newCreate)
  9935. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  9936. this._editBox.placeholderLabel.string = fgui.UBBParser.inst.parse(this._promptText, true);
  9937. if (fgui.UBBParser.inst.lastColor) {
  9938. var c = this._editBox.placeholderLabel.node.color;
  9939. if (!c)
  9940. c = new cc.Color();
  9941. c.fromHEX(fgui.UBBParser.inst.lastColor);
  9942. this.assignFontColor(this._editBox.placeholderLabel, c);
  9943. }
  9944. else
  9945. this.assignFontColor(this._editBox.placeholderLabel, this._color);
  9946. if (fgui.UBBParser.inst.lastSize)
  9947. this._editBox.placeholderLabel.fontSize = parseInt(fgui.UBBParser.inst.lastSize);
  9948. else
  9949. this._editBox.placeholderLabel.fontSize = this._fontSize;
  9950. },
  9951. enumerable: false,
  9952. configurable: true
  9953. });
  9954. Object.defineProperty(GTextInput.prototype, "restrict", {
  9955. get: function () {
  9956. return "";
  9957. },
  9958. set: function (value) {
  9959. },
  9960. enumerable: false,
  9961. configurable: true
  9962. });
  9963. Object.defineProperty(GTextInput.prototype, "password", {
  9964. get: function () {
  9965. return this._editBox.inputFlag == cc.EditBox.InputFlag.PASSWORD;
  9966. ;
  9967. },
  9968. set: function (val) {
  9969. this._editBox.inputFlag = val ? cc.EditBox.InputFlag.PASSWORD : cc.EditBox.InputFlag.DEFAULT;
  9970. },
  9971. enumerable: false,
  9972. configurable: true
  9973. });
  9974. Object.defineProperty(GTextInput.prototype, "align", {
  9975. get: function () {
  9976. return this._editBox.textLabel.horizontalAlign;
  9977. },
  9978. set: function (value) {
  9979. this._editBox.textLabel.horizontalAlign = value;
  9980. if (this._editBox.placeholderLabel) {
  9981. this._editBox.placeholderLabel.horizontalAlign = value;
  9982. }
  9983. },
  9984. enumerable: false,
  9985. configurable: true
  9986. });
  9987. Object.defineProperty(GTextInput.prototype, "verticalAlign", {
  9988. get: function () {
  9989. return this._editBox.textLabel.verticalAlign;
  9990. },
  9991. set: function (value) {
  9992. this._editBox.textLabel.verticalAlign = value;
  9993. if (this._editBox.placeholderLabel) {
  9994. this._editBox.placeholderLabel.verticalAlign = value;
  9995. }
  9996. },
  9997. enumerable: false,
  9998. configurable: true
  9999. });
  10000. Object.defineProperty(GTextInput.prototype, "singleLine", {
  10001. get: function () {
  10002. return this._editBox.inputMode != cc.EditBox.InputMode.ANY;
  10003. },
  10004. set: function (value) {
  10005. this._editBox.inputMode = value ? cc.EditBox.InputMode.SINGLE_LINE : cc.EditBox.InputMode.ANY;
  10006. },
  10007. enumerable: false,
  10008. configurable: true
  10009. });
  10010. GTextInput.prototype.requestFocus = function () {
  10011. this._editBox.focus();
  10012. };
  10013. GTextInput.prototype.markSizeChanged = function () {
  10014. };
  10015. GTextInput.prototype.updateText = function () {
  10016. var text2 = this._text;
  10017. if (this._templateVars)
  10018. text2 = this.parseTemplate(text2);
  10019. if (this._ubbEnabled)
  10020. text2 = fgui.UBBParser.inst.parse(fgui.ToolSet.encodeHTML(text2), true);
  10021. this._editBox.string = text2;
  10022. };
  10023. GTextInput.prototype.updateFont = function () {
  10024. this.assignFont(this._editBox.textLabel, this._realFont);
  10025. if (this._editBox.placeholderLabel)
  10026. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  10027. };
  10028. GTextInput.prototype.updateFontColor = function () {
  10029. this.assignFontColor(this._editBox.textLabel, this._color);
  10030. };
  10031. GTextInput.prototype.updateFontSize = function () {
  10032. this._editBox.textLabel.fontSize = this._fontSize;
  10033. this._editBox.textLabel.lineHeight = this._fontSize + this._leading;
  10034. if (this._editBox.placeholderLabel)
  10035. this._editBox.placeholderLabel.fontSize = this._editBox.textLabel.fontSize;
  10036. };
  10037. GTextInput.prototype.updateOverflow = function () {
  10038. };
  10039. GTextInput.prototype.onTextChanged = function () {
  10040. this._text = this._editBox.string;
  10041. };
  10042. GTextInput.prototype.onTouchEnd1 = function (evt) {
  10043. this._editBox.openKeyboard(evt.touch);
  10044. };
  10045. GTextInput.prototype.setup_beforeAdd = function (buffer, beginPos) {
  10046. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  10047. buffer.seek(beginPos, 4);
  10048. var str = buffer.readS();
  10049. if (str != null)
  10050. this.promptText = str;
  10051. str = buffer.readS();
  10052. if (str != null)
  10053. this.restrict = str;
  10054. var iv = buffer.readInt();
  10055. if (iv != 0)
  10056. this.maxLength = iv;
  10057. iv = buffer.readInt();
  10058. if (iv != 0) {
  10059. }
  10060. if (buffer.readBool())
  10061. this.password = true;
  10062. if (this._editBox.placeholderLabel) {
  10063. var hAlign = this._editBox.textLabel.horizontalAlign;
  10064. this._editBox.placeholderLabel.horizontalAlign = hAlign;
  10065. var vAlign = this._editBox.textLabel.verticalAlign;
  10066. this._editBox.placeholderLabel.verticalAlign = vAlign;
  10067. }
  10068. };
  10069. return GTextInput;
  10070. }(fgui.GTextField));
  10071. fgui.GTextInput = GTextInput;
  10072. var MyEditBox = (function (_super) {
  10073. __extends(MyEditBox, _super);
  10074. function MyEditBox() {
  10075. return _super !== null && _super.apply(this, arguments) || this;
  10076. }
  10077. MyEditBox.prototype._registerEvent = function () {
  10078. };
  10079. MyEditBox.prototype._syncSize = function () {
  10080. var size = this.node.getContentSize();
  10081. var impl = this["_impl"];
  10082. impl.setSize(size.width, size.height);
  10083. if (this.textLabel)
  10084. this.textLabel.node.setContentSize(size.width, size.height);
  10085. if (this.placeholderLabel)
  10086. this.placeholderLabel.node.setContentSize(size.width, size.height);
  10087. };
  10088. MyEditBox.prototype.openKeyboard = function (touch) {
  10089. var impl = this["_impl"];
  10090. if (impl) {
  10091. impl.beginEditing();
  10092. }
  10093. };
  10094. return MyEditBox;
  10095. }(cc.EditBox));
  10096. })(fgui || (fgui = {}));
  10097. (function (fgui) {
  10098. var GTree = (function (_super) {
  10099. __extends(GTree, _super);
  10100. function GTree() {
  10101. var _this = _super.call(this) || this;
  10102. _this._indent = 15;
  10103. _this._rootNode = new fgui.GTreeNode(true);
  10104. _this._rootNode._setTree(_this);
  10105. _this._rootNode.expanded = true;
  10106. return _this;
  10107. }
  10108. Object.defineProperty(GTree.prototype, "rootNode", {
  10109. get: function () {
  10110. return this._rootNode;
  10111. },
  10112. enumerable: false,
  10113. configurable: true
  10114. });
  10115. Object.defineProperty(GTree.prototype, "indent", {
  10116. get: function () {
  10117. return this._indent;
  10118. },
  10119. set: function (value) {
  10120. this._indent = value;
  10121. },
  10122. enumerable: false,
  10123. configurable: true
  10124. });
  10125. Object.defineProperty(GTree.prototype, "clickToExpand", {
  10126. get: function () {
  10127. return this._clickToExpand;
  10128. },
  10129. set: function (value) {
  10130. this._clickToExpand = value;
  10131. },
  10132. enumerable: false,
  10133. configurable: true
  10134. });
  10135. GTree.prototype.getSelectedNode = function () {
  10136. if (this.selectedIndex != -1)
  10137. return this.getChildAt(this.selectedIndex)._treeNode;
  10138. else
  10139. return null;
  10140. };
  10141. GTree.prototype.getSelectedNodes = function (result) {
  10142. if (!result)
  10143. result = new Array();
  10144. s_list.length = 0;
  10145. _super.prototype.getSelection.call(this, s_list);
  10146. var cnt = s_list.length;
  10147. var ret = new Array();
  10148. for (var i = 0; i < cnt; i++) {
  10149. var node = this.getChildAt(s_list[i])._treeNode;
  10150. ret.push(node);
  10151. }
  10152. return ret;
  10153. };
  10154. GTree.prototype.selectNode = function (node, scrollItToView) {
  10155. var parentNode = node.parent;
  10156. while (parentNode && parentNode != this._rootNode) {
  10157. parentNode.expanded = true;
  10158. parentNode = parentNode.parent;
  10159. }
  10160. if (!node._cell)
  10161. return;
  10162. this.addSelection(this.getChildIndex(node._cell), scrollItToView);
  10163. };
  10164. GTree.prototype.unselectNode = function (node) {
  10165. if (!node._cell)
  10166. return;
  10167. this.removeSelection(this.getChildIndex(node._cell));
  10168. };
  10169. GTree.prototype.expandAll = function (folderNode) {
  10170. if (!folderNode)
  10171. folderNode = this._rootNode;
  10172. folderNode.expanded = true;
  10173. var cnt = folderNode.numChildren;
  10174. for (var i = 0; i < cnt; i++) {
  10175. var node = folderNode.getChildAt(i);
  10176. if (node.isFolder)
  10177. this.expandAll(node);
  10178. }
  10179. };
  10180. GTree.prototype.collapseAll = function (folderNode) {
  10181. if (!folderNode)
  10182. folderNode = this._rootNode;
  10183. if (folderNode != this._rootNode)
  10184. folderNode.expanded = false;
  10185. var cnt = folderNode.numChildren;
  10186. for (var i = 0; i < cnt; i++) {
  10187. var node = folderNode.getChildAt(i);
  10188. if (node.isFolder)
  10189. this.collapseAll(node);
  10190. }
  10191. };
  10192. GTree.prototype.createCell = function (node) {
  10193. var child = this.getFromPool(node._resURL);
  10194. if (!(child instanceof fgui.GComponent))
  10195. throw new Error("cannot create tree node object.");
  10196. child._treeNode = node;
  10197. node._cell = child;
  10198. var indentObj = child.getChild("indent");
  10199. if (indentObj)
  10200. indentObj.width = (node.level - 1) * this._indent;
  10201. var cc;
  10202. cc = child.getController("expanded");
  10203. if (cc) {
  10204. cc.on(fgui.Event.STATUS_CHANGED, this.__expandedStateChanged, this);
  10205. cc.selectedIndex = node.expanded ? 1 : 0;
  10206. }
  10207. cc = child.getController("leaf");
  10208. if (cc)
  10209. cc.selectedIndex = node.isFolder ? 0 : 1;
  10210. if (node.isFolder)
  10211. node._cell.on(fgui.Event.TOUCH_BEGIN, this.__cellMouseDown, this);
  10212. if (this.treeNodeRender)
  10213. this.treeNodeRender(node, child);
  10214. };
  10215. GTree.prototype._afterInserted = function (node) {
  10216. if (!node._cell)
  10217. this.createCell(node);
  10218. var index = this.getInsertIndexForNode(node);
  10219. this.addChildAt(node._cell, index);
  10220. if (this.treeNodeRender)
  10221. this.treeNodeRender(node, node._cell);
  10222. if (node.isFolder && node.expanded)
  10223. this.checkChildren(node, index);
  10224. };
  10225. GTree.prototype.getInsertIndexForNode = function (node) {
  10226. var prevNode = node.getPrevSibling();
  10227. if (prevNode == null)
  10228. prevNode = node.parent;
  10229. var insertIndex = this.getChildIndex(prevNode._cell) + 1;
  10230. var myLevel = node.level;
  10231. var cnt = this.numChildren;
  10232. for (var i = insertIndex; i < cnt; i++) {
  10233. var testNode = this.getChildAt(i)._treeNode;
  10234. if (testNode.level <= myLevel)
  10235. break;
  10236. insertIndex++;
  10237. }
  10238. return insertIndex;
  10239. };
  10240. GTree.prototype._afterRemoved = function (node) {
  10241. this.removeNode(node);
  10242. };
  10243. GTree.prototype._afterExpanded = function (node) {
  10244. if (node == this._rootNode) {
  10245. this.checkChildren(this._rootNode, 0);
  10246. return;
  10247. }
  10248. if (this.treeNodeWillExpand != null)
  10249. this.treeNodeWillExpand(node, true);
  10250. if (node._cell == null)
  10251. return;
  10252. if (this.treeNodeRender)
  10253. this.treeNodeRender(node, node._cell);
  10254. var cc = node._cell.getController("expanded");
  10255. if (cc)
  10256. cc.selectedIndex = 1;
  10257. if (node._cell.parent)
  10258. this.checkChildren(node, this.getChildIndex(node._cell));
  10259. };
  10260. GTree.prototype._afterCollapsed = function (node) {
  10261. if (node == this._rootNode) {
  10262. this.checkChildren(this._rootNode, 0);
  10263. return;
  10264. }
  10265. if (this.treeNodeWillExpand)
  10266. this.treeNodeWillExpand(node, false);
  10267. if (node._cell == null)
  10268. return;
  10269. if (this.treeNodeRender)
  10270. this.treeNodeRender(node, node._cell);
  10271. var cc = node._cell.getController("expanded");
  10272. if (cc)
  10273. cc.selectedIndex = 0;
  10274. if (node._cell.parent)
  10275. this.hideFolderNode(node);
  10276. };
  10277. GTree.prototype._afterMoved = function (node) {
  10278. var startIndex = this.getChildIndex(node._cell);
  10279. var endIndex;
  10280. if (node.isFolder)
  10281. endIndex = this.getFolderEndIndex(startIndex, node.level);
  10282. else
  10283. endIndex = startIndex + 1;
  10284. var insertIndex = this.getInsertIndexForNode(node);
  10285. var i;
  10286. var cnt = endIndex - startIndex;
  10287. var obj;
  10288. if (insertIndex < startIndex) {
  10289. for (i = 0; i < cnt; i++) {
  10290. obj = this.getChildAt(startIndex + i);
  10291. this.setChildIndex(obj, insertIndex + i);
  10292. }
  10293. }
  10294. else {
  10295. for (i = 0; i < cnt; i++) {
  10296. obj = this.getChildAt(startIndex);
  10297. this.setChildIndex(obj, insertIndex);
  10298. }
  10299. }
  10300. };
  10301. GTree.prototype.getFolderEndIndex = function (startIndex, level) {
  10302. var cnt = this.numChildren;
  10303. for (var i = startIndex + 1; i < cnt; i++) {
  10304. var node = this.getChildAt(i)._treeNode;
  10305. if (node.level <= level)
  10306. return i;
  10307. }
  10308. return cnt;
  10309. };
  10310. GTree.prototype.checkChildren = function (folderNode, index) {
  10311. var cnt = folderNode.numChildren;
  10312. for (var i = 0; i < cnt; i++) {
  10313. index++;
  10314. var node = folderNode.getChildAt(i);
  10315. if (node._cell == null)
  10316. this.createCell(node);
  10317. if (!node._cell.parent)
  10318. this.addChildAt(node._cell, index);
  10319. if (node.isFolder && node.expanded)
  10320. index = this.checkChildren(node, index);
  10321. }
  10322. return index;
  10323. };
  10324. GTree.prototype.hideFolderNode = function (folderNode) {
  10325. var cnt = folderNode.numChildren;
  10326. for (var i = 0; i < cnt; i++) {
  10327. var node = folderNode.getChildAt(i);
  10328. if (node._cell)
  10329. this.removeChild(node._cell);
  10330. if (node.isFolder && node.expanded)
  10331. this.hideFolderNode(node);
  10332. }
  10333. };
  10334. GTree.prototype.removeNode = function (node) {
  10335. if (node._cell) {
  10336. if (node._cell.parent)
  10337. this.removeChild(node._cell);
  10338. this.returnToPool(node._cell);
  10339. node._cell._treeNode = null;
  10340. node._cell = null;
  10341. }
  10342. if (node.isFolder) {
  10343. var cnt = node.numChildren;
  10344. for (var i = 0; i < cnt; i++) {
  10345. var node2 = node.getChildAt(i);
  10346. this.removeNode(node2);
  10347. }
  10348. }
  10349. };
  10350. GTree.prototype.__cellMouseDown = function (evt) {
  10351. var node = fgui.GObject.cast(evt.currentTarget)._treeNode;
  10352. this._expandedStatusInEvt = node.expanded;
  10353. };
  10354. GTree.prototype.__expandedStateChanged = function (cc) {
  10355. var node = cc.parent._treeNode;
  10356. node.expanded = cc.selectedIndex == 1;
  10357. };
  10358. GTree.prototype.dispatchItemEvent = function (item, evt) {
  10359. if (this._clickToExpand != 0) {
  10360. var node = item._treeNode;
  10361. if (node && this._expandedStatusInEvt == node.expanded) {
  10362. if (this._clickToExpand == 2) {
  10363. }
  10364. else
  10365. node.expanded = !node.expanded;
  10366. }
  10367. }
  10368. _super.prototype.dispatchItemEvent.call(this, item, evt);
  10369. };
  10370. GTree.prototype.setup_beforeAdd = function (buffer, beginPos) {
  10371. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  10372. buffer.seek(beginPos, 9);
  10373. this._indent = buffer.readInt();
  10374. this._clickToExpand = buffer.readByte();
  10375. };
  10376. GTree.prototype.readItems = function (buffer) {
  10377. var cnt;
  10378. var i;
  10379. var nextPos;
  10380. var str;
  10381. var isFolder;
  10382. var lastNode;
  10383. var level;
  10384. var prevLevel = 0;
  10385. cnt = buffer.readShort();
  10386. for (i = 0; i < cnt; i++) {
  10387. nextPos = buffer.readShort();
  10388. nextPos += buffer.position;
  10389. str = buffer.readS();
  10390. if (str == null) {
  10391. str = this.defaultItem;
  10392. if (!str) {
  10393. buffer.position = nextPos;
  10394. continue;
  10395. }
  10396. }
  10397. isFolder = buffer.readBool();
  10398. level = buffer.readByte();
  10399. var node = new fgui.GTreeNode(isFolder, str);
  10400. node.expanded = true;
  10401. if (i == 0)
  10402. this._rootNode.addChild(node);
  10403. else {
  10404. if (level > prevLevel)
  10405. lastNode.addChild(node);
  10406. else if (level < prevLevel) {
  10407. for (var j = level; j <= prevLevel; j++)
  10408. lastNode = lastNode.parent;
  10409. lastNode.addChild(node);
  10410. }
  10411. else
  10412. lastNode.parent.addChild(node);
  10413. }
  10414. lastNode = node;
  10415. prevLevel = level;
  10416. this.setupItem(buffer, node.cell);
  10417. buffer.position = nextPos;
  10418. }
  10419. };
  10420. return GTree;
  10421. }(fgui.GList));
  10422. fgui.GTree = GTree;
  10423. var s_list = new Array();
  10424. })(fgui || (fgui = {}));
  10425. (function (fgui) {
  10426. var GTreeNode = (function () {
  10427. function GTreeNode(hasChild, resURL) {
  10428. this._level = 0;
  10429. this._resURL = resURL;
  10430. if (hasChild)
  10431. this._children = new Array();
  10432. }
  10433. Object.defineProperty(GTreeNode.prototype, "expanded", {
  10434. get: function () {
  10435. return this._expanded;
  10436. },
  10437. set: function (value) {
  10438. if (this._children == null)
  10439. return;
  10440. if (this._expanded != value) {
  10441. this._expanded = value;
  10442. if (this._tree) {
  10443. if (this._expanded)
  10444. this._tree._afterExpanded(this);
  10445. else
  10446. this._tree._afterCollapsed(this);
  10447. }
  10448. }
  10449. },
  10450. enumerable: false,
  10451. configurable: true
  10452. });
  10453. Object.defineProperty(GTreeNode.prototype, "isFolder", {
  10454. get: function () {
  10455. return this._children != null;
  10456. },
  10457. enumerable: false,
  10458. configurable: true
  10459. });
  10460. Object.defineProperty(GTreeNode.prototype, "parent", {
  10461. get: function () {
  10462. return this._parent;
  10463. },
  10464. enumerable: false,
  10465. configurable: true
  10466. });
  10467. Object.defineProperty(GTreeNode.prototype, "text", {
  10468. get: function () {
  10469. if (this._cell)
  10470. return this._cell.text;
  10471. else
  10472. return null;
  10473. },
  10474. set: function (value) {
  10475. if (this._cell)
  10476. this._cell.text = value;
  10477. },
  10478. enumerable: false,
  10479. configurable: true
  10480. });
  10481. Object.defineProperty(GTreeNode.prototype, "icon", {
  10482. get: function () {
  10483. if (this._cell)
  10484. return this._cell.icon;
  10485. else
  10486. return null;
  10487. },
  10488. set: function (value) {
  10489. if (this._cell)
  10490. this._cell.icon = value;
  10491. },
  10492. enumerable: false,
  10493. configurable: true
  10494. });
  10495. Object.defineProperty(GTreeNode.prototype, "cell", {
  10496. get: function () {
  10497. return this._cell;
  10498. },
  10499. enumerable: false,
  10500. configurable: true
  10501. });
  10502. Object.defineProperty(GTreeNode.prototype, "level", {
  10503. get: function () {
  10504. return this._level;
  10505. },
  10506. enumerable: false,
  10507. configurable: true
  10508. });
  10509. GTreeNode.prototype._setLevel = function (value) {
  10510. this._level = value;
  10511. };
  10512. GTreeNode.prototype.addChild = function (child) {
  10513. this.addChildAt(child, this._children.length);
  10514. return child;
  10515. };
  10516. GTreeNode.prototype.addChildAt = function (child, index) {
  10517. if (!child)
  10518. throw new Error("child is null");
  10519. var numChildren = this._children.length;
  10520. if (index >= 0 && index <= numChildren) {
  10521. if (child._parent == this) {
  10522. this.setChildIndex(child, index);
  10523. }
  10524. else {
  10525. if (child._parent)
  10526. child._parent.removeChild(child);
  10527. var cnt = this._children.length;
  10528. if (index == cnt)
  10529. this._children.push(child);
  10530. else
  10531. this._children.splice(index, 0, child);
  10532. child._parent = this;
  10533. child._level = this._level + 1;
  10534. child._setTree(this._tree);
  10535. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  10536. this._tree._afterInserted(child);
  10537. }
  10538. return child;
  10539. }
  10540. else {
  10541. throw new RangeError("Invalid child index");
  10542. }
  10543. };
  10544. GTreeNode.prototype.removeChild = function (child) {
  10545. var childIndex = this._children.indexOf(child);
  10546. if (childIndex != -1) {
  10547. this.removeChildAt(childIndex);
  10548. }
  10549. return child;
  10550. };
  10551. GTreeNode.prototype.removeChildAt = function (index) {
  10552. if (index >= 0 && index < this.numChildren) {
  10553. var child = this._children[index];
  10554. this._children.splice(index, 1);
  10555. child._parent = null;
  10556. if (this._tree) {
  10557. child._setTree(null);
  10558. this._tree._afterRemoved(child);
  10559. }
  10560. return child;
  10561. }
  10562. else {
  10563. throw "Invalid child index";
  10564. }
  10565. };
  10566. GTreeNode.prototype.removeChildren = function (beginIndex, endIndex) {
  10567. beginIndex = beginIndex || 0;
  10568. if (endIndex == null)
  10569. endIndex = -1;
  10570. if (endIndex < 0 || endIndex >= this.numChildren)
  10571. endIndex = this.numChildren - 1;
  10572. for (var i = beginIndex; i <= endIndex; ++i)
  10573. this.removeChildAt(beginIndex);
  10574. };
  10575. GTreeNode.prototype.getChildAt = function (index) {
  10576. if (index >= 0 && index < this.numChildren)
  10577. return this._children[index];
  10578. else
  10579. throw "Invalid child index";
  10580. };
  10581. GTreeNode.prototype.getChildIndex = function (child) {
  10582. return this._children.indexOf(child);
  10583. };
  10584. GTreeNode.prototype.getPrevSibling = function () {
  10585. if (this._parent == null)
  10586. return null;
  10587. var i = this._parent._children.indexOf(this);
  10588. if (i <= 0)
  10589. return null;
  10590. return this._parent._children[i - 1];
  10591. };
  10592. GTreeNode.prototype.getNextSibling = function () {
  10593. if (this._parent == null)
  10594. return null;
  10595. var i = this._parent._children.indexOf(this);
  10596. if (i < 0 || i >= this._parent._children.length - 1)
  10597. return null;
  10598. return this._parent._children[i + 1];
  10599. };
  10600. GTreeNode.prototype.setChildIndex = function (child, index) {
  10601. var oldIndex = this._children.indexOf(child);
  10602. if (oldIndex == -1)
  10603. throw "Not a child of this container";
  10604. var cnt = this._children.length;
  10605. if (index < 0)
  10606. index = 0;
  10607. else if (index > cnt)
  10608. index = cnt;
  10609. if (oldIndex == index)
  10610. return;
  10611. this._children.splice(oldIndex, 1);
  10612. this._children.splice(index, 0, child);
  10613. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  10614. this._tree._afterMoved(child);
  10615. };
  10616. GTreeNode.prototype.swapChildren = function (child1, child2) {
  10617. var index1 = this._children.indexOf(child1);
  10618. var index2 = this._children.indexOf(child2);
  10619. if (index1 == -1 || index2 == -1)
  10620. throw "Not a child of this container";
  10621. this.swapChildrenAt(index1, index2);
  10622. };
  10623. GTreeNode.prototype.swapChildrenAt = function (index1, index2) {
  10624. var child1 = this._children[index1];
  10625. var child2 = this._children[index2];
  10626. this.setChildIndex(child1, index2);
  10627. this.setChildIndex(child2, index1);
  10628. };
  10629. Object.defineProperty(GTreeNode.prototype, "numChildren", {
  10630. get: function () {
  10631. return this._children.length;
  10632. },
  10633. enumerable: false,
  10634. configurable: true
  10635. });
  10636. GTreeNode.prototype.expandToRoot = function () {
  10637. var p = this;
  10638. while (p) {
  10639. p.expanded = true;
  10640. p = p.parent;
  10641. }
  10642. };
  10643. Object.defineProperty(GTreeNode.prototype, "tree", {
  10644. get: function () {
  10645. return this._tree;
  10646. },
  10647. enumerable: false,
  10648. configurable: true
  10649. });
  10650. GTreeNode.prototype._setTree = function (value) {
  10651. this._tree = value;
  10652. if (this._tree && this._tree.treeNodeWillExpand && this._expanded)
  10653. this._tree.treeNodeWillExpand(this, true);
  10654. if (this._children) {
  10655. var cnt = this._children.length;
  10656. for (var i = 0; i < cnt; i++) {
  10657. var node = this._children[i];
  10658. node._level = this._level + 1;
  10659. node._setTree(value);
  10660. }
  10661. }
  10662. };
  10663. return GTreeNode;
  10664. }());
  10665. fgui.GTreeNode = GTreeNode;
  10666. })(fgui || (fgui = {}));
  10667. (function (fgui) {
  10668. var Margin = (function () {
  10669. function Margin() {
  10670. this.left = 0;
  10671. this.right = 0;
  10672. this.top = 0;
  10673. this.bottom = 0;
  10674. }
  10675. Margin.prototype.copy = function (source) {
  10676. this.top = source.top;
  10677. this.bottom = source.bottom;
  10678. this.left = source.left;
  10679. this.right = source.right;
  10680. };
  10681. Margin.prototype.isNone = function () {
  10682. return this.left == 0 && this.right == 0 && this.top == 0 && this.bottom == 0;
  10683. };
  10684. return Margin;
  10685. }());
  10686. fgui.Margin = Margin;
  10687. })(fgui || (fgui = {}));
  10688. (function (fgui) {
  10689. var PackageItem = (function () {
  10690. function PackageItem() {
  10691. this.width = 0;
  10692. this.height = 0;
  10693. }
  10694. PackageItem.prototype.load = function () {
  10695. return this.owner.getItemAsset(this);
  10696. };
  10697. PackageItem.prototype.getBranch = function () {
  10698. if (this.branches && this.owner._branchIndex != -1) {
  10699. var itemId = this.branches[this.owner._branchIndex];
  10700. if (itemId)
  10701. return this.owner.getItemById(itemId);
  10702. }
  10703. return this;
  10704. };
  10705. PackageItem.prototype.getHighResolution = function () {
  10706. if (this.highResolution && fgui.GRoot.contentScaleLevel > 0) {
  10707. var itemId = this.highResolution[fgui.GRoot.contentScaleLevel - 1];
  10708. if (itemId)
  10709. return this.owner.getItemById(itemId);
  10710. }
  10711. return this;
  10712. };
  10713. PackageItem.prototype.toString = function () {
  10714. return this.name;
  10715. };
  10716. return PackageItem;
  10717. }());
  10718. fgui.PackageItem = PackageItem;
  10719. })(fgui || (fgui = {}));
  10720. (function (fgui) {
  10721. var PopupMenu = (function () {
  10722. function PopupMenu(url) {
  10723. if (!url) {
  10724. url = fgui.UIConfig.popupMenu;
  10725. if (!url)
  10726. throw "UIConfig.popupMenu not defined";
  10727. }
  10728. this._contentPane = fgui.UIPackage.createObjectFromURL(url);
  10729. this._contentPane.on(fgui.Event.DISPLAY, this.onDisplay, this);
  10730. this._list = (this._contentPane.getChild("list"));
  10731. this._list.removeChildrenToPool();
  10732. this._list.addRelation(this._contentPane, fgui.RelationType.Width);
  10733. this._list.removeRelation(this._contentPane, fgui.RelationType.Height);
  10734. this._contentPane.addRelation(this._list, fgui.RelationType.Height);
  10735. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  10736. }
  10737. PopupMenu.prototype.dispose = function () {
  10738. this._contentPane.dispose();
  10739. };
  10740. PopupMenu.prototype.addItem = function (caption, callback) {
  10741. var item = this._list.addItemFromPool();
  10742. item.title = caption;
  10743. item.data = callback;
  10744. item.grayed = false;
  10745. var c = item.getController("checked");
  10746. if (c)
  10747. c.selectedIndex = 0;
  10748. return item;
  10749. };
  10750. PopupMenu.prototype.addItemAt = function (caption, index, callback) {
  10751. var item = this._list.getFromPool();
  10752. this._list.addChildAt(item, index);
  10753. item.title = caption;
  10754. item.data = callback;
  10755. item.grayed = false;
  10756. var c = item.getController("checked");
  10757. if (c)
  10758. c.selectedIndex = 0;
  10759. return item;
  10760. };
  10761. PopupMenu.prototype.addSeperator = function () {
  10762. if (fgui.UIConfig.popupMenu_seperator == null)
  10763. throw "UIConfig.popupMenu_seperator not defined";
  10764. this.list.addItemFromPool(fgui.UIConfig.popupMenu_seperator);
  10765. };
  10766. PopupMenu.prototype.getItemName = function (index) {
  10767. var item = this._list.getChildAt(index);
  10768. return item.name;
  10769. };
  10770. PopupMenu.prototype.setItemText = function (name, caption) {
  10771. var item = this._list.getChild(name);
  10772. item.title = caption;
  10773. };
  10774. PopupMenu.prototype.setItemVisible = function (name, visible) {
  10775. var item = this._list.getChild(name);
  10776. if (item.visible != visible) {
  10777. item.visible = visible;
  10778. this._list.setBoundsChangedFlag();
  10779. }
  10780. };
  10781. PopupMenu.prototype.setItemGrayed = function (name, grayed) {
  10782. var item = this._list.getChild(name);
  10783. item.grayed = grayed;
  10784. };
  10785. PopupMenu.prototype.setItemCheckable = function (name, checkable) {
  10786. var item = this._list.getChild(name);
  10787. var c = item.getController("checked");
  10788. if (c) {
  10789. if (checkable) {
  10790. if (c.selectedIndex == 0)
  10791. c.selectedIndex = 1;
  10792. }
  10793. else
  10794. c.selectedIndex = 0;
  10795. }
  10796. };
  10797. PopupMenu.prototype.setItemChecked = function (name, checked) {
  10798. var item = this._list.getChild(name);
  10799. var c = item.getController("checked");
  10800. if (c)
  10801. c.selectedIndex = checked ? 2 : 1;
  10802. };
  10803. PopupMenu.prototype.isItemChecked = function (name) {
  10804. var item = this._list.getChild(name);
  10805. var c = item.getController("checked");
  10806. if (c)
  10807. return c.selectedIndex == 2;
  10808. else
  10809. return false;
  10810. };
  10811. PopupMenu.prototype.removeItem = function (name) {
  10812. var item = this._list.getChild(name);
  10813. if (item) {
  10814. var index = this._list.getChildIndex(item);
  10815. this._list.removeChildToPoolAt(index);
  10816. return true;
  10817. }
  10818. else
  10819. return false;
  10820. };
  10821. PopupMenu.prototype.clearItems = function () {
  10822. this._list.removeChildrenToPool();
  10823. };
  10824. Object.defineProperty(PopupMenu.prototype, "itemCount", {
  10825. get: function () {
  10826. return this._list.numChildren;
  10827. },
  10828. enumerable: false,
  10829. configurable: true
  10830. });
  10831. Object.defineProperty(PopupMenu.prototype, "contentPane", {
  10832. get: function () {
  10833. return this._contentPane;
  10834. },
  10835. enumerable: false,
  10836. configurable: true
  10837. });
  10838. Object.defineProperty(PopupMenu.prototype, "list", {
  10839. get: function () {
  10840. return this._list;
  10841. },
  10842. enumerable: false,
  10843. configurable: true
  10844. });
  10845. PopupMenu.prototype.show = function (target, dir) {
  10846. if (target === void 0) { target = null; }
  10847. var r = target != null ? target.root : fgui.GRoot.inst;
  10848. r.showPopup(this.contentPane, (target instanceof fgui.GRoot) ? null : target, dir);
  10849. };
  10850. PopupMenu.prototype.onClickItem = function (item, evt) {
  10851. var _this = this;
  10852. this._list._partner.callLater(function (dt) {
  10853. _this.onClickItem2(item, evt);
  10854. }, 0.1);
  10855. };
  10856. PopupMenu.prototype.onClickItem2 = function (item, evt) {
  10857. if (!(item instanceof fgui.GButton))
  10858. return;
  10859. if (item.grayed) {
  10860. this._list.selectedIndex = -1;
  10861. return;
  10862. }
  10863. var c = item.getController("checked");
  10864. if (c && c.selectedIndex != 0) {
  10865. if (c.selectedIndex == 1)
  10866. c.selectedIndex = 2;
  10867. else
  10868. c.selectedIndex = 1;
  10869. }
  10870. var r = (this._contentPane.parent);
  10871. r.hidePopup(this.contentPane);
  10872. if (item.data instanceof Function)
  10873. item.data(item, evt);
  10874. };
  10875. PopupMenu.prototype.onDisplay = function () {
  10876. this._list.selectedIndex = -1;
  10877. this._list.resizeToFit(100000, 10);
  10878. };
  10879. return PopupMenu;
  10880. }());
  10881. fgui.PopupMenu = PopupMenu;
  10882. })(fgui || (fgui = {}));
  10883. (function (fgui) {
  10884. var RelationItem = (function () {
  10885. function RelationItem(owner) {
  10886. this._owner = owner;
  10887. this._defs = new Array();
  10888. }
  10889. Object.defineProperty(RelationItem.prototype, "owner", {
  10890. get: function () {
  10891. return this._owner;
  10892. },
  10893. enumerable: false,
  10894. configurable: true
  10895. });
  10896. Object.defineProperty(RelationItem.prototype, "target", {
  10897. get: function () {
  10898. return this._target;
  10899. },
  10900. set: function (value) {
  10901. if (this._target != value) {
  10902. if (this._target)
  10903. this.releaseRefTarget(this._target);
  10904. this._target = value;
  10905. if (this._target)
  10906. this.addRefTarget(this._target);
  10907. }
  10908. },
  10909. enumerable: false,
  10910. configurable: true
  10911. });
  10912. RelationItem.prototype.add = function (relationType, usePercent) {
  10913. if (relationType == fgui.RelationType.Size) {
  10914. this.add(fgui.RelationType.Width, usePercent);
  10915. this.add(fgui.RelationType.Height, usePercent);
  10916. return;
  10917. }
  10918. var length = this._defs.length;
  10919. for (var i = 0; i < length; i++) {
  10920. var def = this._defs[i];
  10921. if (def.type == relationType)
  10922. return;
  10923. }
  10924. this.internalAdd(relationType, usePercent);
  10925. };
  10926. RelationItem.prototype.internalAdd = function (relationType, usePercent) {
  10927. if (relationType == fgui.RelationType.Size) {
  10928. this.internalAdd(fgui.RelationType.Width, usePercent);
  10929. this.internalAdd(fgui.RelationType.Height, usePercent);
  10930. return;
  10931. }
  10932. var info = new RelationDef();
  10933. info.percent = usePercent;
  10934. info.type = relationType;
  10935. info.axis = (relationType <= fgui.RelationType.Right_Right || relationType == fgui.RelationType.Width || relationType >= fgui.RelationType.LeftExt_Left && relationType <= fgui.RelationType.RightExt_Right) ? 0 : 1;
  10936. this._defs.push(info);
  10937. };
  10938. RelationItem.prototype.remove = function (relationType) {
  10939. if (relationType == fgui.RelationType.Size) {
  10940. this.remove(fgui.RelationType.Width);
  10941. this.remove(fgui.RelationType.Height);
  10942. return;
  10943. }
  10944. var dc = this._defs.length;
  10945. for (var k = 0; k < dc; k++) {
  10946. if (this._defs[k].type == relationType) {
  10947. this._defs.splice(k, 1);
  10948. break;
  10949. }
  10950. }
  10951. };
  10952. RelationItem.prototype.copyFrom = function (source) {
  10953. this.target = source.target;
  10954. this._defs.length = 0;
  10955. var length = source._defs.length;
  10956. for (var i = 0; i < length; i++) {
  10957. var info = source._defs[i];
  10958. var info2 = new RelationDef();
  10959. info2.copyFrom(info);
  10960. this._defs.push(info2);
  10961. }
  10962. };
  10963. RelationItem.prototype.dispose = function () {
  10964. if (this._target) {
  10965. this.releaseRefTarget(this._target);
  10966. this._target = null;
  10967. }
  10968. };
  10969. Object.defineProperty(RelationItem.prototype, "isEmpty", {
  10970. get: function () {
  10971. return this._defs.length == 0;
  10972. },
  10973. enumerable: false,
  10974. configurable: true
  10975. });
  10976. RelationItem.prototype.applyOnSelfResized = function (dWidth, dHeight, applyPivot) {
  10977. var ox = this._owner.x;
  10978. var oy = this._owner.y;
  10979. var length = this._defs.length;
  10980. for (var i = 0; i < length; i++) {
  10981. var info = this._defs[i];
  10982. switch (info.type) {
  10983. case fgui.RelationType.Center_Center:
  10984. this._owner.x -= (0.5 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10985. break;
  10986. case fgui.RelationType.Right_Center:
  10987. case fgui.RelationType.Right_Left:
  10988. case fgui.RelationType.Right_Right:
  10989. this._owner.x -= (1 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10990. break;
  10991. case fgui.RelationType.Middle_Middle:
  10992. this._owner.y -= (0.5 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10993. break;
  10994. case fgui.RelationType.Bottom_Middle:
  10995. case fgui.RelationType.Bottom_Top:
  10996. case fgui.RelationType.Bottom_Bottom:
  10997. this._owner.y -= (1 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10998. break;
  10999. }
  11000. }
  11001. if (ox != this._owner.x || oy != this._owner.y) {
  11002. ox = this._owner.x - ox;
  11003. oy = this._owner.y - oy;
  11004. this._owner.updateGearFromRelations(1, ox, oy);
  11005. if (this._owner.parent) {
  11006. var len = this._owner.parent._transitions.length;
  11007. if (len > 0) {
  11008. for (var i = 0; i < len; ++i) {
  11009. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  11010. }
  11011. }
  11012. }
  11013. }
  11014. };
  11015. RelationItem.prototype.applyOnXYChanged = function (info, dx, dy) {
  11016. var tmp;
  11017. switch (info.type) {
  11018. case fgui.RelationType.Left_Left:
  11019. case fgui.RelationType.Left_Center:
  11020. case fgui.RelationType.Left_Right:
  11021. case fgui.RelationType.Center_Center:
  11022. case fgui.RelationType.Right_Left:
  11023. case fgui.RelationType.Right_Center:
  11024. case fgui.RelationType.Right_Right:
  11025. this._owner.x += dx;
  11026. break;
  11027. case fgui.RelationType.Top_Top:
  11028. case fgui.RelationType.Top_Middle:
  11029. case fgui.RelationType.Top_Bottom:
  11030. case fgui.RelationType.Middle_Middle:
  11031. case fgui.RelationType.Bottom_Top:
  11032. case fgui.RelationType.Bottom_Middle:
  11033. case fgui.RelationType.Bottom_Bottom:
  11034. this._owner.y += dy;
  11035. break;
  11036. case fgui.RelationType.Width:
  11037. case fgui.RelationType.Height:
  11038. break;
  11039. case fgui.RelationType.LeftExt_Left:
  11040. case fgui.RelationType.LeftExt_Right:
  11041. if (this._owner != this._target.parent) {
  11042. tmp = this._owner.xMin;
  11043. this._owner.width = this._owner._rawWidth - dx;
  11044. this._owner.xMin = tmp + dx;
  11045. }
  11046. else
  11047. this._owner.width = this._owner._rawWidth - dx;
  11048. break;
  11049. case fgui.RelationType.RightExt_Left:
  11050. case fgui.RelationType.RightExt_Right:
  11051. if (this._owner != this._target.parent) {
  11052. tmp = this._owner.xMin;
  11053. this._owner.width = this._owner._rawWidth + dx;
  11054. this._owner.xMin = tmp;
  11055. }
  11056. else
  11057. this._owner.width = this._owner._rawWidth + dx;
  11058. break;
  11059. case fgui.RelationType.TopExt_Top:
  11060. case fgui.RelationType.TopExt_Bottom:
  11061. if (this._owner != this._target.parent) {
  11062. tmp = this._owner.yMin;
  11063. this._owner.height = this._owner._rawHeight - dy;
  11064. this._owner.yMin = tmp + dy;
  11065. }
  11066. else
  11067. this._owner.height = this._owner._rawHeight - dy;
  11068. break;
  11069. case fgui.RelationType.BottomExt_Top:
  11070. case fgui.RelationType.BottomExt_Bottom:
  11071. if (this._owner != this._target.parent) {
  11072. tmp = this._owner.yMin;
  11073. this._owner.height = this._owner._rawHeight + dy;
  11074. this._owner.yMin = tmp;
  11075. }
  11076. else
  11077. this._owner.height = this._owner._rawHeight + dy;
  11078. break;
  11079. }
  11080. };
  11081. RelationItem.prototype.applyOnSizeChanged = function (info) {
  11082. var pos = 0, pivot = 0, delta = 0;
  11083. var v, tmp;
  11084. if (info.axis == 0) {
  11085. if (this._target != this._owner.parent) {
  11086. pos = this._target.x;
  11087. if (this._target.pivotAsAnchor)
  11088. pivot = this._target.pivotX;
  11089. }
  11090. if (info.percent) {
  11091. if (this._targetWidth != 0)
  11092. delta = this._target._width / this._targetWidth;
  11093. }
  11094. else
  11095. delta = this._target._width - this._targetWidth;
  11096. }
  11097. else {
  11098. if (this._target != this._owner.parent) {
  11099. pos = this._target.y;
  11100. if (this._target.pivotAsAnchor)
  11101. pivot = this._target.pivotY;
  11102. }
  11103. if (info.percent) {
  11104. if (this._targetHeight != 0)
  11105. delta = this._target._height / this._targetHeight;
  11106. }
  11107. else
  11108. delta = this._target._height - this._targetHeight;
  11109. }
  11110. switch (info.type) {
  11111. case fgui.RelationType.Left_Left:
  11112. if (info.percent)
  11113. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11114. else if (pivot != 0)
  11115. this._owner.x += delta * (-pivot);
  11116. break;
  11117. case fgui.RelationType.Left_Center:
  11118. if (info.percent)
  11119. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11120. else
  11121. this._owner.x += delta * (0.5 - pivot);
  11122. break;
  11123. case fgui.RelationType.Left_Right:
  11124. if (info.percent)
  11125. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11126. else
  11127. this._owner.x += delta * (1 - pivot);
  11128. break;
  11129. case fgui.RelationType.Center_Center:
  11130. if (info.percent)
  11131. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth * 0.5 - pos) * delta - this._owner._rawWidth * 0.5;
  11132. else
  11133. this._owner.x += delta * (0.5 - pivot);
  11134. break;
  11135. case fgui.RelationType.Right_Left:
  11136. if (info.percent)
  11137. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11138. else if (pivot != 0)
  11139. this._owner.x += delta * (-pivot);
  11140. break;
  11141. case fgui.RelationType.Right_Center:
  11142. if (info.percent)
  11143. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11144. else
  11145. this._owner.x += delta * (0.5 - pivot);
  11146. break;
  11147. case fgui.RelationType.Right_Right:
  11148. if (info.percent)
  11149. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11150. else
  11151. this._owner.x += delta * (1 - pivot);
  11152. break;
  11153. case fgui.RelationType.Top_Top:
  11154. if (info.percent)
  11155. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11156. else if (pivot != 0)
  11157. this._owner.y += delta * (-pivot);
  11158. break;
  11159. case fgui.RelationType.Top_Middle:
  11160. if (info.percent)
  11161. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11162. else
  11163. this._owner.y += delta * (0.5 - pivot);
  11164. break;
  11165. case fgui.RelationType.Top_Bottom:
  11166. if (info.percent)
  11167. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11168. else
  11169. this._owner.y += delta * (1 - pivot);
  11170. break;
  11171. case fgui.RelationType.Middle_Middle:
  11172. if (info.percent)
  11173. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight * 0.5 - pos) * delta - this._owner._rawHeight * 0.5;
  11174. else
  11175. this._owner.y += delta * (0.5 - pivot);
  11176. break;
  11177. case fgui.RelationType.Bottom_Top:
  11178. if (info.percent)
  11179. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11180. else if (pivot != 0)
  11181. this._owner.y += delta * (-pivot);
  11182. break;
  11183. case fgui.RelationType.Bottom_Middle:
  11184. if (info.percent)
  11185. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11186. else
  11187. this._owner.y += delta * (0.5 - pivot);
  11188. break;
  11189. case fgui.RelationType.Bottom_Bottom:
  11190. if (info.percent)
  11191. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11192. else
  11193. this._owner.y += delta * (1 - pivot);
  11194. break;
  11195. case fgui.RelationType.Width:
  11196. if (this._owner._underConstruct && this._owner == this._target.parent)
  11197. v = this._owner.sourceWidth - this._target.initWidth;
  11198. else
  11199. v = this._owner._rawWidth - this._targetWidth;
  11200. if (info.percent)
  11201. v = v * delta;
  11202. if (this._target == this._owner.parent) {
  11203. if (this._owner.pivotAsAnchor) {
  11204. tmp = this._owner.xMin;
  11205. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  11206. this._owner.xMin = tmp;
  11207. }
  11208. else
  11209. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  11210. }
  11211. else
  11212. this._owner.width = this._target._width + v;
  11213. break;
  11214. case fgui.RelationType.Height:
  11215. if (this._owner._underConstruct && this._owner == this._target.parent)
  11216. v = this._owner.sourceHeight - this._target.initHeight;
  11217. else
  11218. v = this._owner._rawHeight - this._targetHeight;
  11219. if (info.percent)
  11220. v = v * delta;
  11221. if (this._target == this._owner.parent) {
  11222. if (this._owner.pivotAsAnchor) {
  11223. tmp = this._owner.yMin;
  11224. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  11225. this._owner.yMin = tmp;
  11226. }
  11227. else
  11228. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  11229. }
  11230. else
  11231. this._owner.height = this._target._height + v;
  11232. break;
  11233. case fgui.RelationType.LeftExt_Left:
  11234. tmp = this._owner.xMin;
  11235. if (info.percent)
  11236. v = pos + (tmp - pos) * delta - tmp;
  11237. else
  11238. v = delta * (-pivot);
  11239. this._owner.width = this._owner._rawWidth - v;
  11240. this._owner.xMin = tmp + v;
  11241. break;
  11242. case fgui.RelationType.LeftExt_Right:
  11243. tmp = this._owner.xMin;
  11244. if (info.percent)
  11245. v = pos + (tmp - pos) * delta - tmp;
  11246. else
  11247. v = delta * (1 - pivot);
  11248. this._owner.width = this._owner._rawWidth - v;
  11249. this._owner.xMin = tmp + v;
  11250. break;
  11251. case fgui.RelationType.RightExt_Left:
  11252. tmp = this._owner.xMin;
  11253. if (info.percent)
  11254. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  11255. else
  11256. v = delta * (-pivot);
  11257. this._owner.width = this._owner._rawWidth + v;
  11258. this._owner.xMin = tmp;
  11259. break;
  11260. case fgui.RelationType.RightExt_Right:
  11261. tmp = this._owner.xMin;
  11262. if (info.percent) {
  11263. if (this._owner == this._target.parent) {
  11264. if (this._owner._underConstruct)
  11265. this._owner.width = pos + this._target._width - this._target._width * pivot +
  11266. (this._owner.sourceWidth - pos - this._target.initWidth + this._target.initWidth * pivot) * delta;
  11267. else
  11268. this._owner.width = pos + (this._owner._rawWidth - pos) * delta;
  11269. }
  11270. else {
  11271. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  11272. this._owner.width = this._owner._rawWidth + v;
  11273. this._owner.xMin = tmp;
  11274. }
  11275. }
  11276. else {
  11277. if (this._owner == this._target.parent) {
  11278. if (this._owner._underConstruct)
  11279. this._owner.width = this._owner.sourceWidth + (this._target._width - this._target.initWidth) * (1 - pivot);
  11280. else
  11281. this._owner.width = this._owner._rawWidth + delta * (1 - pivot);
  11282. }
  11283. else {
  11284. v = delta * (1 - pivot);
  11285. this._owner.width = this._owner._rawWidth + v;
  11286. this._owner.xMin = tmp;
  11287. }
  11288. }
  11289. break;
  11290. case fgui.RelationType.TopExt_Top:
  11291. tmp = this._owner.yMin;
  11292. if (info.percent)
  11293. v = pos + (tmp - pos) * delta - tmp;
  11294. else
  11295. v = delta * (-pivot);
  11296. this._owner.height = this._owner._rawHeight - v;
  11297. this._owner.yMin = tmp + v;
  11298. break;
  11299. case fgui.RelationType.TopExt_Bottom:
  11300. tmp = this._owner.yMin;
  11301. if (info.percent)
  11302. v = pos + (tmp - pos) * delta - tmp;
  11303. else
  11304. v = delta * (1 - pivot);
  11305. this._owner.height = this._owner._rawHeight - v;
  11306. this._owner.yMin = tmp + v;
  11307. break;
  11308. case fgui.RelationType.BottomExt_Top:
  11309. tmp = this._owner.yMin;
  11310. if (info.percent)
  11311. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  11312. else
  11313. v = delta * (-pivot);
  11314. this._owner.height = this._owner._rawHeight + v;
  11315. this._owner.yMin = tmp;
  11316. break;
  11317. case fgui.RelationType.BottomExt_Bottom:
  11318. tmp = this._owner.yMin;
  11319. if (info.percent) {
  11320. if (this._owner == this._target.parent) {
  11321. if (this._owner._underConstruct)
  11322. this._owner.height = pos + this._target._height - this._target._height * pivot +
  11323. (this._owner.sourceHeight - pos - this._target.initHeight + this._target.initHeight * pivot) * delta;
  11324. else
  11325. this._owner.height = pos + (this._owner._rawHeight - pos) * delta;
  11326. }
  11327. else {
  11328. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  11329. this._owner.height = this._owner._rawHeight + v;
  11330. this._owner.yMin = tmp;
  11331. }
  11332. }
  11333. else {
  11334. if (this._owner == this._target.parent) {
  11335. if (this._owner._underConstruct)
  11336. this._owner.height = this._owner.sourceHeight + (this._target._height - this._target.initHeight) * (1 - pivot);
  11337. else
  11338. this._owner.height = this._owner._rawHeight + delta * (1 - pivot);
  11339. }
  11340. else {
  11341. v = delta * (1 - pivot);
  11342. this._owner.height = this._owner._rawHeight + v;
  11343. this._owner.yMin = tmp;
  11344. }
  11345. }
  11346. break;
  11347. }
  11348. };
  11349. RelationItem.prototype.addRefTarget = function (target) {
  11350. if (target != this._owner.parent)
  11351. target.on(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  11352. target.on(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  11353. target.on(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  11354. this._targetX = this._target.x;
  11355. this._targetY = this._target.y;
  11356. this._targetWidth = this._target._width;
  11357. this._targetHeight = this._target._height;
  11358. };
  11359. RelationItem.prototype.releaseRefTarget = function (target) {
  11360. if (!target.node)
  11361. return;
  11362. target.off(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  11363. target.off(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  11364. target.off(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  11365. };
  11366. RelationItem.prototype.__targetXYChanged = function (evt) {
  11367. if (this._owner.relations.handling != null || this._owner.group != null && this._owner.group._updating) {
  11368. this._targetX = this._target.x;
  11369. this._targetY = this._target.y;
  11370. return;
  11371. }
  11372. this._owner.relations.handling = this._target;
  11373. var ox = this._owner.x;
  11374. var oy = this._owner.y;
  11375. var dx = this._target.x - this._targetX;
  11376. var dy = this._target.y - this._targetY;
  11377. var length = this._defs.length;
  11378. for (var i = 0; i < length; i++) {
  11379. var info = this._defs[i];
  11380. this.applyOnXYChanged(info, dx, dy);
  11381. }
  11382. this._targetX = this._target.x;
  11383. this._targetY = this._target.y;
  11384. if (ox != this._owner.x || oy != this._owner.y) {
  11385. ox = this._owner.x - ox;
  11386. oy = this._owner.y - oy;
  11387. this._owner.updateGearFromRelations(1, ox, oy);
  11388. if (this._owner.parent) {
  11389. var len = this._owner.parent._transitions.length;
  11390. if (len > 0) {
  11391. for (var i = 0; i < len; ++i) {
  11392. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  11393. }
  11394. }
  11395. }
  11396. }
  11397. this._owner.relations.handling = null;
  11398. };
  11399. RelationItem.prototype.__targetSizeChanged = function (evt) {
  11400. if (this._owner.relations.handling != null)
  11401. return;
  11402. this._owner.relations.handling = this._target;
  11403. var ox = this._owner.x;
  11404. var oy = this._owner.y;
  11405. var ow = this._owner._rawWidth;
  11406. var oh = this._owner._rawHeight;
  11407. var length = this._defs.length;
  11408. for (var i = 0; i < length; i++) {
  11409. var info = this._defs[i];
  11410. this.applyOnSizeChanged(info);
  11411. }
  11412. this._targetWidth = this._target._width;
  11413. this._targetHeight = this._target._height;
  11414. if (ox != this._owner.x || oy != this._owner.y) {
  11415. ox = this._owner.x - ox;
  11416. oy = this._owner.y - oy;
  11417. this._owner.updateGearFromRelations(1, ox, oy);
  11418. if (this._owner.parent) {
  11419. var len = this._owner.parent._transitions.length;
  11420. if (len > 0) {
  11421. for (var i = 0; i < len; ++i) {
  11422. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  11423. }
  11424. }
  11425. }
  11426. }
  11427. if (ow != this._owner._rawWidth || oh != this._owner._rawHeight) {
  11428. ow = this._owner._rawWidth - ow;
  11429. oh = this._owner._rawHeight - oh;
  11430. this._owner.updateGearFromRelations(2, ow, oh);
  11431. }
  11432. this._owner.relations.handling = null;
  11433. };
  11434. RelationItem.prototype.__targetSizeWillChange = function (evt) {
  11435. this._owner.relations.sizeDirty = true;
  11436. };
  11437. return RelationItem;
  11438. }());
  11439. fgui.RelationItem = RelationItem;
  11440. var RelationDef = (function () {
  11441. function RelationDef() {
  11442. }
  11443. RelationDef.prototype.copyFrom = function (source) {
  11444. this.percent = source.percent;
  11445. this.type = source.type;
  11446. this.axis = source.axis;
  11447. };
  11448. return RelationDef;
  11449. }());
  11450. fgui.RelationDef = RelationDef;
  11451. })(fgui || (fgui = {}));
  11452. (function (fgui) {
  11453. var Relations = (function () {
  11454. function Relations(owner) {
  11455. this._owner = owner;
  11456. this._items = new Array();
  11457. }
  11458. Relations.prototype.add = function (target, relationType, usePercent) {
  11459. var length = this._items.length;
  11460. for (var i = 0; i < length; i++) {
  11461. var item = this._items[i];
  11462. if (item.target == target) {
  11463. item.add(relationType, usePercent);
  11464. return;
  11465. }
  11466. }
  11467. var newItem = new fgui.RelationItem(this._owner);
  11468. newItem.target = target;
  11469. newItem.add(relationType, usePercent);
  11470. this._items.push(newItem);
  11471. };
  11472. Relations.prototype.remove = function (target, relationType) {
  11473. relationType = relationType || 0;
  11474. var cnt = this._items.length;
  11475. var i = 0;
  11476. while (i < cnt) {
  11477. var item = this._items[i];
  11478. if (item.target == target) {
  11479. item.remove(relationType);
  11480. if (item.isEmpty) {
  11481. item.dispose();
  11482. this._items.splice(i, 1);
  11483. cnt--;
  11484. }
  11485. else
  11486. i++;
  11487. }
  11488. else
  11489. i++;
  11490. }
  11491. };
  11492. Relations.prototype.contains = function (target) {
  11493. var length = this._items.length;
  11494. for (var i = 0; i < length; i++) {
  11495. var item = this._items[i];
  11496. if (item.target == target)
  11497. return true;
  11498. }
  11499. return false;
  11500. };
  11501. Relations.prototype.clearFor = function (target) {
  11502. var cnt = this._items.length;
  11503. var i = 0;
  11504. while (i < cnt) {
  11505. var item = this._items[i];
  11506. if (item.target == target) {
  11507. item.dispose();
  11508. this._items.splice(i, 1);
  11509. cnt--;
  11510. }
  11511. else
  11512. i++;
  11513. }
  11514. };
  11515. Relations.prototype.clearAll = function () {
  11516. var length = this._items.length;
  11517. for (var i = 0; i < length; i++) {
  11518. var item = this._items[i];
  11519. item.dispose();
  11520. }
  11521. this._items.length = 0;
  11522. };
  11523. Relations.prototype.copyFrom = function (source) {
  11524. this.clearAll();
  11525. var arr = source._items;
  11526. var length = arr.length;
  11527. for (var i = 0; i < length; i++) {
  11528. var ri = arr[i];
  11529. var item = new fgui.RelationItem(this._owner);
  11530. item.copyFrom(ri);
  11531. this._items.push(item);
  11532. }
  11533. };
  11534. Relations.prototype.dispose = function () {
  11535. this.clearAll();
  11536. };
  11537. Relations.prototype.onOwnerSizeChanged = function (dWidth, dHeight, applyPivot) {
  11538. if (this._items.length == 0)
  11539. return;
  11540. var length = this._items.length;
  11541. for (var i = 0; i < length; i++) {
  11542. var item = this._items[i];
  11543. item.applyOnSelfResized(dWidth, dHeight, applyPivot);
  11544. }
  11545. };
  11546. Relations.prototype.ensureRelationsSizeCorrect = function () {
  11547. if (this._items.length == 0)
  11548. return;
  11549. this.sizeDirty = false;
  11550. var length = this._items.length;
  11551. for (var i = 0; i < length; i++) {
  11552. var item = this._items[i];
  11553. item.target.ensureSizeCorrect();
  11554. }
  11555. };
  11556. Object.defineProperty(Relations.prototype, "empty", {
  11557. get: function () {
  11558. return this._items.length == 0;
  11559. },
  11560. enumerable: false,
  11561. configurable: true
  11562. });
  11563. Relations.prototype.setup = function (buffer, parentToChild) {
  11564. var cnt = buffer.readByte();
  11565. var target;
  11566. for (var i = 0; i < cnt; i++) {
  11567. var targetIndex = buffer.readShort();
  11568. if (targetIndex == -1)
  11569. target = this._owner.parent;
  11570. else if (parentToChild)
  11571. target = this._owner.getChildAt(targetIndex);
  11572. else
  11573. target = this._owner.parent.getChildAt(targetIndex);
  11574. var newItem = new fgui.RelationItem(this._owner);
  11575. newItem.target = target;
  11576. this._items.push(newItem);
  11577. var cnt2 = buffer.readByte();
  11578. for (var j = 0; j < cnt2; j++) {
  11579. var rt = buffer.readByte();
  11580. var usePercent = buffer.readBool();
  11581. newItem.internalAdd(rt, usePercent);
  11582. }
  11583. }
  11584. };
  11585. return Relations;
  11586. }());
  11587. fgui.Relations = Relations;
  11588. })(fgui || (fgui = {}));
  11589. (function (fgui) {
  11590. var ScrollPane = (function (_super) {
  11591. __extends(ScrollPane, _super);
  11592. function ScrollPane() {
  11593. var _this = _super !== null && _super.apply(this, arguments) || this;
  11594. _this._aniFlag = 0;
  11595. return _this;
  11596. }
  11597. ScrollPane.prototype.setup = function (buffer) {
  11598. var o = this._owner = (this.node["$gobj"]);
  11599. this._maskContainer = new cc.Node("ScrollPane");
  11600. this._maskContainer.setAnchorPoint(0, 1);
  11601. this._maskContainer.parent = o.node;
  11602. this._container = o._container;
  11603. this._container.parent = this._maskContainer;
  11604. this._scrollBarMargin = new fgui.Margin();
  11605. this._mouseWheelEnabled = true;
  11606. this._xPos = 0;
  11607. this._yPos = 0;
  11608. this._aniFlag = 0;
  11609. this._tweening = 0;
  11610. this._footerLockedSize = 0;
  11611. this._headerLockedSize = 0;
  11612. this._viewSize = new cc.Vec2();
  11613. this._contentSize = new cc.Vec2();
  11614. this._pageSize = new cc.Vec2(1, 1);
  11615. this._overlapSize = new cc.Vec2();
  11616. this._tweenTime = new cc.Vec2();
  11617. this._tweenStart = new cc.Vec2();
  11618. this._tweenDuration = new cc.Vec2();
  11619. this._tweenChange = new cc.Vec2();
  11620. this._velocity = new cc.Vec2();
  11621. this._containerPos = new cc.Vec2();
  11622. this._beginTouchPos = new cc.Vec2();
  11623. this._lastTouchPos = new cc.Vec2();
  11624. this._lastTouchGlobalPos = new cc.Vec2();
  11625. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  11626. this._mouseWheelStep = this._scrollStep * 2;
  11627. this._decelerationRate = fgui.UIConfig.defaultScrollDecelerationRate;
  11628. this._snappingPolicy = 0;
  11629. o.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin, this);
  11630. o.on(fgui.Event.TOUCH_MOVE, this.onTouchMove, this);
  11631. o.on(fgui.Event.TOUCH_END, this.onTouchEnd, this);
  11632. o.on(fgui.Event.MOUSE_WHEEL, this.onMouseWheel, this);
  11633. this._scrollType = buffer.readByte();
  11634. var scrollBarDisplay = buffer.readByte();
  11635. var flags = buffer.readInt();
  11636. if (buffer.readBool()) {
  11637. this._scrollBarMargin.top = buffer.readInt();
  11638. this._scrollBarMargin.bottom = buffer.readInt();
  11639. this._scrollBarMargin.left = buffer.readInt();
  11640. this._scrollBarMargin.right = buffer.readInt();
  11641. }
  11642. var vtScrollBarRes = buffer.readS();
  11643. var hzScrollBarRes = buffer.readS();
  11644. var headerRes = buffer.readS();
  11645. var footerRes = buffer.readS();
  11646. if ((flags & 1) != 0)
  11647. this._displayOnLeft = true;
  11648. if ((flags & 2) != 0)
  11649. this._snapToItem = true;
  11650. if ((flags & 4) != 0)
  11651. this._displayInDemand = true;
  11652. if ((flags & 8) != 0)
  11653. this._pageMode = true;
  11654. if (flags & 16)
  11655. this._touchEffect = true;
  11656. else if (flags & 32)
  11657. this._touchEffect = false;
  11658. else
  11659. this._touchEffect = fgui.UIConfig.defaultScrollTouchEffect;
  11660. if (flags & 64)
  11661. this._bouncebackEffect = true;
  11662. else if (flags & 128)
  11663. this._bouncebackEffect = false;
  11664. else
  11665. this._bouncebackEffect = fgui.UIConfig.defaultScrollBounceEffect;
  11666. if ((flags & 256) != 0)
  11667. this._inertiaDisabled = true;
  11668. if ((flags & 512) == 0)
  11669. this._maskContainer.addComponent(cc.Mask);
  11670. if ((flags & 1024) != 0)
  11671. this._floating = true;
  11672. if ((flags & 2048) != 0)
  11673. this._dontClipMargin = true;
  11674. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Default)
  11675. scrollBarDisplay = fgui.UIConfig.defaultScrollBarDisplay;
  11676. if (scrollBarDisplay != fgui.ScrollBarDisplayType.Hidden) {
  11677. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) {
  11678. var res = vtScrollBarRes ? vtScrollBarRes : fgui.UIConfig.verticalScrollBar;
  11679. if (res) {
  11680. this._vtScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  11681. if (!this._vtScrollBar)
  11682. throw "cannot create scrollbar from " + res;
  11683. this._vtScrollBar.setScrollPane(this, true);
  11684. this._vtScrollBar.node.parent = o.node;
  11685. }
  11686. }
  11687. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Horizontal) {
  11688. var res = hzScrollBarRes ? hzScrollBarRes : fgui.UIConfig.horizontalScrollBar;
  11689. if (res) {
  11690. this._hzScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  11691. if (!this._hzScrollBar)
  11692. throw "cannot create scrollbar from " + res;
  11693. this._hzScrollBar.setScrollPane(this, false);
  11694. this._hzScrollBar.node.parent = o.node;
  11695. }
  11696. }
  11697. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Auto)
  11698. this._scrollBarDisplayAuto = true;
  11699. if (this._scrollBarDisplayAuto) {
  11700. if (this._vtScrollBar)
  11701. this._vtScrollBar.node.active = false;
  11702. if (this._hzScrollBar)
  11703. this._hzScrollBar.node.active = false;
  11704. o.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  11705. o.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  11706. }
  11707. }
  11708. if (headerRes) {
  11709. this._header = (fgui.UIPackage.createObjectFromURL(headerRes));
  11710. if (this._header == null)
  11711. throw "cannot create scrollPane header from " + headerRes;
  11712. else
  11713. this._maskContainer.insertChild(this._header.node, 0);
  11714. }
  11715. if (footerRes) {
  11716. this._footer = (fgui.UIPackage.createObjectFromURL(footerRes));
  11717. if (this._footer == null)
  11718. throw "cannot create scrollPane footer from " + footerRes;
  11719. else
  11720. this._maskContainer.insertChild(this._footer.node, 0);
  11721. }
  11722. this._refreshBarAxis = (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) ? "y" : "x";
  11723. this.setSize(o.width, o.height);
  11724. };
  11725. ScrollPane.prototype.onDestroy = function () {
  11726. delete this._pageController;
  11727. if (this._hzScrollBar)
  11728. this._hzScrollBar.dispose();
  11729. if (this._vtScrollBar)
  11730. this._vtScrollBar.dispose();
  11731. if (this._header)
  11732. this._header.dispose();
  11733. if (this._footer)
  11734. this._footer.dispose();
  11735. };
  11736. ScrollPane.prototype.hitTest = function (pt, globalPt) {
  11737. var target;
  11738. if (this._vtScrollBar) {
  11739. target = this._vtScrollBar.hitTest(globalPt);
  11740. if (target)
  11741. return target;
  11742. }
  11743. if (this._hzScrollBar) {
  11744. target = this._hzScrollBar.hitTest(globalPt);
  11745. if (target)
  11746. return target;
  11747. }
  11748. if (this._header && this._header.node.activeInHierarchy) {
  11749. target = this._header.hitTest(globalPt);
  11750. if (target)
  11751. return target;
  11752. }
  11753. if (this._footer && this._footer.node.activeInHierarchy) {
  11754. target = this._footer.hitTest(globalPt);
  11755. if (target)
  11756. return target;
  11757. }
  11758. if (pt.x >= this._owner.margin.left && pt.y >= this._owner.margin.top
  11759. && pt.x < this._owner.margin.left + this._viewSize.x && pt.y < this._owner.margin.top + this._viewSize.y)
  11760. return this._owner;
  11761. else
  11762. return null;
  11763. };
  11764. Object.defineProperty(ScrollPane.prototype, "owner", {
  11765. get: function () {
  11766. return this._owner;
  11767. },
  11768. enumerable: false,
  11769. configurable: true
  11770. });
  11771. Object.defineProperty(ScrollPane.prototype, "hzScrollBar", {
  11772. get: function () {
  11773. return this._hzScrollBar;
  11774. },
  11775. enumerable: false,
  11776. configurable: true
  11777. });
  11778. Object.defineProperty(ScrollPane.prototype, "vtScrollBar", {
  11779. get: function () {
  11780. return this._vtScrollBar;
  11781. },
  11782. enumerable: false,
  11783. configurable: true
  11784. });
  11785. Object.defineProperty(ScrollPane.prototype, "header", {
  11786. get: function () {
  11787. return this._header;
  11788. },
  11789. enumerable: false,
  11790. configurable: true
  11791. });
  11792. Object.defineProperty(ScrollPane.prototype, "footer", {
  11793. get: function () {
  11794. return this._footer;
  11795. },
  11796. enumerable: false,
  11797. configurable: true
  11798. });
  11799. Object.defineProperty(ScrollPane.prototype, "bouncebackEffect", {
  11800. get: function () {
  11801. return this._bouncebackEffect;
  11802. },
  11803. set: function (sc) {
  11804. this._bouncebackEffect = sc;
  11805. },
  11806. enumerable: false,
  11807. configurable: true
  11808. });
  11809. Object.defineProperty(ScrollPane.prototype, "touchEffect", {
  11810. get: function () {
  11811. return this._touchEffect;
  11812. },
  11813. set: function (sc) {
  11814. this._touchEffect = sc;
  11815. },
  11816. enumerable: false,
  11817. configurable: true
  11818. });
  11819. Object.defineProperty(ScrollPane.prototype, "scrollStep", {
  11820. get: function () {
  11821. return this._scrollStep;
  11822. },
  11823. set: function (val) {
  11824. this._scrollStep = val;
  11825. if (this._scrollStep == 0)
  11826. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  11827. this._mouseWheelStep = this._scrollStep * 2;
  11828. },
  11829. enumerable: false,
  11830. configurable: true
  11831. });
  11832. Object.defineProperty(ScrollPane.prototype, "decelerationRate", {
  11833. get: function () {
  11834. return this._decelerationRate;
  11835. },
  11836. set: function (val) {
  11837. this._decelerationRate = val;
  11838. },
  11839. enumerable: false,
  11840. configurable: true
  11841. });
  11842. Object.defineProperty(ScrollPane.prototype, "snapToItem", {
  11843. get: function () {
  11844. return this._snapToItem;
  11845. },
  11846. set: function (value) {
  11847. this._snapToItem = value;
  11848. },
  11849. enumerable: false,
  11850. configurable: true
  11851. });
  11852. Object.defineProperty(ScrollPane.prototype, "snappingPolicy", {
  11853. get: function () {
  11854. return this._snappingPolicy;
  11855. },
  11856. set: function (value) {
  11857. this._snappingPolicy = value;
  11858. },
  11859. enumerable: false,
  11860. configurable: true
  11861. });
  11862. Object.defineProperty(ScrollPane.prototype, "mouseWheelEnabled", {
  11863. get: function () {
  11864. return this._mouseWheelEnabled;
  11865. },
  11866. set: function (value) {
  11867. this._mouseWheelEnabled = value;
  11868. },
  11869. enumerable: false,
  11870. configurable: true
  11871. });
  11872. Object.defineProperty(ScrollPane.prototype, "isDragged", {
  11873. get: function () {
  11874. return this._dragged;
  11875. },
  11876. enumerable: false,
  11877. configurable: true
  11878. });
  11879. Object.defineProperty(ScrollPane.prototype, "percX", {
  11880. get: function () {
  11881. return this._overlapSize.x == 0 ? 0 : this._xPos / this._overlapSize.x;
  11882. },
  11883. set: function (value) {
  11884. this.setPercX(value, false);
  11885. },
  11886. enumerable: false,
  11887. configurable: true
  11888. });
  11889. ScrollPane.prototype.setPercX = function (value, ani) {
  11890. this._owner.ensureBoundsCorrect();
  11891. this.setPosX(this._overlapSize.x * fgui.ToolSet.clamp01(value), ani);
  11892. };
  11893. Object.defineProperty(ScrollPane.prototype, "percY", {
  11894. get: function () {
  11895. return this._overlapSize.y == 0 ? 0 : this._yPos / this._overlapSize.y;
  11896. },
  11897. set: function (value) {
  11898. this.setPercY(value, false);
  11899. },
  11900. enumerable: false,
  11901. configurable: true
  11902. });
  11903. ScrollPane.prototype.setPercY = function (value, ani) {
  11904. this._owner.ensureBoundsCorrect();
  11905. this.setPosY(this._overlapSize.y * fgui.ToolSet.clamp01(value), ani);
  11906. };
  11907. Object.defineProperty(ScrollPane.prototype, "posX", {
  11908. get: function () {
  11909. return this._xPos;
  11910. },
  11911. set: function (value) {
  11912. this.setPosX(value, false);
  11913. },
  11914. enumerable: false,
  11915. configurable: true
  11916. });
  11917. ScrollPane.prototype.setPosX = function (value, ani) {
  11918. this._owner.ensureBoundsCorrect();
  11919. if (this._loop == 1)
  11920. value = this.loopCheckingNewPos(value, "x");
  11921. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.x);
  11922. if (value != this._xPos) {
  11923. this._xPos = value;
  11924. this.posChanged(ani);
  11925. }
  11926. };
  11927. Object.defineProperty(ScrollPane.prototype, "posY", {
  11928. get: function () {
  11929. return this._yPos;
  11930. },
  11931. set: function (value) {
  11932. this.setPosY(value, false);
  11933. },
  11934. enumerable: false,
  11935. configurable: true
  11936. });
  11937. ScrollPane.prototype.setPosY = function (value, ani) {
  11938. this._owner.ensureBoundsCorrect();
  11939. if (this._loop == 1)
  11940. value = this.loopCheckingNewPos(value, "y");
  11941. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.y);
  11942. if (value != this._yPos) {
  11943. this._yPos = value;
  11944. this.posChanged(ani);
  11945. }
  11946. };
  11947. Object.defineProperty(ScrollPane.prototype, "contentWidth", {
  11948. get: function () {
  11949. return this._contentSize.x;
  11950. },
  11951. enumerable: false,
  11952. configurable: true
  11953. });
  11954. Object.defineProperty(ScrollPane.prototype, "contentHeight", {
  11955. get: function () {
  11956. return this._contentSize.y;
  11957. },
  11958. enumerable: false,
  11959. configurable: true
  11960. });
  11961. Object.defineProperty(ScrollPane.prototype, "viewWidth", {
  11962. get: function () {
  11963. return this._viewSize.x;
  11964. },
  11965. set: function (value) {
  11966. value = value + this._owner.margin.left + this._owner.margin.right;
  11967. if (this._vtScrollBar && !this._floating)
  11968. value += this._vtScrollBar.width;
  11969. this._owner.width = value;
  11970. },
  11971. enumerable: false,
  11972. configurable: true
  11973. });
  11974. Object.defineProperty(ScrollPane.prototype, "viewHeight", {
  11975. get: function () {
  11976. return this._viewSize.y;
  11977. },
  11978. set: function (value) {
  11979. value = value + this._owner.margin.top + this._owner.margin.bottom;
  11980. if (this._hzScrollBar && !this._floating)
  11981. value += this._hzScrollBar.height;
  11982. this._owner.height = value;
  11983. },
  11984. enumerable: false,
  11985. configurable: true
  11986. });
  11987. Object.defineProperty(ScrollPane.prototype, "currentPageX", {
  11988. get: function () {
  11989. if (!this._pageMode)
  11990. return 0;
  11991. var page = Math.floor(this._xPos / this._pageSize.x);
  11992. if (this._xPos - page * this._pageSize.x > this._pageSize.x * 0.5)
  11993. page++;
  11994. return page;
  11995. },
  11996. set: function (value) {
  11997. this.setCurrentPageX(value, false);
  11998. },
  11999. enumerable: false,
  12000. configurable: true
  12001. });
  12002. Object.defineProperty(ScrollPane.prototype, "currentPageY", {
  12003. get: function () {
  12004. if (!this._pageMode)
  12005. return 0;
  12006. var page = Math.floor(this._yPos / this._pageSize.y);
  12007. if (this._yPos - page * this._pageSize.y > this._pageSize.y * 0.5)
  12008. page++;
  12009. return page;
  12010. },
  12011. set: function (value) {
  12012. this.setCurrentPageY(value, false);
  12013. },
  12014. enumerable: false,
  12015. configurable: true
  12016. });
  12017. ScrollPane.prototype.setCurrentPageX = function (value, ani) {
  12018. if (!this._pageMode)
  12019. return;
  12020. this._owner.ensureBoundsCorrect();
  12021. if (this._overlapSize.x > 0)
  12022. this.setPosX(value * this._pageSize.x, ani);
  12023. };
  12024. ScrollPane.prototype.setCurrentPageY = function (value, ani) {
  12025. if (!this._pageMode)
  12026. return;
  12027. this._owner.ensureBoundsCorrect();
  12028. if (this._overlapSize.y > 0)
  12029. this.setPosY(value * this._pageSize.y, ani);
  12030. };
  12031. Object.defineProperty(ScrollPane.prototype, "isBottomMost", {
  12032. get: function () {
  12033. return this._yPos == this._overlapSize.y || this._overlapSize.y == 0;
  12034. },
  12035. enumerable: false,
  12036. configurable: true
  12037. });
  12038. Object.defineProperty(ScrollPane.prototype, "isRightMost", {
  12039. get: function () {
  12040. return this._xPos == this._overlapSize.x || this._overlapSize.x == 0;
  12041. },
  12042. enumerable: false,
  12043. configurable: true
  12044. });
  12045. Object.defineProperty(ScrollPane.prototype, "pageController", {
  12046. get: function () {
  12047. return this._pageController;
  12048. },
  12049. set: function (value) {
  12050. this._pageController = value;
  12051. },
  12052. enumerable: false,
  12053. configurable: true
  12054. });
  12055. Object.defineProperty(ScrollPane.prototype, "scrollingPosX", {
  12056. get: function () {
  12057. return fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  12058. },
  12059. enumerable: false,
  12060. configurable: true
  12061. });
  12062. Object.defineProperty(ScrollPane.prototype, "scrollingPosY", {
  12063. get: function () {
  12064. return fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  12065. },
  12066. enumerable: false,
  12067. configurable: true
  12068. });
  12069. ScrollPane.prototype.scrollTop = function (ani) {
  12070. this.setPercY(0, ani);
  12071. };
  12072. ScrollPane.prototype.scrollBottom = function (ani) {
  12073. this.setPercY(1, ani);
  12074. };
  12075. ScrollPane.prototype.scrollUp = function (ratio, ani) {
  12076. if (ratio == undefined)
  12077. ratio = 1;
  12078. if (this._pageMode)
  12079. this.setPosY(this._yPos - this._pageSize.y * ratio, ani);
  12080. else
  12081. this.setPosY(this._yPos - this._scrollStep * ratio, ani);
  12082. ;
  12083. };
  12084. ScrollPane.prototype.scrollDown = function (ratio, ani) {
  12085. if (ratio == undefined)
  12086. ratio = 1;
  12087. if (this._pageMode)
  12088. this.setPosY(this._yPos + this._pageSize.y * ratio, ani);
  12089. else
  12090. this.setPosY(this._yPos + this._scrollStep * ratio, ani);
  12091. };
  12092. ScrollPane.prototype.scrollLeft = function (ratio, ani) {
  12093. if (ratio == undefined)
  12094. ratio = 1;
  12095. if (this._pageMode)
  12096. this.setPosX(this._xPos - this._pageSize.x * ratio, ani);
  12097. else
  12098. this.setPosX(this._xPos - this._scrollStep * ratio, ani);
  12099. };
  12100. ScrollPane.prototype.scrollRight = function (ratio, ani) {
  12101. if (ratio == undefined)
  12102. ratio = 1;
  12103. if (this._pageMode)
  12104. this.setPosX(this._xPos + this._pageSize.x * ratio, ani);
  12105. else
  12106. this.setPosX(this._xPos + this._scrollStep * ratio, ani);
  12107. };
  12108. ScrollPane.prototype.scrollToView = function (target, ani, setFirst) {
  12109. this._owner.ensureBoundsCorrect();
  12110. if (this._needRefresh)
  12111. this.refresh();
  12112. var rect;
  12113. if (target instanceof fgui.GObject) {
  12114. if (target.parent != this._owner) {
  12115. target.parent.localToGlobalRect(target.x, target.y, target.width, target.height, s_rect);
  12116. rect = this._owner.globalToLocalRect(s_rect.x, s_rect.y, s_rect.width, s_rect.height, s_rect);
  12117. }
  12118. else {
  12119. rect = s_rect;
  12120. rect.x = target.x;
  12121. rect.y = target.y;
  12122. rect.width = target.width;
  12123. rect.height = target.height;
  12124. }
  12125. }
  12126. else
  12127. rect = target;
  12128. if (this._overlapSize.y > 0) {
  12129. var bottom = this._yPos + this._viewSize.y;
  12130. if (setFirst || rect.y <= this._yPos || rect.height >= this._viewSize.y) {
  12131. if (this._pageMode)
  12132. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  12133. else
  12134. this.setPosY(rect.y, ani);
  12135. }
  12136. else if (rect.y + rect.height > bottom) {
  12137. if (this._pageMode)
  12138. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  12139. else if (rect.height <= this._viewSize.y / 2)
  12140. this.setPosY(rect.y + rect.height * 2 - this._viewSize.y, ani);
  12141. else
  12142. this.setPosY(rect.y + rect.height - this._viewSize.y, ani);
  12143. }
  12144. }
  12145. if (this._overlapSize.x > 0) {
  12146. var right = this._xPos + this._viewSize.x;
  12147. if (setFirst || rect.x <= this._xPos || rect.width >= this._viewSize.x) {
  12148. if (this._pageMode)
  12149. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  12150. else
  12151. this.setPosX(rect.x, ani);
  12152. }
  12153. else if (rect.x + rect.width > right) {
  12154. if (this._pageMode)
  12155. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  12156. else if (rect.width <= this._viewSize.x / 2)
  12157. this.setPosX(rect.x + rect.width * 2 - this._viewSize.x, ani);
  12158. else
  12159. this.setPosX(rect.x + rect.width - this._viewSize.x, ani);
  12160. }
  12161. }
  12162. if (!ani && this._needRefresh)
  12163. this.refresh();
  12164. };
  12165. ScrollPane.prototype.isChildInView = function (obj) {
  12166. if (this._overlapSize.y > 0) {
  12167. var dist = obj.y + (-this._container.y);
  12168. if (dist < -obj.height || dist > this._viewSize.y)
  12169. return false;
  12170. }
  12171. if (this._overlapSize.x > 0) {
  12172. dist = obj.x + this._container.x;
  12173. if (dist < -obj.width || dist > this._viewSize.x)
  12174. return false;
  12175. }
  12176. return true;
  12177. };
  12178. ScrollPane.prototype.cancelDragging = function () {
  12179. if (ScrollPane.draggingPane == this)
  12180. ScrollPane.draggingPane = null;
  12181. _gestureFlag = 0;
  12182. this._dragged = false;
  12183. };
  12184. ScrollPane.prototype.lockHeader = function (size) {
  12185. if (this._headerLockedSize == size)
  12186. return;
  12187. var cx = this._container.x;
  12188. var cy = -this._container.y;
  12189. var cr = this._refreshBarAxis == "x" ? cx : cy;
  12190. this._headerLockedSize = size;
  12191. if (!this._refreshEventDispatching && cr >= 0) {
  12192. this._tweenStart.x = cx;
  12193. this._tweenStart.y = cy;
  12194. this._tweenChange.set(cc.Vec2.ZERO);
  12195. this._tweenChange[this._refreshBarAxis] = this._headerLockedSize - this._tweenStart[this._refreshBarAxis];
  12196. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12197. this.startTween(2);
  12198. }
  12199. };
  12200. ScrollPane.prototype.lockFooter = function (size) {
  12201. if (this._footerLockedSize == size)
  12202. return;
  12203. var cx = this._container.x;
  12204. var cy = -this._container.y;
  12205. var cr = this._refreshBarAxis == "x" ? cx : cy;
  12206. this._footerLockedSize = size;
  12207. if (!this._refreshEventDispatching && cr <= -this._overlapSize[this._refreshBarAxis]) {
  12208. this._tweenStart.x = cx;
  12209. this._tweenStart.y = cy;
  12210. this._tweenChange.set(cc.Vec2.ZERO);
  12211. var max = this._overlapSize[this._refreshBarAxis];
  12212. if (max == 0)
  12213. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12214. else
  12215. max += this._footerLockedSize;
  12216. this._tweenChange[this._refreshBarAxis] = -max - this._tweenStart[this._refreshBarAxis];
  12217. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12218. this.startTween(2);
  12219. }
  12220. };
  12221. ScrollPane.prototype.onOwnerSizeChanged = function () {
  12222. this.setSize(this._owner.width, this._owner.height);
  12223. this.posChanged(false);
  12224. };
  12225. ScrollPane.prototype.handleControllerChanged = function (c) {
  12226. if (this._pageController == c) {
  12227. if (this._scrollType == fgui.ScrollType.Horizontal)
  12228. this.setCurrentPageX(c.selectedIndex, true);
  12229. else
  12230. this.setCurrentPageY(c.selectedIndex, true);
  12231. }
  12232. };
  12233. ScrollPane.prototype.updatePageController = function () {
  12234. if (this._pageController && !this._pageController.changing) {
  12235. var index;
  12236. if (this._scrollType == fgui.ScrollType.Horizontal)
  12237. index = this.currentPageX;
  12238. else
  12239. index = this.currentPageY;
  12240. if (index < this._pageController.pageCount) {
  12241. var c = this._pageController;
  12242. this._pageController = null;
  12243. c.selectedIndex = index;
  12244. this._pageController = c;
  12245. }
  12246. }
  12247. };
  12248. ScrollPane.prototype.adjustMaskContainer = function () {
  12249. var mx = 0;
  12250. if (this._displayOnLeft && this._vtScrollBar && !this._floating)
  12251. mx = this._vtScrollBar.width;
  12252. var o = this._owner;
  12253. if (this._dontClipMargin)
  12254. this._maskContainer.setAnchorPoint((o.margin.left + o._alignOffset.x) / o.width, 1 - (o.margin.top + o._alignOffset.y) / o.height);
  12255. else
  12256. this._maskContainer.setAnchorPoint(o._alignOffset.x / this._viewSize.x, 1 - o._alignOffset.y / this._viewSize.y);
  12257. if (o._customMask)
  12258. this._maskContainer.setPosition(mx + o._alignOffset.x, -o._alignOffset.y);
  12259. else
  12260. this._maskContainer.setPosition(o._pivotCorrectX + mx + o._alignOffset.x, o._pivotCorrectY - o._alignOffset.y);
  12261. };
  12262. ScrollPane.prototype.setSize = function (aWidth, aHeight) {
  12263. if (this._hzScrollBar) {
  12264. this._hzScrollBar.y = aHeight - this._hzScrollBar.height;
  12265. if (this._vtScrollBar) {
  12266. this._hzScrollBar.width = aWidth - this._vtScrollBar.width - this._scrollBarMargin.left - this._scrollBarMargin.right;
  12267. if (this._displayOnLeft)
  12268. this._hzScrollBar.x = this._scrollBarMargin.left + this._vtScrollBar.width;
  12269. else
  12270. this._hzScrollBar.x = this._scrollBarMargin.left;
  12271. }
  12272. else {
  12273. this._hzScrollBar.width = aWidth - this._scrollBarMargin.left - this._scrollBarMargin.right;
  12274. this._hzScrollBar.x = this._scrollBarMargin.left;
  12275. }
  12276. }
  12277. if (this._vtScrollBar) {
  12278. if (!this._displayOnLeft)
  12279. this._vtScrollBar.x = aWidth - this._vtScrollBar.width;
  12280. if (this._hzScrollBar)
  12281. this._vtScrollBar.height = aHeight - this._hzScrollBar.height - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  12282. else
  12283. this._vtScrollBar.height = aHeight - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  12284. this._vtScrollBar.y = this._scrollBarMargin.top;
  12285. }
  12286. this._viewSize.x = aWidth;
  12287. this._viewSize.y = aHeight;
  12288. if (this._hzScrollBar && !this._floating)
  12289. this._viewSize.y -= this._hzScrollBar.height;
  12290. if (this._vtScrollBar && !this._floating)
  12291. this._viewSize.x -= this._vtScrollBar.width;
  12292. this._viewSize.x -= (this._owner.margin.left + this._owner.margin.right);
  12293. this._viewSize.y -= (this._owner.margin.top + this._owner.margin.bottom);
  12294. this._viewSize.x = Math.max(1, this._viewSize.x);
  12295. this._viewSize.y = Math.max(1, this._viewSize.y);
  12296. this._pageSize.x = this._viewSize.x;
  12297. this._pageSize.y = this._viewSize.y;
  12298. this.adjustMaskContainer();
  12299. this.handleSizeChanged();
  12300. };
  12301. ScrollPane.prototype.setContentSize = function (aWidth, aHeight) {
  12302. if (this._contentSize.x == aWidth && this._contentSize.y == aHeight)
  12303. return;
  12304. this._contentSize.x = aWidth;
  12305. this._contentSize.y = aHeight;
  12306. this.handleSizeChanged();
  12307. if (this._snapToItem && this._snappingPolicy != 0 && this._xPos == 0 && this._yPos == 0)
  12308. this.posChanged(false);
  12309. };
  12310. ScrollPane.prototype.changeContentSizeOnScrolling = function (deltaWidth, deltaHeight, deltaPosX, deltaPosY) {
  12311. var isRightmost = this._xPos == this._overlapSize.x;
  12312. var isBottom = this._yPos == this._overlapSize.y;
  12313. this._contentSize.x += deltaWidth;
  12314. this._contentSize.y += deltaHeight;
  12315. this.handleSizeChanged();
  12316. if (this._tweening == 1) {
  12317. if (deltaWidth != 0 && isRightmost && this._tweenChange.x < 0) {
  12318. this._xPos = this._overlapSize.x;
  12319. this._tweenChange.x = -this._xPos - this._tweenStart.x;
  12320. }
  12321. if (deltaHeight != 0 && isBottom && this._tweenChange.y < 0) {
  12322. this._yPos = this._overlapSize.y;
  12323. this._tweenChange.y = -this._yPos - this._tweenStart.y;
  12324. }
  12325. }
  12326. else if (this._tweening == 2) {
  12327. if (deltaPosX != 0) {
  12328. this._container.x -= deltaPosX;
  12329. this._tweenStart.x -= deltaPosX;
  12330. this._xPos = -this._container.x;
  12331. }
  12332. if (deltaPosY != 0) {
  12333. this._container.y += deltaPosY;
  12334. this._tweenStart.y -= deltaPosY;
  12335. this._yPos = -(-this._container.y);
  12336. }
  12337. }
  12338. else if (this._dragged) {
  12339. if (deltaPosX != 0) {
  12340. this._container.x -= deltaPosX;
  12341. this._containerPos.x -= deltaPosX;
  12342. this._xPos = -this._container.x;
  12343. }
  12344. if (deltaPosY != 0) {
  12345. this._container.y += deltaPosY;
  12346. this._containerPos.y -= deltaPosY;
  12347. this._yPos = -(-this._container.y);
  12348. }
  12349. }
  12350. else {
  12351. if (deltaWidth != 0 && isRightmost) {
  12352. this._xPos = this._overlapSize.x;
  12353. this._container.x = -this._xPos;
  12354. }
  12355. if (deltaHeight != 0 && isBottom) {
  12356. this._yPos = this._overlapSize.y;
  12357. this._container.y = this._yPos;
  12358. }
  12359. }
  12360. if (this._pageMode)
  12361. this.updatePageController();
  12362. };
  12363. ScrollPane.prototype.handleSizeChanged = function () {
  12364. if (this._displayInDemand) {
  12365. this._vScrollNone = this._contentSize.y <= this._viewSize.y;
  12366. this._hScrollNone = this._contentSize.x <= this._viewSize.x;
  12367. }
  12368. if (this._vtScrollBar) {
  12369. if (this._contentSize.y == 0)
  12370. this._vtScrollBar.setDisplayPerc(0);
  12371. else
  12372. this._vtScrollBar.setDisplayPerc(Math.min(1, this._viewSize.y / this._contentSize.y));
  12373. }
  12374. if (this._hzScrollBar) {
  12375. if (this._contentSize.x == 0)
  12376. this._hzScrollBar.setDisplayPerc(0);
  12377. else
  12378. this._hzScrollBar.setDisplayPerc(Math.min(1, this._viewSize.x / this._contentSize.x));
  12379. }
  12380. this.updateScrollBarVisible();
  12381. var maskWidth = this._viewSize.x;
  12382. var maskHeight = this._viewSize.y;
  12383. if (this._vScrollNone && this._vtScrollBar)
  12384. maskWidth += this._vtScrollBar.width;
  12385. if (this._hScrollNone && this._hzScrollBar)
  12386. maskHeight += this._hzScrollBar.height;
  12387. if (this._dontClipMargin) {
  12388. maskWidth += (this._owner.margin.left + this._owner.margin.right);
  12389. maskHeight += (this._owner.margin.top + this._owner.margin.bottom);
  12390. }
  12391. this._maskContainer.setContentSize(maskWidth, maskHeight);
  12392. if (this._vtScrollBar)
  12393. this._vtScrollBar.handlePositionChanged();
  12394. if (this._hzScrollBar)
  12395. this._hzScrollBar.handlePositionChanged();
  12396. if (this._header)
  12397. this._header.handlePositionChanged();
  12398. if (this._footer)
  12399. this._footer.handlePositionChanged();
  12400. if (this._scrollType == fgui.ScrollType.Horizontal || this._scrollType == fgui.ScrollType.Both)
  12401. this._overlapSize.x = Math.ceil(Math.max(0, this._contentSize.x - this._viewSize.x));
  12402. else
  12403. this._overlapSize.x = 0;
  12404. if (this._scrollType == fgui.ScrollType.Vertical || this._scrollType == fgui.ScrollType.Both)
  12405. this._overlapSize.y = Math.ceil(Math.max(0, this._contentSize.y - this._viewSize.y));
  12406. else
  12407. this._overlapSize.y = 0;
  12408. this._xPos = fgui.ToolSet.clamp(this._xPos, 0, this._overlapSize.x);
  12409. this._yPos = fgui.ToolSet.clamp(this._yPos, 0, this._overlapSize.y);
  12410. var max = this._overlapSize[this._refreshBarAxis];
  12411. if (max == 0)
  12412. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12413. else
  12414. max += this._footerLockedSize;
  12415. if (this._refreshBarAxis == "x")
  12416. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -max, this._headerLockedSize), -fgui.ToolSet.clamp((-this._container.y), -this._overlapSize.y, 0));
  12417. else
  12418. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -this._overlapSize.x, 0), -fgui.ToolSet.clamp((-this._container.y), -max, this._headerLockedSize));
  12419. if (this._header) {
  12420. if (this._refreshBarAxis == "x")
  12421. this._header.height = this._viewSize.y;
  12422. else
  12423. this._header.width = this._viewSize.x;
  12424. }
  12425. if (this._footer) {
  12426. if (this._refreshBarAxis == "y")
  12427. this._footer.height = this._viewSize.y;
  12428. else
  12429. this._footer.width = this._viewSize.x;
  12430. }
  12431. this.updateScrollBarPos();
  12432. if (this._pageMode)
  12433. this.updatePageController();
  12434. };
  12435. ScrollPane.prototype.posChanged = function (ani) {
  12436. if (this._aniFlag == 0)
  12437. this._aniFlag = ani ? 1 : -1;
  12438. else if (this._aniFlag == 1 && !ani)
  12439. this._aniFlag = -1;
  12440. this._needRefresh = true;
  12441. if (!cc.director.getScheduler().isScheduled(this.refresh, this))
  12442. this.scheduleOnce(this.refresh);
  12443. };
  12444. ScrollPane.prototype.refresh = function (dt) {
  12445. this._needRefresh = false;
  12446. this.unschedule(this.refresh);
  12447. if (this._pageMode || this._snapToItem) {
  12448. sEndPos.x = -this._xPos;
  12449. sEndPos.y = -this._yPos;
  12450. this.alignPosition(sEndPos, false);
  12451. this._xPos = -sEndPos.x;
  12452. this._yPos = -sEndPos.y;
  12453. }
  12454. this.refresh2();
  12455. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  12456. if (this._needRefresh) {
  12457. this._needRefresh = false;
  12458. this.unschedule(this.refresh);
  12459. this.refresh2();
  12460. }
  12461. this.updateScrollBarPos();
  12462. this._aniFlag = 0;
  12463. };
  12464. ScrollPane.prototype.refresh2 = function () {
  12465. if (this._aniFlag == 1 && !this._dragged) {
  12466. var posX;
  12467. var posY;
  12468. if (this._overlapSize.x > 0)
  12469. posX = -Math.floor(this._xPos);
  12470. else {
  12471. if (this._container.x != 0)
  12472. this._container.x = 0;
  12473. posX = 0;
  12474. }
  12475. if (this._overlapSize.y > 0)
  12476. posY = -Math.floor(this._yPos);
  12477. else {
  12478. if (this._container.y != 0)
  12479. this._container.y = 0;
  12480. posY = 0;
  12481. }
  12482. if (posX != this._container.x || posY != (-this._container.y)) {
  12483. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_GO;
  12484. this._tweenStart.x = this._container.x;
  12485. this._tweenStart.y = (-this._container.y);
  12486. this._tweenChange.x = posX - this._tweenStart.x;
  12487. this._tweenChange.y = posY - this._tweenStart.y;
  12488. this.startTween(1);
  12489. }
  12490. else if (this._tweening != 0)
  12491. this.killTween();
  12492. }
  12493. else {
  12494. if (this._tweening != 0)
  12495. this.killTween();
  12496. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  12497. this.loopCheckingCurrent();
  12498. }
  12499. if (this._pageMode)
  12500. this.updatePageController();
  12501. };
  12502. ScrollPane.prototype.onTouchBegin = function (evt) {
  12503. if (!this._touchEffect)
  12504. return;
  12505. evt.captureTouch();
  12506. if (this._tweening != 0) {
  12507. this.killTween();
  12508. fgui.GRoot.inst.inputProcessor.cancelClick(evt.touchId);
  12509. this._dragged = true;
  12510. }
  12511. else
  12512. this._dragged = false;
  12513. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  12514. this._containerPos.x = this._container.x;
  12515. this._containerPos.y = -this._container.y;
  12516. this._beginTouchPos.set(pt);
  12517. this._lastTouchPos.set(pt);
  12518. this._lastTouchGlobalPos.set(evt.pos);
  12519. this._isHoldAreaDone = false;
  12520. this._velocity.set(cc.Vec2.ZERO);
  12521. ;
  12522. this._velocityScale = 1;
  12523. this._lastMoveTime = fgui.ToolSet.getTime();
  12524. };
  12525. ScrollPane.prototype.onTouchMove = function (evt) {
  12526. if (!cc.isValid(this._owner.node))
  12527. return;
  12528. if (!this._touchEffect)
  12529. return;
  12530. if (fgui.GObject.draggingObject && fgui.GObject.draggingObject.onStage)
  12531. return;
  12532. if (ScrollPane.draggingPane && ScrollPane.draggingPane != this && ScrollPane.draggingPane._owner.onStage)
  12533. return;
  12534. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  12535. var sensitivity = fgui.UIConfig.touchScrollSensitivity;
  12536. var diff, diff2;
  12537. var sv, sh, st;
  12538. if (this._scrollType == fgui.ScrollType.Vertical) {
  12539. if (!this._isHoldAreaDone) {
  12540. _gestureFlag |= 1;
  12541. diff = Math.abs(this._beginTouchPos.y - pt.y);
  12542. if (diff < sensitivity)
  12543. return;
  12544. if ((_gestureFlag & 2) != 0) {
  12545. diff2 = Math.abs(this._beginTouchPos.x - pt.x);
  12546. if (diff < diff2)
  12547. return;
  12548. }
  12549. }
  12550. sv = true;
  12551. }
  12552. else if (this._scrollType == fgui.ScrollType.Horizontal) {
  12553. if (!this._isHoldAreaDone) {
  12554. _gestureFlag |= 2;
  12555. diff = Math.abs(this._beginTouchPos.x - pt.x);
  12556. if (diff < sensitivity)
  12557. return;
  12558. if ((_gestureFlag & 1) != 0) {
  12559. diff2 = Math.abs(this._beginTouchPos.y - pt.y);
  12560. if (diff < diff2)
  12561. return;
  12562. }
  12563. }
  12564. sh = true;
  12565. }
  12566. else {
  12567. _gestureFlag = 3;
  12568. if (!this._isHoldAreaDone) {
  12569. diff = Math.abs(this._beginTouchPos.y - pt.y);
  12570. if (diff < sensitivity) {
  12571. diff = Math.abs(this._beginTouchPos.x - pt.x);
  12572. if (diff < sensitivity)
  12573. return;
  12574. }
  12575. }
  12576. sv = sh = true;
  12577. }
  12578. var newPosX = Math.floor(this._containerPos.x + pt.x - this._beginTouchPos.x);
  12579. var newPosY = Math.floor(this._containerPos.y + pt.y - this._beginTouchPos.y);
  12580. if (sv) {
  12581. if (newPosY > 0) {
  12582. if (!this._bouncebackEffect)
  12583. this._container.y = 0;
  12584. else if (this._header && this._header.maxHeight != 0)
  12585. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._header.maxHeight));
  12586. else
  12587. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._viewSize.y * PULL_RATIO));
  12588. }
  12589. else if (newPosY < -this._overlapSize.y) {
  12590. if (!this._bouncebackEffect)
  12591. this._container.y = this._overlapSize.y;
  12592. else if (this._footer && this._footer.maxHeight > 0)
  12593. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._footer.maxHeight) - this._overlapSize.y);
  12594. else
  12595. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._viewSize.y * PULL_RATIO) - this._overlapSize.y);
  12596. }
  12597. else
  12598. this._container.y = -newPosY;
  12599. }
  12600. if (sh) {
  12601. if (newPosX > 0) {
  12602. if (!this._bouncebackEffect)
  12603. this._container.x = 0;
  12604. else if (this._header && this._header.maxWidth != 0)
  12605. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._header.maxWidth));
  12606. else
  12607. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._viewSize.x * PULL_RATIO));
  12608. }
  12609. else if (newPosX < 0 - this._overlapSize.x) {
  12610. if (!this._bouncebackEffect)
  12611. this._container.x = -this._overlapSize.x;
  12612. else if (this._footer && this._footer.maxWidth > 0)
  12613. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._footer.maxWidth) - this._overlapSize.x);
  12614. else
  12615. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._viewSize.x * PULL_RATIO) - this._overlapSize.x);
  12616. }
  12617. else
  12618. this._container.x = newPosX;
  12619. }
  12620. var now = fgui.ToolSet.getTime();
  12621. var deltaTime = Math.max(now - this._lastMoveTime, 1 / 60);
  12622. var deltaPositionX = pt.x - this._lastTouchPos.x;
  12623. var deltaPositionY = pt.y - this._lastTouchPos.y;
  12624. if (!sh)
  12625. deltaPositionX = 0;
  12626. if (!sv)
  12627. deltaPositionY = 0;
  12628. if (deltaTime != 0) {
  12629. var frameRate = 60;
  12630. var elapsed = deltaTime * frameRate - 1;
  12631. if (elapsed > 1) {
  12632. var factor = Math.pow(0.833, elapsed);
  12633. this._velocity.x = this._velocity.x * factor;
  12634. this._velocity.y = this._velocity.y * factor;
  12635. }
  12636. this._velocity.x = fgui.ToolSet.lerp(this._velocity.x, deltaPositionX * 60 / frameRate / deltaTime, deltaTime * 10);
  12637. this._velocity.y = fgui.ToolSet.lerp(this._velocity.y, deltaPositionY * 60 / frameRate / deltaTime, deltaTime * 10);
  12638. }
  12639. var deltaGlobalPositionX = this._lastTouchGlobalPos.x - evt.pos.x;
  12640. var deltaGlobalPositionY = this._lastTouchGlobalPos.y - evt.pos.y;
  12641. if (deltaPositionX != 0)
  12642. this._velocityScale = Math.abs(deltaGlobalPositionX / deltaPositionX);
  12643. else if (deltaPositionY != 0)
  12644. this._velocityScale = Math.abs(deltaGlobalPositionY / deltaPositionY);
  12645. this._lastTouchPos.set(pt);
  12646. this._lastTouchGlobalPos.x = evt.pos.x;
  12647. this._lastTouchGlobalPos.y = evt.pos.y;
  12648. this._lastMoveTime = now;
  12649. if (this._overlapSize.x > 0)
  12650. this._xPos = fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  12651. if (this._overlapSize.y > 0)
  12652. this._yPos = fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  12653. if (this._loop != 0) {
  12654. newPosX = this._container.x;
  12655. newPosY = (-this._container.y);
  12656. if (this.loopCheckingCurrent()) {
  12657. this._containerPos.x += this._container.x - newPosX;
  12658. this._containerPos.y += (-this._container.y) - newPosY;
  12659. }
  12660. }
  12661. ScrollPane.draggingPane = this;
  12662. this._isHoldAreaDone = true;
  12663. this._dragged = true;
  12664. this.updateScrollBarPos();
  12665. this.updateScrollBarVisible();
  12666. if (this._pageMode)
  12667. this.updatePageController();
  12668. this._owner.node.emit(fgui.Event.SCROLL), this._owner;
  12669. };
  12670. ScrollPane.prototype.onTouchEnd = function (evt) {
  12671. if (ScrollPane.draggingPane == this)
  12672. ScrollPane.draggingPane = null;
  12673. _gestureFlag = 0;
  12674. if (!this._dragged || !this._touchEffect || !this._owner.node.activeInHierarchy) {
  12675. this._dragged = false;
  12676. return;
  12677. }
  12678. this._dragged = false;
  12679. this._tweenStart.x = this._container.x;
  12680. this._tweenStart.y = -this._container.y;
  12681. sEndPos.set(this._tweenStart);
  12682. var flag = false;
  12683. if (this._container.x > 0) {
  12684. sEndPos.x = 0;
  12685. flag = true;
  12686. }
  12687. else if (this._container.x < -this._overlapSize.x) {
  12688. sEndPos.x = -this._overlapSize.x;
  12689. flag = true;
  12690. }
  12691. if ((-this._container.y) > 0) {
  12692. sEndPos.y = 0;
  12693. flag = true;
  12694. }
  12695. else if ((-this._container.y) < -this._overlapSize.y) {
  12696. sEndPos.y = -this._overlapSize.y;
  12697. flag = true;
  12698. }
  12699. if (flag) {
  12700. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12701. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12702. if (this._tweenChange.x < -fgui.UIConfig.touchDragSensitivity || this._tweenChange.y < -fgui.UIConfig.touchDragSensitivity) {
  12703. this._refreshEventDispatching = true;
  12704. this._owner.node.emit(fgui.Event.PULL_DOWN_RELEASE), this._owner;
  12705. this._refreshEventDispatching = false;
  12706. }
  12707. else if (this._tweenChange.x > fgui.UIConfig.touchDragSensitivity || this._tweenChange.y > fgui.UIConfig.touchDragSensitivity) {
  12708. this._refreshEventDispatching = true;
  12709. this._owner.node.emit(fgui.Event.PULL_UP_RELEASE, this._owner);
  12710. this._refreshEventDispatching = false;
  12711. }
  12712. if (this._headerLockedSize > 0 && sEndPos[this._refreshBarAxis] == 0) {
  12713. sEndPos[this._refreshBarAxis] = this._headerLockedSize;
  12714. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12715. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12716. }
  12717. else if (this._footerLockedSize > 0 && sEndPos[this._refreshBarAxis] == -this._overlapSize[this._refreshBarAxis]) {
  12718. var max = this._overlapSize[this._refreshBarAxis];
  12719. if (max == 0)
  12720. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12721. else
  12722. max += this._footerLockedSize;
  12723. sEndPos[this._refreshBarAxis] = -max;
  12724. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12725. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12726. }
  12727. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12728. }
  12729. else {
  12730. if (!this._inertiaDisabled) {
  12731. var frameRate = 60;
  12732. var elapsed = (fgui.ToolSet.getTime() - this._lastMoveTime) * frameRate - 1;
  12733. if (elapsed > 1) {
  12734. var factor = Math.pow(0.833, elapsed);
  12735. this._velocity.x = this._velocity.x * factor;
  12736. this._velocity.y = this._velocity.y * factor;
  12737. }
  12738. this.updateTargetAndDuration(this._tweenStart, sEndPos);
  12739. }
  12740. else
  12741. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12742. sOldChange.x = sEndPos.x - this._tweenStart.x;
  12743. sOldChange.y = sEndPos.y - this._tweenStart.y;
  12744. this.loopCheckingTarget(sEndPos);
  12745. if (this._pageMode || this._snapToItem)
  12746. this.alignPosition(sEndPos, true);
  12747. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12748. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12749. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  12750. this.updateScrollBarVisible();
  12751. return;
  12752. }
  12753. if (this._pageMode || this._snapToItem) {
  12754. this.fixDuration("x", sOldChange.x);
  12755. this.fixDuration("y", sOldChange.y);
  12756. }
  12757. }
  12758. this.startTween(2);
  12759. };
  12760. ScrollPane.prototype.onRollOver = function () {
  12761. this._hover = true;
  12762. this.updateScrollBarVisible();
  12763. };
  12764. ScrollPane.prototype.onRollOut = function () {
  12765. this._hover = false;
  12766. this.updateScrollBarVisible();
  12767. };
  12768. ScrollPane.prototype.onMouseWheel = function (evt) {
  12769. if (!this._mouseWheelEnabled)
  12770. return;
  12771. var delta = evt.mouseWheelDelta > 0 ? -1 : 1;
  12772. if (this._overlapSize.x > 0 && this._overlapSize.y == 0) {
  12773. if (this._pageMode)
  12774. this.setPosX(this._xPos + this._pageSize.x * delta, false);
  12775. else
  12776. this.setPosX(this._xPos + this._mouseWheelStep * delta, false);
  12777. }
  12778. else {
  12779. if (this._pageMode)
  12780. this.setPosY(this._yPos + this._pageSize.y * delta, false);
  12781. else
  12782. this.setPosY(this._yPos + this._mouseWheelStep * delta, false);
  12783. }
  12784. };
  12785. ScrollPane.prototype.updateScrollBarPos = function () {
  12786. if (this._vtScrollBar)
  12787. this._vtScrollBar.setScrollPerc(this._overlapSize.y == 0 ? 0 : fgui.ToolSet.clamp(this._container.y, 0, this._overlapSize.y) / this._overlapSize.y);
  12788. if (this._hzScrollBar)
  12789. this._hzScrollBar.setScrollPerc(this._overlapSize.x == 0 ? 0 : fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x) / this._overlapSize.x);
  12790. this.checkRefreshBar();
  12791. };
  12792. ScrollPane.prototype.updateScrollBarVisible = function () {
  12793. if (this._vtScrollBar) {
  12794. if (this._viewSize.y <= this._vtScrollBar.minSize || this._vScrollNone)
  12795. this._vtScrollBar.node.active = false;
  12796. else
  12797. this.updateScrollBarVisible2(this._vtScrollBar);
  12798. }
  12799. if (this._hzScrollBar) {
  12800. if (this._viewSize.x <= this._hzScrollBar.minSize || this._hScrollNone)
  12801. this._hzScrollBar.node.active = false;
  12802. else
  12803. this.updateScrollBarVisible2(this._hzScrollBar);
  12804. }
  12805. };
  12806. ScrollPane.prototype.updateScrollBarVisible2 = function (bar) {
  12807. if (this._scrollBarDisplayAuto)
  12808. fgui.GTween.kill(bar, false, "alpha");
  12809. if (this._scrollBarDisplayAuto && !this._hover && this._tweening == 0 && !this._dragged && !bar.gripDragging) {
  12810. if (bar.node.active)
  12811. fgui.GTween.to(1, 0, 0.5).setDelay(0.5).onComplete(this.__barTweenComplete, this).setTarget(bar, "alpha");
  12812. }
  12813. else {
  12814. bar.alpha = 1;
  12815. bar.node.active = true;
  12816. }
  12817. };
  12818. ScrollPane.prototype.__barTweenComplete = function (tweener) {
  12819. var bar = (tweener.target);
  12820. bar.alpha = 1;
  12821. bar.node.active = false;
  12822. };
  12823. ScrollPane.prototype.getLoopPartSize = function (division, axis) {
  12824. return (this._contentSize[axis] + (axis == "x" ? this._owner.columnGap : this._owner.lineGap)) / division;
  12825. };
  12826. ScrollPane.prototype.loopCheckingCurrent = function () {
  12827. var changed = false;
  12828. if (this._loop == 1 && this._overlapSize.x > 0) {
  12829. if (this._xPos < 0.001) {
  12830. this._xPos += this.getLoopPartSize(2, "x");
  12831. changed = true;
  12832. }
  12833. else if (this._xPos >= this._overlapSize.x) {
  12834. this._xPos -= this.getLoopPartSize(2, "x");
  12835. changed = true;
  12836. }
  12837. }
  12838. else if (this._loop == 2 && this._overlapSize.y > 0) {
  12839. if (this._yPos < 0.001) {
  12840. this._yPos += this.getLoopPartSize(2, "y");
  12841. changed = true;
  12842. }
  12843. else if (this._yPos >= this._overlapSize.y) {
  12844. this._yPos -= this.getLoopPartSize(2, "y");
  12845. changed = true;
  12846. }
  12847. }
  12848. if (changed) {
  12849. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  12850. }
  12851. return changed;
  12852. };
  12853. ScrollPane.prototype.loopCheckingTarget = function (endPos) {
  12854. if (this._loop == 1)
  12855. this.loopCheckingTarget2(endPos, "x");
  12856. if (this._loop == 2)
  12857. this.loopCheckingTarget2(endPos, "y");
  12858. };
  12859. ScrollPane.prototype.loopCheckingTarget2 = function (endPos, axis) {
  12860. var halfSize;
  12861. var tmp;
  12862. if (endPos[axis] > 0) {
  12863. halfSize = this.getLoopPartSize(2, axis);
  12864. tmp = this._tweenStart[axis] - halfSize;
  12865. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  12866. endPos[axis] -= halfSize;
  12867. this._tweenStart[axis] = tmp;
  12868. }
  12869. }
  12870. else if (endPos[axis] < -this._overlapSize[axis]) {
  12871. halfSize = this.getLoopPartSize(2, axis);
  12872. tmp = this._tweenStart[axis] + halfSize;
  12873. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  12874. endPos[axis] += halfSize;
  12875. this._tweenStart[axis] = tmp;
  12876. }
  12877. }
  12878. };
  12879. ScrollPane.prototype.loopCheckingNewPos = function (value, axis) {
  12880. if (this._overlapSize[axis] == 0)
  12881. return value;
  12882. var pos = axis == "x" ? this._xPos : this._yPos;
  12883. var changed = false;
  12884. var v;
  12885. if (value < 0.001) {
  12886. value += this.getLoopPartSize(2, axis);
  12887. if (value > pos) {
  12888. v = this.getLoopPartSize(6, axis);
  12889. v = Math.ceil((value - pos) / v) * v;
  12890. pos = fgui.ToolSet.clamp(pos + v, 0, this._overlapSize[axis]);
  12891. changed = true;
  12892. }
  12893. }
  12894. else if (value >= this._overlapSize[axis]) {
  12895. value -= this.getLoopPartSize(2, axis);
  12896. if (value < pos) {
  12897. v = this.getLoopPartSize(6, axis);
  12898. v = Math.ceil((pos - value) / v) * v;
  12899. pos = fgui.ToolSet.clamp(pos - v, 0, this._overlapSize[axis]);
  12900. changed = true;
  12901. }
  12902. }
  12903. if (changed) {
  12904. if (axis == "x")
  12905. this._container.x = -Math.floor(pos);
  12906. else
  12907. this._container.y = Math.floor(pos);
  12908. }
  12909. return value;
  12910. };
  12911. ScrollPane.prototype.alignPosition = function (pos, inertialScrolling) {
  12912. var ax = 0, ay = 0;
  12913. if (this._snappingPolicy == 1) {
  12914. if (this._owner.numChildren > 0) {
  12915. var obj = this._owner.getChildAt(0);
  12916. ax = Math.floor(this._viewSize.x * 0.5 - obj.width * 0.5);
  12917. ay = Math.floor(this._viewSize.y * 0.5 - obj.height * 0.5);
  12918. }
  12919. }
  12920. else if (this._snappingPolicy == 2) {
  12921. if (this._owner.numChildren > 0) {
  12922. var obj = this._owner.getChildAt(0);
  12923. ax = Math.floor(this._viewSize.x - obj.width);
  12924. ay = Math.floor(this._viewSize.y - obj.height);
  12925. }
  12926. }
  12927. pos.x -= ax;
  12928. pos.y -= ay;
  12929. if (this._pageMode) {
  12930. pos.x = this.alignByPage(pos.x, "x", inertialScrolling);
  12931. pos.y = this.alignByPage(pos.y, "y", inertialScrolling);
  12932. }
  12933. else if (this._snapToItem) {
  12934. var pt = this._owner.getSnappingPosition(-pos.x, -pos.y, s_vec2);
  12935. if (pos.x < 0 && pos.x > -this._overlapSize.x)
  12936. pos.x = -pt.x;
  12937. if (pos.y < 0 && pos.y > -this._overlapSize.y)
  12938. pos.y = -pt.y;
  12939. }
  12940. pos.x += ax;
  12941. pos.y += ay;
  12942. };
  12943. ScrollPane.prototype.alignByPage = function (pos, axis, inertialScrolling) {
  12944. var page;
  12945. if (pos > 0)
  12946. page = 0;
  12947. else if (pos < -this._overlapSize[axis])
  12948. page = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  12949. else {
  12950. page = Math.floor(-pos / this._pageSize[axis]);
  12951. var change = inertialScrolling ? (pos - this._containerPos[axis]) : (pos - (axis == "x" ? this._container.x : (-this._container.y)));
  12952. var testPageSize = Math.min(this._pageSize[axis], this._contentSize[axis] - (page + 1) * this._pageSize[axis]);
  12953. var delta = -pos - page * this._pageSize[axis];
  12954. if (Math.abs(change) > this._pageSize[axis]) {
  12955. if (delta > testPageSize * 0.5)
  12956. page++;
  12957. }
  12958. else {
  12959. if (delta > testPageSize * (change < 0 ? 0.3 : 0.7))
  12960. page++;
  12961. }
  12962. pos = -page * this._pageSize[axis];
  12963. if (pos < -this._overlapSize[axis])
  12964. pos = -this._overlapSize[axis];
  12965. }
  12966. if (inertialScrolling) {
  12967. var oldPos = this._tweenStart[axis];
  12968. var oldPage;
  12969. if (oldPos > 0)
  12970. oldPage = 0;
  12971. else if (oldPos < -this._overlapSize[axis])
  12972. oldPage = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  12973. else
  12974. oldPage = Math.floor(-oldPos / this._pageSize[axis]);
  12975. var startPage = Math.floor(-this._containerPos[axis] / this._pageSize[axis]);
  12976. if (Math.abs(page - startPage) > 1 && Math.abs(oldPage - startPage) <= 1) {
  12977. if (page > startPage)
  12978. page = startPage + 1;
  12979. else
  12980. page = startPage - 1;
  12981. pos = -page * this._pageSize[axis];
  12982. }
  12983. }
  12984. return pos;
  12985. };
  12986. ScrollPane.prototype.updateTargetAndDuration = function (orignPos, resultPos) {
  12987. resultPos.x = this.updateTargetAndDuration2(orignPos.x, "x");
  12988. resultPos.y = this.updateTargetAndDuration2(orignPos.y, "y");
  12989. };
  12990. ScrollPane.prototype.updateTargetAndDuration2 = function (pos, axis) {
  12991. var v = this._velocity[axis];
  12992. var duration = 0;
  12993. if (pos > 0)
  12994. pos = 0;
  12995. else if (pos < -this._overlapSize[axis])
  12996. pos = -this._overlapSize[axis];
  12997. else {
  12998. var isMobile = cc.sys.isMobile;
  12999. var v2 = Math.abs(v) * this._velocityScale;
  13000. if (isMobile)
  13001. v2 *= 1136 / Math.max(cc.winSize.width, cc.winSize.height);
  13002. var ratio = 0;
  13003. if (this._pageMode || !isMobile) {
  13004. if (v2 > 500)
  13005. ratio = Math.pow((v2 - 500) / 500, 2);
  13006. }
  13007. else {
  13008. if (v2 > 1000)
  13009. ratio = Math.pow((v2 - 1000) / 1000, 2);
  13010. }
  13011. if (ratio != 0) {
  13012. if (ratio > 1)
  13013. ratio = 1;
  13014. v2 *= ratio;
  13015. v *= ratio;
  13016. this._velocity[axis] = v;
  13017. duration = Math.log(60 / v2) / Math.log(this._decelerationRate) / 60;
  13018. var change = Math.floor(v * duration * 0.4);
  13019. pos += change;
  13020. }
  13021. }
  13022. if (duration < TWEEN_TIME_DEFAULT)
  13023. duration = TWEEN_TIME_DEFAULT;
  13024. this._tweenDuration[axis] = duration;
  13025. return pos;
  13026. };
  13027. ScrollPane.prototype.fixDuration = function (axis, oldChange) {
  13028. if (this._tweenChange[axis] == 0 || Math.abs(this._tweenChange[axis]) >= Math.abs(oldChange))
  13029. return;
  13030. var newDuration = Math.abs(this._tweenChange[axis] / oldChange) * this._tweenDuration[axis];
  13031. if (newDuration < TWEEN_TIME_DEFAULT)
  13032. newDuration = TWEEN_TIME_DEFAULT;
  13033. this._tweenDuration[axis] = newDuration;
  13034. };
  13035. ScrollPane.prototype.startTween = function (type) {
  13036. this._tweenTime.set(cc.Vec2.ZERO);
  13037. this._tweening = type;
  13038. this.updateScrollBarVisible();
  13039. };
  13040. ScrollPane.prototype.killTween = function () {
  13041. if (this._tweening == 1) {
  13042. this._container.setPosition(this._tweenStart.x + this._tweenChange.x, -(this._tweenStart.y + this._tweenChange.y));
  13043. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13044. }
  13045. this._tweening = 0;
  13046. this.updateScrollBarVisible();
  13047. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  13048. };
  13049. ScrollPane.prototype.checkRefreshBar = function () {
  13050. if (this._header == null && this._footer == null)
  13051. return;
  13052. var pos = (this._refreshBarAxis == "x" ? this._container.x : (-this._container.y));
  13053. if (this._header) {
  13054. if (pos > 0) {
  13055. this._header.node.active = true;
  13056. var pt = s_vec2;
  13057. pt.x = this._header.width;
  13058. pt.y = this._header.height;
  13059. pt[this._refreshBarAxis] = pos;
  13060. this._header.setSize(pt.x, pt.y);
  13061. }
  13062. else {
  13063. this._header.node.active = false;
  13064. }
  13065. }
  13066. if (this._footer) {
  13067. var max = this._overlapSize[this._refreshBarAxis];
  13068. if (pos < -max || max == 0 && this._footerLockedSize > 0) {
  13069. this._footer.node.active = true;
  13070. pt = s_vec2;
  13071. pt.x = this._footer.x;
  13072. pt.y = this._footer.y;
  13073. if (max > 0)
  13074. pt[this._refreshBarAxis] = pos + this._contentSize[this._refreshBarAxis];
  13075. else
  13076. 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]);
  13077. this._footer.setPosition(pt.x, pt.y);
  13078. pt.x = this._footer.width;
  13079. pt.y = this._footer.height;
  13080. if (max > 0)
  13081. pt[this._refreshBarAxis] = -max - pos;
  13082. else
  13083. pt[this._refreshBarAxis] = this._viewSize[this._refreshBarAxis] - this._footer[this._refreshBarAxis];
  13084. this._footer.setSize(pt.x, pt.y);
  13085. }
  13086. else {
  13087. this._footer.node.active = false;
  13088. }
  13089. }
  13090. };
  13091. ScrollPane.prototype.update = function (dt) {
  13092. if (this._tweening == 0)
  13093. return;
  13094. var nx = this.runTween("x", dt);
  13095. var ny = this.runTween("y", dt);
  13096. this._container.setPosition(nx, -ny);
  13097. if (this._tweening == 2) {
  13098. if (this._overlapSize.x > 0)
  13099. this._xPos = fgui.ToolSet.clamp(-nx, 0, this._overlapSize.x);
  13100. if (this._overlapSize.y > 0)
  13101. this._yPos = fgui.ToolSet.clamp(-ny, 0, this._overlapSize.y);
  13102. if (this._pageMode)
  13103. this.updatePageController();
  13104. }
  13105. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  13106. this._tweening = 0;
  13107. this.loopCheckingCurrent();
  13108. this.updateScrollBarPos();
  13109. this.updateScrollBarVisible();
  13110. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13111. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  13112. }
  13113. else {
  13114. this.updateScrollBarPos();
  13115. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13116. }
  13117. return true;
  13118. };
  13119. ScrollPane.prototype.runTween = function (axis, dt) {
  13120. var newValue;
  13121. if (this._tweenChange[axis] != 0) {
  13122. this._tweenTime[axis] += dt;
  13123. if (this._tweenTime[axis] >= this._tweenDuration[axis]) {
  13124. newValue = this._tweenStart[axis] + this._tweenChange[axis];
  13125. this._tweenChange[axis] = 0;
  13126. }
  13127. else {
  13128. var ratio = easeFunc(this._tweenTime[axis], this._tweenDuration[axis]);
  13129. newValue = this._tweenStart[axis] + Math.floor(this._tweenChange[axis] * ratio);
  13130. }
  13131. var threshold1 = 0;
  13132. var threshold2 = -this._overlapSize[axis];
  13133. if (this._headerLockedSize > 0 && this._refreshBarAxis == axis)
  13134. threshold1 = this._headerLockedSize;
  13135. if (this._footerLockedSize > 0 && this._refreshBarAxis == axis) {
  13136. var max = this._overlapSize[this._refreshBarAxis];
  13137. if (max == 0)
  13138. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  13139. else
  13140. max += this._footerLockedSize;
  13141. threshold2 = -max;
  13142. }
  13143. if (this._tweening == 2 && this._bouncebackEffect) {
  13144. if (newValue > 20 + threshold1 && this._tweenChange[axis] > 0
  13145. || newValue > threshold1 && this._tweenChange[axis] == 0) {
  13146. this._tweenTime[axis] = 0;
  13147. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  13148. this._tweenChange[axis] = -newValue + threshold1;
  13149. this._tweenStart[axis] = newValue;
  13150. }
  13151. else if (newValue < threshold2 - 20 && this._tweenChange[axis] < 0
  13152. || newValue < threshold2 && this._tweenChange[axis] == 0) {
  13153. this._tweenTime[axis] = 0;
  13154. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  13155. this._tweenChange[axis] = threshold2 - newValue;
  13156. this._tweenStart[axis] = newValue;
  13157. }
  13158. }
  13159. else {
  13160. if (newValue > threshold1) {
  13161. newValue = threshold1;
  13162. this._tweenChange[axis] = 0;
  13163. }
  13164. else if (newValue < threshold2) {
  13165. newValue = threshold2;
  13166. this._tweenChange[axis] = 0;
  13167. }
  13168. }
  13169. }
  13170. else
  13171. newValue = (axis == "x" ? this._container.x : (-this._container.y));
  13172. return newValue;
  13173. };
  13174. return ScrollPane;
  13175. }(cc.Component));
  13176. fgui.ScrollPane = ScrollPane;
  13177. var _gestureFlag = 0;
  13178. var TWEEN_TIME_GO = 0.5;
  13179. var TWEEN_TIME_DEFAULT = 0.3;
  13180. var PULL_RATIO = 0.5;
  13181. var s_vec2 = new cc.Vec2();
  13182. var s_rect = new cc.Rect();
  13183. var sEndPos = new cc.Vec2();
  13184. var sOldChange = new cc.Vec2();
  13185. function easeFunc(t, d) {
  13186. return (t = t / d - 1) * t * t + 1;
  13187. }
  13188. })(fgui || (fgui = {}));
  13189. (function (fgui) {
  13190. var Transition = (function () {
  13191. function Transition(owner) {
  13192. this._ownerBaseX = 0;
  13193. this._ownerBaseY = 0;
  13194. this._totalTimes = 0;
  13195. this._totalTasks = 0;
  13196. this._options = 0;
  13197. this._totalDuration = 0;
  13198. this._autoPlayTimes = 1;
  13199. this._autoPlayDelay = 0;
  13200. this._timeScale = 1;
  13201. this._startTime = 0;
  13202. this._endTime = 0;
  13203. this._owner = owner;
  13204. this._items = new Array();
  13205. }
  13206. Transition.prototype.play = function (onComplete, times, delay, startTime, endTime) {
  13207. this._play(onComplete, times, delay, startTime, endTime, false);
  13208. };
  13209. Transition.prototype.playReverse = function (onComplete, times, delay) {
  13210. this._play(onComplete, times, delay, 0, -1, true);
  13211. };
  13212. Transition.prototype.changePlayTimes = function (value) {
  13213. this._totalTimes = value;
  13214. };
  13215. Transition.prototype.setAutoPlay = function (value, times, delay) {
  13216. if (times == undefined)
  13217. times = -1;
  13218. if (delay == undefined)
  13219. delay = 0;
  13220. if (this._autoPlay != value) {
  13221. this._autoPlay = value;
  13222. this._autoPlayTimes = times;
  13223. this._autoPlayDelay = delay;
  13224. if (this._autoPlay) {
  13225. if (this._owner.onStage)
  13226. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  13227. }
  13228. else {
  13229. if (!this._owner.onStage)
  13230. this.stop(false, true);
  13231. }
  13232. }
  13233. };
  13234. Transition.prototype._play = function (onComplete, times, delay, startTime, endTime, reversed) {
  13235. if (times == undefined)
  13236. times = 1;
  13237. if (delay == undefined)
  13238. delay = 0;
  13239. if (startTime == undefined)
  13240. startTime = 0;
  13241. if (endTime == undefined)
  13242. endTime = -1;
  13243. this.stop(true, true);
  13244. this._totalTimes = times;
  13245. this._reversed = reversed;
  13246. this._startTime = startTime;
  13247. this._endTime = endTime;
  13248. this._playing = true;
  13249. this._paused = false;
  13250. this._onComplete = onComplete;
  13251. var cnt = this._items.length;
  13252. for (var i = 0; i < cnt; i++) {
  13253. var item = this._items[i];
  13254. if (item.target == null) {
  13255. if (item.targetId)
  13256. item.target = this._owner.getChildById(item.targetId);
  13257. else
  13258. item.target = this._owner;
  13259. }
  13260. else if (item.target != this._owner && item.target.parent != this._owner)
  13261. item.target = null;
  13262. if (item.target && item.type == ActionType.Transition) {
  13263. var trans = item.target.getTransition(item.value.transName);
  13264. if (trans == this)
  13265. trans = null;
  13266. if (trans) {
  13267. if (item.value.playTimes == 0) {
  13268. var j;
  13269. for (j = i - 1; j >= 0; j--) {
  13270. var item2 = this._items[j];
  13271. if (item2.type == ActionType.Transition) {
  13272. if (item2.value.trans == trans) {
  13273. item2.value.stopTime = item.time - item2.time;
  13274. break;
  13275. }
  13276. }
  13277. }
  13278. if (j < 0)
  13279. item.value.stopTime = 0;
  13280. else
  13281. trans = null;
  13282. }
  13283. else
  13284. item.value.stopTime = -1;
  13285. }
  13286. item.value.trans = trans;
  13287. }
  13288. }
  13289. if (delay == 0)
  13290. this.onDelayedPlay();
  13291. else
  13292. fgui.GTween.delayedCall(delay).setTarget(this).onComplete(this.onDelayedPlay, this);
  13293. };
  13294. Transition.prototype.stop = function (setToComplete, processCallback) {
  13295. if (setToComplete == undefined)
  13296. setToComplete = true;
  13297. if (!this._playing)
  13298. return;
  13299. this._playing = false;
  13300. this._totalTasks = 0;
  13301. this._totalTimes = 0;
  13302. var func = this._onComplete;
  13303. this._onComplete = null;
  13304. fgui.GTween.kill(this);
  13305. var cnt = this._items.length;
  13306. if (this._reversed) {
  13307. for (var i = cnt - 1; i >= 0; i--) {
  13308. var item = this._items[i];
  13309. if (item.target == null)
  13310. continue;
  13311. this.stopItem(item, setToComplete);
  13312. }
  13313. }
  13314. else {
  13315. for (i = 0; i < cnt; i++) {
  13316. item = this._items[i];
  13317. if (item.target == null)
  13318. continue;
  13319. this.stopItem(item, setToComplete);
  13320. }
  13321. }
  13322. if (processCallback && func != null) {
  13323. func();
  13324. }
  13325. };
  13326. Transition.prototype.stopItem = function (item, setToComplete) {
  13327. if (item.displayLockToken != 0) {
  13328. item.target.releaseDisplayLock(item.displayLockToken);
  13329. item.displayLockToken = 0;
  13330. }
  13331. if (item.tweener) {
  13332. item.tweener.kill(setToComplete);
  13333. item.tweener = null;
  13334. if (item.type == ActionType.Shake && !setToComplete) {
  13335. item.target._gearLocked = true;
  13336. item.target.setPosition(item.target.x - item.value.lastOffsetX, item.target.y - item.value.lastOffsetY);
  13337. item.target._gearLocked = false;
  13338. }
  13339. }
  13340. if (item.type == ActionType.Transition) {
  13341. var trans = item.value.trans;
  13342. if (trans)
  13343. trans.stop(setToComplete, false);
  13344. }
  13345. };
  13346. Transition.prototype.setPaused = function (paused) {
  13347. if (!this._playing || this._paused == paused)
  13348. return;
  13349. this._paused = paused;
  13350. var tweener = fgui.GTween.getTween(this);
  13351. if (tweener)
  13352. tweener.setPaused(paused);
  13353. var cnt = this._items.length;
  13354. for (var i = 0; i < cnt; i++) {
  13355. var item = this._items[i];
  13356. if (item.target == null)
  13357. continue;
  13358. if (item.type == ActionType.Transition) {
  13359. if (item.value.trans)
  13360. item.value.trans.setPaused(paused);
  13361. }
  13362. else if (item.type == ActionType.Animation) {
  13363. if (paused) {
  13364. item.value.flag = item.target.getProp(fgui.ObjectPropID.Playing);
  13365. item.target.setProp(fgui.ObjectPropID.Playing, false);
  13366. }
  13367. else
  13368. item.target.setProp(fgui.ObjectPropID.Playing, item.value.flag);
  13369. }
  13370. if (item.tweener)
  13371. item.tweener.setPaused(paused);
  13372. }
  13373. };
  13374. Transition.prototype.dispose = function () {
  13375. if (this._playing)
  13376. fgui.GTween.kill(this);
  13377. var cnt = this._items.length;
  13378. for (var i = 0; i < cnt; i++) {
  13379. var item = this._items[i];
  13380. if (item.tweener) {
  13381. item.tweener.kill();
  13382. item.tweener = null;
  13383. }
  13384. item.target = null;
  13385. item.hook = null;
  13386. if (item.tweenConfig)
  13387. item.tweenConfig.endHook = null;
  13388. }
  13389. this._items.length = 0;
  13390. this._playing = false;
  13391. this._onComplete = null;
  13392. };
  13393. Object.defineProperty(Transition.prototype, "playing", {
  13394. get: function () {
  13395. return this._playing;
  13396. },
  13397. enumerable: false,
  13398. configurable: true
  13399. });
  13400. Transition.prototype.setValue = function (label) {
  13401. var args = [];
  13402. for (var _i = 1; _i < arguments.length; _i++) {
  13403. args[_i - 1] = arguments[_i];
  13404. }
  13405. var cnt = this._items.length;
  13406. var value;
  13407. for (var i = 0; i < cnt; i++) {
  13408. var item = this._items[i];
  13409. if (item.label == label) {
  13410. if (item.tweenConfig)
  13411. value = item.tweenConfig.startValue;
  13412. else
  13413. value = item.value;
  13414. }
  13415. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  13416. value = item.tweenConfig.endValue;
  13417. }
  13418. else
  13419. continue;
  13420. switch (item.type) {
  13421. case ActionType.XY:
  13422. case ActionType.Size:
  13423. case ActionType.Pivot:
  13424. case ActionType.Scale:
  13425. case ActionType.Skew:
  13426. value.b1 = true;
  13427. value.b2 = true;
  13428. value.f1 = parseFloat(args[0]);
  13429. value.f2 = parseFloat(args[1]);
  13430. break;
  13431. case ActionType.Alpha:
  13432. value.f1 = parseFloat(args[0]);
  13433. break;
  13434. case ActionType.Rotation:
  13435. value.f1 = parseFloat(args[0]);
  13436. break;
  13437. case ActionType.Color:
  13438. value.f1 = parseFloat(args[0]);
  13439. break;
  13440. case ActionType.Animation:
  13441. value.frame = parseInt(args[0]);
  13442. if (args.length > 1)
  13443. value.playing = args[1];
  13444. break;
  13445. case ActionType.Visible:
  13446. value.visible = args[0];
  13447. break;
  13448. case ActionType.Sound:
  13449. value.sound = args[0];
  13450. if (args.length > 1)
  13451. value.volume = parseFloat(args[1]);
  13452. break;
  13453. case ActionType.Transition:
  13454. value.transName = args[0];
  13455. if (args.length > 1)
  13456. value.playTimes = parseInt(args[1]);
  13457. break;
  13458. case ActionType.Shake:
  13459. value.amplitude = parseFloat(args[0]);
  13460. if (args.length > 1)
  13461. value.duration = parseFloat(args[1]);
  13462. break;
  13463. case ActionType.ColorFilter:
  13464. value.f1 = parseFloat(args[0]);
  13465. value.f2 = parseFloat(args[1]);
  13466. value.f3 = parseFloat(args[2]);
  13467. value.f4 = parseFloat(args[3]);
  13468. break;
  13469. case ActionType.Text:
  13470. case ActionType.Icon:
  13471. value.text = args[0];
  13472. break;
  13473. }
  13474. }
  13475. };
  13476. Transition.prototype.setHook = function (label, callback) {
  13477. var cnt = this._items.length;
  13478. for (var i = 0; i < cnt; i++) {
  13479. var item = this._items[i];
  13480. if (item.label == label) {
  13481. item.hook = callback;
  13482. break;
  13483. }
  13484. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  13485. item.tweenConfig.endHook = callback;
  13486. break;
  13487. }
  13488. }
  13489. };
  13490. Transition.prototype.clearHooks = function () {
  13491. var cnt = this._items.length;
  13492. for (var i = 0; i < cnt; i++) {
  13493. var item = this._items[i];
  13494. item.hook = null;
  13495. if (item.tweenConfig)
  13496. item.tweenConfig.endHook = null;
  13497. }
  13498. };
  13499. Transition.prototype.setTarget = function (label, newTarget) {
  13500. var cnt = this._items.length;
  13501. for (var i = 0; i < cnt; i++) {
  13502. var item = this._items[i];
  13503. if (item.label == label) {
  13504. item.targetId = newTarget.id;
  13505. item.target = null;
  13506. }
  13507. }
  13508. };
  13509. Transition.prototype.setDuration = function (label, value) {
  13510. var cnt = this._items.length;
  13511. for (var i = 0; i < cnt; i++) {
  13512. var item = this._items[i];
  13513. if (item.tweenConfig && item.label == label)
  13514. item.tweenConfig.duration = value;
  13515. }
  13516. };
  13517. Transition.prototype.getLabelTime = function (label) {
  13518. var cnt = this._items.length;
  13519. for (var i = 0; i < cnt; i++) {
  13520. var item = this._items[i];
  13521. if (item.label == label)
  13522. return item.time;
  13523. else if (item.tweenConfig && item.tweenConfig.endLabel == label)
  13524. return item.time + item.tweenConfig.duration;
  13525. }
  13526. return Number.NaN;
  13527. };
  13528. Object.defineProperty(Transition.prototype, "timeScale", {
  13529. get: function () {
  13530. return this._timeScale;
  13531. },
  13532. set: function (value) {
  13533. if (this._timeScale != value) {
  13534. this._timeScale = value;
  13535. if (this._playing) {
  13536. var cnt = this._items.length;
  13537. for (var i = 0; i < cnt; i++) {
  13538. var item = this._items[i];
  13539. if (item.tweener)
  13540. item.tweener.setTimeScale(value);
  13541. else if (item.type == ActionType.Transition) {
  13542. if (item.value.trans)
  13543. item.value.trans.timeScale = value;
  13544. }
  13545. else if (item.type == ActionType.Animation) {
  13546. if (item.target)
  13547. item.target.setProp(fgui.ObjectPropID.TimeScale, value);
  13548. }
  13549. }
  13550. }
  13551. }
  13552. },
  13553. enumerable: false,
  13554. configurable: true
  13555. });
  13556. Transition.prototype.updateFromRelations = function (targetId, dx, dy) {
  13557. var cnt = this._items.length;
  13558. if (cnt == 0)
  13559. return;
  13560. for (var i = 0; i < cnt; i++) {
  13561. var item = this._items[i];
  13562. if (item.type == ActionType.XY && item.targetId == targetId) {
  13563. if (item.tweenConfig) {
  13564. item.tweenConfig.startValue.f1 += dx;
  13565. item.tweenConfig.startValue.f2 += dy;
  13566. item.tweenConfig.endValue.f1 += dx;
  13567. item.tweenConfig.endValue.f2 += dy;
  13568. }
  13569. else {
  13570. item.value.f1 += dx;
  13571. item.value.f2 += dy;
  13572. }
  13573. }
  13574. }
  13575. };
  13576. Transition.prototype.onEnable = function () {
  13577. if (this._autoPlay && !this._playing)
  13578. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  13579. };
  13580. Transition.prototype.onDisable = function () {
  13581. if ((this._options & OPTION_AUTO_STOP_DISABLED) == 0)
  13582. this.stop((this._options & OPTION_AUTO_STOP_AT_END) != 0 ? true : false, false);
  13583. };
  13584. Transition.prototype.onDelayedPlay = function () {
  13585. this.internalPlay();
  13586. this._playing = this._totalTasks > 0;
  13587. if (this._playing) {
  13588. if ((this._options & OPTION_IGNORE_DISPLAY_CONTROLLER) != 0) {
  13589. var cnt = this._items.length;
  13590. for (var i = 0; i < cnt; i++) {
  13591. var item = this._items[i];
  13592. if (item.target && item.target != this._owner)
  13593. item.displayLockToken = item.target.addDisplayLock();
  13594. }
  13595. }
  13596. }
  13597. else if (this._onComplete != null) {
  13598. var func = this._onComplete;
  13599. this._onComplete = null;
  13600. func();
  13601. }
  13602. };
  13603. Transition.prototype.internalPlay = function () {
  13604. this._ownerBaseX = this._owner.x;
  13605. this._ownerBaseY = this._owner.y;
  13606. this._totalTasks = 1;
  13607. var cnt = this._items.length;
  13608. var item;
  13609. var needSkipAnimations = false;
  13610. var i;
  13611. if (!this._reversed) {
  13612. for (i = 0; i < cnt; i++) {
  13613. item = this._items[i];
  13614. if (item.target == null)
  13615. continue;
  13616. if (item.type == ActionType.Animation && this._startTime != 0 && item.time <= this._startTime) {
  13617. needSkipAnimations = true;
  13618. item.value.flag = false;
  13619. }
  13620. else
  13621. this.playItem(item);
  13622. }
  13623. }
  13624. else {
  13625. for (i = cnt - 1; i >= 0; i--) {
  13626. item = this._items[i];
  13627. if (item.target == null)
  13628. continue;
  13629. this.playItem(item);
  13630. }
  13631. }
  13632. if (needSkipAnimations)
  13633. this.skipAnimations();
  13634. this._totalTasks--;
  13635. };
  13636. Transition.prototype.playItem = function (item) {
  13637. var time;
  13638. if (item.tweenConfig) {
  13639. if (this._reversed)
  13640. time = (this._totalDuration - item.time - item.tweenConfig.duration);
  13641. else
  13642. time = item.time;
  13643. if (this._endTime == -1 || time <= this._endTime) {
  13644. var startValue;
  13645. var endValue;
  13646. if (this._reversed) {
  13647. startValue = item.tweenConfig.endValue;
  13648. endValue = item.tweenConfig.startValue;
  13649. }
  13650. else {
  13651. startValue = item.tweenConfig.startValue;
  13652. endValue = item.tweenConfig.endValue;
  13653. }
  13654. item.value.b1 = startValue.b1 || endValue.b1;
  13655. item.value.b2 = startValue.b2 || endValue.b2;
  13656. switch (item.type) {
  13657. case ActionType.XY:
  13658. case ActionType.Size:
  13659. case ActionType.Scale:
  13660. case ActionType.Skew:
  13661. item.tweener = fgui.GTween.to2(startValue.f1, startValue.f2, endValue.f1, endValue.f2, item.tweenConfig.duration);
  13662. break;
  13663. case ActionType.Alpha:
  13664. case ActionType.Rotation:
  13665. item.tweener = fgui.GTween.to(startValue.f1, endValue.f1, item.tweenConfig.duration);
  13666. break;
  13667. case ActionType.Color:
  13668. item.tweener = fgui.GTween.toColor(startValue.f1, endValue.f1, item.tweenConfig.duration);
  13669. break;
  13670. case ActionType.ColorFilter:
  13671. item.tweener = fgui.GTween.to4(startValue.f1, startValue.f2, startValue.f3, startValue.f4, endValue.f1, endValue.f2, endValue.f3, endValue.f4, item.tweenConfig.duration);
  13672. break;
  13673. }
  13674. item.tweener.setDelay(time)
  13675. .setEase(item.tweenConfig.easeType)
  13676. .setRepeat(item.tweenConfig.repeat, item.tweenConfig.yoyo)
  13677. .setTimeScale(this._timeScale)
  13678. .setTarget(item)
  13679. .onStart(this.onTweenStart, this)
  13680. .onUpdate(this.onTweenUpdate, this)
  13681. .onComplete(this.onTweenComplete, this);
  13682. if (this._endTime >= 0)
  13683. item.tweener.setBreakpoint(this._endTime - time);
  13684. this._totalTasks++;
  13685. }
  13686. }
  13687. else if (item.type == ActionType.Shake) {
  13688. if (this._reversed)
  13689. time = (this._totalDuration - item.time - item.value.duration);
  13690. else
  13691. time = item.time;
  13692. item.value.offsetX = item.value.offsetY = 0;
  13693. item.value.lastOffsetX = item.value.lastOffsetY = 0;
  13694. item.tweener = fgui.GTween.shake(0, 0, item.value.amplitude, item.value.duration)
  13695. .setDelay(time)
  13696. .setTimeScale(this._timeScale)
  13697. .setTarget(item)
  13698. .onUpdate(this.onTweenUpdate, this)
  13699. .onComplete(this.onTweenComplete, this);
  13700. if (this._endTime >= 0)
  13701. item.tweener.setBreakpoint(this._endTime - item.time);
  13702. this._totalTasks++;
  13703. }
  13704. else {
  13705. if (this._reversed)
  13706. time = (this._totalDuration - item.time);
  13707. else
  13708. time = item.time;
  13709. if (time <= this._startTime) {
  13710. this.applyValue(item);
  13711. this.callHook(item, false);
  13712. }
  13713. else if (this._endTime == -1 || time <= this._endTime) {
  13714. this._totalTasks++;
  13715. item.tweener = fgui.GTween.delayedCall(time)
  13716. .setTimeScale(this._timeScale)
  13717. .setTarget(item)
  13718. .onComplete(this.onDelayedPlayItem, this);
  13719. }
  13720. }
  13721. if (item.tweener)
  13722. item.tweener.seek(this._startTime);
  13723. };
  13724. Transition.prototype.skipAnimations = function () {
  13725. var frame;
  13726. var playStartTime;
  13727. var playTotalTime;
  13728. var value;
  13729. var target;
  13730. var item;
  13731. var cnt = this._items.length;
  13732. for (var i = 0; i < cnt; i++) {
  13733. item = this._items[i];
  13734. if (item.type != ActionType.Animation || item.time > this._startTime)
  13735. continue;
  13736. value = item.value;
  13737. if (value.flag)
  13738. continue;
  13739. target = item.target;
  13740. frame = target.getProp(fgui.ObjectPropID.Frame);
  13741. playStartTime = target.getProp(fgui.ObjectPropID.Playing) ? 0 : -1;
  13742. playTotalTime = 0;
  13743. for (var j = i; j < cnt; j++) {
  13744. item = this._items[j];
  13745. if (item.type != ActionType.Animation || item.target != target || item.time > this._startTime)
  13746. continue;
  13747. value = item.value;
  13748. value.flag = true;
  13749. if (value.frame != -1) {
  13750. frame = value.frame;
  13751. if (value.playing)
  13752. playStartTime = item.time;
  13753. else
  13754. playStartTime = -1;
  13755. playTotalTime = 0;
  13756. }
  13757. else {
  13758. if (value.playing) {
  13759. if (playStartTime < 0)
  13760. playStartTime = item.time;
  13761. }
  13762. else {
  13763. if (playStartTime >= 0)
  13764. playTotalTime += (item.time - playStartTime);
  13765. playStartTime = -1;
  13766. }
  13767. }
  13768. this.callHook(item, false);
  13769. }
  13770. if (playStartTime >= 0)
  13771. playTotalTime += (this._startTime - playStartTime);
  13772. target.setProp(fgui.ObjectPropID.Playing, playStartTime >= 0);
  13773. target.setProp(fgui.ObjectPropID.Frame, frame);
  13774. if (playTotalTime > 0)
  13775. target.setProp(fgui.ObjectPropID.DeltaTime, playTotalTime);
  13776. }
  13777. };
  13778. Transition.prototype.onDelayedPlayItem = function (tweener) {
  13779. var item = tweener.target;
  13780. item.tweener = null;
  13781. this._totalTasks--;
  13782. this.applyValue(item);
  13783. this.callHook(item, false);
  13784. this.checkAllComplete();
  13785. };
  13786. Transition.prototype.onTweenStart = function (tweener) {
  13787. var item = tweener.target;
  13788. if (item.type == ActionType.XY || item.type == ActionType.Size) {
  13789. var startValue;
  13790. var endValue;
  13791. if (this._reversed) {
  13792. startValue = item.tweenConfig.endValue;
  13793. endValue = item.tweenConfig.startValue;
  13794. }
  13795. else {
  13796. startValue = item.tweenConfig.startValue;
  13797. endValue = item.tweenConfig.endValue;
  13798. }
  13799. if (item.type == ActionType.XY) {
  13800. if (item.target != this._owner) {
  13801. if (!startValue.b1)
  13802. tweener.startValue.x = item.target.x;
  13803. else if (startValue.b3)
  13804. tweener.startValue.x = startValue.f1 * this._owner.width;
  13805. if (!startValue.b2)
  13806. tweener.startValue.y = item.target.y;
  13807. else if (startValue.b3)
  13808. tweener.startValue.y = startValue.f2 * this._owner.height;
  13809. if (!endValue.b1)
  13810. tweener.endValue.x = tweener.startValue.x;
  13811. else if (endValue.b3)
  13812. tweener.endValue.x = endValue.f1 * this._owner.width;
  13813. if (!endValue.b2)
  13814. tweener.endValue.y = tweener.startValue.y;
  13815. else if (endValue.b3)
  13816. tweener.endValue.y = endValue.f2 * this._owner.height;
  13817. }
  13818. else {
  13819. if (!startValue.b1)
  13820. tweener.startValue.x = item.target.x - this._ownerBaseX;
  13821. if (!startValue.b2)
  13822. tweener.startValue.y = item.target.y - this._ownerBaseY;
  13823. if (!endValue.b1)
  13824. tweener.endValue.x = tweener.startValue.x;
  13825. if (!endValue.b2)
  13826. tweener.endValue.y = tweener.startValue.y;
  13827. }
  13828. }
  13829. else {
  13830. if (!startValue.b1)
  13831. tweener.startValue.x = item.target.width;
  13832. if (!startValue.b2)
  13833. tweener.startValue.y = item.target.height;
  13834. if (!endValue.b1)
  13835. tweener.endValue.x = tweener.startValue.x;
  13836. if (!endValue.b2)
  13837. tweener.endValue.y = tweener.startValue.y;
  13838. }
  13839. if (item.tweenConfig.path) {
  13840. item.value.b1 = item.value.b2 = true;
  13841. tweener.setPath(item.tweenConfig.path);
  13842. }
  13843. }
  13844. this.callHook(item, false);
  13845. };
  13846. Transition.prototype.onTweenUpdate = function (tweener) {
  13847. var item = tweener.target;
  13848. switch (item.type) {
  13849. case ActionType.XY:
  13850. case ActionType.Size:
  13851. case ActionType.Scale:
  13852. case ActionType.Skew:
  13853. item.value.f1 = tweener.value.x;
  13854. item.value.f2 = tweener.value.y;
  13855. if (item.tweenConfig.path) {
  13856. item.value.f1 += tweener.startValue.x;
  13857. item.value.f2 += tweener.startValue.y;
  13858. }
  13859. break;
  13860. case ActionType.Alpha:
  13861. case ActionType.Rotation:
  13862. item.value.f1 = tweener.value.x;
  13863. break;
  13864. case ActionType.Color:
  13865. item.value.f1 = tweener.value.color;
  13866. break;
  13867. case ActionType.ColorFilter:
  13868. item.value.f1 = tweener.value.x;
  13869. item.value.f2 = tweener.value.y;
  13870. item.value.f3 = tweener.value.z;
  13871. item.value.f4 = tweener.value.w;
  13872. break;
  13873. case ActionType.Shake:
  13874. item.value.offsetX = tweener.deltaValue.x;
  13875. item.value.offsetY = tweener.deltaValue.y;
  13876. break;
  13877. }
  13878. this.applyValue(item);
  13879. };
  13880. Transition.prototype.onTweenComplete = function (tweener) {
  13881. var item = tweener.target;
  13882. item.tweener = null;
  13883. this._totalTasks--;
  13884. if (tweener.allCompleted)
  13885. this.callHook(item, true);
  13886. this.checkAllComplete();
  13887. };
  13888. Transition.prototype.onPlayTransCompleted = function (item) {
  13889. this._totalTasks--;
  13890. this.checkAllComplete();
  13891. };
  13892. Transition.prototype.callHook = function (item, tweenEnd) {
  13893. if (tweenEnd) {
  13894. if (item.tweenConfig && item.tweenConfig.endHook != null)
  13895. item.tweenConfig.endHook(item.label);
  13896. }
  13897. else {
  13898. if (item.time >= this._startTime && item.hook != null)
  13899. item.hook(item.label);
  13900. }
  13901. };
  13902. Transition.prototype.checkAllComplete = function () {
  13903. if (this._playing && this._totalTasks == 0) {
  13904. if (this._totalTimes < 0) {
  13905. this.internalPlay();
  13906. if (this._totalTasks == 0)
  13907. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  13908. }
  13909. else {
  13910. this._totalTimes--;
  13911. if (this._totalTimes > 0) {
  13912. this.internalPlay();
  13913. if (this._totalTasks == 0)
  13914. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  13915. }
  13916. else {
  13917. this._playing = false;
  13918. var cnt = this._items.length;
  13919. for (var i = 0; i < cnt; i++) {
  13920. var item = this._items[i];
  13921. if (item.target && item.displayLockToken != 0) {
  13922. item.target.releaseDisplayLock(item.displayLockToken);
  13923. item.displayLockToken = 0;
  13924. }
  13925. }
  13926. if (this._onComplete != null) {
  13927. var func = this._onComplete;
  13928. this._onComplete = null;
  13929. func();
  13930. }
  13931. }
  13932. }
  13933. }
  13934. };
  13935. Transition.prototype.applyValue = function (item) {
  13936. item.target._gearLocked = true;
  13937. var value = item.value;
  13938. switch (item.type) {
  13939. case ActionType.XY:
  13940. if (item.target == this._owner) {
  13941. if (value.b1 && value.b2)
  13942. item.target.setPosition(value.f1 + this._ownerBaseX, value.f2 + this._ownerBaseY);
  13943. else if (value.b1)
  13944. item.target.x = value.f1 + this._ownerBaseX;
  13945. else
  13946. item.target.y = value.f2 + this._ownerBaseY;
  13947. }
  13948. else {
  13949. if (value.b3) {
  13950. if (value.b1 && value.b2)
  13951. item.target.setPosition(value.f1 * this._owner.width, value.f2 * this._owner.height);
  13952. else if (value.b1)
  13953. item.target.x = value.f1 * this._owner.width;
  13954. else if (value.b2)
  13955. item.target.y = value.f2 * this._owner.height;
  13956. }
  13957. else {
  13958. if (value.b1 && value.b2)
  13959. item.target.setPosition(value.f1, value.f2);
  13960. else if (value.b1)
  13961. item.target.x = value.f1;
  13962. else if (value.b2)
  13963. item.target.y = value.f2;
  13964. }
  13965. }
  13966. break;
  13967. case ActionType.Size:
  13968. if (!value.b1)
  13969. value.f1 = item.target.width;
  13970. if (!value.b2)
  13971. value.f2 = item.target.height;
  13972. item.target.setSize(value.f1, value.f2);
  13973. break;
  13974. case ActionType.Pivot:
  13975. item.target.setPivot(value.f1, value.f2, item.target.pivotAsAnchor);
  13976. break;
  13977. case ActionType.Alpha:
  13978. item.target.alpha = value.f1;
  13979. break;
  13980. case ActionType.Rotation:
  13981. item.target.rotation = value.f1;
  13982. break;
  13983. case ActionType.Scale:
  13984. item.target.setScale(value.f1, value.f2);
  13985. break;
  13986. case ActionType.Skew:
  13987. item.target.setSkew(value.f1, value.f2);
  13988. break;
  13989. case ActionType.Color:
  13990. var color = item.target.getProp(fgui.ObjectPropID.Color);
  13991. if (color instanceof cc.Color) {
  13992. var i = Math.floor(value.f1);
  13993. color.setR((i >> 16) & 0xFF).setG((i >> 8) & 0xFF).setB(i & 0xFF);
  13994. item.target.setProp(fgui.ObjectPropID.Color, color);
  13995. }
  13996. break;
  13997. case ActionType.Animation:
  13998. if (value.frame >= 0)
  13999. item.target.setProp(fgui.ObjectPropID.Frame, value.frame);
  14000. item.target.setProp(fgui.ObjectPropID.Playing, value.playing);
  14001. item.target.setProp(fgui.ObjectPropID.TimeScale, this._timeScale);
  14002. break;
  14003. case ActionType.Visible:
  14004. item.target.visible = value.visible;
  14005. break;
  14006. case ActionType.Transition:
  14007. if (this._playing) {
  14008. var trans = value.trans;
  14009. if (trans) {
  14010. this._totalTasks++;
  14011. var startTime = this._startTime > item.time ? (this._startTime - item.time) : 0;
  14012. var endTime = this._endTime >= 0 ? (this._endTime - item.time) : -1;
  14013. if (value.stopTime >= 0 && (endTime < 0 || endTime > value.stopTime))
  14014. endTime = value.stopTime;
  14015. trans.timeScale = this._timeScale;
  14016. trans._play(function () { this.onPlayTransCompleted(item); }.bind(this), value.playTimes, 0, startTime, endTime, this._reversed);
  14017. }
  14018. }
  14019. break;
  14020. case ActionType.Sound:
  14021. if (this._playing && item.time >= this._startTime) {
  14022. if (value.audioClip == null) {
  14023. var pi = fgui.UIPackage.getItemByURL(value.sound);
  14024. if (pi)
  14025. value.audioClip = pi.owner.getItemAsset(pi);
  14026. }
  14027. if (value.audioClip)
  14028. fgui.GRoot.inst.playOneShotSound(value.audioClip, value.volume);
  14029. }
  14030. break;
  14031. case ActionType.Shake:
  14032. item.target.setPosition(item.target.x - value.lastOffsetX + value.offsetX, item.target.y - value.lastOffsetY + value.offsetY);
  14033. value.lastOffsetX = value.offsetX;
  14034. value.lastOffsetY = value.offsetY;
  14035. break;
  14036. case ActionType.ColorFilter:
  14037. {
  14038. break;
  14039. }
  14040. case ActionType.Text:
  14041. item.target.text = value.text;
  14042. break;
  14043. case ActionType.Icon:
  14044. item.target.icon = value.text;
  14045. break;
  14046. }
  14047. item.target._gearLocked = false;
  14048. };
  14049. Transition.prototype.setup = function (buffer) {
  14050. this.name = buffer.readS();
  14051. this._options = buffer.readInt();
  14052. this._autoPlay = buffer.readBool();
  14053. this._autoPlayTimes = buffer.readInt();
  14054. this._autoPlayDelay = buffer.readFloat();
  14055. var cnt = buffer.readShort();
  14056. for (var i = 0; i < cnt; i++) {
  14057. var dataLen = buffer.readShort();
  14058. var curPos = buffer.position;
  14059. buffer.seek(curPos, 0);
  14060. var item = new Item(buffer.readByte());
  14061. this._items[i] = item;
  14062. item.time = buffer.readFloat();
  14063. var targetId = buffer.readShort();
  14064. if (targetId < 0)
  14065. item.targetId = "";
  14066. else
  14067. item.targetId = this._owner.getChildAt(targetId).id;
  14068. item.label = buffer.readS();
  14069. if (buffer.readBool()) {
  14070. buffer.seek(curPos, 1);
  14071. item.tweenConfig = new TweenConfig();
  14072. item.tweenConfig.duration = buffer.readFloat();
  14073. if (item.time + item.tweenConfig.duration > this._totalDuration)
  14074. this._totalDuration = item.time + item.tweenConfig.duration;
  14075. item.tweenConfig.easeType = buffer.readByte();
  14076. item.tweenConfig.repeat = buffer.readInt();
  14077. item.tweenConfig.yoyo = buffer.readBool();
  14078. item.tweenConfig.endLabel = buffer.readS();
  14079. buffer.seek(curPos, 2);
  14080. this.decodeValue(item, buffer, item.tweenConfig.startValue);
  14081. buffer.seek(curPos, 3);
  14082. this.decodeValue(item, buffer, item.tweenConfig.endValue);
  14083. if (buffer.version >= 2) {
  14084. var pathLen = buffer.readInt();
  14085. if (pathLen > 0) {
  14086. item.tweenConfig.path = new fgui.GPath();
  14087. var pts = new Array();
  14088. for (var j = 0; j < pathLen; j++) {
  14089. var curveType = buffer.readByte();
  14090. switch (curveType) {
  14091. case fgui.CurveType.Bezier:
  14092. pts.push(fgui.GPathPoint.newBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  14093. break;
  14094. case fgui.CurveType.CubicBezier:
  14095. pts.push(fgui.GPathPoint.newCubicBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  14096. break;
  14097. default:
  14098. pts.push(fgui.GPathPoint.newPoint(buffer.readFloat(), buffer.readFloat(), curveType));
  14099. break;
  14100. }
  14101. }
  14102. item.tweenConfig.path.create(pts);
  14103. }
  14104. }
  14105. }
  14106. else {
  14107. if (item.time > this._totalDuration)
  14108. this._totalDuration = item.time;
  14109. buffer.seek(curPos, 2);
  14110. this.decodeValue(item, buffer, item.value);
  14111. }
  14112. buffer.position = curPos + dataLen;
  14113. }
  14114. };
  14115. Transition.prototype.decodeValue = function (item, buffer, value) {
  14116. switch (item.type) {
  14117. case ActionType.XY:
  14118. case ActionType.Size:
  14119. case ActionType.Pivot:
  14120. case ActionType.Skew:
  14121. value.b1 = buffer.readBool();
  14122. value.b2 = buffer.readBool();
  14123. value.f1 = buffer.readFloat();
  14124. value.f2 = buffer.readFloat();
  14125. if (buffer.version >= 2 && item.type == ActionType.XY)
  14126. value.b3 = buffer.readBool();
  14127. break;
  14128. case ActionType.Alpha:
  14129. case ActionType.Rotation:
  14130. value.f1 = buffer.readFloat();
  14131. break;
  14132. case ActionType.Scale:
  14133. value.f1 = buffer.readFloat();
  14134. value.f2 = buffer.readFloat();
  14135. break;
  14136. case ActionType.Color:
  14137. var color = buffer.readColor();
  14138. value.f1 = (color.getR() << 16) + (color.getG() << 8) + color.getB();
  14139. break;
  14140. case ActionType.Animation:
  14141. value.playing = buffer.readBool();
  14142. value.frame = buffer.readInt();
  14143. break;
  14144. case ActionType.Visible:
  14145. value.visible = buffer.readBool();
  14146. break;
  14147. case ActionType.Sound:
  14148. value.sound = buffer.readS();
  14149. value.volume = buffer.readFloat();
  14150. break;
  14151. case ActionType.Transition:
  14152. value.transName = buffer.readS();
  14153. value.playTimes = buffer.readInt();
  14154. break;
  14155. case ActionType.Shake:
  14156. value.amplitude = buffer.readFloat();
  14157. value.duration = buffer.readFloat();
  14158. break;
  14159. case ActionType.ColorFilter:
  14160. value.f1 = buffer.readFloat();
  14161. value.f2 = buffer.readFloat();
  14162. value.f3 = buffer.readFloat();
  14163. value.f4 = buffer.readFloat();
  14164. break;
  14165. case ActionType.Text:
  14166. case ActionType.Icon:
  14167. value.text = buffer.readS();
  14168. break;
  14169. }
  14170. };
  14171. return Transition;
  14172. }());
  14173. fgui.Transition = Transition;
  14174. var OPTION_IGNORE_DISPLAY_CONTROLLER = 1;
  14175. var OPTION_AUTO_STOP_DISABLED = 2;
  14176. var OPTION_AUTO_STOP_AT_END = 4;
  14177. var ActionType;
  14178. (function (ActionType) {
  14179. ActionType[ActionType["XY"] = 0] = "XY";
  14180. ActionType[ActionType["Size"] = 1] = "Size";
  14181. ActionType[ActionType["Scale"] = 2] = "Scale";
  14182. ActionType[ActionType["Pivot"] = 3] = "Pivot";
  14183. ActionType[ActionType["Alpha"] = 4] = "Alpha";
  14184. ActionType[ActionType["Rotation"] = 5] = "Rotation";
  14185. ActionType[ActionType["Color"] = 6] = "Color";
  14186. ActionType[ActionType["Animation"] = 7] = "Animation";
  14187. ActionType[ActionType["Visible"] = 8] = "Visible";
  14188. ActionType[ActionType["Sound"] = 9] = "Sound";
  14189. ActionType[ActionType["Transition"] = 10] = "Transition";
  14190. ActionType[ActionType["Shake"] = 11] = "Shake";
  14191. ActionType[ActionType["ColorFilter"] = 12] = "ColorFilter";
  14192. ActionType[ActionType["Skew"] = 13] = "Skew";
  14193. ActionType[ActionType["Text"] = 14] = "Text";
  14194. ActionType[ActionType["Icon"] = 15] = "Icon";
  14195. ActionType[ActionType["Unknown"] = 16] = "Unknown";
  14196. })(ActionType || (ActionType = {}));
  14197. var Item = (function () {
  14198. function Item(type) {
  14199. this.type = type;
  14200. this.value = {};
  14201. this.displayLockToken = 0;
  14202. }
  14203. return Item;
  14204. }());
  14205. var TweenConfig = (function () {
  14206. function TweenConfig() {
  14207. this.easeType = fgui.EaseType.QuadOut;
  14208. this.startValue = { b1: true, b2: true };
  14209. this.endValue = { b1: true, b2: true };
  14210. }
  14211. return TweenConfig;
  14212. }());
  14213. })(fgui || (fgui = {}));
  14214. (function (fgui) {
  14215. var TranslationHelper = (function () {
  14216. function TranslationHelper() {
  14217. }
  14218. TranslationHelper.loadFromXML = function (source) {
  14219. var strings = {};
  14220. TranslationHelper.strings = strings;
  14221. var xml = new cc["SAXParser"]().parse(source).documentElement;
  14222. var nodes = xml.childNodes;
  14223. var length1 = nodes.length;
  14224. for (var i1 = 0; i1 < length1; i1++) {
  14225. var cxml = nodes[i1];
  14226. if (cxml.tagName == "string") {
  14227. var key = cxml.getAttribute("name");
  14228. var text = cxml.childNodes.length > 0 ? cxml.firstChild.nodeValue : "";
  14229. var i = key.indexOf("-");
  14230. if (i == -1)
  14231. continue;
  14232. var key2 = key.substr(0, i);
  14233. var key3 = key.substr(i + 1);
  14234. var col = strings[key2];
  14235. if (!col) {
  14236. col = {};
  14237. strings[key2] = col;
  14238. }
  14239. col[key3] = text;
  14240. }
  14241. }
  14242. };
  14243. TranslationHelper.translateComponent = function (item) {
  14244. if (TranslationHelper.strings == null)
  14245. return;
  14246. var compStrings = TranslationHelper.strings[item.owner.id + item.id];
  14247. if (compStrings == null)
  14248. return;
  14249. var elementId, value;
  14250. var buffer = item.rawData;
  14251. var nextPos;
  14252. var itemCount;
  14253. var i, j, k;
  14254. var dataLen;
  14255. var curPos;
  14256. var valueCnt;
  14257. var page;
  14258. buffer.seek(0, 2);
  14259. var childCount = buffer.readShort();
  14260. for (i = 0; i < childCount; i++) {
  14261. dataLen = buffer.readShort();
  14262. curPos = buffer.position;
  14263. buffer.seek(curPos, 0);
  14264. var baseType = buffer.readByte();
  14265. var type = baseType;
  14266. buffer.skip(4);
  14267. elementId = buffer.readS();
  14268. if (type == fgui.ObjectType.Component) {
  14269. if (buffer.seek(curPos, 6))
  14270. type = buffer.readByte();
  14271. }
  14272. buffer.seek(curPos, 1);
  14273. if ((value = compStrings[elementId + "-tips"]) != null)
  14274. buffer.writeS(value);
  14275. buffer.seek(curPos, 2);
  14276. var gearCnt = buffer.readShort();
  14277. for (j = 0; j < gearCnt; j++) {
  14278. nextPos = buffer.readShort();
  14279. nextPos += buffer.position;
  14280. if (buffer.readByte() == 6) {
  14281. buffer.skip(2);
  14282. valueCnt = buffer.readShort();
  14283. for (k = 0; k < valueCnt; k++) {
  14284. page = buffer.readS();
  14285. if (page != null) {
  14286. if ((value = compStrings[elementId + "-texts_" + k]) != null)
  14287. buffer.writeS(value);
  14288. else
  14289. buffer.skip(2);
  14290. }
  14291. }
  14292. if (buffer.readBool() && (value = compStrings[elementId + "-texts_def"]) != null)
  14293. buffer.writeS(value);
  14294. }
  14295. buffer.position = nextPos;
  14296. }
  14297. if (baseType == fgui.ObjectType.Component && buffer.version >= 2) {
  14298. buffer.seek(curPos, 4);
  14299. buffer.skip(2);
  14300. buffer.skip(4 * buffer.readShort());
  14301. var cpCount = buffer.readShort();
  14302. for (var k = 0; k < cpCount; k++) {
  14303. var target = buffer.readS();
  14304. var propertyId = buffer.readShort();
  14305. if (propertyId == 0 && (value = compStrings[elementId + "-cp-" + target]) != null)
  14306. buffer.writeS(value);
  14307. else
  14308. buffer.skip(2);
  14309. }
  14310. }
  14311. switch (type) {
  14312. case fgui.ObjectType.Text:
  14313. case fgui.ObjectType.RichText:
  14314. case fgui.ObjectType.InputText:
  14315. {
  14316. if ((value = compStrings[elementId]) != null) {
  14317. buffer.seek(curPos, 6);
  14318. buffer.writeS(value);
  14319. }
  14320. if ((value = compStrings[elementId + "-prompt"]) != null) {
  14321. buffer.seek(curPos, 4);
  14322. buffer.writeS(value);
  14323. }
  14324. break;
  14325. }
  14326. case fgui.ObjectType.List:
  14327. case fgui.ObjectType.Tree:
  14328. {
  14329. buffer.seek(curPos, 8);
  14330. buffer.skip(2);
  14331. itemCount = buffer.readShort();
  14332. for (j = 0; j < itemCount; j++) {
  14333. nextPos = buffer.readShort();
  14334. nextPos += buffer.position;
  14335. buffer.skip(2);
  14336. if (type == fgui.ObjectType.Tree)
  14337. buffer.skip(2);
  14338. if ((value = compStrings[elementId + "-" + j]) != null)
  14339. buffer.writeS(value);
  14340. else
  14341. buffer.skip(2);
  14342. if ((value = compStrings[elementId + "-" + j + "-0"]) != null)
  14343. buffer.writeS(value);
  14344. else
  14345. buffer.skip(2);
  14346. if (buffer.version >= 2) {
  14347. buffer.skip(6);
  14348. buffer.skip(buffer.readUshort() * 4);
  14349. var cpCount = buffer.readUshort();
  14350. for (var k = 0; k < cpCount; k++) {
  14351. var target = buffer.readS();
  14352. var propertyId = buffer.readUshort();
  14353. if (propertyId == 0 && (value = compStrings[elementId + "-" + j + "-" + target]) != null)
  14354. buffer.writeS(value);
  14355. else
  14356. buffer.skip(2);
  14357. }
  14358. }
  14359. buffer.position = nextPos;
  14360. }
  14361. break;
  14362. }
  14363. case fgui.ObjectType.Label:
  14364. {
  14365. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14366. if ((value = compStrings[elementId]) != null)
  14367. buffer.writeS(value);
  14368. else
  14369. buffer.skip(2);
  14370. buffer.skip(2);
  14371. if (buffer.readBool())
  14372. buffer.skip(4);
  14373. buffer.skip(4);
  14374. if (buffer.readBool() && (value = compStrings[elementId + "-prompt"]) != null)
  14375. buffer.writeS(value);
  14376. }
  14377. break;
  14378. }
  14379. case fgui.ObjectType.Button:
  14380. {
  14381. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14382. if ((value = compStrings[elementId]) != null)
  14383. buffer.writeS(value);
  14384. else
  14385. buffer.skip(2);
  14386. if ((value = compStrings[elementId + "-0"]) != null)
  14387. buffer.writeS(value);
  14388. }
  14389. break;
  14390. }
  14391. case fgui.ObjectType.ComboBox:
  14392. {
  14393. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14394. itemCount = buffer.readShort();
  14395. for (j = 0; j < itemCount; j++) {
  14396. nextPos = buffer.readShort();
  14397. nextPos += buffer.position;
  14398. if ((value = compStrings[elementId + "-" + j]) != null)
  14399. buffer.writeS(value);
  14400. buffer.position = nextPos;
  14401. }
  14402. if ((value = compStrings[elementId]) != null)
  14403. buffer.writeS(value);
  14404. }
  14405. break;
  14406. }
  14407. }
  14408. buffer.position = curPos + dataLen;
  14409. }
  14410. };
  14411. return TranslationHelper;
  14412. }());
  14413. fgui.TranslationHelper = TranslationHelper;
  14414. })(fgui || (fgui = {}));
  14415. (function (fgui) {
  14416. var UIConfig = (function () {
  14417. function UIConfig() {
  14418. }
  14419. UIConfig.defaultFont = "Arial";
  14420. UIConfig.modalLayerColor = new cc.Color(0x33, 0x33, 0x33, 0x33);
  14421. UIConfig.buttonSoundVolumeScale = 1;
  14422. UIConfig.defaultScrollStep = 25;
  14423. UIConfig.defaultScrollDecelerationRate = 0.967;
  14424. UIConfig.defaultScrollBarDisplay = fgui.ScrollBarDisplayType.Visible;
  14425. UIConfig.defaultScrollTouchEffect = true;
  14426. UIConfig.defaultScrollBounceEffect = true;
  14427. UIConfig.defaultComboBoxVisibleItemCount = 10;
  14428. UIConfig.touchScrollSensitivity = 20;
  14429. UIConfig.touchDragSensitivity = 10;
  14430. UIConfig.clickDragSensitivity = 2;
  14431. UIConfig.bringWindowToFrontOnClick = true;
  14432. UIConfig.frameTimeForAsyncUIConstruction = 0.002;
  14433. UIConfig.linkUnderline = true;
  14434. UIConfig.defaultUIGroup = "UI";
  14435. return UIConfig;
  14436. }());
  14437. fgui.UIConfig = UIConfig;
  14438. function addLoadHandler(ext) {
  14439. }
  14440. fgui.addLoadHandler = addLoadHandler;
  14441. ;
  14442. var _fontRegistry = {};
  14443. function registerFont(name, font) {
  14444. if (font instanceof cc.Font)
  14445. _fontRegistry[name] = font;
  14446. else
  14447. _fontRegistry[name] = cc.loader.getRes(name, cc.Font);
  14448. }
  14449. fgui.registerFont = registerFont;
  14450. ;
  14451. function getFontByName(name) {
  14452. return _fontRegistry[name];
  14453. }
  14454. fgui.getFontByName = getFontByName;
  14455. })(fgui || (fgui = {}));
  14456. (function (fgui) {
  14457. var UIObjectFactory = (function () {
  14458. function UIObjectFactory() {
  14459. }
  14460. UIObjectFactory.setExtension = function (url, type) {
  14461. if (url == null)
  14462. throw new Error("Invaild url: " + url);
  14463. var pi = fgui.UIPackage.getItemByURL(url);
  14464. if (pi)
  14465. pi.extensionType = type;
  14466. UIObjectFactory.extensions[url] = type;
  14467. };
  14468. UIObjectFactory.setLoaderExtension = function (type) {
  14469. UIObjectFactory.loaderType = type;
  14470. };
  14471. UIObjectFactory.resolveExtension = function (pi) {
  14472. var extensionType = UIObjectFactory.extensions["ui://" + pi.owner.id + pi.id];
  14473. if (!extensionType)
  14474. extensionType = UIObjectFactory.extensions["ui://" + pi.owner.name + "/" + pi.name];
  14475. if (extensionType)
  14476. pi.extensionType = extensionType;
  14477. };
  14478. UIObjectFactory.newObject = function (type, userClass) {
  14479. var obj;
  14480. UIObjectFactory.counter++;
  14481. if (typeof type === 'number') {
  14482. switch (type) {
  14483. case fgui.ObjectType.Image:
  14484. return new fgui.GImage();
  14485. case fgui.ObjectType.MovieClip:
  14486. return new fgui.GMovieClip();
  14487. case fgui.ObjectType.Component:
  14488. return new fgui.GComponent();
  14489. case fgui.ObjectType.Text:
  14490. return new fgui.GTextField();
  14491. case fgui.ObjectType.RichText:
  14492. return new fgui.GRichTextField();
  14493. case fgui.ObjectType.InputText:
  14494. return new fgui.GTextInput();
  14495. case fgui.ObjectType.Group:
  14496. return new fgui.GGroup();
  14497. case fgui.ObjectType.List:
  14498. return new fgui.GList();
  14499. case fgui.ObjectType.Graph:
  14500. return new fgui.GGraph();
  14501. case fgui.ObjectType.Loader:
  14502. if (UIObjectFactory.loaderType)
  14503. return new UIObjectFactory.loaderType();
  14504. else
  14505. return new fgui.GLoader();
  14506. case fgui.ObjectType.Button:
  14507. return new fgui.GButton();
  14508. case fgui.ObjectType.Label:
  14509. return new fgui.GLabel();
  14510. case fgui.ObjectType.ProgressBar:
  14511. return new fgui.GProgressBar();
  14512. case fgui.ObjectType.Slider:
  14513. return new fgui.GSlider();
  14514. case fgui.ObjectType.ScrollBar:
  14515. return new fgui.GScrollBar();
  14516. case fgui.ObjectType.ComboBox:
  14517. return new fgui.GComboBox();
  14518. case fgui.ObjectType.Tree:
  14519. return new fgui.GTree();
  14520. case fgui.ObjectType.Loader3D:
  14521. return new fgui.GLoader3D();
  14522. default:
  14523. return null;
  14524. }
  14525. }
  14526. else {
  14527. if (type.type == fgui.PackageItemType.Component) {
  14528. if (userClass)
  14529. obj = new userClass();
  14530. else if (type.extensionType)
  14531. obj = new type.extensionType();
  14532. else
  14533. obj = UIObjectFactory.newObject(type.objectType);
  14534. }
  14535. else
  14536. obj = UIObjectFactory.newObject(type.objectType);
  14537. if (obj)
  14538. obj.packageItem = type;
  14539. }
  14540. return obj;
  14541. };
  14542. UIObjectFactory.counter = 0;
  14543. UIObjectFactory.extensions = {};
  14544. return UIObjectFactory;
  14545. }());
  14546. fgui.UIObjectFactory = UIObjectFactory;
  14547. })(fgui || (fgui = {}));
  14548. (function (fgui) {
  14549. var _a;
  14550. var UIPackage = (function () {
  14551. function UIPackage() {
  14552. this._items = [];
  14553. this._itemsById = {};
  14554. this._itemsByName = {};
  14555. this._sprites = {};
  14556. this._dependencies = [];
  14557. this._branches = [];
  14558. this._branchIndex = -1;
  14559. }
  14560. Object.defineProperty(UIPackage, "branch", {
  14561. get: function () {
  14562. return UIPackage._branch;
  14563. },
  14564. set: function (value) {
  14565. UIPackage._branch = value;
  14566. for (var pkgId in UIPackage._instById) {
  14567. var pkg = UIPackage._instById[pkgId];
  14568. if (pkg._branches) {
  14569. pkg._branchIndex = pkg._branches.indexOf(value);
  14570. }
  14571. }
  14572. },
  14573. enumerable: false,
  14574. configurable: true
  14575. });
  14576. UIPackage.getVar = function (key) {
  14577. return UIPackage._vars[key];
  14578. };
  14579. UIPackage.setVar = function (key, value) {
  14580. UIPackage._vars[key] = value;
  14581. };
  14582. UIPackage.getById = function (id) {
  14583. return UIPackage._instById[id];
  14584. };
  14585. UIPackage.getByName = function (name) {
  14586. return UIPackage._instByName[name];
  14587. };
  14588. UIPackage.addPackage = function (path) {
  14589. var pkg = UIPackage._instById[path];
  14590. if (pkg)
  14591. return pkg;
  14592. var asset = cc.resources.get(path, cc.BufferAsset);
  14593. if (!asset)
  14594. throw "Resource '" + path + "' not ready";
  14595. if (!asset._buffer)
  14596. throw "Missing asset data.";
  14597. pkg = new UIPackage();
  14598. pkg._bundle = cc.resources;
  14599. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  14600. UIPackage._instById[pkg.id] = pkg;
  14601. UIPackage._instByName[pkg.name] = pkg;
  14602. UIPackage._instById[pkg._path] = pkg;
  14603. return pkg;
  14604. };
  14605. UIPackage.loadPackage = function () {
  14606. var args = [];
  14607. for (var _i = 0; _i < arguments.length; _i++) {
  14608. args[_i] = arguments[_i];
  14609. }
  14610. var path;
  14611. var onProgress;
  14612. var onComplete;
  14613. var bundle;
  14614. if (args[0] instanceof cc.AssetManager.Bundle) {
  14615. bundle = args[0];
  14616. path = args[1];
  14617. if (args.length > 3) {
  14618. onProgress = args[2];
  14619. onComplete = args[3];
  14620. }
  14621. else
  14622. onComplete = args[2];
  14623. }
  14624. else {
  14625. path = args[0];
  14626. if (args.length > 2) {
  14627. onProgress = args[1];
  14628. onComplete = args[2];
  14629. }
  14630. else
  14631. onComplete = args[1];
  14632. }
  14633. bundle = bundle || cc.resources;
  14634. bundle.load(path, cc.BufferAsset, onProgress, function (err, asset) {
  14635. if (err) {
  14636. if (onComplete != null)
  14637. onComplete(err, null);
  14638. return;
  14639. }
  14640. var pkg = new UIPackage();
  14641. pkg._bundle = bundle;
  14642. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  14643. var cnt = pkg._items.length;
  14644. var urls = [];
  14645. var types = [];
  14646. for (var i = 0; i < cnt; i++) {
  14647. var pi = pkg._items[i];
  14648. if (pi.type == fgui.PackageItemType.Atlas || pi.type == fgui.PackageItemType.Sound) {
  14649. var assetType = ItemTypeToAssetType[pi.type];
  14650. urls.push(pi.file);
  14651. types.push(assetType);
  14652. }
  14653. }
  14654. var total = urls.length;
  14655. var lastErr;
  14656. var taskComplete = function (err) {
  14657. total--;
  14658. if (err)
  14659. lastErr = err;
  14660. if (total <= 0) {
  14661. UIPackage._instById[pkg.id] = pkg;
  14662. UIPackage._instByName[pkg.name] = pkg;
  14663. if (pkg._path)
  14664. UIPackage._instById[pkg._path] = pkg;
  14665. if (onComplete != null)
  14666. onComplete(lastErr, pkg);
  14667. }
  14668. };
  14669. if (total > 0) {
  14670. urls.forEach(function (url, index) {
  14671. bundle.load(url, types[index], onProgress, taskComplete);
  14672. });
  14673. }
  14674. else
  14675. taskComplete();
  14676. });
  14677. };
  14678. UIPackage.removeAllPackage = function () {
  14679. for (let key in UIPackage._instById) {
  14680. UIPackage._instById[key].dispose();
  14681. }
  14682. UIPackage._instById = {};
  14683. UIPackage._instByName = {};
  14684. };
  14685. UIPackage.removePackage = function (packageIdOrName) {
  14686. var pkg = UIPackage._instById[packageIdOrName];
  14687. if (!pkg)
  14688. pkg = UIPackage._instByName[packageIdOrName];
  14689. if (!pkg)
  14690. throw "No package found: " + packageIdOrName;
  14691. pkg.dispose();
  14692. delete UIPackage._instById[pkg.id];
  14693. delete UIPackage._instByName[pkg.name];
  14694. if (pkg._path)
  14695. delete UIPackage._instById[pkg._path];
  14696. };
  14697. UIPackage.createObject = function (pkgName, resName, userClass) {
  14698. var pkg = UIPackage.getByName(pkgName);
  14699. if (pkg)
  14700. return pkg.createObject(resName, userClass);
  14701. else
  14702. return null;
  14703. };
  14704. UIPackage.createObjectFromURL = function (url, userClass) {
  14705. var pi = UIPackage.getItemByURL(url);
  14706. if (pi)
  14707. return pi.owner.internalCreateObject(pi, userClass);
  14708. else
  14709. return null;
  14710. };
  14711. UIPackage.getItemURL = function (pkgName, resName) {
  14712. var pkg = UIPackage.getByName(pkgName);
  14713. if (!pkg)
  14714. return null;
  14715. var pi = pkg._itemsByName[resName];
  14716. if (!pi)
  14717. return null;
  14718. return "ui://" + pkg.id + pi.id;
  14719. };
  14720. UIPackage.getItemByURL = function (url) {
  14721. var pos1 = url.indexOf("//");
  14722. if (pos1 == -1)
  14723. return null;
  14724. var pos2 = url.indexOf("/", pos1 + 2);
  14725. if (pos2 == -1) {
  14726. if (url.length > 13) {
  14727. var pkgId = url.substr(5, 8);
  14728. var pkg = UIPackage.getById(pkgId);
  14729. if (pkg != null) {
  14730. var srcId = url.substr(13);
  14731. return pkg.getItemById(srcId);
  14732. }
  14733. }
  14734. }
  14735. else {
  14736. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  14737. pkg = UIPackage.getByName(pkgName);
  14738. if (pkg != null) {
  14739. var srcName = url.substr(pos2 + 1);
  14740. return pkg.getItemByName(srcName);
  14741. }
  14742. }
  14743. return null;
  14744. };
  14745. UIPackage.normalizeURL = function (url) {
  14746. if (url == null)
  14747. return null;
  14748. var pos1 = url.indexOf("//");
  14749. if (pos1 == -1)
  14750. return null;
  14751. var pos2 = url.indexOf("/", pos1 + 2);
  14752. if (pos2 == -1)
  14753. return url;
  14754. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  14755. var srcName = url.substr(pos2 + 1);
  14756. return UIPackage.getItemURL(pkgName, srcName);
  14757. };
  14758. UIPackage.setStringsSource = function (source) {
  14759. fgui.TranslationHelper.loadFromXML(source);
  14760. };
  14761. UIPackage.prototype.loadPackage = function (buffer, path) {
  14762. if (buffer.readUint() != 0x46475549)
  14763. throw "FairyGUI: old package format found in '" + path + "'";
  14764. this._path = path;
  14765. buffer.version = buffer.readInt();
  14766. var ver2 = buffer.version >= 2;
  14767. var compressed = buffer.readBool();
  14768. this._id = buffer.readString();
  14769. this._name = buffer.readString();
  14770. buffer.skip(20);
  14771. var indexTablePos = buffer.position;
  14772. var cnt;
  14773. var i;
  14774. var nextPos;
  14775. var str;
  14776. var branchIncluded;
  14777. buffer.seek(indexTablePos, 4);
  14778. cnt = buffer.readInt();
  14779. var stringTable = new Array(cnt);
  14780. buffer.stringTable = stringTable;
  14781. for (i = 0; i < cnt; i++)
  14782. stringTable[i] = buffer.readString();
  14783. if (buffer.seek(indexTablePos, 5)) {
  14784. cnt = buffer.readInt();
  14785. for (i = 0; i < cnt; i++) {
  14786. var index = buffer.readUshort();
  14787. var len = buffer.readInt();
  14788. stringTable[index] = buffer.readString(len);
  14789. }
  14790. }
  14791. buffer.seek(indexTablePos, 0);
  14792. cnt = buffer.readShort();
  14793. for (i = 0; i < cnt; i++)
  14794. this._dependencies.push({ id: buffer.readS(), name: buffer.readS() });
  14795. if (ver2) {
  14796. cnt = buffer.readShort();
  14797. if (cnt > 0) {
  14798. this._branches = buffer.readSArray(cnt);
  14799. if (UIPackage._branch)
  14800. this._branchIndex = this._branches.indexOf(UIPackage._branch);
  14801. }
  14802. branchIncluded = cnt > 0;
  14803. }
  14804. buffer.seek(indexTablePos, 1);
  14805. var pi;
  14806. var pos = path.lastIndexOf('/');
  14807. var shortPath = pos == -1 ? "" : path.substr(0, pos + 1);
  14808. path = path + "_";
  14809. cnt = buffer.readShort();
  14810. for (i = 0; i < cnt; i++) {
  14811. nextPos = buffer.readInt();
  14812. nextPos += buffer.position;
  14813. pi = new fgui.PackageItem();
  14814. pi.owner = this;
  14815. pi.type = buffer.readByte();
  14816. pi.id = buffer.readS();
  14817. pi.name = buffer.readS();
  14818. buffer.readS();
  14819. pi.file = buffer.readS();
  14820. buffer.readBool();
  14821. pi.width = buffer.readInt();
  14822. pi.height = buffer.readInt();
  14823. switch (pi.type) {
  14824. case fgui.PackageItemType.Image:
  14825. {
  14826. pi.objectType = fgui.ObjectType.Image;
  14827. var scaleOption = buffer.readByte();
  14828. if (scaleOption == 1) {
  14829. pi.scale9Grid = new cc.Rect();
  14830. pi.scale9Grid.x = buffer.readInt();
  14831. pi.scale9Grid.y = buffer.readInt();
  14832. pi.scale9Grid.width = buffer.readInt();
  14833. pi.scale9Grid.height = buffer.readInt();
  14834. pi.tileGridIndice = buffer.readInt();
  14835. }
  14836. else if (scaleOption == 2)
  14837. pi.scaleByTile = true;
  14838. pi.smoothing = buffer.readBool();
  14839. break;
  14840. }
  14841. case fgui.PackageItemType.MovieClip:
  14842. {
  14843. pi.smoothing = buffer.readBool();
  14844. pi.objectType = fgui.ObjectType.MovieClip;
  14845. pi.rawData = buffer.readBuffer();
  14846. break;
  14847. }
  14848. case fgui.PackageItemType.Font:
  14849. {
  14850. pi.rawData = buffer.readBuffer();
  14851. break;
  14852. }
  14853. case fgui.PackageItemType.Component:
  14854. {
  14855. var extension = buffer.readByte();
  14856. if (extension > 0)
  14857. pi.objectType = extension;
  14858. else
  14859. pi.objectType = fgui.ObjectType.Component;
  14860. pi.rawData = buffer.readBuffer();
  14861. fgui.UIObjectFactory.resolveExtension(pi);
  14862. break;
  14863. }
  14864. case fgui.PackageItemType.Atlas:
  14865. case fgui.PackageItemType.Sound:
  14866. case fgui.PackageItemType.Misc:
  14867. {
  14868. pi.file = path + cc.path.mainFileName(pi.file);
  14869. break;
  14870. }
  14871. case fgui.PackageItemType.Spine:
  14872. case fgui.PackageItemType.DragonBones:
  14873. {
  14874. pi.file = shortPath + cc.path.mainFileName(pi.file);
  14875. pi.skeletonAnchor = new cc.Vec2();
  14876. pi.skeletonAnchor.x = buffer.readFloat();
  14877. pi.skeletonAnchor.y = buffer.readFloat();
  14878. break;
  14879. }
  14880. }
  14881. if (ver2) {
  14882. str = buffer.readS();
  14883. if (str)
  14884. pi.name = str + "/" + pi.name;
  14885. var branchCnt = buffer.readUbyte();
  14886. if (branchCnt > 0) {
  14887. if (branchIncluded)
  14888. pi.branches = buffer.readSArray(branchCnt);
  14889. else
  14890. this._itemsById[buffer.readS()] = pi;
  14891. }
  14892. var highResCnt = buffer.readUbyte();
  14893. if (highResCnt > 0)
  14894. pi.highResolution = buffer.readSArray(highResCnt);
  14895. }
  14896. this._items.push(pi);
  14897. this._itemsById[pi.id] = pi;
  14898. if (pi.name != null)
  14899. this._itemsByName[pi.name] = pi;
  14900. buffer.position = nextPos;
  14901. }
  14902. buffer.seek(indexTablePos, 2);
  14903. cnt = buffer.readShort();
  14904. for (i = 0; i < cnt; i++) {
  14905. nextPos = buffer.readShort();
  14906. nextPos += buffer.position;
  14907. var itemId = buffer.readS();
  14908. pi = this._itemsById[buffer.readS()];
  14909. var rect = new cc.Rect();
  14910. rect.x = buffer.readInt();
  14911. rect.y = buffer.readInt();
  14912. rect.width = buffer.readInt();
  14913. rect.height = buffer.readInt();
  14914. var sprite = { atlas: pi, rect: rect, offset: new cc.Vec2(), originalSize: new cc.Size(0, 0) };
  14915. sprite.rotated = buffer.readBool();
  14916. if (ver2 && buffer.readBool()) {
  14917. sprite.offset.x = buffer.readInt();
  14918. sprite.offset.y = buffer.readInt();
  14919. sprite.originalSize.width = buffer.readInt();
  14920. sprite.originalSize.height = buffer.readInt();
  14921. }
  14922. else {
  14923. sprite.originalSize.width = sprite.rect.width;
  14924. sprite.originalSize.height = sprite.rect.height;
  14925. }
  14926. this._sprites[itemId] = sprite;
  14927. buffer.position = nextPos;
  14928. }
  14929. if (buffer.seek(indexTablePos, 3)) {
  14930. cnt = buffer.readShort();
  14931. for (i = 0; i < cnt; i++) {
  14932. nextPos = buffer.readInt();
  14933. nextPos += buffer.position;
  14934. pi = this._itemsById[buffer.readS()];
  14935. if (pi && pi.type == fgui.PackageItemType.Image)
  14936. pi.hitTestData = new fgui.PixelHitTestData(buffer);
  14937. buffer.position = nextPos;
  14938. }
  14939. }
  14940. };
  14941. UIPackage.prototype.dispose = function () {
  14942. var cnt = this._items.length;
  14943. for (var i = 0; i < cnt; i++) {
  14944. var pi = this._items[i];
  14945. if (pi.asset)
  14946. cc.assetManager.releaseAsset(pi.asset);
  14947. }
  14948. };
  14949. Object.defineProperty(UIPackage.prototype, "id", {
  14950. get: function () {
  14951. return this._id;
  14952. },
  14953. enumerable: false,
  14954. configurable: true
  14955. });
  14956. Object.defineProperty(UIPackage.prototype, "name", {
  14957. get: function () {
  14958. return this._name;
  14959. },
  14960. enumerable: false,
  14961. configurable: true
  14962. });
  14963. Object.defineProperty(UIPackage.prototype, "path", {
  14964. get: function () {
  14965. return this._path;
  14966. },
  14967. enumerable: false,
  14968. configurable: true
  14969. });
  14970. Object.defineProperty(UIPackage.prototype, "dependencies", {
  14971. get: function () {
  14972. return this._dependencies;
  14973. },
  14974. enumerable: false,
  14975. configurable: true
  14976. });
  14977. UIPackage.prototype.createObject = function (resName, userClass) {
  14978. var pi = this._itemsByName[resName];
  14979. if (pi)
  14980. return this.internalCreateObject(pi, userClass);
  14981. else
  14982. return null;
  14983. };
  14984. UIPackage.prototype.internalCreateObject = function (item, userClass) {
  14985. var g = fgui.UIObjectFactory.newObject(item, userClass);
  14986. if (g == null)
  14987. return null;
  14988. UIPackage._constructing++;
  14989. g.constructFromResource();
  14990. UIPackage._constructing--;
  14991. return g;
  14992. };
  14993. UIPackage.prototype.getItemById = function (itemId) {
  14994. return this._itemsById[itemId];
  14995. };
  14996. UIPackage.prototype.getItemByName = function (resName) {
  14997. return this._itemsByName[resName];
  14998. };
  14999. UIPackage.prototype.getItemAssetByName = function (resName) {
  15000. var pi = this._itemsByName[resName];
  15001. if (pi == null) {
  15002. throw "Resource not found -" + resName;
  15003. }
  15004. return this.getItemAsset(pi);
  15005. };
  15006. UIPackage.prototype.getItemAsset = function (item) {
  15007. switch (item.type) {
  15008. case fgui.PackageItemType.Image:
  15009. if (!item.decoded) {
  15010. item.decoded = true;
  15011. var sprite = this._sprites[item.id];
  15012. if (sprite) {
  15013. var atlasTexture = this.getItemAsset(sprite.atlas);
  15014. if (atlasTexture) {
  15015. 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);
  15016. if (item.scale9Grid) {
  15017. sf.insetLeft = item.scale9Grid.x;
  15018. sf.insetTop = item.scale9Grid.y;
  15019. sf.insetRight = item.width - item.scale9Grid.xMax;
  15020. sf.insetBottom = item.height - item.scale9Grid.yMax;
  15021. }
  15022. item.asset = sf;
  15023. }
  15024. }
  15025. }
  15026. break;
  15027. case fgui.PackageItemType.Atlas:
  15028. case fgui.PackageItemType.Sound:
  15029. if (!item.decoded) {
  15030. item.decoded = true;
  15031. item.asset = this._bundle.get(item.file, ItemTypeToAssetType[item.type]);
  15032. if (!item.asset)
  15033. console.log("Resource '" + item.file + "' not found");
  15034. }
  15035. break;
  15036. case fgui.PackageItemType.Font:
  15037. if (!item.decoded) {
  15038. item.decoded = true;
  15039. this.loadFont(item);
  15040. }
  15041. break;
  15042. case fgui.PackageItemType.MovieClip:
  15043. if (!item.decoded) {
  15044. item.decoded = true;
  15045. this.loadMovieClip(item);
  15046. }
  15047. break;
  15048. default:
  15049. break;
  15050. }
  15051. return item.asset;
  15052. };
  15053. UIPackage.prototype.getItemAssetAsync = function (item, onComplete) {
  15054. if (item.decoded) {
  15055. onComplete(null, item);
  15056. return;
  15057. }
  15058. if (item.loading) {
  15059. item.loading.push(onComplete);
  15060. return;
  15061. }
  15062. switch (item.type) {
  15063. case fgui.PackageItemType.Spine:
  15064. item.loading = [onComplete];
  15065. this.loadSpine(item);
  15066. break;
  15067. case fgui.PackageItemType.DragonBones:
  15068. item.loading = [onComplete];
  15069. this.loadDragonBones(item);
  15070. break;
  15071. default:
  15072. this.getItemAsset(item);
  15073. onComplete(null, item);
  15074. break;
  15075. }
  15076. };
  15077. UIPackage.prototype.loadAllAssets = function () {
  15078. var cnt = this._items.length;
  15079. for (var i = 0; i < cnt; i++) {
  15080. var pi = this._items[i];
  15081. this.getItemAsset(pi);
  15082. }
  15083. };
  15084. UIPackage.prototype.loadMovieClip = function (item) {
  15085. var buffer = item.rawData;
  15086. buffer.seek(0, 0);
  15087. item.interval = buffer.readInt() / 1000;
  15088. item.swing = buffer.readBool();
  15089. item.repeatDelay = buffer.readInt() / 1000;
  15090. buffer.seek(0, 1);
  15091. var frameCount = buffer.readShort();
  15092. item.frames = Array(frameCount);
  15093. var spriteId;
  15094. var sprite;
  15095. for (var i = 0; i < frameCount; i++) {
  15096. var nextPos = buffer.readShort();
  15097. nextPos += buffer.position;
  15098. var rect = new cc.Rect();
  15099. rect.x = buffer.readInt();
  15100. rect.y = buffer.readInt();
  15101. rect.width = buffer.readInt();
  15102. rect.height = buffer.readInt();
  15103. var addDelay = buffer.readInt() / 1000;
  15104. var frame = { rect: rect, addDelay: addDelay };
  15105. spriteId = buffer.readS();
  15106. if (spriteId != null && (sprite = this._sprites[spriteId]) != null) {
  15107. var atlasTexture = this.getItemAsset(sprite.atlas);
  15108. if (atlasTexture) {
  15109. var sx = item.width / frame.rect.width;
  15110. 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));
  15111. }
  15112. }
  15113. item.frames[i] = frame;
  15114. buffer.position = nextPos;
  15115. }
  15116. };
  15117. UIPackage.prototype.loadFont = function (item) {
  15118. var font = new cc.LabelAtlas();
  15119. item.asset = font;
  15120. font._fntConfig = {
  15121. commonHeight: 0,
  15122. fontSize: 0,
  15123. kerningDict: {},
  15124. fontDefDictionary: {}
  15125. };
  15126. var dict = font._fntConfig.fontDefDictionary;
  15127. var buffer = item.rawData;
  15128. buffer.seek(0, 0);
  15129. var ttf = buffer.readBool();
  15130. var canTint = buffer.readBool();
  15131. var resizable = buffer.readBool();
  15132. buffer.readBool();
  15133. var fontSize = buffer.readInt();
  15134. var xadvance = buffer.readInt();
  15135. var lineHeight = buffer.readInt();
  15136. var mainTexture;
  15137. var mainSprite = this._sprites[item.id];
  15138. if (mainSprite)
  15139. mainTexture = (this.getItemAsset(mainSprite.atlas));
  15140. buffer.seek(0, 1);
  15141. var bg;
  15142. var cnt = buffer.readInt();
  15143. for (var i = 0; i < cnt; i++) {
  15144. var nextPos = buffer.readShort();
  15145. nextPos += buffer.position;
  15146. bg = {};
  15147. var ch = buffer.readUshort();
  15148. dict[ch] = bg;
  15149. var rect = new cc.Rect();
  15150. bg.rect = rect;
  15151. var img = buffer.readS();
  15152. rect.x = buffer.readInt();
  15153. rect.y = buffer.readInt();
  15154. bg.xOffset = buffer.readInt();
  15155. bg.yOffset = buffer.readInt();
  15156. rect.width = buffer.readInt();
  15157. rect.height = buffer.readInt();
  15158. bg.xAdvance = buffer.readInt();
  15159. bg.channel = buffer.readByte();
  15160. if (bg.channel == 1)
  15161. bg.channel = 3;
  15162. else if (bg.channel == 2)
  15163. bg.channel = 2;
  15164. else if (bg.channel == 3)
  15165. bg.channel = 1;
  15166. if (ttf) {
  15167. rect.x += mainSprite.rect.x;
  15168. rect.y += mainSprite.rect.y;
  15169. }
  15170. else {
  15171. var sprite = this._sprites[img];
  15172. if (sprite) {
  15173. rect.set(sprite.rect);
  15174. bg.xOffset += sprite.offset.x;
  15175. bg.yOffset += sprite.offset.y;
  15176. if (fontSize == 0)
  15177. fontSize = sprite.originalSize.height;
  15178. if (!mainTexture) {
  15179. sprite.atlas.load();
  15180. mainTexture = sprite.atlas.asset;
  15181. }
  15182. }
  15183. if (bg.xAdvance == 0) {
  15184. if (xadvance == 0)
  15185. bg.xAdvance = bg.xOffset + bg.rect.width;
  15186. else
  15187. bg.xAdvance = xadvance;
  15188. }
  15189. }
  15190. buffer.position = nextPos;
  15191. }
  15192. font.fontSize = fontSize;
  15193. font._fntConfig.fontSize = fontSize;
  15194. font._fntConfig.commonHeight = lineHeight == 0 ? fontSize : lineHeight;
  15195. font._fntConfig.resizable = resizable;
  15196. font._fntConfig.canTint = canTint;
  15197. var spriteFrame = new cc.SpriteFrame();
  15198. spriteFrame.setTexture(mainTexture);
  15199. font.spriteFrame = spriteFrame;
  15200. font.onLoad();
  15201. };
  15202. UIPackage.prototype.loadSpine = function (item) {
  15203. this._bundle.load(item.file, sp.SkeletonData, function (err, asset) {
  15204. item.decoded = true;
  15205. item.asset = asset;
  15206. var arr = item.loading;
  15207. delete item.loading;
  15208. arr.forEach(function (e) { return e(err, item); });
  15209. });
  15210. };
  15211. UIPackage.prototype.loadDragonBones = function (item) {
  15212. var _this = this;
  15213. this._bundle.load(item.file, dragonBones.DragonBonesAsset, function (err, asset) {
  15214. if (err) {
  15215. item.decoded = true;
  15216. var arr = item.loading;
  15217. delete item.loading;
  15218. arr.forEach(function (e) { return e(err, item); });
  15219. return;
  15220. }
  15221. item.asset = asset;
  15222. var atlasFile = item.file.replace("_ske", "_tex");
  15223. var pos = atlasFile.lastIndexOf('.');
  15224. if (pos != -1)
  15225. atlasFile = atlasFile.substr(0, pos + 1) + "json";
  15226. _this._bundle.load(atlasFile, dragonBones.DragonBonesAtlasAsset, function (err, asset) {
  15227. item.decoded = true;
  15228. item.atlasAsset = asset;
  15229. var arr = item.loading;
  15230. delete item.loading;
  15231. arr.forEach(function (e) { return e(err, item); });
  15232. });
  15233. });
  15234. };
  15235. UIPackage._constructing = 0;
  15236. UIPackage._instById = {};
  15237. UIPackage._instByName = {};
  15238. UIPackage._branch = "";
  15239. UIPackage._vars = {};
  15240. return UIPackage;
  15241. }());
  15242. fgui.UIPackage = UIPackage;
  15243. var ItemTypeToAssetType = (_a = {},
  15244. _a[fgui.PackageItemType.Atlas] = cc.Texture2D,
  15245. _a[fgui.PackageItemType.Sound] = cc.AudioClip,
  15246. _a);
  15247. })(fgui || (fgui = {}));
  15248. (function (fgui) {
  15249. var Window = (function (_super) {
  15250. __extends(Window, _super);
  15251. function Window() {
  15252. var _this = _super.call(this) || this;
  15253. _this._requestingCmd = 0;
  15254. _this._uiSources = new Array();
  15255. _this.bringToFontOnClick = fgui.UIConfig.bringWindowToFrontOnClick;
  15256. _this._node.on(fgui.Event.TOUCH_BEGIN, _this.onTouchBegin_1, _this, true);
  15257. return _this;
  15258. }
  15259. Window.prototype.addUISource = function (source) {
  15260. this._uiSources.push(source);
  15261. };
  15262. Object.defineProperty(Window.prototype, "contentPane", {
  15263. get: function () {
  15264. return this._contentPane;
  15265. },
  15266. set: function (val) {
  15267. if (this._contentPane != val) {
  15268. if (this._contentPane)
  15269. this.removeChild(this._contentPane);
  15270. this._contentPane = val;
  15271. if (this._contentPane) {
  15272. this.addChild(this._contentPane);
  15273. this.setSize(this._contentPane.width, this._contentPane.height);
  15274. this._contentPane.addRelation(this, fgui.RelationType.Size);
  15275. this._frame = (this._contentPane.getChild("frame"));
  15276. if (this._frame) {
  15277. this.closeButton = this._frame.getChild("closeButton");
  15278. this.dragArea = this._frame.getChild("dragArea");
  15279. this.contentArea = this._frame.getChild("contentArea");
  15280. }
  15281. }
  15282. }
  15283. },
  15284. enumerable: false,
  15285. configurable: true
  15286. });
  15287. Object.defineProperty(Window.prototype, "frame", {
  15288. get: function () {
  15289. return this._frame;
  15290. },
  15291. enumerable: false,
  15292. configurable: true
  15293. });
  15294. Object.defineProperty(Window.prototype, "closeButton", {
  15295. get: function () {
  15296. return this._closeButton;
  15297. },
  15298. set: function (value) {
  15299. if (this._closeButton)
  15300. this._closeButton.offClick(this.closeEventHandler, this);
  15301. this._closeButton = value;
  15302. if (this._closeButton)
  15303. this._closeButton.onClick(this.closeEventHandler, this);
  15304. },
  15305. enumerable: false,
  15306. configurable: true
  15307. });
  15308. Object.defineProperty(Window.prototype, "dragArea", {
  15309. get: function () {
  15310. return this._dragArea;
  15311. },
  15312. set: function (value) {
  15313. if (this._dragArea != value) {
  15314. if (this._dragArea) {
  15315. this._dragArea.draggable = false;
  15316. this._dragArea.off(fgui.Event.DRAG_START, this.onDragStart_1, this);
  15317. }
  15318. this._dragArea = value;
  15319. if (this._dragArea) {
  15320. this._dragArea.draggable = true;
  15321. this._dragArea.on(fgui.Event.DRAG_START, this.onDragStart_1, this);
  15322. }
  15323. }
  15324. },
  15325. enumerable: false,
  15326. configurable: true
  15327. });
  15328. Object.defineProperty(Window.prototype, "contentArea", {
  15329. get: function () {
  15330. return this._contentArea;
  15331. },
  15332. set: function (value) {
  15333. this._contentArea = value;
  15334. },
  15335. enumerable: false,
  15336. configurable: true
  15337. });
  15338. Window.prototype.show = function () {
  15339. fgui.GRoot.inst.showWindow(this);
  15340. };
  15341. Window.prototype.showOn = function (root) {
  15342. root.showWindow(this);
  15343. };
  15344. Window.prototype.hide = function () {
  15345. if (this.isShowing)
  15346. this.doHideAnimation();
  15347. };
  15348. Window.prototype.hideImmediately = function () {
  15349. var r = (this.parent instanceof fgui.GRoot) ? this.parent : null;
  15350. if (!r)
  15351. r = fgui.GRoot.inst;
  15352. r.hideWindowImmediately(this);
  15353. };
  15354. Window.prototype.centerOn = function (r, restraint) {
  15355. this.setPosition(Math.round((r.width - this.width) / 2), Math.round((r.height - this.height) / 2));
  15356. if (restraint) {
  15357. this.addRelation(r, fgui.RelationType.Center_Center);
  15358. this.addRelation(r, fgui.RelationType.Middle_Middle);
  15359. }
  15360. };
  15361. Window.prototype.toggleStatus = function () {
  15362. if (this.isTop)
  15363. this.hide();
  15364. else
  15365. this.show();
  15366. };
  15367. Object.defineProperty(Window.prototype, "isShowing", {
  15368. get: function () {
  15369. return this.parent != null;
  15370. },
  15371. enumerable: false,
  15372. configurable: true
  15373. });
  15374. Object.defineProperty(Window.prototype, "isTop", {
  15375. get: function () {
  15376. return this.parent && this.parent.getChildIndex(this) == this.parent.numChildren - 1;
  15377. },
  15378. enumerable: false,
  15379. configurable: true
  15380. });
  15381. Object.defineProperty(Window.prototype, "modal", {
  15382. get: function () {
  15383. return this._modal;
  15384. },
  15385. set: function (val) {
  15386. this._modal = val;
  15387. },
  15388. enumerable: false,
  15389. configurable: true
  15390. });
  15391. Window.prototype.bringToFront = function () {
  15392. this.root.bringToFront(this);
  15393. };
  15394. Window.prototype.showModalWait = function (requestingCmd) {
  15395. if (requestingCmd != null)
  15396. this._requestingCmd = requestingCmd;
  15397. if (fgui.UIConfig.windowModalWaiting) {
  15398. if (!this._modalWaitPane)
  15399. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.windowModalWaiting);
  15400. this.layoutModalWaitPane();
  15401. this.addChild(this._modalWaitPane);
  15402. }
  15403. };
  15404. Window.prototype.layoutModalWaitPane = function () {
  15405. if (this._contentArea) {
  15406. var pt = this._frame.localToGlobal();
  15407. pt = this.globalToLocal(pt.x, pt.y, pt);
  15408. this._modalWaitPane.setPosition(pt.x + this._contentArea.x, pt.y + this._contentArea.y);
  15409. this._modalWaitPane.setSize(this._contentArea.width, this._contentArea.height);
  15410. }
  15411. else
  15412. this._modalWaitPane.setSize(this.width, this.height);
  15413. };
  15414. Window.prototype.closeModalWait = function (requestingCmd) {
  15415. if (requestingCmd != null) {
  15416. if (this._requestingCmd != requestingCmd)
  15417. return false;
  15418. }
  15419. this._requestingCmd = 0;
  15420. if (this._modalWaitPane && this._modalWaitPane.parent)
  15421. this.removeChild(this._modalWaitPane);
  15422. return true;
  15423. };
  15424. Object.defineProperty(Window.prototype, "modalWaiting", {
  15425. get: function () {
  15426. return this._modalWaitPane && this._modalWaitPane.parent != null;
  15427. },
  15428. enumerable: false,
  15429. configurable: true
  15430. });
  15431. Window.prototype.init = function () {
  15432. if (this._inited || this._loading)
  15433. return;
  15434. if (this._uiSources.length > 0) {
  15435. this._loading = false;
  15436. var cnt = this._uiSources.length;
  15437. for (var i = 0; i < cnt; i++) {
  15438. var lib = this._uiSources[i];
  15439. if (!lib.loaded) {
  15440. lib.load(this.__uiLoadComplete, this);
  15441. this._loading = true;
  15442. }
  15443. }
  15444. if (!this._loading)
  15445. this._init();
  15446. }
  15447. else
  15448. this._init();
  15449. };
  15450. Window.prototype.onInit = function () {
  15451. };
  15452. Window.prototype.onShown = function () {
  15453. };
  15454. Window.prototype.onHide = function () {
  15455. };
  15456. Window.prototype.doShowAnimation = function () {
  15457. this.onShown();
  15458. };
  15459. Window.prototype.doHideAnimation = function () {
  15460. this.hideImmediately();
  15461. };
  15462. Window.prototype.__uiLoadComplete = function () {
  15463. var cnt = this._uiSources.length;
  15464. for (var i = 0; i < cnt; i++) {
  15465. var lib = this._uiSources[i];
  15466. if (!lib.loaded)
  15467. return;
  15468. }
  15469. this._loading = false;
  15470. this._init();
  15471. };
  15472. Window.prototype._init = function () {
  15473. this._inited = true;
  15474. this.onInit();
  15475. if (this.isShowing)
  15476. this.doShowAnimation();
  15477. };
  15478. Window.prototype.dispose = function () {
  15479. if (this.parent)
  15480. this.hideImmediately();
  15481. _super.prototype.dispose.call(this);
  15482. };
  15483. Window.prototype.closeEventHandler = function (evt) {
  15484. this.hide();
  15485. };
  15486. Window.prototype.onEnable = function () {
  15487. _super.prototype.onEnable.call(this);
  15488. if (!this._inited)
  15489. this.init();
  15490. else
  15491. this.doShowAnimation();
  15492. };
  15493. Window.prototype.onDisable = function () {
  15494. _super.prototype.onDisable.call(this);
  15495. this.closeModalWait();
  15496. this.onHide();
  15497. };
  15498. Window.prototype.onTouchBegin_1 = function (evt) {
  15499. if (this.isShowing && this.bringToFontOnClick)
  15500. this.bringToFront();
  15501. };
  15502. Window.prototype.onDragStart_1 = function (evt) {
  15503. var original = fgui.GObject.cast(evt.currentTarget);
  15504. original.stopDrag();
  15505. this.startDrag(evt.touchId);
  15506. };
  15507. return Window;
  15508. }(fgui.GComponent));
  15509. fgui.Window = Window;
  15510. })(fgui || (fgui = {}));
  15511. (function (fgui) {
  15512. var ControllerAction = (function () {
  15513. function ControllerAction() {
  15514. }
  15515. ControllerAction.createAction = function (type) {
  15516. switch (type) {
  15517. case 0:
  15518. return new fgui.PlayTransitionAction();
  15519. case 1:
  15520. return new fgui.ChangePageAction();
  15521. }
  15522. return null;
  15523. };
  15524. ControllerAction.prototype.run = function (controller, prevPage, curPage) {
  15525. if ((this.fromPage == null || this.fromPage.length == 0 || this.fromPage.indexOf(prevPage) != -1)
  15526. && (this.toPage == null || this.toPage.length == 0 || this.toPage.indexOf(curPage) != -1))
  15527. this.enter(controller);
  15528. else
  15529. this.leave(controller);
  15530. };
  15531. ControllerAction.prototype.enter = function (controller) {
  15532. };
  15533. ControllerAction.prototype.leave = function (controller) {
  15534. };
  15535. ControllerAction.prototype.setup = function (buffer) {
  15536. var cnt;
  15537. var i;
  15538. cnt = buffer.readShort();
  15539. this.fromPage = [];
  15540. for (i = 0; i < cnt; i++)
  15541. this.fromPage[i] = buffer.readS();
  15542. cnt = buffer.readShort();
  15543. this.toPage = [];
  15544. for (i = 0; i < cnt; i++)
  15545. this.toPage[i] = buffer.readS();
  15546. };
  15547. return ControllerAction;
  15548. }());
  15549. fgui.ControllerAction = ControllerAction;
  15550. })(fgui || (fgui = {}));
  15551. (function (fgui) {
  15552. var ChangePageAction = (function (_super) {
  15553. __extends(ChangePageAction, _super);
  15554. function ChangePageAction() {
  15555. return _super.call(this) || this;
  15556. }
  15557. ChangePageAction.prototype.enter = function (controller) {
  15558. if (!this.controllerName)
  15559. return;
  15560. var gcom;
  15561. if (this.objectId) {
  15562. var obj = controller.parent.getChildById(this.objectId);
  15563. if (obj instanceof fgui.GComponent)
  15564. gcom = obj;
  15565. else
  15566. return;
  15567. }
  15568. else
  15569. gcom = controller.parent;
  15570. if (gcom) {
  15571. var cc = gcom.getController(this.controllerName);
  15572. if (cc && cc != controller && !cc.changing) {
  15573. if (this.targetPage == "~1") {
  15574. if (controller.selectedIndex < cc.pageCount)
  15575. cc.selectedIndex = controller.selectedIndex;
  15576. }
  15577. else if (this.targetPage == "~2")
  15578. cc.selectedPage = controller.selectedPage;
  15579. else
  15580. cc.selectedPageId = this.targetPage;
  15581. }
  15582. }
  15583. };
  15584. ChangePageAction.prototype.setup = function (buffer) {
  15585. _super.prototype.setup.call(this, buffer);
  15586. this.objectId = buffer.readS();
  15587. this.controllerName = buffer.readS();
  15588. this.targetPage = buffer.readS();
  15589. };
  15590. return ChangePageAction;
  15591. }(fgui.ControllerAction));
  15592. fgui.ChangePageAction = ChangePageAction;
  15593. })(fgui || (fgui = {}));
  15594. (function (fgui) {
  15595. var PlayTransitionAction = (function (_super) {
  15596. __extends(PlayTransitionAction, _super);
  15597. function PlayTransitionAction() {
  15598. var _this = _super.call(this) || this;
  15599. _this.playTimes = 1;
  15600. _this.delay = 0;
  15601. _this.stopOnExit = false;
  15602. return _this;
  15603. }
  15604. PlayTransitionAction.prototype.enter = function (controller) {
  15605. var trans = controller.parent.getTransition(this.transitionName);
  15606. if (trans) {
  15607. if (this._currentTransition && this._currentTransition.playing)
  15608. trans.changePlayTimes(this.playTimes);
  15609. else
  15610. trans.play(null, this.playTimes, this.delay);
  15611. this._currentTransition = trans;
  15612. }
  15613. };
  15614. PlayTransitionAction.prototype.leave = function (controller) {
  15615. if (this.stopOnExit && this._currentTransition) {
  15616. this._currentTransition.stop();
  15617. this._currentTransition = null;
  15618. }
  15619. };
  15620. PlayTransitionAction.prototype.setup = function (buffer) {
  15621. _super.prototype.setup.call(this, buffer);
  15622. this.transitionName = buffer.readS();
  15623. this.playTimes = buffer.readInt();
  15624. this.delay = buffer.readFloat();
  15625. this.stopOnExit = buffer.readBool();
  15626. };
  15627. return PlayTransitionAction;
  15628. }(fgui.ControllerAction));
  15629. fgui.PlayTransitionAction = PlayTransitionAction;
  15630. })(fgui || (fgui = {}));
  15631. (function (fgui) {
  15632. var BlendMode;
  15633. (function (BlendMode) {
  15634. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  15635. BlendMode[BlendMode["None"] = 1] = "None";
  15636. BlendMode[BlendMode["Add"] = 2] = "Add";
  15637. BlendMode[BlendMode["Multiply"] = 3] = "Multiply";
  15638. BlendMode[BlendMode["Screen"] = 4] = "Screen";
  15639. BlendMode[BlendMode["Erase"] = 5] = "Erase";
  15640. BlendMode[BlendMode["Mask"] = 6] = "Mask";
  15641. BlendMode[BlendMode["Below"] = 7] = "Below";
  15642. BlendMode[BlendMode["Off"] = 8] = "Off";
  15643. BlendMode[BlendMode["Custom1"] = 9] = "Custom1";
  15644. BlendMode[BlendMode["Custom2"] = 10] = "Custom2";
  15645. BlendMode[BlendMode["Custom3"] = 11] = "Custom3";
  15646. })(BlendMode = fgui.BlendMode || (fgui.BlendMode = {}));
  15647. var BlendModeUtils = (function () {
  15648. function BlendModeUtils() {
  15649. }
  15650. BlendModeUtils.apply = function (node, blendMode) {
  15651. var f = factors[blendMode];
  15652. var renderers = node.getComponentsInChildren(cc.RenderComponent);
  15653. renderers.forEach(function (element) {
  15654. element.srcBlendFactor = f[0];
  15655. element.dstBlendFactor = f[1];
  15656. });
  15657. };
  15658. BlendModeUtils.override = function (blendMode, srcFactor, dstFactor) {
  15659. factors[blendMode][0] = srcFactor;
  15660. factors[blendMode][1] = dstFactor;
  15661. };
  15662. return BlendModeUtils;
  15663. }());
  15664. fgui.BlendModeUtils = BlendModeUtils;
  15665. var factors = [
  15666. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15667. [cc.macro.ONE, cc.macro.ONE],
  15668. [cc.macro.SRC_ALPHA, cc.macro.ONE],
  15669. [cc.macro.DST_COLOR, cc.macro.ONE_MINUS_SRC_ALPHA],
  15670. [cc.macro.ONE, cc.macro.ONE_MINUS_SRC_COLOR],
  15671. [cc.macro.ZERO, cc.macro.ONE_MINUS_SRC_ALPHA],
  15672. [cc.macro.ZERO, cc.macro.SRC_ALPHA],
  15673. [cc.macro.ONE_MINUS_DST_ALPHA, cc.macro.DST_ALPHA],
  15674. [cc.macro.ONE, cc.macro.ZERO],
  15675. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15676. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15677. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15678. ];
  15679. })(fgui || (fgui = {}));
  15680. (function (fgui) {
  15681. var Image = (function (_super) {
  15682. __extends(Image, _super);
  15683. function Image() {
  15684. var _this = _super.call(this) || this;
  15685. _this._flip = fgui.FlipType.None;
  15686. _this._fillMethod = fgui.FillMethod.None;
  15687. _this._fillOrigin = fgui.FillOrigin.Left;
  15688. _this._fillAmount = 0;
  15689. return _this;
  15690. }
  15691. Object.defineProperty(Image.prototype, "flip", {
  15692. get: function () {
  15693. return this._flip;
  15694. },
  15695. set: function (value) {
  15696. if (this._flip != value) {
  15697. this._flip = value;
  15698. var sx = 1, sy = 1;
  15699. if (this._flip == fgui.FlipType.Horizontal || this._flip == fgui.FlipType.Both)
  15700. sx = -1;
  15701. if (this._flip == fgui.FlipType.Vertical || this._flip == fgui.FlipType.Both)
  15702. sy = -1;
  15703. if (sx != 1 || sy != 1)
  15704. this.node.setAnchorPoint(0.5, 0.5);
  15705. this.node.setScale(sx, sy);
  15706. }
  15707. },
  15708. enumerable: false,
  15709. configurable: true
  15710. });
  15711. Object.defineProperty(Image.prototype, "fillMethod", {
  15712. get: function () {
  15713. return this._fillMethod;
  15714. },
  15715. set: function (value) {
  15716. if (this._fillMethod != value) {
  15717. this._fillMethod = value;
  15718. if (this._fillMethod != 0) {
  15719. this.type = cc.Sprite.Type.FILLED;
  15720. if (this._fillMethod <= 3)
  15721. this.fillType = this._fillMethod - 1;
  15722. else
  15723. this.fillType = cc.Sprite.FillType.RADIAL;
  15724. this.fillCenter = new cc.Vec2(0.5, 0.5);
  15725. this.setupFill();
  15726. }
  15727. else {
  15728. this.type = cc.Sprite.Type.SIMPLE;
  15729. }
  15730. }
  15731. },
  15732. enumerable: false,
  15733. configurable: true
  15734. });
  15735. Object.defineProperty(Image.prototype, "fillOrigin", {
  15736. get: function () {
  15737. return this._fillOrigin;
  15738. },
  15739. set: function (value) {
  15740. if (this._fillOrigin != value) {
  15741. this._fillOrigin = value;
  15742. if (this._fillMethod != 0)
  15743. this.setupFill();
  15744. }
  15745. },
  15746. enumerable: false,
  15747. configurable: true
  15748. });
  15749. Object.defineProperty(Image.prototype, "fillClockwise", {
  15750. get: function () {
  15751. return this._fillClockwise;
  15752. },
  15753. set: function (value) {
  15754. if (this._fillClockwise != value) {
  15755. this._fillClockwise = value;
  15756. if (this._fillMethod != 0)
  15757. this.setupFill();
  15758. }
  15759. },
  15760. enumerable: false,
  15761. configurable: true
  15762. });
  15763. Object.defineProperty(Image.prototype, "fillAmount", {
  15764. get: function () {
  15765. return this._fillAmount;
  15766. },
  15767. set: function (value) {
  15768. if (this._fillAmount != value) {
  15769. this._fillAmount = value;
  15770. if (this._fillMethod != 0) {
  15771. if (this._fillClockwise)
  15772. this.fillRange = -this._fillAmount;
  15773. else
  15774. this.fillRange = this._fillAmount;
  15775. }
  15776. }
  15777. },
  15778. enumerable: false,
  15779. configurable: true
  15780. });
  15781. Image.prototype.setupFill = function () {
  15782. if (this._fillMethod == fgui.FillMethod.Horizontal) {
  15783. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Right || this._fillOrigin == fgui.FillOrigin.Bottom;
  15784. this.fillStart = this._fillClockwise ? 1 : 0;
  15785. }
  15786. else if (this._fillMethod == fgui.FillMethod.Vertical) {
  15787. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Left || this._fillOrigin == fgui.FillOrigin.Top;
  15788. this.fillStart = this._fillClockwise ? 1 : 0;
  15789. }
  15790. else {
  15791. switch (this._fillOrigin) {
  15792. case fgui.FillOrigin.Right:
  15793. this.fillOrigin = 0;
  15794. break;
  15795. case fgui.FillOrigin.Top:
  15796. this.fillStart = 0.25;
  15797. break;
  15798. case fgui.FillOrigin.Left:
  15799. this.fillStart = 0.5;
  15800. break;
  15801. case fgui.FillOrigin.Bottom:
  15802. this.fillStart = 0.75;
  15803. break;
  15804. }
  15805. }
  15806. };
  15807. Object.defineProperty(Image.prototype, "grayed", {
  15808. get: function () {
  15809. return this._grayed;
  15810. },
  15811. set: function (value) {
  15812. if (this._grayed == value)
  15813. return;
  15814. this._grayed = value;
  15815. var material;
  15816. if (value) {
  15817. material = this._graySpriteMaterial;
  15818. if (!material)
  15819. material = cc.Material.getBuiltinMaterial('2d-gray-sprite');
  15820. material = this._graySpriteMaterial = cc.MaterialVariant.create(material, this);
  15821. }
  15822. else {
  15823. material = this._spriteMaterial;
  15824. if (!material)
  15825. material = cc.Material.getBuiltinMaterial('2d-sprite', this);
  15826. material = this._spriteMaterial = cc.MaterialVariant.create(material, this);
  15827. }
  15828. this.setMaterial(0, material);
  15829. },
  15830. enumerable: false,
  15831. configurable: true
  15832. });
  15833. ;
  15834. return Image;
  15835. }(cc.Sprite));
  15836. fgui.Image = Image;
  15837. })(fgui || (fgui = {}));
  15838. (function (fgui) {
  15839. var MovieClip = (function (_super) {
  15840. __extends(MovieClip, _super);
  15841. function MovieClip() {
  15842. var _this = _super.call(this) || this;
  15843. _this.interval = 0;
  15844. _this.repeatDelay = 0;
  15845. _this.timeScale = 1;
  15846. _this._playing = true;
  15847. _this._frameCount = 0;
  15848. _this._frame = 0;
  15849. _this._start = 0;
  15850. _this._end = 0;
  15851. _this._times = 0;
  15852. _this._endAt = 0;
  15853. _this._status = 0;
  15854. _this._smoothing = true;
  15855. _this._frameElapsed = 0;
  15856. _this._reversed = false;
  15857. _this._repeatedCount = 0;
  15858. return _this;
  15859. }
  15860. Object.defineProperty(MovieClip.prototype, "frames", {
  15861. get: function () {
  15862. return this._frames;
  15863. },
  15864. set: function (value) {
  15865. this._frames = value;
  15866. if (this._frames) {
  15867. this._frameCount = this._frames.length;
  15868. if (this._end == -1 || this._end > this._frameCount - 1)
  15869. this._end = this._frameCount - 1;
  15870. if (this._endAt == -1 || this._endAt > this._frameCount - 1)
  15871. this._endAt = this._frameCount - 1;
  15872. if (this._frame < 0 || this._frame > this._frameCount - 1)
  15873. this._frame = this._frameCount - 1;
  15874. this.type = cc.Sprite.Type.SIMPLE;
  15875. this.drawFrame();
  15876. this._frameElapsed = 0;
  15877. this._repeatedCount = 0;
  15878. this._reversed = false;
  15879. }
  15880. else {
  15881. this._frameCount = 0;
  15882. }
  15883. },
  15884. enumerable: false,
  15885. configurable: true
  15886. });
  15887. Object.defineProperty(MovieClip.prototype, "frameCount", {
  15888. get: function () {
  15889. return this._frameCount;
  15890. },
  15891. enumerable: false,
  15892. configurable: true
  15893. });
  15894. Object.defineProperty(MovieClip.prototype, "frame", {
  15895. get: function () {
  15896. return this._frame;
  15897. },
  15898. set: function (value) {
  15899. if (this._frame != value) {
  15900. if (this._frames && value >= this._frameCount)
  15901. value = this._frameCount - 1;
  15902. this._frame = value;
  15903. this._frameElapsed = 0;
  15904. this.drawFrame();
  15905. }
  15906. },
  15907. enumerable: false,
  15908. configurable: true
  15909. });
  15910. Object.defineProperty(MovieClip.prototype, "playing", {
  15911. get: function () {
  15912. return this._playing;
  15913. },
  15914. set: function (value) {
  15915. if (this._playing != value) {
  15916. this._playing = value;
  15917. }
  15918. },
  15919. enumerable: false,
  15920. configurable: true
  15921. });
  15922. Object.defineProperty(MovieClip.prototype, "smoothing", {
  15923. get: function () {
  15924. return this._smoothing;
  15925. },
  15926. set: function (value) {
  15927. this._smoothing = value;
  15928. },
  15929. enumerable: false,
  15930. configurable: true
  15931. });
  15932. MovieClip.prototype.rewind = function () {
  15933. this._frame = 0;
  15934. this._frameElapsed = 0;
  15935. this._reversed = false;
  15936. this._repeatedCount = 0;
  15937. this.drawFrame();
  15938. };
  15939. MovieClip.prototype.syncStatus = function (anotherMc) {
  15940. this._frame = anotherMc._frame;
  15941. this._frameElapsed = anotherMc._frameElapsed;
  15942. this._reversed = anotherMc._reversed;
  15943. this._repeatedCount = anotherMc._repeatedCount;
  15944. this.drawFrame();
  15945. };
  15946. MovieClip.prototype.advance = function (timeInSeconds) {
  15947. var beginFrame = this._frame;
  15948. var beginReversed = this._reversed;
  15949. var backupTime = timeInSeconds;
  15950. while (true) {
  15951. var tt = this.interval + this._frames[this._frame].addDelay;
  15952. if (this._frame == 0 && this._repeatedCount > 0)
  15953. tt += this.repeatDelay;
  15954. if (timeInSeconds < tt) {
  15955. this._frameElapsed = 0;
  15956. break;
  15957. }
  15958. timeInSeconds -= tt;
  15959. if (this.swing) {
  15960. if (this._reversed) {
  15961. this._frame--;
  15962. if (this._frame <= 0) {
  15963. this._frame = 0;
  15964. this._repeatedCount++;
  15965. this._reversed = !this._reversed;
  15966. }
  15967. }
  15968. else {
  15969. this._frame++;
  15970. if (this._frame > this._frameCount - 1) {
  15971. this._frame = Math.max(0, this._frameCount - 2);
  15972. this._repeatedCount++;
  15973. this._reversed = !this._reversed;
  15974. }
  15975. }
  15976. }
  15977. else {
  15978. this._frame++;
  15979. if (this._frame > this._frameCount - 1) {
  15980. this._frame = 0;
  15981. this._repeatedCount++;
  15982. }
  15983. }
  15984. if (this._frame == beginFrame && this._reversed == beginReversed) {
  15985. var roundTime = backupTime - timeInSeconds;
  15986. timeInSeconds -= Math.floor(timeInSeconds / roundTime) * roundTime;
  15987. }
  15988. }
  15989. this.drawFrame();
  15990. };
  15991. MovieClip.prototype.setPlaySettings = function (start, end, times, endAt, endCallback, callbackObj) {
  15992. if (start == undefined)
  15993. start = 0;
  15994. if (end == undefined)
  15995. end = -1;
  15996. if (times == undefined)
  15997. times = 0;
  15998. if (endAt == undefined)
  15999. endAt = -1;
  16000. this._start = start;
  16001. this._end = end;
  16002. if (this._end == -1 || this._end > this._frameCount - 1)
  16003. this._end = this._frameCount - 1;
  16004. this._times = times;
  16005. this._endAt = endAt;
  16006. if (this._endAt == -1)
  16007. this._endAt = this._end;
  16008. this._status = 0;
  16009. this._callback = endCallback;
  16010. this._callbackObj = callbackObj;
  16011. this.frame = start;
  16012. };
  16013. MovieClip.prototype.update = function (dt) {
  16014. if (!this._playing || this._frameCount == 0 || this._status == 3)
  16015. return;
  16016. if (this.timeScale != 1)
  16017. dt *= this.timeScale;
  16018. this._frameElapsed += dt;
  16019. var tt = this.interval + this._frames[this._frame].addDelay;
  16020. if (this._frame == 0 && this._repeatedCount > 0)
  16021. tt += this.repeatDelay;
  16022. if (this._frameElapsed < tt)
  16023. return;
  16024. this._frameElapsed -= tt;
  16025. if (this._frameElapsed > this.interval)
  16026. this._frameElapsed = this.interval;
  16027. if (this.swing) {
  16028. if (this._reversed) {
  16029. this._frame--;
  16030. if (this._frame <= 0) {
  16031. this._frame = 0;
  16032. this._repeatedCount++;
  16033. this._reversed = !this._reversed;
  16034. }
  16035. }
  16036. else {
  16037. this._frame++;
  16038. if (this._frame > this._frameCount - 1) {
  16039. this._frame = Math.max(0, this._frameCount - 2);
  16040. this._repeatedCount++;
  16041. this._reversed = !this._reversed;
  16042. }
  16043. }
  16044. }
  16045. else {
  16046. this._frame++;
  16047. if (this._frame > this._frameCount - 1) {
  16048. this._frame = 0;
  16049. this._repeatedCount++;
  16050. }
  16051. }
  16052. if (this._status == 1) {
  16053. this._frame = this._start;
  16054. this._frameElapsed = 0;
  16055. this._status = 0;
  16056. }
  16057. else if (this._status == 2) {
  16058. this._frame = this._endAt;
  16059. this._frameElapsed = 0;
  16060. this._status = 3;
  16061. if (this._callback != null) {
  16062. var callback = this._callback;
  16063. var caller = this._callbackObj;
  16064. this._callback = null;
  16065. this._callbackObj = null;
  16066. callback.call(caller);
  16067. }
  16068. }
  16069. else {
  16070. if (this._frame == this._end) {
  16071. if (this._times > 0) {
  16072. this._times--;
  16073. if (this._times == 0)
  16074. this._status = 2;
  16075. else
  16076. this._status = 1;
  16077. }
  16078. else if (this._start != 0)
  16079. this._status = 1;
  16080. }
  16081. }
  16082. this.drawFrame();
  16083. };
  16084. MovieClip.prototype.drawFrame = function () {
  16085. if (this._frameCount > 0 && this._frame < this._frames.length) {
  16086. var frame = this._frames[this._frame];
  16087. this.spriteFrame = frame.texture;
  16088. }
  16089. };
  16090. return MovieClip;
  16091. }(fgui.Image));
  16092. fgui.MovieClip = MovieClip;
  16093. })(fgui || (fgui = {}));
  16094. (function (fgui) {
  16095. var Event = (function (_super) {
  16096. __extends(Event, _super);
  16097. function Event(type, bubbles) {
  16098. var _this = _super.call(this, type, bubbles) || this;
  16099. _this.pos = new cc.Vec2();
  16100. _this.touchId = 0;
  16101. _this.clickCount = 0;
  16102. _this.button = 0;
  16103. _this.keyModifiers = 0;
  16104. _this.mouseWheelDelta = 0;
  16105. return _this;
  16106. }
  16107. Object.defineProperty(Event.prototype, "isShiftDown", {
  16108. get: function () {
  16109. return false;
  16110. },
  16111. enumerable: false,
  16112. configurable: true
  16113. });
  16114. Object.defineProperty(Event.prototype, "isCtrlDown", {
  16115. get: function () {
  16116. return false;
  16117. },
  16118. enumerable: false,
  16119. configurable: true
  16120. });
  16121. Event.prototype.captureTouch = function () {
  16122. var obj = fgui.GObject.cast(this.currentTarget);
  16123. if (obj)
  16124. this._processor.addTouchMonitor(this.touchId, obj);
  16125. };
  16126. Event._borrow = function (type, bubbles) {
  16127. var evt;
  16128. if (eventPool.length) {
  16129. evt = eventPool.pop();
  16130. evt.type = type;
  16131. evt.bubbles = bubbles;
  16132. }
  16133. else {
  16134. evt = new Event(type, bubbles);
  16135. }
  16136. return evt;
  16137. };
  16138. Event._return = function (evt) {
  16139. evt.initiator = null;
  16140. evt.touch = null;
  16141. evt.unuse();
  16142. eventPool.push(evt);
  16143. };
  16144. Event.TOUCH_BEGIN = "fui_touch_begin";
  16145. Event.TOUCH_MOVE = "fui_touch_move";
  16146. Event.TOUCH_END = "fui_touch_end";
  16147. Event.CLICK = "fui_click";
  16148. Event.ROLL_OVER = "fui_roll_over";
  16149. Event.ROLL_OUT = "fui_roll_out";
  16150. Event.MOUSE_WHEEL = "fui_mouse_wheel";
  16151. Event.DISPLAY = "fui_display";
  16152. Event.UNDISPLAY = "fui_undisplay";
  16153. Event.GEAR_STOP = "fui_gear_stop";
  16154. Event.LINK = "fui_text_link";
  16155. Event.Submit = "editing-return";
  16156. Event.TEXT_CHANGE = "text-changed";
  16157. Event.STATUS_CHANGED = "fui_status_changed";
  16158. Event.XY_CHANGED = "fui_xy_changed";
  16159. Event.SIZE_CHANGED = "fui_size_changed";
  16160. Event.SIZE_DELAY_CHANGE = "fui_size_delay_change";
  16161. Event.DRAG_START = "fui_drag_start";
  16162. Event.DRAG_MOVE = "fui_drag_move";
  16163. Event.DRAG_END = "fui_drag_end";
  16164. Event.DROP = "fui_drop";
  16165. Event.SCROLL = "fui_scroll";
  16166. Event.SCROLL_END = "fui_scroll_end";
  16167. Event.PULL_DOWN_RELEASE = "fui_pull_down_release";
  16168. Event.PULL_UP_RELEASE = "fui_pull_up_release";
  16169. Event.CLICK_ITEM = "fui_click_item";
  16170. return Event;
  16171. }(cc.Event));
  16172. fgui.Event = Event;
  16173. var eventPool = new Array();
  16174. })(fgui || (fgui = {}));
  16175. (function (fgui) {
  16176. var PixelHitTest = (function () {
  16177. function PixelHitTest(data, offsetX, offsetY) {
  16178. this._data = data;
  16179. this.offsetX = offsetX == undefined ? 0 : offsetX;
  16180. this.offsetY = offsetY == undefined ? 0 : offsetY;
  16181. this.scaleX = 1;
  16182. this.scaleY = 1;
  16183. }
  16184. PixelHitTest.prototype.hitTest = function (pt) {
  16185. var x = Math.floor((pt.x / this.scaleX - this.offsetX) * this._data.scale);
  16186. var y = Math.floor((pt.y / this.scaleY - this.offsetY) * this._data.scale);
  16187. if (x < 0 || y < 0 || x >= this._data.pixelWidth)
  16188. return false;
  16189. var pos = y * this._data.pixelWidth + x;
  16190. var pos2 = Math.floor(pos / 8);
  16191. var pos3 = pos % 8;
  16192. if (pos2 >= 0 && pos2 < this._data.pixels.length)
  16193. return ((this._data.pixels[pos2] >> pos3) & 0x1) == 1;
  16194. else
  16195. return false;
  16196. };
  16197. return PixelHitTest;
  16198. }());
  16199. fgui.PixelHitTest = PixelHitTest;
  16200. var PixelHitTestData = (function () {
  16201. function PixelHitTestData(ba) {
  16202. ba.readInt();
  16203. this.pixelWidth = ba.readInt();
  16204. this.scale = 1 / ba.readByte();
  16205. this.pixels = ba.readBuffer().data;
  16206. }
  16207. return PixelHitTestData;
  16208. }());
  16209. fgui.PixelHitTestData = PixelHitTestData;
  16210. var ChildHitArea = (function () {
  16211. function ChildHitArea(child) {
  16212. this._child = child;
  16213. }
  16214. ChildHitArea.prototype.hitTest = function (pt, globalPt) {
  16215. return this._child.hitTest(globalPt, false) != null;
  16216. };
  16217. return ChildHitArea;
  16218. }());
  16219. fgui.ChildHitArea = ChildHitArea;
  16220. })(fgui || (fgui = {}));
  16221. (function (fgui) {
  16222. var InputProcessor = (function (_super) {
  16223. __extends(InputProcessor, _super);
  16224. function InputProcessor() {
  16225. var _this = _super.call(this) || this;
  16226. _this._touches = new Array();
  16227. _this._rollOutChain = new Array();
  16228. _this._rollOverChain = new Array();
  16229. _this._touchPos = new cc.Vec2();
  16230. return _this;
  16231. }
  16232. InputProcessor.prototype.onLoad = function () {
  16233. this._owner = this.node["$gobj"];
  16234. };
  16235. InputProcessor.prototype.onEnable = function () {
  16236. var node = this.node;
  16237. node.on(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  16238. node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  16239. node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  16240. node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  16241. node.on(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  16242. node.on(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  16243. node.on(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  16244. node.on(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  16245. this._touchListener = this.node["_touchListener"];
  16246. };
  16247. InputProcessor.prototype.onDisable = function () {
  16248. var node = this.node;
  16249. node.off(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  16250. node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  16251. node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  16252. node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  16253. node.off(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  16254. node.off(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  16255. node.off(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  16256. node.off(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  16257. this._touchListener = null;
  16258. };
  16259. InputProcessor.prototype.getAllTouches = function (touchIds) {
  16260. touchIds = touchIds || new Array();
  16261. var cnt = this._touches.length;
  16262. for (var i = 0; i < cnt; i++) {
  16263. var ti = this._touches[i];
  16264. if (ti.touchId != -1)
  16265. touchIds.push(ti.touchId);
  16266. }
  16267. return touchIds;
  16268. };
  16269. InputProcessor.prototype.getTouchPosition = function (touchId) {
  16270. if (touchId === undefined)
  16271. touchId = -1;
  16272. var cnt = this._touches.length;
  16273. for (var i = 0; i < cnt; i++) {
  16274. var ti = this._touches[i];
  16275. if (ti.touchId != -1 && (touchId == -1 || ti.touchId == touchId))
  16276. return ti.pos;
  16277. }
  16278. return cc.Vec2.ZERO;
  16279. };
  16280. InputProcessor.prototype.getTouchTarget = function () {
  16281. var cnt = this._touches.length;
  16282. for (var i = 0; i < cnt; i++) {
  16283. var ti = this._touches[i];
  16284. if (ti.touchId != -1)
  16285. return ti.target;
  16286. }
  16287. return null;
  16288. };
  16289. InputProcessor.prototype.addTouchMonitor = function (touchId, target) {
  16290. var ti = this.getInfo(touchId, false);
  16291. if (!ti)
  16292. return;
  16293. var index = ti.touchMonitors.indexOf(target);
  16294. if (index == -1)
  16295. ti.touchMonitors.push(target);
  16296. };
  16297. InputProcessor.prototype.removeTouchMonitor = function (target) {
  16298. var cnt = this._touches.length;
  16299. for (var i = 0; i < cnt; i++) {
  16300. var ti = this._touches[i];
  16301. var index = ti.touchMonitors.indexOf(target);
  16302. if (index != -1)
  16303. ti.touchMonitors.splice(index, 1);
  16304. }
  16305. };
  16306. InputProcessor.prototype.cancelClick = function (touchId) {
  16307. var ti = this.getInfo(touchId, false);
  16308. if (ti)
  16309. ti.clickCancelled = true;
  16310. };
  16311. InputProcessor.prototype.simulateClick = function (target) {
  16312. var evt;
  16313. evt = fgui.Event._borrow(fgui.Event.TOUCH_BEGIN, true);
  16314. evt.initiator = target;
  16315. evt.pos.set(target.localToGlobal());
  16316. evt.touchId = 0;
  16317. evt.clickCount = 1;
  16318. evt.button = 0;
  16319. evt._processor = this;
  16320. if (this._captureCallback)
  16321. this._captureCallback.call(this._owner, evt);
  16322. target.node.dispatchEvent(evt);
  16323. evt.unuse();
  16324. evt.type = fgui.Event.TOUCH_END;
  16325. evt.bubbles = true;
  16326. target.node.dispatchEvent(evt);
  16327. evt.unuse();
  16328. evt.type = fgui.Event.CLICK;
  16329. evt.bubbles = true;
  16330. target.node.dispatchEvent(evt);
  16331. fgui.Event._return(evt);
  16332. };
  16333. InputProcessor.prototype.touchBeginHandler = function (touch, evt) {
  16334. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16335. this._touchListener.setSwallowTouches(ti.target != this._owner);
  16336. this.setBegin(ti);
  16337. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_BEGIN, true);
  16338. if (this._captureCallback)
  16339. this._captureCallback.call(this._owner, evt2);
  16340. ti.target.node.dispatchEvent(evt2);
  16341. this.handleRollOver(ti, ti.target);
  16342. return true;
  16343. };
  16344. InputProcessor.prototype.touchMoveHandler = function (touch, evt) {
  16345. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16346. this.handleRollOver(ti, ti.target);
  16347. if (ti.began) {
  16348. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  16349. var done = false;
  16350. var cnt = ti.touchMonitors.length;
  16351. for (var i = 0; i < cnt; i++) {
  16352. var mm = ti.touchMonitors[i];
  16353. if (mm.node == null || !mm.node.activeInHierarchy)
  16354. continue;
  16355. evt2.unuse();
  16356. evt2.type = fgui.Event.TOUCH_MOVE;
  16357. mm.node.dispatchEvent(evt2);
  16358. if (mm == this._owner)
  16359. done = true;
  16360. }
  16361. if (!done && this.node) {
  16362. evt2.unuse();
  16363. evt2.type = fgui.Event.TOUCH_MOVE;
  16364. this.node.dispatchEvent(evt2);
  16365. }
  16366. fgui.Event._return(evt2);
  16367. }
  16368. };
  16369. InputProcessor.prototype.touchEndHandler = function (touch, evt) {
  16370. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16371. this.setEnd(ti);
  16372. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  16373. var cnt = ti.touchMonitors.length;
  16374. for (var i = 0; i < cnt; i++) {
  16375. var mm = ti.touchMonitors[i];
  16376. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy
  16377. || (mm instanceof fgui.GComponent) && mm.isAncestorOf(ti.target))
  16378. continue;
  16379. evt2.unuse();
  16380. evt2.type = fgui.Event.TOUCH_END;
  16381. mm.node.dispatchEvent(evt2);
  16382. }
  16383. ti.touchMonitors.length = 0;
  16384. if (ti.target && ti.target.node) {
  16385. if (ti.target instanceof fgui.GRichTextField)
  16386. ti.target.node.getComponent(cc.RichText)["_onTouchEnded"](evt2);
  16387. evt2.unuse();
  16388. evt2.type = fgui.Event.TOUCH_END;
  16389. evt2.bubbles = true;
  16390. ti.target.node.dispatchEvent(evt2);
  16391. }
  16392. fgui.Event._return(evt2);
  16393. ti.target = this.clickTest(ti);
  16394. if (ti.target) {
  16395. evt2 = this.getEvent(ti, ti.target, fgui.Event.CLICK, true);
  16396. ti.target.node.dispatchEvent(evt2);
  16397. fgui.Event._return(evt2);
  16398. }
  16399. if (cc.sys.isMobile)
  16400. this.handleRollOver(ti, null);
  16401. else
  16402. this.handleRollOver(ti, ti.target);
  16403. ti.target = null;
  16404. ti.touchId = -1;
  16405. ti.button = -1;
  16406. };
  16407. InputProcessor.prototype.touchCancelHandler = function (touch, evt) {
  16408. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16409. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  16410. var cnt = ti.touchMonitors.length;
  16411. for (var i = 0; i < cnt; i++) {
  16412. var mm = ti.touchMonitors[i];
  16413. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy
  16414. || (mm instanceof fgui.GComponent) && mm.isAncestorOf(ti.target))
  16415. continue;
  16416. evt2.initiator = mm;
  16417. mm.node.dispatchEvent(evt2);
  16418. }
  16419. ti.touchMonitors.length = 0;
  16420. if (ti.target && ti.target.node) {
  16421. evt2.bubbles = true;
  16422. ti.target.node.dispatchEvent(evt2);
  16423. }
  16424. fgui.Event._return(evt2);
  16425. this.handleRollOver(ti, null);
  16426. ti.target = null;
  16427. ti.touchId = -1;
  16428. ti.button = -1;
  16429. };
  16430. InputProcessor.prototype.mouseDownHandler = function (evt) {
  16431. var ti = this.getInfo(0, true);
  16432. ti.button = evt.getButton();
  16433. };
  16434. InputProcessor.prototype.mouseUpHandler = function (evt) {
  16435. var ti = this.getInfo(0, true);
  16436. ti.button = evt.getButton();
  16437. };
  16438. InputProcessor.prototype.mouseMoveHandler = function (evt) {
  16439. var ti = this.getInfo(0, false);
  16440. if (ti
  16441. && Math.abs(ti.pos.x - evt.getLocationX()) < 1
  16442. && Math.abs(ti.pos.y - (fgui.GRoot.inst.height - evt.getLocationY())) < 1)
  16443. return;
  16444. ti = this.updateInfo(0, evt.getLocation());
  16445. this.handleRollOver(ti, ti.target);
  16446. if (ti.began) {
  16447. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  16448. var done = false;
  16449. var cnt = ti.touchMonitors.length;
  16450. for (var i = 0; i < cnt; i++) {
  16451. var mm = ti.touchMonitors[i];
  16452. if (mm.node == null || !mm.node.activeInHierarchy)
  16453. continue;
  16454. evt2.initiator = mm;
  16455. mm.node.dispatchEvent(evt2);
  16456. if (mm == this._owner)
  16457. done = true;
  16458. }
  16459. if (!done && this.node) {
  16460. evt2.initiator = this._owner;
  16461. this.node.dispatchEvent(evt2);
  16462. fgui.Event._return(evt2);
  16463. }
  16464. fgui.Event._return(evt2);
  16465. }
  16466. };
  16467. InputProcessor.prototype.mouseWheelHandler = function (evt) {
  16468. var ti = this.updateInfo(0, evt.getLocation());
  16469. ti.mouseWheelDelta = Math.max(evt.getScrollX(), evt.getScrollY());
  16470. var evt2 = this.getEvent(ti, ti.target, fgui.Event.MOUSE_WHEEL, true);
  16471. ti.target.node.dispatchEvent(evt2);
  16472. fgui.Event._return(evt2);
  16473. };
  16474. InputProcessor.prototype.updateInfo = function (touchId, pos, touch) {
  16475. var camera = cc.Camera.findCamera(this.node);
  16476. if (camera)
  16477. camera.getScreenToWorldPoint(pos, this._touchPos);
  16478. else
  16479. this._touchPos.set(pos);
  16480. this._touchPos.y = fgui.GRoot.inst.height - this._touchPos.y;
  16481. var target = this._owner.hitTest(this._touchPos);
  16482. if (!target)
  16483. target = this._owner;
  16484. var ti = this.getInfo(touchId);
  16485. ti.target = target;
  16486. ti.pos.set(this._touchPos);
  16487. ti.button = cc.Event.EventMouse.BUTTON_LEFT;
  16488. ti.touch = touch;
  16489. return ti;
  16490. };
  16491. InputProcessor.prototype.getInfo = function (touchId, createIfNotExisits) {
  16492. if (createIfNotExisits === undefined)
  16493. createIfNotExisits = true;
  16494. var ret = null;
  16495. var cnt = this._touches.length;
  16496. for (var i = 0; i < cnt; i++) {
  16497. var ti = this._touches[i];
  16498. if (ti.touchId == touchId)
  16499. return ti;
  16500. else if (ti.touchId == -1)
  16501. ret = ti;
  16502. }
  16503. if (!ret) {
  16504. if (!createIfNotExisits)
  16505. return null;
  16506. ret = new TouchInfo();
  16507. this._touches.push(ret);
  16508. }
  16509. ret.touchId = touchId;
  16510. return ret;
  16511. };
  16512. InputProcessor.prototype.setBegin = function (ti) {
  16513. ti.began = true;
  16514. ti.clickCancelled = false;
  16515. ti.downPos.set(ti.pos);
  16516. ti.downTargets.length = 0;
  16517. var obj = ti.target;
  16518. while (obj) {
  16519. ti.downTargets.push(obj);
  16520. obj = obj.findParent();
  16521. }
  16522. };
  16523. InputProcessor.prototype.setEnd = function (ti) {
  16524. ti.began = false;
  16525. var now = fgui.ToolSet.getTime();
  16526. var elapsed = now - ti.lastClickTime;
  16527. if (elapsed < 0.45) {
  16528. if (ti.clickCount == 2)
  16529. ti.clickCount = 1;
  16530. else
  16531. ti.clickCount++;
  16532. }
  16533. else
  16534. ti.clickCount = 1;
  16535. ti.lastClickTime = now;
  16536. };
  16537. InputProcessor.prototype.clickTest = function (ti) {
  16538. if (ti.downTargets.length == 0
  16539. || ti.clickCancelled
  16540. || Math.abs(ti.pos.x - ti.downPos.x) > 50 || Math.abs(ti.pos.y - ti.downPos.y) > 50)
  16541. return null;
  16542. var obj = ti.downTargets[0];
  16543. if (obj && obj.node && obj.node.activeInHierarchy)
  16544. return obj;
  16545. obj = ti.target;
  16546. while (obj) {
  16547. var index = ti.downTargets.indexOf(obj);
  16548. if (index != -1 && obj.node && obj.node.activeInHierarchy)
  16549. break;
  16550. obj = obj.findParent();
  16551. }
  16552. return obj;
  16553. };
  16554. InputProcessor.prototype.handleRollOver = function (ti, target) {
  16555. if (ti.lastRollOver == target)
  16556. return;
  16557. var element = ti.lastRollOver;
  16558. while (element && element.node) {
  16559. this._rollOutChain.push(element);
  16560. element = element.findParent();
  16561. }
  16562. element = target;
  16563. while (element && element.node) {
  16564. var i = this._rollOutChain.indexOf(element);
  16565. if (i != -1) {
  16566. this._rollOutChain.length = i;
  16567. break;
  16568. }
  16569. this._rollOverChain.push(element);
  16570. element = element.findParent();
  16571. }
  16572. ti.lastRollOver = target;
  16573. var cnt = this._rollOutChain.length;
  16574. for (var i = 0; i < cnt; i++) {
  16575. element = this._rollOutChain[i];
  16576. if (element.node && element.node.activeInHierarchy) {
  16577. var evt = this.getEvent(ti, element, fgui.Event.ROLL_OUT, false);
  16578. element.node.dispatchEvent(evt);
  16579. fgui.Event._return(evt);
  16580. }
  16581. }
  16582. cnt = this._rollOverChain.length;
  16583. for (var i = 0; i < cnt; i++) {
  16584. element = this._rollOverChain[i];
  16585. if (element.node && element.node.activeInHierarchy) {
  16586. var evt = this.getEvent(ti, element, fgui.Event.ROLL_OVER, false);
  16587. element.node.dispatchEvent(evt);
  16588. fgui.Event._return(evt);
  16589. }
  16590. }
  16591. this._rollOutChain.length = 0;
  16592. this._rollOverChain.length = 0;
  16593. };
  16594. InputProcessor.prototype.getEvent = function (ti, target, type, bubbles) {
  16595. var evt = fgui.Event._borrow(type, bubbles);
  16596. evt.initiator = target;
  16597. evt.touch = ti.touch;
  16598. evt.pos.set(ti.pos);
  16599. evt.touchId = ti.touch ? ti.touch.getID() : 0;
  16600. evt.clickCount = ti.clickCount;
  16601. evt.button = ti.button;
  16602. evt.mouseWheelDelta = ti.mouseWheelDelta;
  16603. evt._processor = this;
  16604. return evt;
  16605. };
  16606. return InputProcessor;
  16607. }(cc.Component));
  16608. fgui.InputProcessor = InputProcessor;
  16609. var TouchInfo = (function () {
  16610. function TouchInfo() {
  16611. this.pos = new cc.Vec2();
  16612. this.touchId = 0;
  16613. this.clickCount = 0;
  16614. this.mouseWheelDelta = 0;
  16615. this.button = -1;
  16616. this.downPos = new cc.Vec2();
  16617. this.began = false;
  16618. this.clickCancelled = false;
  16619. this.lastClickTime = 0;
  16620. this.downTargets = new Array();
  16621. this.touchMonitors = new Array();
  16622. }
  16623. return TouchInfo;
  16624. }());
  16625. ;
  16626. })(fgui || (fgui = {}));
  16627. (function (fgui) {
  16628. var GearBase = (function () {
  16629. function GearBase(owner) {
  16630. this._owner = owner;
  16631. }
  16632. GearBase.create = function (owner, index) {
  16633. if (!Classes)
  16634. Classes = [
  16635. fgui.GearDisplay, fgui.GearXY, fgui.GearSize, fgui.GearLook, fgui.GearColor,
  16636. fgui.GearAnimation, fgui.GearText, fgui.GearIcon, fgui.GearDisplay2, fgui.GearFontSize
  16637. ];
  16638. return new (Classes[index])(owner);
  16639. };
  16640. GearBase.prototype.dispose = function () {
  16641. if (this._tweenConfig && this._tweenConfig._tweener) {
  16642. this._tweenConfig._tweener.kill();
  16643. this._tweenConfig._tweener = null;
  16644. }
  16645. };
  16646. Object.defineProperty(GearBase.prototype, "controller", {
  16647. get: function () {
  16648. return this._controller;
  16649. },
  16650. set: function (val) {
  16651. if (val != this._controller) {
  16652. this._controller = val;
  16653. if (this._controller)
  16654. this.init();
  16655. }
  16656. },
  16657. enumerable: false,
  16658. configurable: true
  16659. });
  16660. Object.defineProperty(GearBase.prototype, "tweenConfig", {
  16661. get: function () {
  16662. if (!this._tweenConfig)
  16663. this._tweenConfig = new GearTweenConfig();
  16664. return this._tweenConfig;
  16665. },
  16666. enumerable: false,
  16667. configurable: true
  16668. });
  16669. GearBase.prototype.setup = function (buffer) {
  16670. this._controller = this._owner.parent.getControllerAt(buffer.readShort());
  16671. this.init();
  16672. var i;
  16673. var page;
  16674. var cnt = buffer.readShort();
  16675. if (this instanceof fgui.GearDisplay) {
  16676. this.pages = buffer.readSArray(cnt);
  16677. }
  16678. else if (this instanceof fgui.GearDisplay2) {
  16679. this.pages = buffer.readSArray(cnt);
  16680. }
  16681. else {
  16682. for (i = 0; i < cnt; i++) {
  16683. page = buffer.readS();
  16684. if (page == null)
  16685. continue;
  16686. this.addStatus(page, buffer);
  16687. }
  16688. if (buffer.readBool())
  16689. this.addStatus(null, buffer);
  16690. }
  16691. if (buffer.readBool()) {
  16692. this._tweenConfig = new GearTweenConfig();
  16693. this._tweenConfig.easeType = buffer.readByte();
  16694. this._tweenConfig.duration = buffer.readFloat();
  16695. this._tweenConfig.delay = buffer.readFloat();
  16696. }
  16697. if (buffer.version >= 2) {
  16698. if (this instanceof fgui.GearXY) {
  16699. if (buffer.readBool()) {
  16700. this.positionsInPercent = true;
  16701. for (i = 0; i < cnt; i++) {
  16702. page = buffer.readS();
  16703. if (page == null)
  16704. continue;
  16705. this.addExtStatus(page, buffer);
  16706. }
  16707. if (buffer.readBool())
  16708. this.addExtStatus(null, buffer);
  16709. }
  16710. }
  16711. else if (this instanceof fgui.GearDisplay2)
  16712. this.condition = buffer.readByte();
  16713. }
  16714. };
  16715. GearBase.prototype.updateFromRelations = function (dx, dy) {
  16716. };
  16717. GearBase.prototype.addStatus = function (pageId, buffer) {
  16718. };
  16719. GearBase.prototype.init = function () {
  16720. };
  16721. GearBase.prototype.apply = function () {
  16722. };
  16723. GearBase.prototype.updateState = function () {
  16724. };
  16725. return GearBase;
  16726. }());
  16727. fgui.GearBase = GearBase;
  16728. var Classes;
  16729. var GearTweenConfig = (function () {
  16730. function GearTweenConfig() {
  16731. this.tween = true;
  16732. this.easeType = fgui.EaseType.QuadOut;
  16733. this.duration = 0.3;
  16734. this.delay = 0;
  16735. }
  16736. return GearTweenConfig;
  16737. }());
  16738. fgui.GearTweenConfig = GearTweenConfig;
  16739. })(fgui || (fgui = {}));
  16740. (function (fgui) {
  16741. var GearAnimation = (function (_super) {
  16742. __extends(GearAnimation, _super);
  16743. function GearAnimation(owner) {
  16744. return _super.call(this, owner) || this;
  16745. }
  16746. GearAnimation.prototype.init = function () {
  16747. this._default = {
  16748. playing: this._owner.getProp(fgui.ObjectPropID.Playing),
  16749. frame: this._owner.getProp(fgui.ObjectPropID.Frame)
  16750. };
  16751. this._storage = {};
  16752. };
  16753. GearAnimation.prototype.addStatus = function (pageId, buffer) {
  16754. var gv;
  16755. if (pageId == null)
  16756. gv = this._default;
  16757. else
  16758. this._storage[pageId] = gv = {};
  16759. gv.playing = buffer.readBool();
  16760. gv.frame = buffer.readInt();
  16761. };
  16762. GearAnimation.prototype.apply = function () {
  16763. this._owner._gearLocked = true;
  16764. var gv = this._storage[this._controller.selectedPageId];
  16765. if (!gv)
  16766. gv = this._default;
  16767. this._owner.setProp(fgui.ObjectPropID.Playing, gv.playing);
  16768. this._owner.setProp(fgui.ObjectPropID.Frame, gv.frame);
  16769. this._owner._gearLocked = false;
  16770. };
  16771. GearAnimation.prototype.updateState = function () {
  16772. var gv = this._storage[this._controller.selectedPageId];
  16773. if (!gv)
  16774. this._storage[this._controller.selectedPageId] = gv = {};
  16775. gv.playing = this._owner.getProp(fgui.ObjectPropID.Playing);
  16776. gv.frame = this._owner.getProp(fgui.ObjectPropID.Frame);
  16777. };
  16778. return GearAnimation;
  16779. }(fgui.GearBase));
  16780. fgui.GearAnimation = GearAnimation;
  16781. })(fgui || (fgui = {}));
  16782. (function (fgui) {
  16783. var GearColor = (function (_super) {
  16784. __extends(GearColor, _super);
  16785. function GearColor(owner) {
  16786. return _super.call(this, owner) || this;
  16787. }
  16788. GearColor.prototype.init = function () {
  16789. this._default = {
  16790. color: this._owner.getProp(fgui.ObjectPropID.Color),
  16791. strokeColor: this._owner.getProp(fgui.ObjectPropID.OutlineColor)
  16792. };
  16793. this._storage = {};
  16794. };
  16795. GearColor.prototype.addStatus = function (pageId, buffer) {
  16796. var gv;
  16797. if (pageId == null)
  16798. gv = this._default;
  16799. else
  16800. this._storage[pageId] = gv = {};
  16801. gv.color = buffer.readColor();
  16802. gv.strokeColor = buffer.readColor();
  16803. };
  16804. GearColor.prototype.apply = function () {
  16805. this._owner._gearLocked = true;
  16806. var gv = this._storage[this._controller.selectedPageId];
  16807. if (!gv)
  16808. gv = this._default;
  16809. this._owner.setProp(fgui.ObjectPropID.Color, gv.color);
  16810. this._owner.setProp(fgui.ObjectPropID.OutlineColor, gv.strokeColor);
  16811. this._owner._gearLocked = false;
  16812. };
  16813. GearColor.prototype.updateState = function () {
  16814. var gv = this._storage[this._controller.selectedPageId];
  16815. if (!gv)
  16816. this._storage[this._controller.selectedPageId] = gv = {};
  16817. gv.color = this._owner.getProp(fgui.ObjectPropID.Color);
  16818. gv.strokeColor = this._owner.getProp(fgui.ObjectPropID.OutlineColor);
  16819. };
  16820. return GearColor;
  16821. }(fgui.GearBase));
  16822. fgui.GearColor = GearColor;
  16823. })(fgui || (fgui = {}));
  16824. (function (fgui) {
  16825. var GearDisplay = (function (_super) {
  16826. __extends(GearDisplay, _super);
  16827. function GearDisplay(owner) {
  16828. var _this = _super.call(this, owner) || this;
  16829. _this._displayLockToken = 1;
  16830. _this._visible = 0;
  16831. return _this;
  16832. }
  16833. GearDisplay.prototype.init = function () {
  16834. this.pages = null;
  16835. };
  16836. GearDisplay.prototype.apply = function () {
  16837. this._displayLockToken++;
  16838. if (this._displayLockToken == 0)
  16839. this._displayLockToken = 1;
  16840. if (this.pages == null || this.pages.length == 0
  16841. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  16842. this._visible = 1;
  16843. else
  16844. this._visible = 0;
  16845. };
  16846. GearDisplay.prototype.addLock = function () {
  16847. this._visible++;
  16848. return this._displayLockToken;
  16849. };
  16850. GearDisplay.prototype.releaseLock = function (token) {
  16851. if (token == this._displayLockToken)
  16852. this._visible--;
  16853. };
  16854. Object.defineProperty(GearDisplay.prototype, "connected", {
  16855. get: function () {
  16856. return this._controller == null || this._visible > 0;
  16857. },
  16858. enumerable: false,
  16859. configurable: true
  16860. });
  16861. return GearDisplay;
  16862. }(fgui.GearBase));
  16863. fgui.GearDisplay = GearDisplay;
  16864. })(fgui || (fgui = {}));
  16865. (function (fgui) {
  16866. var GearDisplay2 = (function (_super) {
  16867. __extends(GearDisplay2, _super);
  16868. function GearDisplay2(owner) {
  16869. var _this = _super.call(this, owner) || this;
  16870. _this._visible = 0;
  16871. return _this;
  16872. }
  16873. GearDisplay2.prototype.init = function () {
  16874. this.pages = null;
  16875. };
  16876. GearDisplay2.prototype.apply = function () {
  16877. if (this.pages == null || this.pages.length == 0
  16878. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  16879. this._visible = 1;
  16880. else
  16881. this._visible = 0;
  16882. };
  16883. GearDisplay2.prototype.evaluate = function (connected) {
  16884. var v = this._controller == null || this._visible > 0;
  16885. if (this.condition == 0)
  16886. v = v && connected;
  16887. else
  16888. v = v || connected;
  16889. return v;
  16890. };
  16891. return GearDisplay2;
  16892. }(fgui.GearBase));
  16893. fgui.GearDisplay2 = GearDisplay2;
  16894. })(fgui || (fgui = {}));
  16895. (function (fgui) {
  16896. var GearFontSize = (function (_super) {
  16897. __extends(GearFontSize, _super);
  16898. function GearFontSize(owner) {
  16899. var _this = _super.call(this, owner) || this;
  16900. _this._default = 0;
  16901. return _this;
  16902. }
  16903. GearFontSize.prototype.init = function () {
  16904. this._default = this._owner.getProp(fgui.ObjectPropID.FontSize);
  16905. this._storage = {};
  16906. };
  16907. GearFontSize.prototype.addStatus = function (pageId, buffer) {
  16908. if (pageId == null)
  16909. this._default = buffer.readInt();
  16910. else
  16911. this._storage[pageId] = buffer.readInt();
  16912. };
  16913. GearFontSize.prototype.apply = function () {
  16914. this._owner._gearLocked = true;
  16915. var data = this._storage[this._controller.selectedPageId];
  16916. if (data != undefined)
  16917. this._owner.setProp(fgui.ObjectPropID.FontSize, data);
  16918. else
  16919. this._owner.setProp(fgui.ObjectPropID.FontSize, this._default);
  16920. this._owner._gearLocked = false;
  16921. };
  16922. GearFontSize.prototype.updateState = function () {
  16923. this._storage[this._controller.selectedPageId] = this._owner.getProp(fgui.ObjectPropID.FontSize);
  16924. };
  16925. return GearFontSize;
  16926. }(fgui.GearBase));
  16927. fgui.GearFontSize = GearFontSize;
  16928. })(fgui || (fgui = {}));
  16929. (function (fgui) {
  16930. var GearIcon = (function (_super) {
  16931. __extends(GearIcon, _super);
  16932. function GearIcon(owner) {
  16933. return _super.call(this, owner) || this;
  16934. }
  16935. GearIcon.prototype.init = function () {
  16936. this._default = this._owner.icon;
  16937. this._storage = {};
  16938. };
  16939. GearIcon.prototype.addStatus = function (pageId, buffer) {
  16940. if (pageId == null)
  16941. this._default = buffer.readS();
  16942. else
  16943. this._storage[pageId] = buffer.readS();
  16944. };
  16945. GearIcon.prototype.apply = function () {
  16946. this._owner._gearLocked = true;
  16947. var data = this._storage[this._controller.selectedPageId];
  16948. if (data !== undefined)
  16949. this._owner.icon = data;
  16950. else
  16951. this._owner.icon = this._default;
  16952. this._owner._gearLocked = false;
  16953. };
  16954. GearIcon.prototype.updateState = function () {
  16955. this._storage[this._controller.selectedPageId] = this._owner.icon;
  16956. };
  16957. return GearIcon;
  16958. }(fgui.GearBase));
  16959. fgui.GearIcon = GearIcon;
  16960. })(fgui || (fgui = {}));
  16961. (function (fgui) {
  16962. var GearLook = (function (_super) {
  16963. __extends(GearLook, _super);
  16964. function GearLook(owner) {
  16965. return _super.call(this, owner) || this;
  16966. }
  16967. GearLook.prototype.init = function () {
  16968. this._default = {
  16969. alpha: this._owner.alpha,
  16970. rotation: this._owner.rotation,
  16971. grayed: this._owner.grayed,
  16972. touchable: this._owner.touchable
  16973. };
  16974. this._storage = {};
  16975. };
  16976. GearLook.prototype.addStatus = function (pageId, buffer) {
  16977. var gv;
  16978. if (pageId == null)
  16979. gv = this._default;
  16980. else
  16981. this._storage[pageId] = gv = {};
  16982. gv.alpha = buffer.readFloat();
  16983. gv.rotation = buffer.readFloat();
  16984. gv.grayed = buffer.readBool();
  16985. gv.touchable = buffer.readBool();
  16986. };
  16987. GearLook.prototype.apply = function () {
  16988. var gv = this._storage[this._controller.selectedPageId];
  16989. if (!gv)
  16990. gv = this._default;
  16991. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  16992. this._owner._gearLocked = true;
  16993. this._owner.grayed = gv.grayed;
  16994. this._owner.touchable = gv.touchable;
  16995. this._owner._gearLocked = false;
  16996. if (this._tweenConfig._tweener) {
  16997. if (this._tweenConfig._tweener.endValue.x != gv.alpha || this._tweenConfig._tweener.endValue.y != gv.rotation) {
  16998. this._tweenConfig._tweener.kill(true);
  16999. this._tweenConfig._tweener = null;
  17000. }
  17001. else
  17002. return;
  17003. }
  17004. var a = gv.alpha != this._owner.alpha;
  17005. var b = gv.rotation != this._owner.rotation;
  17006. if (a || b) {
  17007. if (this._owner.checkGearController(0, this._controller))
  17008. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  17009. this._tweenConfig._tweener = fgui.GTween.to2(this._owner.alpha, this._owner.rotation, gv.alpha, gv.rotation, this._tweenConfig.duration)
  17010. .setDelay(this._tweenConfig.delay)
  17011. .setEase(this._tweenConfig.easeType)
  17012. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  17013. .setTarget(this)
  17014. .onUpdate(this.__tweenUpdate, this)
  17015. .onComplete(this.__tweenComplete, this);
  17016. }
  17017. }
  17018. else {
  17019. this._owner._gearLocked = true;
  17020. this._owner.grayed = gv.grayed;
  17021. this._owner.touchable = gv.touchable;
  17022. this._owner.alpha = gv.alpha;
  17023. this._owner.rotation = gv.rotation;
  17024. this._owner._gearLocked = false;
  17025. }
  17026. };
  17027. GearLook.prototype.__tweenUpdate = function (tweener) {
  17028. var flag = tweener.userData;
  17029. this._owner._gearLocked = true;
  17030. if ((flag & 1) != 0)
  17031. this._owner.alpha = tweener.value.x;
  17032. if ((flag & 2) != 0)
  17033. this._owner.rotation = tweener.value.y;
  17034. this._owner._gearLocked = false;
  17035. };
  17036. GearLook.prototype.__tweenComplete = function () {
  17037. if (this._tweenConfig._displayLockToken != 0) {
  17038. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17039. this._tweenConfig._displayLockToken = 0;
  17040. }
  17041. this._tweenConfig._tweener = null;
  17042. };
  17043. GearLook.prototype.updateState = function () {
  17044. var gv = this._storage[this._controller.selectedPageId];
  17045. if (!gv)
  17046. this._storage[this._controller.selectedPageId] = gv = {};
  17047. gv.alpha = this._owner.alpha;
  17048. gv.rotation = this._owner.rotation;
  17049. gv.grayed = this._owner.grayed;
  17050. gv.touchable = this._owner.touchable;
  17051. };
  17052. return GearLook;
  17053. }(fgui.GearBase));
  17054. fgui.GearLook = GearLook;
  17055. })(fgui || (fgui = {}));
  17056. (function (fgui) {
  17057. var GearSize = (function (_super) {
  17058. __extends(GearSize, _super);
  17059. function GearSize(owner) {
  17060. return _super.call(this, owner) || this;
  17061. }
  17062. GearSize.prototype.init = function () {
  17063. this._default = {
  17064. width: this._owner.width,
  17065. height: this._owner.height,
  17066. scaleX: this._owner.scaleX,
  17067. scaleY: this._owner.scaleY
  17068. };
  17069. this._storage = {};
  17070. };
  17071. GearSize.prototype.addStatus = function (pageId, buffer) {
  17072. var gv;
  17073. if (pageId == null)
  17074. gv = this._default;
  17075. else
  17076. this._storage[pageId] = gv = {};
  17077. gv.width = buffer.readInt();
  17078. gv.height = buffer.readInt();
  17079. gv.scaleX = buffer.readFloat();
  17080. gv.scaleY = buffer.readFloat();
  17081. };
  17082. GearSize.prototype.apply = function () {
  17083. var gv = this._storage[this._controller.selectedPageId];
  17084. if (!gv)
  17085. gv = this._default;
  17086. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  17087. if (this._tweenConfig._tweener) {
  17088. if (this._tweenConfig._tweener.endValue.x != gv.width || this._tweenConfig._tweener.endValue.y != gv.height
  17089. || this._tweenConfig._tweener.endValue.z != gv.scaleX || this._tweenConfig._tweener.endValue.w != gv.scaleY) {
  17090. this._tweenConfig._tweener.kill(true);
  17091. this._tweenConfig._tweener = null;
  17092. }
  17093. else
  17094. return;
  17095. }
  17096. var a = gv.width != this._owner.width || gv.height != this._owner.height;
  17097. var b = gv.scaleX != this._owner.scaleX || gv.scaleY != this._owner.scaleY;
  17098. if (a || b) {
  17099. if (this._owner.checkGearController(0, this._controller))
  17100. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  17101. 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)
  17102. .setDelay(this._tweenConfig.delay)
  17103. .setEase(this._tweenConfig.easeType)
  17104. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  17105. .setTarget(this)
  17106. .onUpdate(this.__tweenUpdate, this)
  17107. .onComplete(this.__tweenComplete, this);
  17108. }
  17109. }
  17110. else {
  17111. this._owner._gearLocked = true;
  17112. this._owner.setSize(gv.width, gv.height, this._owner.gearXY.controller == this._controller);
  17113. this._owner.setScale(gv.scaleX, gv.scaleY);
  17114. this._owner._gearLocked = false;
  17115. }
  17116. };
  17117. GearSize.prototype.__tweenUpdate = function (tweener) {
  17118. var flag = tweener.userData;
  17119. this._owner._gearLocked = true;
  17120. if ((flag & 1) != 0)
  17121. this._owner.setSize(tweener.value.x, tweener.value.y, this._owner.checkGearController(1, this._controller));
  17122. if ((flag & 2) != 0)
  17123. this._owner.setScale(tweener.value.z, tweener.value.w);
  17124. this._owner._gearLocked = false;
  17125. };
  17126. GearSize.prototype.__tweenComplete = function () {
  17127. if (this._tweenConfig._displayLockToken != 0) {
  17128. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17129. this._tweenConfig._displayLockToken = 0;
  17130. }
  17131. this._tweenConfig._tweener = null;
  17132. };
  17133. GearSize.prototype.updateState = function () {
  17134. var gv = this._storage[this._controller.selectedPageId];
  17135. if (!gv)
  17136. this._storage[this._controller.selectedPageId] = gv = {};
  17137. gv.width = this._owner.width;
  17138. gv.height = this._owner.height;
  17139. gv.scaleX = this._owner.scaleX;
  17140. gv.scaleY = this._owner.scaleY;
  17141. };
  17142. GearSize.prototype.updateFromRelations = function (dx, dy) {
  17143. if (this._controller == null || this._storage == null)
  17144. return;
  17145. for (var key in this._storage) {
  17146. var gv = this._storage[key];
  17147. gv.width += dx;
  17148. gv.height += dy;
  17149. }
  17150. this._default.width += dx;
  17151. this._default.height += dy;
  17152. this.updateState();
  17153. };
  17154. return GearSize;
  17155. }(fgui.GearBase));
  17156. fgui.GearSize = GearSize;
  17157. })(fgui || (fgui = {}));
  17158. (function (fgui) {
  17159. var GearText = (function (_super) {
  17160. __extends(GearText, _super);
  17161. function GearText(owner) {
  17162. return _super.call(this, owner) || this;
  17163. }
  17164. GearText.prototype.init = function () {
  17165. this._default = this._owner.text;
  17166. this._storage = {};
  17167. };
  17168. GearText.prototype.addStatus = function (pageId, buffer) {
  17169. if (pageId == null)
  17170. this._default = buffer.readS();
  17171. else
  17172. this._storage[pageId] = buffer.readS();
  17173. };
  17174. GearText.prototype.apply = function () {
  17175. this._owner._gearLocked = true;
  17176. var data = this._storage[this._controller.selectedPageId];
  17177. if (data !== undefined)
  17178. this._owner.text = data;
  17179. else
  17180. this._owner.text = this._default;
  17181. this._owner._gearLocked = false;
  17182. };
  17183. GearText.prototype.updateState = function () {
  17184. this._storage[this._controller.selectedPageId] = this._owner.text;
  17185. };
  17186. return GearText;
  17187. }(fgui.GearBase));
  17188. fgui.GearText = GearText;
  17189. })(fgui || (fgui = {}));
  17190. (function (fgui) {
  17191. var GearXY = (function (_super) {
  17192. __extends(GearXY, _super);
  17193. function GearXY(owner) {
  17194. return _super.call(this, owner) || this;
  17195. }
  17196. GearXY.prototype.init = function () {
  17197. this._default = {
  17198. x: this._owner.x,
  17199. y: this._owner.y,
  17200. px: this._owner.x / this._owner.parent.width,
  17201. py: this._owner.y / this._owner.parent.height
  17202. };
  17203. this._storage = {};
  17204. };
  17205. GearXY.prototype.addStatus = function (pageId, buffer) {
  17206. var gv;
  17207. if (pageId == null)
  17208. gv = this._default;
  17209. else
  17210. this._storage[pageId] = gv = {};
  17211. gv.x = buffer.readInt();
  17212. gv.y = buffer.readInt();
  17213. };
  17214. GearXY.prototype.addExtStatus = function (pageId, buffer) {
  17215. var gv;
  17216. if (pageId == null)
  17217. gv = this._default;
  17218. else
  17219. gv = this._storage[pageId];
  17220. gv.px = buffer.readFloat();
  17221. gv.py = buffer.readFloat();
  17222. };
  17223. GearXY.prototype.apply = function () {
  17224. var gv = this._storage[this._controller.selectedPageId];
  17225. if (!gv)
  17226. gv = this._default;
  17227. var ex;
  17228. var ey;
  17229. if (this.positionsInPercent && this._owner.parent) {
  17230. ex = gv.px * this._owner.parent.width;
  17231. ey = gv.py * this._owner.parent.height;
  17232. }
  17233. else {
  17234. ex = gv.x;
  17235. ey = gv.y;
  17236. }
  17237. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  17238. if (this._tweenConfig._tweener) {
  17239. if (this._tweenConfig._tweener.endValue.x != ex || this._tweenConfig._tweener.endValue.y != ey) {
  17240. this._tweenConfig._tweener.kill(true);
  17241. this._tweenConfig._tweener = null;
  17242. }
  17243. else
  17244. return;
  17245. }
  17246. var ox = this._owner.x;
  17247. var oy = this._owner.y;
  17248. if (ox != ex || oy != ey) {
  17249. if (this._owner.checkGearController(0, this._controller))
  17250. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  17251. this._tweenConfig._tweener = fgui.GTween.to2(ox, oy, ex, ey, this._tweenConfig.duration)
  17252. .setDelay(this._tweenConfig.delay)
  17253. .setEase(this._tweenConfig.easeType)
  17254. .setTarget(this)
  17255. .onUpdate(this.__tweenUpdate, this)
  17256. .onComplete(this.__tweenComplete, this);
  17257. }
  17258. }
  17259. else {
  17260. this._owner._gearLocked = true;
  17261. this._owner.setPosition(ex, ey);
  17262. this._owner._gearLocked = false;
  17263. }
  17264. };
  17265. GearXY.prototype.__tweenUpdate = function (tweener) {
  17266. this._owner._gearLocked = true;
  17267. this._owner.setPosition(tweener.value.x, tweener.value.y);
  17268. this._owner._gearLocked = false;
  17269. };
  17270. GearXY.prototype.__tweenComplete = function () {
  17271. if (this._tweenConfig._displayLockToken != 0) {
  17272. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17273. this._tweenConfig._displayLockToken = 0;
  17274. }
  17275. this._tweenConfig._tweener = null;
  17276. };
  17277. GearXY.prototype.updateState = function () {
  17278. var gv = this._storage[this._controller.selectedPageId];
  17279. if (!gv)
  17280. this._storage[this._controller.selectedPageId] = gv = {};
  17281. gv.x = this._owner.x;
  17282. gv.y = this._owner.y;
  17283. gv.px = this._owner.x / this._owner.parent.width;
  17284. gv.py = this._owner.y / this._owner.parent.height;
  17285. };
  17286. GearXY.prototype.updateFromRelations = function (dx, dy) {
  17287. if (this._controller == null || this._storage == null || this.positionsInPercent)
  17288. return;
  17289. for (var key in this._storage) {
  17290. var pt = this._storage[key];
  17291. pt.x += dx;
  17292. pt.y += dy;
  17293. }
  17294. this._default.x += dx;
  17295. this._default.y += dy;
  17296. this.updateState();
  17297. };
  17298. return GearXY;
  17299. }(fgui.GearBase));
  17300. fgui.GearXY = GearXY;
  17301. })(fgui || (fgui = {}));
  17302. (function (fgui) {
  17303. var _PiOver2 = Math.PI * 0.5;
  17304. var _TwoPi = Math.PI * 2;
  17305. function evaluateEase(easeType, time, duration, overshootOrAmplitude, period) {
  17306. switch (easeType) {
  17307. case fgui.EaseType.Linear:
  17308. return time / duration;
  17309. case fgui.EaseType.SineIn:
  17310. return -Math.cos(time / duration * _PiOver2) + 1;
  17311. case fgui.EaseType.SineOut:
  17312. return Math.sin(time / duration * _PiOver2);
  17313. case fgui.EaseType.SineInOut:
  17314. return -0.5 * (Math.cos(Math.PI * time / duration) - 1);
  17315. case fgui.EaseType.QuadIn:
  17316. return (time /= duration) * time;
  17317. case fgui.EaseType.QuadOut:
  17318. return -(time /= duration) * (time - 2);
  17319. case fgui.EaseType.QuadInOut:
  17320. if ((time /= duration * 0.5) < 1)
  17321. return 0.5 * time * time;
  17322. return -0.5 * ((--time) * (time - 2) - 1);
  17323. case fgui.EaseType.CubicIn:
  17324. return (time /= duration) * time * time;
  17325. case fgui.EaseType.CubicOut:
  17326. return ((time = time / duration - 1) * time * time + 1);
  17327. case fgui.EaseType.CubicInOut:
  17328. if ((time /= duration * 0.5) < 1)
  17329. return 0.5 * time * time * time;
  17330. return 0.5 * ((time -= 2) * time * time + 2);
  17331. case fgui.EaseType.QuartIn:
  17332. return (time /= duration) * time * time * time;
  17333. case fgui.EaseType.QuartOut:
  17334. return -((time = time / duration - 1) * time * time * time - 1);
  17335. case fgui.EaseType.QuartInOut:
  17336. if ((time /= duration * 0.5) < 1)
  17337. return 0.5 * time * time * time * time;
  17338. return -0.5 * ((time -= 2) * time * time * time - 2);
  17339. case fgui.EaseType.QuintIn:
  17340. return (time /= duration) * time * time * time * time;
  17341. case fgui.EaseType.QuintOut:
  17342. return ((time = time / duration - 1) * time * time * time * time + 1);
  17343. case fgui.EaseType.QuintInOut:
  17344. if ((time /= duration * 0.5) < 1)
  17345. return 0.5 * time * time * time * time * time;
  17346. return 0.5 * ((time -= 2) * time * time * time * time + 2);
  17347. case fgui.EaseType.ExpoIn:
  17348. return (time == 0) ? 0 : Math.pow(2, 10 * (time / duration - 1));
  17349. case fgui.EaseType.ExpoOut:
  17350. if (time == duration)
  17351. return 1;
  17352. return (-Math.pow(2, -10 * time / duration) + 1);
  17353. case fgui.EaseType.ExpoInOut:
  17354. if (time == 0)
  17355. return 0;
  17356. if (time == duration)
  17357. return 1;
  17358. if ((time /= duration * 0.5) < 1)
  17359. return 0.5 * Math.pow(2, 10 * (time - 1));
  17360. return 0.5 * (-Math.pow(2, -10 * --time) + 2);
  17361. case fgui.EaseType.CircIn:
  17362. return -(Math.sqrt(1 - (time /= duration) * time) - 1);
  17363. case fgui.EaseType.CircOut:
  17364. return Math.sqrt(1 - (time = time / duration - 1) * time);
  17365. case fgui.EaseType.CircInOut:
  17366. if ((time /= duration * 0.5) < 1)
  17367. return -0.5 * (Math.sqrt(1 - time * time) - 1);
  17368. return 0.5 * (Math.sqrt(1 - (time -= 2) * time) + 1);
  17369. case fgui.EaseType.ElasticIn:
  17370. var s0;
  17371. if (time == 0)
  17372. return 0;
  17373. if ((time /= duration) == 1)
  17374. return 1;
  17375. if (period == 0)
  17376. period = duration * 0.3;
  17377. if (overshootOrAmplitude < 1) {
  17378. overshootOrAmplitude = 1;
  17379. s0 = period / 4;
  17380. }
  17381. else
  17382. s0 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17383. return -(overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s0) * _TwoPi / period));
  17384. case fgui.EaseType.ElasticOut:
  17385. var s1;
  17386. if (time == 0)
  17387. return 0;
  17388. if ((time /= duration) == 1)
  17389. return 1;
  17390. if (period == 0)
  17391. period = duration * 0.3;
  17392. if (overshootOrAmplitude < 1) {
  17393. overshootOrAmplitude = 1;
  17394. s1 = period / 4;
  17395. }
  17396. else
  17397. s1 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17398. return (overshootOrAmplitude * Math.pow(2, -10 * time) * Math.sin((time * duration - s1) * _TwoPi / period) + 1);
  17399. case fgui.EaseType.ElasticInOut:
  17400. var s;
  17401. if (time == 0)
  17402. return 0;
  17403. if ((time /= duration * 0.5) == 2)
  17404. return 1;
  17405. if (period == 0)
  17406. period = duration * (0.3 * 1.5);
  17407. if (overshootOrAmplitude < 1) {
  17408. overshootOrAmplitude = 1;
  17409. s = period / 4;
  17410. }
  17411. else
  17412. s = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17413. if (time < 1)
  17414. return -0.5 * (overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period));
  17415. return overshootOrAmplitude * Math.pow(2, -10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period) * 0.5 + 1;
  17416. case fgui.EaseType.BackIn:
  17417. return (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude);
  17418. case fgui.EaseType.BackOut:
  17419. return ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);
  17420. case fgui.EaseType.BackInOut:
  17421. if ((time /= duration * 0.5) < 1)
  17422. return 0.5 * (time * time * (((overshootOrAmplitude *= (1.525)) + 1) * time - overshootOrAmplitude));
  17423. return 0.5 * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525)) + 1) * time + overshootOrAmplitude) + 2);
  17424. case fgui.EaseType.BounceIn:
  17425. return bounce_easeIn(time, duration);
  17426. case fgui.EaseType.BounceOut:
  17427. return bounce_easeOut(time, duration);
  17428. case fgui.EaseType.BounceInOut:
  17429. return bounce_easeInOut(time, duration);
  17430. default:
  17431. return -(time /= duration) * (time - 2);
  17432. }
  17433. }
  17434. fgui.evaluateEase = evaluateEase;
  17435. function bounce_easeIn(time, duration) {
  17436. return 1 - bounce_easeOut(duration - time, duration);
  17437. }
  17438. function bounce_easeOut(time, duration) {
  17439. if ((time /= duration) < (1 / 2.75)) {
  17440. return (7.5625 * time * time);
  17441. }
  17442. if (time < (2 / 2.75)) {
  17443. return (7.5625 * (time -= (1.5 / 2.75)) * time + 0.75);
  17444. }
  17445. if (time < (2.5 / 2.75)) {
  17446. return (7.5625 * (time -= (2.25 / 2.75)) * time + 0.9375);
  17447. }
  17448. return (7.5625 * (time -= (2.625 / 2.75)) * time + 0.984375);
  17449. }
  17450. function bounce_easeInOut(time, duration) {
  17451. if (time < duration * 0.5) {
  17452. return bounce_easeIn(time * 2, duration) * 0.5;
  17453. }
  17454. return bounce_easeOut(time * 2 - duration, duration) * 0.5 + 0.5;
  17455. }
  17456. })(fgui || (fgui = {}));
  17457. (function (fgui) {
  17458. var EaseType = (function () {
  17459. function EaseType() {
  17460. }
  17461. EaseType.Linear = 0;
  17462. EaseType.SineIn = 1;
  17463. EaseType.SineOut = 2;
  17464. EaseType.SineInOut = 3;
  17465. EaseType.QuadIn = 4;
  17466. EaseType.QuadOut = 5;
  17467. EaseType.QuadInOut = 6;
  17468. EaseType.CubicIn = 7;
  17469. EaseType.CubicOut = 8;
  17470. EaseType.CubicInOut = 9;
  17471. EaseType.QuartIn = 10;
  17472. EaseType.QuartOut = 11;
  17473. EaseType.QuartInOut = 12;
  17474. EaseType.QuintIn = 13;
  17475. EaseType.QuintOut = 14;
  17476. EaseType.QuintInOut = 15;
  17477. EaseType.ExpoIn = 16;
  17478. EaseType.ExpoOut = 17;
  17479. EaseType.ExpoInOut = 18;
  17480. EaseType.CircIn = 19;
  17481. EaseType.CircOut = 20;
  17482. EaseType.CircInOut = 21;
  17483. EaseType.ElasticIn = 22;
  17484. EaseType.ElasticOut = 23;
  17485. EaseType.ElasticInOut = 24;
  17486. EaseType.BackIn = 25;
  17487. EaseType.BackOut = 26;
  17488. EaseType.BackInOut = 27;
  17489. EaseType.BounceIn = 28;
  17490. EaseType.BounceOut = 29;
  17491. EaseType.BounceInOut = 30;
  17492. EaseType.Custom = 31;
  17493. return EaseType;
  17494. }());
  17495. fgui.EaseType = EaseType;
  17496. })(fgui || (fgui = {}));
  17497. (function (fgui) {
  17498. var GPath = (function () {
  17499. function GPath() {
  17500. this._segments = new Array();
  17501. this._points = new Array();
  17502. }
  17503. Object.defineProperty(GPath.prototype, "length", {
  17504. get: function () {
  17505. return this._fullLength;
  17506. },
  17507. enumerable: false,
  17508. configurable: true
  17509. });
  17510. GPath.prototype.create = function (pt1, pt2, pt3, pt4) {
  17511. var points;
  17512. if (Array.isArray(pt1))
  17513. points = pt1;
  17514. else {
  17515. points = new Array();
  17516. points.push(pt1);
  17517. points.push(pt2);
  17518. if (pt3)
  17519. points.push(pt3);
  17520. if (pt4)
  17521. points.push(pt4);
  17522. }
  17523. this._segments.length = 0;
  17524. this._points.length = 0;
  17525. this._fullLength = 0;
  17526. var cnt = points.length;
  17527. if (cnt == 0)
  17528. return;
  17529. var splinePoints = s_points;
  17530. splinePoints.length = 0;
  17531. var prev = points[0];
  17532. if (prev.curveType == fgui.CurveType.CRSpline)
  17533. splinePoints.push(new cc.Vec2(prev.x, prev.y));
  17534. for (var i = 1; i < cnt; i++) {
  17535. var current = points[i];
  17536. if (prev.curveType != fgui.CurveType.CRSpline) {
  17537. var seg = {};
  17538. seg.type = prev.curveType;
  17539. seg.ptStart = this._points.length;
  17540. if (prev.curveType == fgui.CurveType.Straight) {
  17541. seg.ptCount = 2;
  17542. this._points.push(new cc.Vec2(prev.x, prev.y));
  17543. this._points.push(new cc.Vec2(current.x, current.y));
  17544. }
  17545. else if (prev.curveType == fgui.CurveType.Bezier) {
  17546. seg.ptCount = 3;
  17547. this._points.push(new cc.Vec2(prev.x, prev.y));
  17548. this._points.push(new cc.Vec2(current.x, current.y));
  17549. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  17550. }
  17551. else if (prev.curveType == fgui.CurveType.CubicBezier) {
  17552. seg.ptCount = 4;
  17553. this._points.push(new cc.Vec2(prev.x, prev.y));
  17554. this._points.push(new cc.Vec2(current.x, current.y));
  17555. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  17556. this._points.push(new cc.Vec2(prev.control2_x, prev.control2_y));
  17557. }
  17558. seg.length = fgui.ToolSet.distance(prev.x, prev.y, current.x, current.y);
  17559. this._fullLength += seg.length;
  17560. this._segments.push(seg);
  17561. }
  17562. if (current.curveType != fgui.CurveType.CRSpline) {
  17563. if (splinePoints.length > 0) {
  17564. splinePoints.push(new cc.Vec2(current.x, current.y));
  17565. this.createSplineSegment();
  17566. }
  17567. }
  17568. else
  17569. splinePoints.push(new cc.Vec2(current.x, current.y));
  17570. prev = current;
  17571. }
  17572. if (splinePoints.length > 1)
  17573. this.createSplineSegment();
  17574. };
  17575. GPath.prototype.createSplineSegment = function () {
  17576. var splinePoints = s_points;
  17577. var cnt = splinePoints.length;
  17578. splinePoints.splice(0, 0, splinePoints[0]);
  17579. splinePoints.push(splinePoints[cnt]);
  17580. splinePoints.push(splinePoints[cnt]);
  17581. cnt += 3;
  17582. var seg = {};
  17583. seg.type = fgui.CurveType.CRSpline;
  17584. seg.ptStart = this._points.length;
  17585. seg.ptCount = cnt;
  17586. this._points = this._points.concat(splinePoints);
  17587. seg.length = 0;
  17588. for (var i = 1; i < cnt; i++) {
  17589. seg.length += fgui.ToolSet.distance(splinePoints[i - 1].x, splinePoints[i - 1].y, splinePoints[i].x, splinePoints[i].y);
  17590. }
  17591. this._fullLength += seg.length;
  17592. this._segments.push(seg);
  17593. splinePoints.length = 0;
  17594. };
  17595. GPath.prototype.clear = function () {
  17596. this._segments.length = 0;
  17597. this._points.length = 0;
  17598. };
  17599. GPath.prototype.getPointAt = function (t, result) {
  17600. if (!result)
  17601. result = new cc.Vec2();
  17602. else
  17603. result.x = result.y = 0;
  17604. t = fgui.ToolSet.clamp01(t);
  17605. var cnt = this._segments.length;
  17606. if (cnt == 0) {
  17607. return result;
  17608. }
  17609. var seg;
  17610. if (t == 1) {
  17611. seg = this._segments[cnt - 1];
  17612. if (seg.type == fgui.CurveType.Straight) {
  17613. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  17614. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  17615. return result;
  17616. }
  17617. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17618. return this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  17619. else
  17620. return this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  17621. }
  17622. var len = t * this._fullLength;
  17623. for (var i = 0; i < cnt; i++) {
  17624. seg = this._segments[i];
  17625. len -= seg.length;
  17626. if (len < 0) {
  17627. t = 1 + len / seg.length;
  17628. if (seg.type == fgui.CurveType.Straight) {
  17629. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  17630. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  17631. }
  17632. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17633. result = this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  17634. else
  17635. result = this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  17636. break;
  17637. }
  17638. }
  17639. return result;
  17640. };
  17641. Object.defineProperty(GPath.prototype, "segmentCount", {
  17642. get: function () {
  17643. return this._segments.length;
  17644. },
  17645. enumerable: false,
  17646. configurable: true
  17647. });
  17648. GPath.prototype.getAnchorsInSegment = function (segmentIndex, points) {
  17649. if (points == null)
  17650. points = new Array();
  17651. var seg = this._segments[segmentIndex];
  17652. for (var i = 0; i < seg.ptCount; i++)
  17653. points.push(new cc.Vec2(this._points[seg.ptStart + i].x, this._points[seg.ptStart + i].y));
  17654. return points;
  17655. };
  17656. GPath.prototype.getPointsInSegment = function (segmentIndex, t0, t1, points, ts, pointDensity) {
  17657. if (points == null)
  17658. points = new Array();
  17659. if (!pointDensity || isNaN(pointDensity))
  17660. pointDensity = 0.1;
  17661. if (ts)
  17662. ts.push(t0);
  17663. var seg = this._segments[segmentIndex];
  17664. if (seg.type == fgui.CurveType.Straight) {
  17665. 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)));
  17666. 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)));
  17667. }
  17668. else {
  17669. var func;
  17670. if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17671. func = this.onBezierCurve;
  17672. else
  17673. func = this.onCRSplineCurve;
  17674. points.push(func.call(this, seg.ptStart, seg.ptCount, t0, new cc.Vec2()));
  17675. var SmoothAmount = Math.min(seg.length * pointDensity, 50);
  17676. for (var j = 0; j <= SmoothAmount; j++) {
  17677. var t = j / SmoothAmount;
  17678. if (t > t0 && t < t1) {
  17679. points.push(func.call(this, seg.ptStart, seg.ptCount, t, new cc.Vec2()));
  17680. if (ts != null)
  17681. ts.push(t);
  17682. }
  17683. }
  17684. points.push(func.call(this, seg.ptStart, seg.ptCount, t1, new cc.Vec2()));
  17685. }
  17686. if (ts != null)
  17687. ts.push(t1);
  17688. return points;
  17689. };
  17690. GPath.prototype.getAllPoints = function (points, ts, pointDensity) {
  17691. if (points == null)
  17692. points = new Array();
  17693. if (!pointDensity || isNaN(pointDensity))
  17694. pointDensity = 0.1;
  17695. var cnt = this._segments.length;
  17696. for (var i = 0; i < cnt; i++)
  17697. this.getPointsInSegment(i, 0, 1, points, ts, pointDensity);
  17698. return points;
  17699. };
  17700. GPath.prototype.onCRSplineCurve = function (ptStart, ptCount, t, result) {
  17701. var adjustedIndex = Math.floor(t * (ptCount - 4)) + ptStart;
  17702. var p0x = this._points[adjustedIndex].x;
  17703. var p0y = this._points[adjustedIndex].y;
  17704. var p1x = this._points[adjustedIndex + 1].x;
  17705. var p1y = this._points[adjustedIndex + 1].y;
  17706. var p2x = this._points[adjustedIndex + 2].x;
  17707. var p2y = this._points[adjustedIndex + 2].y;
  17708. var p3x = this._points[adjustedIndex + 3].x;
  17709. var p3y = this._points[adjustedIndex + 3].y;
  17710. var adjustedT = (t == 1) ? 1 : fgui.ToolSet.repeat(t * (ptCount - 4), 1);
  17711. var t0 = ((-adjustedT + 2) * adjustedT - 1) * adjustedT * 0.5;
  17712. var t1 = (((3 * adjustedT - 5) * adjustedT) * adjustedT + 2) * 0.5;
  17713. var t2 = ((-3 * adjustedT + 4) * adjustedT + 1) * adjustedT * 0.5;
  17714. var t3 = ((adjustedT - 1) * adjustedT * adjustedT) * 0.5;
  17715. result.x = p0x * t0 + p1x * t1 + p2x * t2 + p3x * t3;
  17716. result.y = p0y * t0 + p1y * t1 + p2y * t2 + p3y * t3;
  17717. return result;
  17718. };
  17719. GPath.prototype.onBezierCurve = function (ptStart, ptCount, t, result) {
  17720. var t2 = 1 - t;
  17721. var p0x = this._points[ptStart].x;
  17722. var p0y = this._points[ptStart].y;
  17723. var p1x = this._points[ptStart + 1].x;
  17724. var p1y = this._points[ptStart + 1].y;
  17725. var cp0x = this._points[ptStart + 2].x;
  17726. var cp0y = this._points[ptStart + 2].y;
  17727. if (ptCount == 4) {
  17728. var cp1x = this._points[ptStart + 3].x;
  17729. var cp1y = this._points[ptStart + 3].y;
  17730. result.x = t2 * t2 * t2 * p0x + 3 * t2 * t2 * t * cp0x + 3 * t2 * t * t * cp1x + t * t * t * p1x;
  17731. result.y = t2 * t2 * t2 * p0y + 3 * t2 * t2 * t * cp0y + 3 * t2 * t * t * cp1y + t * t * t * p1y;
  17732. }
  17733. else {
  17734. result.x = t2 * t2 * p0x + 2 * t2 * t * cp0x + t * t * p1x;
  17735. result.y = t2 * t2 * p0y + 2 * t2 * t * cp0y + t * t * p1y;
  17736. }
  17737. return result;
  17738. };
  17739. return GPath;
  17740. }());
  17741. fgui.GPath = GPath;
  17742. var s_points = new Array();
  17743. })(fgui || (fgui = {}));
  17744. (function (fgui) {
  17745. var CurveType;
  17746. (function (CurveType) {
  17747. CurveType[CurveType["CRSpline"] = 0] = "CRSpline";
  17748. CurveType[CurveType["Bezier"] = 1] = "Bezier";
  17749. CurveType[CurveType["CubicBezier"] = 2] = "CubicBezier";
  17750. CurveType[CurveType["Straight"] = 3] = "Straight";
  17751. })(CurveType = fgui.CurveType || (fgui.CurveType = {}));
  17752. var GPathPoint = (function () {
  17753. function GPathPoint() {
  17754. this.x = 0;
  17755. this.y = 0;
  17756. this.control1_x = 0;
  17757. this.control1_y = 0;
  17758. this.control2_x = 0;
  17759. this.control2_y = 0;
  17760. this.curveType = 0;
  17761. }
  17762. GPathPoint.newPoint = function (x, y, curveType) {
  17763. if (x === void 0) { x = 0; }
  17764. if (y === void 0) { y = 0; }
  17765. if (curveType === void 0) { curveType = 0; }
  17766. var pt = new GPathPoint();
  17767. pt.x = x;
  17768. pt.y = y;
  17769. pt.control1_x = 0;
  17770. pt.control1_y = 0;
  17771. pt.control2_x = 0;
  17772. pt.control2_y = 0;
  17773. pt.curveType = curveType;
  17774. return pt;
  17775. };
  17776. GPathPoint.newBezierPoint = function (x, y, control1_x, control1_y) {
  17777. if (x === void 0) { x = 0; }
  17778. if (y === void 0) { y = 0; }
  17779. if (control1_x === void 0) { control1_x = 0; }
  17780. if (control1_y === void 0) { control1_y = 0; }
  17781. var pt = new GPathPoint();
  17782. pt.x = x;
  17783. pt.y = y;
  17784. pt.control1_x = control1_x;
  17785. pt.control1_y = control1_y;
  17786. pt.control2_x = 0;
  17787. pt.control2_y = 0;
  17788. pt.curveType = CurveType.Bezier;
  17789. return pt;
  17790. };
  17791. GPathPoint.newCubicBezierPoint = function (x, y, control1_x, control1_y, control2_x, control2_y) {
  17792. if (x === void 0) { x = 0; }
  17793. if (y === void 0) { y = 0; }
  17794. if (control1_x === void 0) { control1_x = 0; }
  17795. if (control1_y === void 0) { control1_y = 0; }
  17796. if (control2_x === void 0) { control2_x = 0; }
  17797. if (control2_y === void 0) { control2_y = 0; }
  17798. var pt = new GPathPoint();
  17799. pt.x = x;
  17800. pt.y = y;
  17801. pt.control1_x = control1_x;
  17802. pt.control1_y = control1_y;
  17803. pt.control2_x = control2_x;
  17804. pt.control2_y = control2_y;
  17805. pt.curveType = CurveType.CubicBezier;
  17806. return pt;
  17807. };
  17808. GPathPoint.prototype.clone = function () {
  17809. var ret = new GPathPoint();
  17810. ret.x = this.x;
  17811. ret.y = this.y;
  17812. ret.control1_x = this.control1_x;
  17813. ret.control1_y = this.control1_y;
  17814. ret.control2_x = this.control2_x;
  17815. ret.control2_y = this.control2_y;
  17816. ret.curveType = this.curveType;
  17817. return ret;
  17818. };
  17819. return GPathPoint;
  17820. }());
  17821. fgui.GPathPoint = GPathPoint;
  17822. })(fgui || (fgui = {}));
  17823. (function (fgui) {
  17824. var GTween = (function () {
  17825. function GTween() {
  17826. }
  17827. GTween.to = function (start, end, duration) {
  17828. return fgui.TweenManager.createTween()._to(start, end, duration);
  17829. };
  17830. GTween.to2 = function (start, start2, end, end2, duration) {
  17831. return fgui.TweenManager.createTween()._to2(start, start2, end, end2, duration);
  17832. };
  17833. GTween.to3 = function (start, start2, start3, end, end2, end3, duration) {
  17834. return fgui.TweenManager.createTween()._to3(start, start2, start3, end, end2, end3, duration);
  17835. };
  17836. GTween.to4 = function (start, start2, start3, start4, end, end2, end3, end4, duration) {
  17837. return fgui.TweenManager.createTween()._to4(start, start2, start3, start4, end, end2, end3, end4, duration);
  17838. };
  17839. GTween.toColor = function (start, end, duration) {
  17840. return fgui.TweenManager.createTween()._toColor(start, end, duration);
  17841. };
  17842. GTween.delayedCall = function (delay) {
  17843. return fgui.TweenManager.createTween().setDelay(delay);
  17844. };
  17845. GTween.shake = function (startX, startY, amplitude, duration) {
  17846. return fgui.TweenManager.createTween()._shake(startX, startY, amplitude, duration);
  17847. };
  17848. GTween.isTweening = function (target, propType) {
  17849. return fgui.TweenManager.isTweening(target, propType);
  17850. };
  17851. GTween.kill = function (target, complete, propType) {
  17852. fgui.TweenManager.killTweens(target, complete, propType);
  17853. };
  17854. GTween.getTween = function (target, propType) {
  17855. return fgui.TweenManager.getTween(target, propType);
  17856. };
  17857. GTween.catchCallbackExceptions = true;
  17858. return GTween;
  17859. }());
  17860. fgui.GTween = GTween;
  17861. })(fgui || (fgui = {}));
  17862. (function (fgui) {
  17863. var GTweener = (function () {
  17864. function GTweener() {
  17865. this._startValue = new fgui.TweenValue();
  17866. this._endValue = new fgui.TweenValue();
  17867. this._value = new fgui.TweenValue();
  17868. this._deltaValue = new fgui.TweenValue();
  17869. this._reset();
  17870. }
  17871. GTweener.prototype.setDelay = function (value) {
  17872. this._delay = value;
  17873. return this;
  17874. };
  17875. Object.defineProperty(GTweener.prototype, "delay", {
  17876. get: function () {
  17877. return this._delay;
  17878. },
  17879. enumerable: false,
  17880. configurable: true
  17881. });
  17882. GTweener.prototype.setDuration = function (value) {
  17883. this._duration = value;
  17884. return this;
  17885. };
  17886. Object.defineProperty(GTweener.prototype, "duration", {
  17887. get: function () {
  17888. return this._duration;
  17889. },
  17890. enumerable: false,
  17891. configurable: true
  17892. });
  17893. GTweener.prototype.setBreakpoint = function (value) {
  17894. this._breakpoint = value;
  17895. return this;
  17896. };
  17897. GTweener.prototype.setEase = function (value) {
  17898. this._easeType = value;
  17899. return this;
  17900. };
  17901. GTweener.prototype.setEasePeriod = function (value) {
  17902. this._easePeriod = value;
  17903. return this;
  17904. };
  17905. GTweener.prototype.setEaseOvershootOrAmplitude = function (value) {
  17906. this._easeOvershootOrAmplitude = value;
  17907. return this;
  17908. };
  17909. GTweener.prototype.setRepeat = function (repeat, yoyo) {
  17910. this._repeat = repeat;
  17911. this._yoyo = yoyo;
  17912. return this;
  17913. };
  17914. Object.defineProperty(GTweener.prototype, "repeat", {
  17915. get: function () {
  17916. return this._repeat;
  17917. },
  17918. enumerable: false,
  17919. configurable: true
  17920. });
  17921. GTweener.prototype.setTimeScale = function (value) {
  17922. this._timeScale = value;
  17923. return this;
  17924. };
  17925. GTweener.prototype.setSnapping = function (value) {
  17926. this._snapping = value;
  17927. return this;
  17928. };
  17929. GTweener.prototype.setTarget = function (value, propType) {
  17930. this._target = value;
  17931. this._propType = propType;
  17932. if (value instanceof fgui.GObject)
  17933. this._node = value.node;
  17934. else if (value instanceof cc.Node)
  17935. this._node = value;
  17936. return this;
  17937. };
  17938. Object.defineProperty(GTweener.prototype, "target", {
  17939. get: function () {
  17940. return this._target;
  17941. },
  17942. enumerable: false,
  17943. configurable: true
  17944. });
  17945. GTweener.prototype.setPath = function (value) {
  17946. this._path = value;
  17947. return this;
  17948. };
  17949. GTweener.prototype.setUserData = function (value) {
  17950. this._userData = value;
  17951. return this;
  17952. };
  17953. Object.defineProperty(GTweener.prototype, "userData", {
  17954. get: function () {
  17955. return this._userData;
  17956. },
  17957. enumerable: false,
  17958. configurable: true
  17959. });
  17960. GTweener.prototype.onUpdate = function (callback, target) {
  17961. this._onUpdate = callback;
  17962. this._onUpdateCaller = target;
  17963. return this;
  17964. };
  17965. GTweener.prototype.onStart = function (callback, target) {
  17966. this._onStart = callback;
  17967. this._onStartCaller = target;
  17968. return this;
  17969. };
  17970. GTweener.prototype.onComplete = function (callback, target) {
  17971. this._onComplete = callback;
  17972. this._onCompleteCaller = target;
  17973. return this;
  17974. };
  17975. Object.defineProperty(GTweener.prototype, "startValue", {
  17976. get: function () {
  17977. return this._startValue;
  17978. },
  17979. enumerable: false,
  17980. configurable: true
  17981. });
  17982. Object.defineProperty(GTweener.prototype, "endValue", {
  17983. get: function () {
  17984. return this._endValue;
  17985. },
  17986. enumerable: false,
  17987. configurable: true
  17988. });
  17989. Object.defineProperty(GTweener.prototype, "value", {
  17990. get: function () {
  17991. return this._value;
  17992. },
  17993. enumerable: false,
  17994. configurable: true
  17995. });
  17996. Object.defineProperty(GTweener.prototype, "deltaValue", {
  17997. get: function () {
  17998. return this._deltaValue;
  17999. },
  18000. enumerable: false,
  18001. configurable: true
  18002. });
  18003. Object.defineProperty(GTweener.prototype, "normalizedTime", {
  18004. get: function () {
  18005. return this._normalizedTime;
  18006. },
  18007. enumerable: false,
  18008. configurable: true
  18009. });
  18010. Object.defineProperty(GTweener.prototype, "completed", {
  18011. get: function () {
  18012. return this._ended != 0;
  18013. },
  18014. enumerable: false,
  18015. configurable: true
  18016. });
  18017. Object.defineProperty(GTweener.prototype, "allCompleted", {
  18018. get: function () {
  18019. return this._ended == 1;
  18020. },
  18021. enumerable: false,
  18022. configurable: true
  18023. });
  18024. GTweener.prototype.setPaused = function (paused) {
  18025. this._paused = paused;
  18026. return this;
  18027. };
  18028. GTweener.prototype.seek = function (time) {
  18029. if (this._killed)
  18030. return;
  18031. this._elapsedTime = time;
  18032. if (this._elapsedTime < this._delay) {
  18033. if (this._started)
  18034. this._elapsedTime = this._delay;
  18035. else
  18036. return;
  18037. }
  18038. this.update();
  18039. };
  18040. GTweener.prototype.kill = function (complete) {
  18041. if (this._killed)
  18042. return;
  18043. if (complete) {
  18044. if (this._ended == 0) {
  18045. if (this._breakpoint >= 0)
  18046. this._elapsedTime = this._delay + this._breakpoint;
  18047. else if (this._repeat >= 0)
  18048. this._elapsedTime = this._delay + this._duration * (this._repeat + 1);
  18049. else
  18050. this._elapsedTime = this._delay + this._duration * 2;
  18051. this.update();
  18052. }
  18053. this.callCompleteCallback();
  18054. }
  18055. this._killed = true;
  18056. };
  18057. GTweener.prototype._to = function (start, end, duration) {
  18058. this._valueSize = 1;
  18059. this._startValue.x = start;
  18060. this._endValue.x = end;
  18061. this._duration = duration;
  18062. return this;
  18063. };
  18064. GTweener.prototype._to2 = function (start, start2, end, end2, duration) {
  18065. this._valueSize = 2;
  18066. this._startValue.x = start;
  18067. this._endValue.x = end;
  18068. this._startValue.y = start2;
  18069. this._endValue.y = end2;
  18070. this._duration = duration;
  18071. return this;
  18072. };
  18073. GTweener.prototype._to3 = function (start, start2, start3, end, end2, end3, duration) {
  18074. this._valueSize = 3;
  18075. this._startValue.x = start;
  18076. this._endValue.x = end;
  18077. this._startValue.y = start2;
  18078. this._endValue.y = end2;
  18079. this._startValue.z = start3;
  18080. this._endValue.z = end3;
  18081. this._duration = duration;
  18082. return this;
  18083. };
  18084. GTweener.prototype._to4 = function (start, start2, start3, start4, end, end2, end3, end4, duration) {
  18085. this._valueSize = 4;
  18086. this._startValue.x = start;
  18087. this._endValue.x = end;
  18088. this._startValue.y = start2;
  18089. this._endValue.y = end2;
  18090. this._startValue.z = start3;
  18091. this._endValue.z = end3;
  18092. this._startValue.w = start4;
  18093. this._endValue.w = end4;
  18094. this._duration = duration;
  18095. return this;
  18096. };
  18097. GTweener.prototype._toColor = function (start, end, duration) {
  18098. this._valueSize = 5;
  18099. this._startValue.color = start;
  18100. this._endValue.color = end;
  18101. this._duration = duration;
  18102. return this;
  18103. };
  18104. GTweener.prototype._shake = function (startX, startY, amplitude, duration) {
  18105. this._valueSize = 6;
  18106. this._startValue.x = startX;
  18107. this._startValue.y = startY;
  18108. this._startValue.w = amplitude;
  18109. this._duration = duration;
  18110. return this;
  18111. };
  18112. GTweener.prototype._init = function () {
  18113. this._delay = 0;
  18114. this._duration = 0;
  18115. this._breakpoint = -1;
  18116. this._easeType = fgui.EaseType.QuadOut;
  18117. this._timeScale = 1;
  18118. this._easePeriod = 0;
  18119. this._easeOvershootOrAmplitude = 1.70158;
  18120. this._snapping = false;
  18121. this._repeat = 0;
  18122. this._yoyo = false;
  18123. this._valueSize = 0;
  18124. this._started = false;
  18125. this._paused = false;
  18126. this._killed = false;
  18127. this._elapsedTime = 0;
  18128. this._normalizedTime = 0;
  18129. this._ended = 0;
  18130. };
  18131. GTweener.prototype._reset = function () {
  18132. this._target = null;
  18133. this._propType = null;
  18134. this._userData = null;
  18135. this._node = null;
  18136. this._path = null;
  18137. this._onStart = this._onUpdate = this._onComplete = null;
  18138. this._onStartCaller = this._onUpdateCaller = this._onCompleteCaller = null;
  18139. };
  18140. GTweener.prototype._update = function (dt) {
  18141. if (this._node && !cc.isValid(this._node)) {
  18142. this._killed = true;
  18143. return;
  18144. }
  18145. if (this._timeScale != 1)
  18146. dt *= this._timeScale;
  18147. if (dt == 0)
  18148. return;
  18149. if (this._ended != 0) {
  18150. this.callCompleteCallback();
  18151. this._killed = true;
  18152. return;
  18153. }
  18154. this._elapsedTime += dt;
  18155. this.update();
  18156. if (this._ended != 0) {
  18157. if (!this._killed) {
  18158. this.callCompleteCallback();
  18159. this._killed = true;
  18160. }
  18161. }
  18162. };
  18163. GTweener.prototype.update = function () {
  18164. this._ended = 0;
  18165. if (this._valueSize == 0) {
  18166. if (this._elapsedTime >= this._delay + this._duration)
  18167. this._ended = 1;
  18168. return;
  18169. }
  18170. if (!this._started) {
  18171. if (this._elapsedTime < this._delay)
  18172. return;
  18173. this._started = true;
  18174. this.callStartCallback();
  18175. if (this._killed)
  18176. return;
  18177. }
  18178. var reversed = false;
  18179. var tt = this._elapsedTime - this._delay;
  18180. if (this._breakpoint >= 0 && tt >= this._breakpoint) {
  18181. tt = this._breakpoint;
  18182. this._ended = 2;
  18183. }
  18184. if (this._repeat != 0) {
  18185. var round = Math.floor(tt / this._duration);
  18186. tt -= this._duration * round;
  18187. if (this._yoyo)
  18188. reversed = round % 2 == 1;
  18189. if (this._repeat > 0 && this._repeat - round < 0) {
  18190. if (this._yoyo)
  18191. reversed = this._repeat % 2 == 1;
  18192. tt = this._duration;
  18193. this._ended = 1;
  18194. }
  18195. }
  18196. else if (tt >= this._duration) {
  18197. tt = this._duration;
  18198. this._ended = 1;
  18199. }
  18200. this._normalizedTime = fgui.evaluateEase(this._easeType, reversed ? (this._duration - tt) : tt, this._duration, this._easeOvershootOrAmplitude, this._easePeriod);
  18201. this._value.setZero();
  18202. this._deltaValue.setZero();
  18203. if (this._valueSize == 6) {
  18204. if (this._ended == 0) {
  18205. var r = this._startValue.w * (1 - this._normalizedTime);
  18206. var rx = r * (Math.random() > 0.5 ? 1 : -1);
  18207. var ry = r * (Math.random() > 0.5 ? 1 : -1);
  18208. this._deltaValue.x = rx;
  18209. this._deltaValue.y = ry;
  18210. this._value.x = this._startValue.x + rx;
  18211. this._value.y = this._startValue.y + ry;
  18212. }
  18213. else {
  18214. this._value.x = this._startValue.x;
  18215. this._value.y = this._startValue.y;
  18216. }
  18217. }
  18218. else if (this._path) {
  18219. var pt = s_vec2;
  18220. this._path.getPointAt(this._normalizedTime, pt);
  18221. if (this._snapping) {
  18222. pt.x = Math.round(pt.x);
  18223. pt.y = Math.round(pt.y);
  18224. }
  18225. this._deltaValue.x = pt.x - this._value.x;
  18226. this._deltaValue.y = pt.y - this._value.y;
  18227. this._value.x = pt.x;
  18228. this._value.y = pt.y;
  18229. }
  18230. else {
  18231. var cnt = Math.min(this._valueSize, 4);
  18232. for (var i = 0; i < cnt; i++) {
  18233. var n1 = this._startValue.getField(i);
  18234. var n2 = this._endValue.getField(i);
  18235. var f = n1 + (n2 - n1) * this._normalizedTime;
  18236. if (this._snapping)
  18237. f = Math.round(f);
  18238. this._deltaValue.setField(i, f - this._value.getField(i));
  18239. this._value.setField(i, f);
  18240. }
  18241. }
  18242. if (this._target != null && this._propType != null) {
  18243. if (this._propType instanceof Function) {
  18244. switch (this._valueSize) {
  18245. case 1:
  18246. this._propType.call(this._target, this._value.x);
  18247. break;
  18248. case 2:
  18249. this._propType.call(this._target, this._value.x, this._value.y);
  18250. break;
  18251. case 3:
  18252. this._propType.call(this._target, this._value.x, this._value.y, this._value.z);
  18253. break;
  18254. case 4:
  18255. this._propType.call(this._target, this._value.x, this._value.y, this._value.z, this._value.w);
  18256. break;
  18257. case 5:
  18258. this._propType.call(this._target, this._value.color);
  18259. break;
  18260. case 6:
  18261. this._propType.call(this._target, this._value.x, this._value.y);
  18262. break;
  18263. }
  18264. }
  18265. else {
  18266. if (this._valueSize == 5)
  18267. this._target[this._propType] = this._value.color;
  18268. else
  18269. this._target[this._propType] = this._value.x;
  18270. }
  18271. }
  18272. this.callUpdateCallback();
  18273. };
  18274. GTweener.prototype.callStartCallback = function () {
  18275. if (this._onStart != null) {
  18276. try {
  18277. this._onStart.call(this._onStartCaller, this);
  18278. }
  18279. catch (err) {
  18280. console.log("FairyGUI: error in start callback > " + err);
  18281. }
  18282. }
  18283. };
  18284. GTweener.prototype.callUpdateCallback = function () {
  18285. if (this._onUpdate != null) {
  18286. try {
  18287. this._onUpdate.call(this._onUpdateCaller, this);
  18288. }
  18289. catch (err) {
  18290. console.log("FairyGUI: error in update callback > " + err);
  18291. }
  18292. }
  18293. };
  18294. GTweener.prototype.callCompleteCallback = function () {
  18295. if (this._onComplete != null) {
  18296. try {
  18297. this._onComplete.call(this._onCompleteCaller, this);
  18298. }
  18299. catch (err) {
  18300. console.log("FairyGUI: error in complete callback > " + err);
  18301. }
  18302. }
  18303. };
  18304. return GTweener;
  18305. }());
  18306. fgui.GTweener = GTweener;
  18307. var s_vec2 = new cc.Vec2();
  18308. })(fgui || (fgui = {}));
  18309. (function (fgui) {
  18310. var _activeTweens = new Array(30);
  18311. var _tweenerPool = new Array();
  18312. var _totalActiveTweens = 0;
  18313. var _root;
  18314. var TweenManager = (function () {
  18315. function TweenManager() {
  18316. }
  18317. TweenManager.clearAll = function () {
  18318. _activeTweens = new Array(30);
  18319. _tweenerPool = new Array();
  18320. _totalActiveTweens = 0;
  18321. _root = null;
  18322. }
  18323. TweenManager.createTween = function () {
  18324. //修改引擎,修复cc.game.restart()后导致节点被销毁
  18325. if (!_root || !_root.isValid) {
  18326. _root = new cc.Node("[TweenManager]");
  18327. cc.game["addPersistRootNode"](_root);
  18328. cc.director.getScheduler().schedule(TweenManager.update, _root, 0, false);
  18329. }
  18330. var tweener;
  18331. var cnt = _tweenerPool.length;
  18332. if (cnt > 0) {
  18333. tweener = _tweenerPool.pop();
  18334. }
  18335. else
  18336. tweener = new fgui.GTweener();
  18337. tweener._init();
  18338. _activeTweens[_totalActiveTweens++] = tweener;
  18339. if (_totalActiveTweens == _activeTweens.length)
  18340. _activeTweens.length = _activeTweens.length + Math.ceil(_activeTweens.length * 0.5);
  18341. return tweener;
  18342. };
  18343. TweenManager.isTweening = function (target, propType) {
  18344. if (target == null)
  18345. return false;
  18346. var anyType = propType == null || propType == undefined;
  18347. for (var i = 0; i < _totalActiveTweens; i++) {
  18348. var tweener = _activeTweens[i];
  18349. if (tweener && tweener.target == target && !tweener._killed
  18350. && (anyType || tweener._propType == propType))
  18351. return true;
  18352. }
  18353. return false;
  18354. };
  18355. TweenManager.killTweens = function (target, completed, propType) {
  18356. if (target == null)
  18357. return false;
  18358. var flag = false;
  18359. var cnt = _totalActiveTweens;
  18360. var anyType = propType == null || propType == undefined;
  18361. for (var i = 0; i < cnt; i++) {
  18362. var tweener = _activeTweens[i];
  18363. if (tweener && tweener.target == target && !tweener._killed
  18364. && (anyType || tweener._propType == propType)) {
  18365. tweener.kill(completed);
  18366. flag = true;
  18367. }
  18368. }
  18369. return flag;
  18370. };
  18371. TweenManager.getTween = function (target, propType) {
  18372. if (target == null)
  18373. return null;
  18374. var cnt = _totalActiveTweens;
  18375. var anyType = propType == null || propType == undefined;
  18376. for (var i = 0; i < cnt; i++) {
  18377. var tweener = _activeTweens[i];
  18378. if (tweener && tweener.target == target && !tweener._killed
  18379. && (anyType || tweener._propType == propType)) {
  18380. return tweener;
  18381. }
  18382. }
  18383. return null;
  18384. };
  18385. TweenManager.update = function (dt) {
  18386. var tweens = _activeTweens;
  18387. var cnt = _totalActiveTweens;
  18388. var freePosStart = -1;
  18389. for (var i = 0; i < cnt; i++) {
  18390. var tweener = tweens[i];
  18391. if (tweener == null) {
  18392. if (freePosStart == -1)
  18393. freePosStart = i;
  18394. }
  18395. else if (tweener._killed) {
  18396. tweener._reset();
  18397. _tweenerPool.push(tweener);
  18398. tweens[i] = null;
  18399. if (freePosStart == -1)
  18400. freePosStart = i;
  18401. }
  18402. else {
  18403. if ((tweener._target instanceof fgui.GObject) && tweener._target.node == null)
  18404. tweener._killed = true;
  18405. else if (!tweener._paused)
  18406. tweener._update(dt);
  18407. if (freePosStart != -1) {
  18408. tweens[freePosStart] = tweener;
  18409. tweens[i] = null;
  18410. freePosStart++;
  18411. }
  18412. }
  18413. }
  18414. if (freePosStart >= 0) {
  18415. if (_totalActiveTweens != cnt) {
  18416. var j = cnt;
  18417. cnt = _totalActiveTweens - cnt;
  18418. for (i = 0; i < cnt; i++)
  18419. tweens[freePosStart++] = tweens[j++];
  18420. }
  18421. _totalActiveTweens = freePosStart;
  18422. }
  18423. return false;
  18424. };
  18425. return TweenManager;
  18426. }());
  18427. fgui.TweenManager = TweenManager;
  18428. })(fgui || (fgui = {}));
  18429. (function (fgui) {
  18430. var TweenValue = (function () {
  18431. function TweenValue() {
  18432. this.x = this.y = this.z = this.w = 0;
  18433. }
  18434. Object.defineProperty(TweenValue.prototype, "color", {
  18435. get: function () {
  18436. return (this.w << 24) + (this.x << 16) + (this.y << 8) + this.z;
  18437. },
  18438. set: function (value) {
  18439. this.x = (value & 0xFF0000) >> 16;
  18440. this.y = (value & 0x00FF00) >> 8;
  18441. this.z = (value & 0x0000FF);
  18442. this.w = (value & 0xFF000000) >> 24;
  18443. },
  18444. enumerable: false,
  18445. configurable: true
  18446. });
  18447. TweenValue.prototype.getField = function (index) {
  18448. switch (index) {
  18449. case 0:
  18450. return this.x;
  18451. case 1:
  18452. return this.y;
  18453. case 2:
  18454. return this.z;
  18455. case 3:
  18456. return this.w;
  18457. default:
  18458. throw new Error("Index out of bounds: " + index);
  18459. }
  18460. };
  18461. TweenValue.prototype.setField = function (index, value) {
  18462. switch (index) {
  18463. case 0:
  18464. this.x = value;
  18465. break;
  18466. case 1:
  18467. this.y = value;
  18468. break;
  18469. case 2:
  18470. this.z = value;
  18471. break;
  18472. case 3:
  18473. this.w = value;
  18474. break;
  18475. default:
  18476. throw new Error("Index out of bounds: " + index);
  18477. }
  18478. };
  18479. TweenValue.prototype.setZero = function () {
  18480. this.x = this.y = this.z = this.w = 0;
  18481. };
  18482. return TweenValue;
  18483. }());
  18484. fgui.TweenValue = TweenValue;
  18485. })(fgui || (fgui = {}));
  18486. (function (fgui) {
  18487. var ByteBuffer = (function () {
  18488. function ByteBuffer(buffer, offset, length) {
  18489. if (offset === void 0) { offset = 0; }
  18490. if (length === void 0) { length = -1; }
  18491. this.version = 0;
  18492. if (length == -1)
  18493. length = buffer.byteLength - offset;
  18494. this._bytes = new Uint8Array(buffer, offset, length);
  18495. this._view = new DataView(this._bytes.buffer, offset, length);
  18496. this._pos = 0;
  18497. this._length = length;
  18498. }
  18499. Object.defineProperty(ByteBuffer.prototype, "data", {
  18500. get: function () {
  18501. return this._bytes;
  18502. },
  18503. enumerable: false,
  18504. configurable: true
  18505. });
  18506. Object.defineProperty(ByteBuffer.prototype, "position", {
  18507. get: function () {
  18508. return this._pos;
  18509. },
  18510. set: function (value) {
  18511. if (value > this._length)
  18512. throw "Out of bounds";
  18513. this._pos = value;
  18514. },
  18515. enumerable: false,
  18516. configurable: true
  18517. });
  18518. ByteBuffer.prototype.skip = function (count) {
  18519. this._pos += count;
  18520. };
  18521. ByteBuffer.prototype.validate = function (forward) {
  18522. if (this._pos + forward > this._length)
  18523. throw "Out of bounds";
  18524. };
  18525. ByteBuffer.prototype.readByte = function () {
  18526. this.validate(1);
  18527. return this._view.getInt8(this._pos++);
  18528. };
  18529. ByteBuffer.prototype.readUbyte = function () {
  18530. return this._bytes[this._pos++];
  18531. };
  18532. ByteBuffer.prototype.readBool = function () {
  18533. return this.readByte() == 1;
  18534. };
  18535. ByteBuffer.prototype.readShort = function () {
  18536. this.validate(2);
  18537. var ret = this._view.getInt16(this._pos, this.littleEndian);
  18538. this._pos += 2;
  18539. return ret;
  18540. };
  18541. ByteBuffer.prototype.readUshort = function () {
  18542. this.validate(2);
  18543. var ret = this._view.getUint16(this._pos, this.littleEndian);
  18544. this._pos += 2;
  18545. return ret;
  18546. };
  18547. ByteBuffer.prototype.readInt = function () {
  18548. this.validate(4);
  18549. var ret = this._view.getInt32(this._pos, this.littleEndian);
  18550. this._pos += 4;
  18551. return ret;
  18552. };
  18553. ByteBuffer.prototype.readUint = function () {
  18554. this.validate(4);
  18555. var ret = this._view.getUint32(this._pos, this.littleEndian);
  18556. this._pos += 4;
  18557. return ret;
  18558. };
  18559. ByteBuffer.prototype.readFloat = function () {
  18560. this.validate(4);
  18561. var ret = this._view.getFloat32(this._pos, this.littleEndian);
  18562. this._pos += 4;
  18563. return ret;
  18564. };
  18565. ByteBuffer.prototype.readString = function (len) {
  18566. if (len == undefined)
  18567. len = this.readUshort();
  18568. this.validate(len);
  18569. var v = "", max = this._pos + len, c = 0, c2 = 0, c3 = 0, f = String.fromCharCode;
  18570. var u = this._bytes, i = 0;
  18571. var pos = this._pos;
  18572. while (pos < max) {
  18573. c = u[pos++];
  18574. if (c < 0x80) {
  18575. if (c != 0) {
  18576. v += f(c);
  18577. }
  18578. }
  18579. else if (c < 0xE0) {
  18580. v += f(((c & 0x3F) << 6) | (u[pos++] & 0x7F));
  18581. }
  18582. else if (c < 0xF0) {
  18583. c2 = u[pos++];
  18584. v += f(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (u[pos++] & 0x7F));
  18585. }
  18586. else {
  18587. c2 = u[pos++];
  18588. c3 = u[pos++];
  18589. v += f(((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 << 6) & 0x7F) | (u[pos++] & 0x7F));
  18590. }
  18591. i++;
  18592. }
  18593. this._pos += len;
  18594. return v;
  18595. };
  18596. ByteBuffer.prototype.readS = function () {
  18597. var index = this.readUshort();
  18598. if (index == 65534)
  18599. return null;
  18600. else if (index == 65533)
  18601. return "";
  18602. else
  18603. return this.stringTable[index];
  18604. };
  18605. ByteBuffer.prototype.readSArray = function (cnt) {
  18606. var ret = new Array(cnt);
  18607. for (var i = 0; i < cnt; i++)
  18608. ret[i] = this.readS();
  18609. return ret;
  18610. };
  18611. ByteBuffer.prototype.writeS = function (value) {
  18612. var index = this.readUshort();
  18613. if (index != 65534 && index != 65533)
  18614. this.stringTable[index] = value;
  18615. };
  18616. ByteBuffer.prototype.readColor = function (hasAlpha) {
  18617. var r = this.readUbyte();
  18618. var g = this.readUbyte();
  18619. var b = this.readUbyte();
  18620. var a = this.readUbyte();
  18621. return new cc.Color(r, g, b, (hasAlpha ? a : 255));
  18622. };
  18623. ByteBuffer.prototype.readChar = function () {
  18624. var i = this.readUshort();
  18625. return String.fromCharCode(i);
  18626. };
  18627. ByteBuffer.prototype.readBuffer = function () {
  18628. var count = this.readUint();
  18629. this.validate(count);
  18630. var ba = new ByteBuffer(this._bytes.buffer, this._bytes.byteOffset + this._pos, count);
  18631. ba.stringTable = this.stringTable;
  18632. ba.version = this.version;
  18633. this._pos += count;
  18634. return ba;
  18635. };
  18636. ByteBuffer.prototype.seek = function (indexTablePos, blockIndex) {
  18637. var tmp = this._pos;
  18638. this._pos = indexTablePos;
  18639. var segCount = this.readByte();
  18640. if (blockIndex < segCount) {
  18641. var useShort = this.readByte() == 1;
  18642. var newPos;
  18643. if (useShort) {
  18644. this._pos += 2 * blockIndex;
  18645. newPos = this.readUshort();
  18646. }
  18647. else {
  18648. this._pos += 4 * blockIndex;
  18649. newPos = this.readUint();
  18650. }
  18651. if (newPos > 0) {
  18652. this._pos = indexTablePos + newPos;
  18653. return true;
  18654. }
  18655. else {
  18656. this._pos = tmp;
  18657. return false;
  18658. }
  18659. }
  18660. else {
  18661. this._pos = tmp;
  18662. return false;
  18663. }
  18664. };
  18665. return ByteBuffer;
  18666. }());
  18667. fgui.ByteBuffer = ByteBuffer;
  18668. })(fgui || (fgui = {}));
  18669. (function (fgui) {
  18670. var ColorMatrix = (function () {
  18671. function ColorMatrix(p_brightness, p_contrast, p_saturation, p_hue) {
  18672. this.matrix = new Array(LENGTH);
  18673. this.reset();
  18674. if (p_brightness !== undefined || p_contrast !== undefined || p_saturation !== undefined || p_hue !== undefined)
  18675. this.adjustColor(p_brightness, p_contrast, p_saturation, p_hue);
  18676. }
  18677. ColorMatrix.prototype.reset = function () {
  18678. for (var i = 0; i < LENGTH; i++) {
  18679. this.matrix[i] = IDENTITY_MATRIX[i];
  18680. }
  18681. };
  18682. ColorMatrix.prototype.invert = function () {
  18683. this.multiplyMatrix([-1, 0, 0, 0, 255,
  18684. 0, -1, 0, 0, 255,
  18685. 0, 0, -1, 0, 255,
  18686. 0, 0, 0, 1, 0]);
  18687. };
  18688. ColorMatrix.prototype.adjustColor = function (p_brightness, p_contrast, p_saturation, p_hue) {
  18689. this.adjustHue(p_hue || 0);
  18690. this.adjustContrast(p_contrast || 0);
  18691. this.adjustBrightness(p_brightness || 0);
  18692. this.adjustSaturation(p_saturation || 0);
  18693. };
  18694. ColorMatrix.prototype.adjustBrightness = function (p_val) {
  18695. p_val = this.cleanValue(p_val, 1) * 255;
  18696. this.multiplyMatrix([
  18697. 1, 0, 0, 0, p_val,
  18698. 0, 1, 0, 0, p_val,
  18699. 0, 0, 1, 0, p_val,
  18700. 0, 0, 0, 1, 0
  18701. ]);
  18702. };
  18703. ColorMatrix.prototype.adjustContrast = function (p_val) {
  18704. p_val = this.cleanValue(p_val, 1);
  18705. var s = p_val + 1;
  18706. var o = 128 * (1 - s);
  18707. this.multiplyMatrix([
  18708. s, 0, 0, 0, o,
  18709. 0, s, 0, 0, o,
  18710. 0, 0, s, 0, o,
  18711. 0, 0, 0, 1, 0
  18712. ]);
  18713. };
  18714. ColorMatrix.prototype.adjustSaturation = function (p_val) {
  18715. p_val = this.cleanValue(p_val, 1);
  18716. p_val += 1;
  18717. var invSat = 1 - p_val;
  18718. var invLumR = invSat * LUMA_R;
  18719. var invLumG = invSat * LUMA_G;
  18720. var invLumB = invSat * LUMA_B;
  18721. this.multiplyMatrix([
  18722. (invLumR + p_val), invLumG, invLumB, 0, 0,
  18723. invLumR, (invLumG + p_val), invLumB, 0, 0,
  18724. invLumR, invLumG, (invLumB + p_val), 0, 0,
  18725. 0, 0, 0, 1, 0
  18726. ]);
  18727. };
  18728. ColorMatrix.prototype.adjustHue = function (p_val) {
  18729. p_val = this.cleanValue(p_val, 1);
  18730. p_val *= Math.PI;
  18731. var cos = Math.cos(p_val);
  18732. var sin = Math.sin(p_val);
  18733. this.multiplyMatrix([
  18734. ((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,
  18735. ((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,
  18736. ((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,
  18737. 0, 0, 0, 1, 0
  18738. ]);
  18739. };
  18740. ColorMatrix.prototype.concat = function (p_matrix) {
  18741. if (p_matrix.length != LENGTH) {
  18742. return;
  18743. }
  18744. this.multiplyMatrix(p_matrix);
  18745. };
  18746. ColorMatrix.prototype.clone = function () {
  18747. var result = new ColorMatrix();
  18748. result.copyMatrix(this.matrix);
  18749. return result;
  18750. };
  18751. ColorMatrix.prototype.copyMatrix = function (p_matrix) {
  18752. var l = LENGTH;
  18753. for (var i = 0; i < l; i++) {
  18754. this.matrix[i] = p_matrix[i];
  18755. }
  18756. };
  18757. ColorMatrix.prototype.multiplyMatrix = function (p_matrix) {
  18758. var col = [];
  18759. var i = 0;
  18760. for (var y = 0; y < 4; ++y) {
  18761. for (var x = 0; x < 5; ++x) {
  18762. col[i + x] = p_matrix[i] * this.matrix[x] +
  18763. p_matrix[i + 1] * this.matrix[x + 5] +
  18764. p_matrix[i + 2] * this.matrix[x + 10] +
  18765. p_matrix[i + 3] * this.matrix[x + 15] +
  18766. (x == 4 ? p_matrix[i + 4] : 0);
  18767. }
  18768. i += 5;
  18769. }
  18770. this.copyMatrix(col);
  18771. };
  18772. ColorMatrix.prototype.cleanValue = function (p_val, p_limit) {
  18773. return Math.min(p_limit, Math.max(-p_limit, p_val));
  18774. };
  18775. return ColorMatrix;
  18776. }());
  18777. fgui.ColorMatrix = ColorMatrix;
  18778. var IDENTITY_MATRIX = [
  18779. 1, 0, 0, 0, 0,
  18780. 0, 1, 0, 0, 0,
  18781. 0, 0, 1, 0, 0,
  18782. 0, 0, 0, 1, 0
  18783. ];
  18784. var LENGTH = IDENTITY_MATRIX.length;
  18785. var LUMA_R = 0.299;
  18786. var LUMA_G = 0.587;
  18787. var LUMA_B = 0.114;
  18788. })(fgui || (fgui = {}));
  18789. (function (fgui) {
  18790. var UBBParser = (function () {
  18791. function UBBParser() {
  18792. this._readPos = 0;
  18793. this._handlers = {};
  18794. this._handlers["url"] = this.onTag_URL;
  18795. this._handlers["img"] = this.onTag_IMG;
  18796. this._handlers["b"] = this.onTag_Simple;
  18797. this._handlers["i"] = this.onTag_Simple;
  18798. this._handlers["u"] = this.onTag_Simple;
  18799. this._handlers["color"] = this.onTag_COLOR;
  18800. this._handlers["size"] = this.onTag_SIZE;
  18801. }
  18802. UBBParser.prototype.onTag_URL = function (tagName, end, attr) {
  18803. if (!end) {
  18804. var ret = void 0;
  18805. if (attr != null)
  18806. ret = "<on click=\"onClickLink\" param=\"" + attr + "\">";
  18807. else {
  18808. var href = this.getTagText();
  18809. ret = "<on click=\"onClickLink\" param=\"" + href + "\">";
  18810. }
  18811. if (this.linkUnderline)
  18812. ret += "<u>";
  18813. if (this.linkColor)
  18814. ret += "<color=" + this.linkColor + ">";
  18815. return ret;
  18816. }
  18817. else {
  18818. var ret = "";
  18819. if (this.linkColor)
  18820. ret += "</color>";
  18821. if (this.linkUnderline)
  18822. ret += "</u>";
  18823. ret += "</on>";
  18824. return ret;
  18825. }
  18826. };
  18827. UBBParser.prototype.onTag_IMG = function (tagName, end, attr) {
  18828. if (!end) {
  18829. var src = this.getTagText(true);
  18830. if (!src)
  18831. return null;
  18832. return "<img src=\"" + src + "\"/>";
  18833. }
  18834. else
  18835. return null;
  18836. };
  18837. UBBParser.prototype.onTag_Simple = function (tagName, end, attr) {
  18838. return end ? ("</" + tagName + ">") : ("<" + tagName + ">");
  18839. };
  18840. UBBParser.prototype.onTag_COLOR = function (tagName, end, attr) {
  18841. if (!end) {
  18842. this.lastColor = attr;
  18843. return "<color=" + attr + ">";
  18844. }
  18845. else
  18846. return "</color>";
  18847. };
  18848. UBBParser.prototype.onTag_FONT = function (tagName, end, attr) {
  18849. if (!end)
  18850. return "<font face=\"" + attr + "\">";
  18851. else
  18852. return "</font>";
  18853. };
  18854. UBBParser.prototype.onTag_SIZE = function (tagName, end, attr) {
  18855. if (!end) {
  18856. this.lastSize = attr;
  18857. return "<size=" + attr + ">";
  18858. }
  18859. else
  18860. return "</size>";
  18861. };
  18862. UBBParser.prototype.getTagText = function (remove) {
  18863. var pos1 = this._readPos;
  18864. var pos2;
  18865. var result = "";
  18866. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  18867. if (this._text.charCodeAt(pos2 - 1) == 92) {
  18868. result += this._text.substring(pos1, pos2 - 1);
  18869. result += "[";
  18870. pos1 = pos2 + 1;
  18871. }
  18872. else {
  18873. result += this._text.substring(pos1, pos2);
  18874. break;
  18875. }
  18876. }
  18877. if (pos2 == -1)
  18878. return null;
  18879. if (remove)
  18880. this._readPos = pos2;
  18881. return result;
  18882. };
  18883. UBBParser.prototype.parse = function (text, remove) {
  18884. this._text = text;
  18885. this.lastColor = null;
  18886. this.lastSize = null;
  18887. var pos1 = 0, pos2, pos3;
  18888. var end;
  18889. var tag, attr;
  18890. var repl;
  18891. var func;
  18892. var result = "";
  18893. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  18894. if (pos2 > 0 && this._text.charCodeAt(pos2 - 1) == 92) {
  18895. result += this._text.substring(pos1, pos2 - 1);
  18896. result += "[";
  18897. pos1 = pos2 + 1;
  18898. continue;
  18899. }
  18900. result += this._text.substring(pos1, pos2);
  18901. pos1 = pos2;
  18902. pos2 = this._text.indexOf("]", pos1);
  18903. if (pos2 == -1)
  18904. break;
  18905. end = this._text.charAt(pos1 + 1) == '/';
  18906. tag = this._text.substring(end ? pos1 + 2 : pos1 + 1, pos2);
  18907. this._readPos = pos2 + 1;
  18908. attr = null;
  18909. repl = null;
  18910. pos3 = tag.indexOf("=");
  18911. if (pos3 != -1) {
  18912. attr = tag.substring(pos3 + 1);
  18913. tag = tag.substring(0, pos3);
  18914. }
  18915. tag = tag.toLowerCase();
  18916. func = this._handlers[tag];
  18917. if (func != null) {
  18918. repl = func.call(this, tag, end, attr);
  18919. if (repl != null && !remove)
  18920. result += repl;
  18921. }
  18922. else
  18923. result += this._text.substring(pos1, this._readPos);
  18924. pos1 = this._readPos;
  18925. }
  18926. if (pos1 < this._text.length)
  18927. result += this._text.substr(pos1);
  18928. this._text = null;
  18929. return result;
  18930. };
  18931. UBBParser.inst = new UBBParser();
  18932. return UBBParser;
  18933. }());
  18934. fgui.UBBParser = UBBParser;
  18935. })(fgui || (fgui = {}));
  18936. (function (fgui) {
  18937. var ToolSet = (function () {
  18938. function ToolSet() {
  18939. }
  18940. ToolSet.startsWith = function (source, str, ignoreCase) {
  18941. if (!source)
  18942. return false;
  18943. else if (source.length < str.length)
  18944. return false;
  18945. else {
  18946. source = source.substring(0, str.length);
  18947. if (!ignoreCase)
  18948. return source == str;
  18949. else
  18950. return source.toLowerCase() == str.toLowerCase();
  18951. }
  18952. };
  18953. ToolSet.encodeHTML = function (str) {
  18954. if (!str)
  18955. return "";
  18956. else
  18957. return str.replace(/&/g, "&amp;").replace(/</g, "&lt;")
  18958. .replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/"/g, "&quot;");
  18959. };
  18960. ToolSet.clamp = function (value, min, max) {
  18961. if (value < min)
  18962. value = min;
  18963. else if (value > max)
  18964. value = max;
  18965. return value;
  18966. };
  18967. ToolSet.clamp01 = function (value) {
  18968. if (value > 1)
  18969. value = 1;
  18970. else if (value < 0)
  18971. value = 0;
  18972. return value;
  18973. };
  18974. ToolSet.lerp = function (start, end, percent) {
  18975. return (start + percent * (end - start));
  18976. };
  18977. ToolSet.getTime = function () {
  18978. var currentTime = new Date();
  18979. return currentTime.getMilliseconds() / 1000;
  18980. };
  18981. ToolSet.toGrayed = function (c) {
  18982. var v = c.getR() * 0.299 + c.getG() * 0.587 + c.getB() * 0.114;
  18983. return new cc.Color(v, v, v, c.getA());
  18984. };
  18985. ToolSet.repeat = function (t, length) {
  18986. return t - Math.floor(t / length) * length;
  18987. };
  18988. ToolSet.distance = function (x1, y1, x2, y2) {
  18989. return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  18990. };
  18991. return ToolSet;
  18992. }());
  18993. fgui.ToolSet = ToolSet;
  18994. })(fgui || (fgui = {}));