fairygui.js 683 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720
  1. window.fgui = {};
  2. window.fairygui = window.fgui;
  3. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  4. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  5. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  6. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  7. return c > 3 && r && Object.defineProperty(target, key, r), r;
  8. };
  9. (function (fgui) {
  10. class AsyncListOperationRunner extends cc.Component {
  11. constructor() {
  12. super(...arguments);
  13. this._listCreate = new Array();
  14. this._isFirstCreate = false;
  15. }
  16. set isFirstCreate(value) {
  17. this._isFirstCreate = value;
  18. }
  19. onLoad() {
  20. this._list = fgui.GObject.cast(this.node).asList;
  21. }
  22. update() {
  23. let t = fgui.ToolSet.getTime();
  24. let frameTime = fgui.UIConfig.frameTimeForAsyncUIConstruction;
  25. let created = false;
  26. while (this._listCreate.length > 0) {
  27. created = true;
  28. let obj = this._list.getFromPool(this._listCreate[0]);
  29. this._list.returnToPool(obj);
  30. this._listCreate.splice(0);
  31. if (fgui.ToolSet.getTime() - t >= frameTime) {
  32. break;
  33. }
  34. }
  35. if (!created) {
  36. if (this._isFirstCreate) {
  37. this._list.node.emit(fgui.Event.LIST_ITEM_CREATED);
  38. this._isFirstCreate = false;
  39. }
  40. return;
  41. }
  42. this._list.node.emit(fgui.Event.LIST_ITEM_CREATED_REFRESH);
  43. if (this._listCreate.length <= 0) {
  44. if (this._isFirstCreate) {
  45. this._list.node.emit(fgui.Event.LIST_ITEM_CREATED);
  46. this._isFirstCreate = false;
  47. }
  48. }
  49. }
  50. createObj(url) {
  51. this._listCreate.push(url);
  52. }
  53. }
  54. fgui.AsyncListOperationRunner = AsyncListOperationRunner;
  55. })(fgui || (fgui = {}));
  56. (function (fgui) {
  57. class AsyncOperation {
  58. createObject(pkgName, resName) {
  59. if (this._node)
  60. throw 'Already running';
  61. var pkg = fgui.UIPackage.getByName(pkgName);
  62. if (pkg) {
  63. var pi = pkg.getItemByName(resName);
  64. if (!pi)
  65. throw new Error('resource not found: ' + resName);
  66. this.internalCreateObject(pi);
  67. }
  68. else
  69. throw new Error('package not found: ' + pkgName);
  70. }
  71. createObjectFromURL(url) {
  72. if (this._node)
  73. throw 'Already running';
  74. var pi = fgui.UIPackage.getItemByURL(url);
  75. if (pi)
  76. this.internalCreateObject(pi);
  77. else
  78. throw new Error('resource not found: ' + url);
  79. }
  80. cancel() {
  81. if (this._node) {
  82. this._node.destroy();
  83. this._node = null;
  84. }
  85. }
  86. internalCreateObject(item) {
  87. this._node = new cc.Node('[AsyncCreating:' + item.name + ']');
  88. this._node.parent = cc.director.getScene();
  89. this._node.on('#', this.completed, this);
  90. this._node.addComponent(AsyncOperationRunner).init(item);
  91. }
  92. completed(result) {
  93. this.cancel();
  94. if (this.callback)
  95. this.callback(result);
  96. }
  97. }
  98. fgui.AsyncOperation = AsyncOperation;
  99. class AsyncOperationRunner extends cc.Component {
  100. constructor() {
  101. super();
  102. this._itemList = new Array();
  103. this._objectPool = new Array();
  104. }
  105. init(item) {
  106. this._itemList.length = 0;
  107. this._objectPool.length = 0;
  108. var di = { pi: item, type: item.objectType };
  109. di.childCount = this.collectComponentChildren(item);
  110. this._itemList.push(di);
  111. this._index = 0;
  112. }
  113. onDestroy() {
  114. this._itemList.length = 0;
  115. var cnt = this._objectPool.length;
  116. if (cnt > 0) {
  117. for (var i = 0; i < cnt; i++)
  118. this._objectPool[i].dispose();
  119. this._objectPool.length = 0;
  120. }
  121. }
  122. collectComponentChildren(item) {
  123. var buffer = item.rawData;
  124. buffer.seek(0, 2);
  125. var di;
  126. var pi;
  127. var i;
  128. var dataLen;
  129. var curPos;
  130. var pkg;
  131. var dcnt = buffer.readShort();
  132. for (i = 0; i < dcnt; i++) {
  133. dataLen = buffer.readShort();
  134. curPos = buffer.position;
  135. buffer.seek(curPos, 0);
  136. var type = buffer.readByte();
  137. var src = buffer.readS();
  138. var pkgId = buffer.readS();
  139. buffer.position = curPos;
  140. if (src != null) {
  141. if (pkgId != null)
  142. pkg = fgui.UIPackage.getById(pkgId);
  143. else
  144. pkg = item.owner;
  145. pi = pkg != null ? pkg.getItemById(src) : null;
  146. di = { pi: pi, type: type };
  147. if (pi && pi.type == fgui.PackageItemType.Component)
  148. di.childCount = this.collectComponentChildren(pi);
  149. }
  150. else {
  151. di = { type: type };
  152. if (type == fgui.ObjectType.List)
  153. di.listItemCount = this.collectListChildren(buffer);
  154. }
  155. this._itemList.push(di);
  156. buffer.position = curPos + dataLen;
  157. }
  158. return dcnt;
  159. }
  160. collectListChildren(buffer) {
  161. buffer.seek(buffer.position, 8);
  162. var listItemCount = 0;
  163. var i;
  164. var nextPos;
  165. var url;
  166. var pi;
  167. var di;
  168. var defaultItem = buffer.readS();
  169. var itemCount = buffer.readShort();
  170. for (i = 0; i < itemCount; i++) {
  171. nextPos = buffer.readShort();
  172. nextPos += buffer.position;
  173. url = buffer.readS();
  174. if (url == null)
  175. url = defaultItem;
  176. if (url) {
  177. pi = fgui.UIPackage.getItemByURL(url);
  178. if (pi) {
  179. di = { pi: pi, type: pi.objectType };
  180. if (pi.type == fgui.PackageItemType.Component)
  181. di.childCount = this.collectComponentChildren(pi);
  182. this._itemList.push(di);
  183. listItemCount++;
  184. }
  185. }
  186. buffer.position = nextPos;
  187. }
  188. return listItemCount;
  189. }
  190. update() {
  191. var obj;
  192. var di;
  193. var poolStart;
  194. var k;
  195. var t = fgui.ToolSet.getTime();
  196. var frameTime = fgui.UIConfig.frameTimeForAsyncUIConstruction;
  197. var totalItems = this._itemList.length;
  198. while (this._index < totalItems) {
  199. di = this._itemList[this._index];
  200. if (di.pi) {
  201. obj = fgui.UIObjectFactory.newObject(di.pi);
  202. this._objectPool.push(obj);
  203. fgui.UIPackage._constructing++;
  204. if (di.pi.type == fgui.PackageItemType.Component) {
  205. poolStart = this._objectPool.length - di.childCount - 1;
  206. obj.constructFromResource2(this._objectPool, poolStart);
  207. this._objectPool.splice(poolStart, di.childCount);
  208. }
  209. else {
  210. obj.constructFromResource();
  211. }
  212. fgui.UIPackage._constructing--;
  213. }
  214. else {
  215. obj = fgui.UIObjectFactory.newObject(di.type);
  216. this._objectPool.push(obj);
  217. if (di.type == fgui.ObjectType.List && di.listItemCount > 0) {
  218. poolStart = this._objectPool.length - di.listItemCount - 1;
  219. for (k = 0; k < di.listItemCount; k++)
  220. obj.itemPool.returnObject(this._objectPool[k + poolStart]);
  221. this._objectPool.splice(poolStart, di.listItemCount);
  222. }
  223. }
  224. this._index++;
  225. if (fgui.ToolSet.getTime() - t >= frameTime)
  226. return;
  227. }
  228. var result = this._objectPool[0];
  229. this._itemList.length = 0;
  230. this._objectPool.length = 0;
  231. this.node.emit('#', result);
  232. }
  233. }
  234. })(fgui || (fgui = {}));
  235. (function (fgui) {
  236. var _nextPageId = 0;
  237. class Controller extends cc.EventTarget {
  238. constructor() {
  239. super();
  240. this._pageIds = [];
  241. this._pageNames = [];
  242. this._selectedIndex = -1;
  243. this._previousIndex = -1;
  244. }
  245. dispose() {
  246. }
  247. get selectedIndex() {
  248. return this._selectedIndex;
  249. }
  250. set selectedIndex(value) {
  251. if (this._selectedIndex != value) {
  252. if (value > this._pageIds.length - 1)
  253. throw "index out of bounds: " + value;
  254. this.changing = true;
  255. this._previousIndex = this._selectedIndex;
  256. this._selectedIndex = value;
  257. this.parent.applyController(this);
  258. this.emit(fgui.Event.STATUS_CHANGED, this);
  259. this.changing = false;
  260. }
  261. }
  262. onChanged(callback, target) {
  263. this.on(fgui.Event.STATUS_CHANGED, callback, target);
  264. }
  265. offChanged(callback, target) {
  266. this.off(fgui.Event.STATUS_CHANGED, callback, target);
  267. }
  268. setSelectedIndex(value) {
  269. if (this._selectedIndex != value) {
  270. if (value > this._pageIds.length - 1)
  271. throw "index out of bounds: " + value;
  272. this.changing = true;
  273. this._previousIndex = this._selectedIndex;
  274. this._selectedIndex = value;
  275. this.parent.applyController(this);
  276. this.changing = false;
  277. }
  278. }
  279. get previsousIndex() {
  280. return this._previousIndex;
  281. }
  282. get selectedPage() {
  283. if (this._selectedIndex == -1)
  284. return null;
  285. else
  286. return this._pageNames[this._selectedIndex];
  287. }
  288. set selectedPage(val) {
  289. var i = this._pageNames.indexOf(val);
  290. if (i == -1)
  291. i = 0;
  292. this.selectedIndex = i;
  293. }
  294. setSelectedPage(value) {
  295. var i = this._pageNames.indexOf(value);
  296. if (i == -1)
  297. i = 0;
  298. this.setSelectedIndex(i);
  299. }
  300. get previousPage() {
  301. if (this._previousIndex == -1)
  302. return null;
  303. else
  304. return this._pageNames[this._previousIndex];
  305. }
  306. get pageCount() {
  307. return this._pageIds.length;
  308. }
  309. getPageName(index) {
  310. return this._pageNames[index];
  311. }
  312. addPage(name = "") {
  313. this.addPageAt(name, this._pageIds.length);
  314. }
  315. addPageAt(name, index) {
  316. var nid = "" + (_nextPageId++);
  317. if (index == this._pageIds.length) {
  318. this._pageIds.push(nid);
  319. this._pageNames.push(name);
  320. }
  321. else {
  322. this._pageIds.splice(index, 0, nid);
  323. this._pageNames.splice(index, 0, name);
  324. }
  325. }
  326. removePage(name) {
  327. var i = this._pageNames.indexOf(name);
  328. if (i != -1) {
  329. this._pageIds.splice(i, 1);
  330. this._pageNames.splice(i, 1);
  331. if (this._selectedIndex >= this._pageIds.length)
  332. this.selectedIndex = this._selectedIndex - 1;
  333. else
  334. this.parent.applyController(this);
  335. }
  336. }
  337. removePageAt(index) {
  338. this._pageIds.splice(index, 1);
  339. this._pageNames.splice(index, 1);
  340. if (this._selectedIndex >= this._pageIds.length)
  341. this.selectedIndex = this._selectedIndex - 1;
  342. else
  343. this.parent.applyController(this);
  344. }
  345. clearPages() {
  346. this._pageIds.length = 0;
  347. this._pageNames.length = 0;
  348. if (this._selectedIndex != -1)
  349. this.selectedIndex = -1;
  350. else
  351. this.parent.applyController(this);
  352. }
  353. hasPage(aName) {
  354. return this._pageNames.indexOf(aName) != -1;
  355. }
  356. getPageIndexById(aId) {
  357. return this._pageIds.indexOf(aId);
  358. }
  359. getPageIdByName(aName) {
  360. var i = this._pageNames.indexOf(aName);
  361. if (i != -1)
  362. return this._pageIds[i];
  363. else
  364. return null;
  365. }
  366. getPageNameById(aId) {
  367. var i = this._pageIds.indexOf(aId);
  368. if (i != -1)
  369. return this._pageNames[i];
  370. else
  371. return null;
  372. }
  373. getPageId(index) {
  374. return this._pageIds[index];
  375. }
  376. get selectedPageId() {
  377. if (this._selectedIndex == -1)
  378. return null;
  379. else
  380. return this._pageIds[this._selectedIndex];
  381. }
  382. set selectedPageId(val) {
  383. var i = this._pageIds.indexOf(val);
  384. this.selectedIndex = i;
  385. }
  386. set oppositePageId(val) {
  387. var i = this._pageIds.indexOf(val);
  388. if (i > 0)
  389. this.selectedIndex = 0;
  390. else if (this._pageIds.length > 1)
  391. this.selectedIndex = 1;
  392. }
  393. get previousPageId() {
  394. if (this._previousIndex == -1)
  395. return null;
  396. else
  397. return this._pageIds[this._previousIndex];
  398. }
  399. runActions() {
  400. if (this._actions) {
  401. var cnt = this._actions.length;
  402. for (var i = 0; i < cnt; i++)
  403. this._actions[i].run(this, this.previousPageId, this.selectedPageId);
  404. }
  405. }
  406. setup(buffer) {
  407. var beginPos = buffer.position;
  408. buffer.seek(beginPos, 0);
  409. this.name = buffer.readS();
  410. if (buffer.readBool())
  411. this.autoRadioGroupDepth = true;
  412. buffer.seek(beginPos, 1);
  413. var i;
  414. var nextPos;
  415. var cnt = buffer.readShort();
  416. for (i = 0; i < cnt; i++) {
  417. this._pageIds.push(buffer.readS());
  418. this._pageNames.push(buffer.readS());
  419. }
  420. var homePageIndex = 0;
  421. if (buffer.version >= 2) {
  422. var homePageType = buffer.readByte();
  423. switch (homePageType) {
  424. case 1:
  425. homePageIndex = buffer.readShort();
  426. break;
  427. case 2:
  428. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.branch);
  429. if (homePageIndex == -1)
  430. homePageIndex = 0;
  431. break;
  432. case 3:
  433. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.getVar(buffer.readS()));
  434. if (homePageIndex == -1)
  435. homePageIndex = 0;
  436. break;
  437. }
  438. }
  439. buffer.seek(beginPos, 2);
  440. cnt = buffer.readShort();
  441. if (cnt > 0) {
  442. if (!this._actions)
  443. this._actions = new Array();
  444. for (i = 0; i < cnt; i++) {
  445. nextPos = buffer.readShort();
  446. nextPos += buffer.position;
  447. var action = fgui.ControllerAction.createAction(buffer.readByte());
  448. action.setup(buffer);
  449. this._actions.push(action);
  450. buffer.position = nextPos;
  451. }
  452. }
  453. if (this.parent && this._pageIds.length > 0)
  454. this._selectedIndex = homePageIndex;
  455. else
  456. this._selectedIndex = -1;
  457. }
  458. }
  459. fgui.Controller = Controller;
  460. })(fgui || (fgui = {}));
  461. (function (fgui) {
  462. class DragDropManager {
  463. constructor() {
  464. this._agent = fgui.UIObjectFactory.newObject(fgui.ObjectType.Loader).asLoader;
  465. this._agent.draggable = true;
  466. this._agent.touchable = false;
  467. this._agent.setSize(100, 100);
  468. this._agent.setPivot(0.5, 0.5, true);
  469. this._agent.align = fgui.AlignType.Center;
  470. this._agent.verticalAlign = fgui.VertAlignType.Middle;
  471. this._agent.sortingOrder = 1000000;
  472. this._agent.on(fgui.Event.DRAG_END, this.onDragEnd, this);
  473. }
  474. static get inst() {
  475. if (!DragDropManager._inst)
  476. DragDropManager._inst = new DragDropManager();
  477. return DragDropManager._inst;
  478. }
  479. get dragAgent() {
  480. return this._agent;
  481. }
  482. get dragging() {
  483. return this._agent.parent != null;
  484. }
  485. startDrag(source, icon, sourceData, touchId) {
  486. if (this._agent.parent)
  487. return;
  488. this._sourceData = sourceData;
  489. this._agent.url = icon;
  490. fgui.GRoot.inst.addChild(this._agent);
  491. let pt = fgui.GRoot.inst.getTouchPosition(touchId);
  492. pt = fgui.GRoot.inst.globalToLocal(pt.x, pt.y);
  493. this._agent.setPosition(pt.x, pt.y);
  494. this._agent.startDrag(touchId);
  495. }
  496. cancel() {
  497. if (this._agent.parent) {
  498. this._agent.stopDrag();
  499. fgui.GRoot.inst.removeChild(this._agent);
  500. this._sourceData = null;
  501. }
  502. }
  503. onDragEnd() {
  504. if (!this._agent.parent)
  505. return;
  506. fgui.GRoot.inst.removeChild(this._agent);
  507. var sourceData = this._sourceData;
  508. this._sourceData = null;
  509. var obj = fgui.GRoot.inst.touchTarget;
  510. while (obj) {
  511. if (obj.node.hasEventListener(fgui.Event.DROP)) {
  512. obj.requestFocus();
  513. obj.node.emit(fgui.Event.DROP, obj, sourceData);
  514. return;
  515. }
  516. obj = obj.parent;
  517. }
  518. }
  519. }
  520. fgui.DragDropManager = DragDropManager;
  521. })(fgui || (fgui = {}));
  522. (function (fgui) {
  523. let ButtonMode;
  524. (function (ButtonMode) {
  525. ButtonMode[ButtonMode["Common"] = 0] = "Common";
  526. ButtonMode[ButtonMode["Check"] = 1] = "Check";
  527. ButtonMode[ButtonMode["Radio"] = 2] = "Radio";
  528. })(ButtonMode = fgui.ButtonMode || (fgui.ButtonMode = {}));
  529. let AutoSizeType;
  530. (function (AutoSizeType) {
  531. AutoSizeType[AutoSizeType["None"] = 0] = "None";
  532. AutoSizeType[AutoSizeType["Both"] = 1] = "Both";
  533. AutoSizeType[AutoSizeType["Height"] = 2] = "Height";
  534. AutoSizeType[AutoSizeType["Shrink"] = 3] = "Shrink";
  535. })(AutoSizeType = fgui.AutoSizeType || (fgui.AutoSizeType = {}));
  536. let AlignType;
  537. (function (AlignType) {
  538. AlignType[AlignType["Left"] = 0] = "Left";
  539. AlignType[AlignType["Center"] = 1] = "Center";
  540. AlignType[AlignType["Right"] = 2] = "Right";
  541. })(AlignType = fgui.AlignType || (fgui.AlignType = {}));
  542. let VertAlignType;
  543. (function (VertAlignType) {
  544. VertAlignType[VertAlignType["Top"] = 0] = "Top";
  545. VertAlignType[VertAlignType["Middle"] = 1] = "Middle";
  546. VertAlignType[VertAlignType["Bottom"] = 2] = "Bottom";
  547. })(VertAlignType = fgui.VertAlignType || (fgui.VertAlignType = {}));
  548. let LoaderFillType;
  549. (function (LoaderFillType) {
  550. LoaderFillType[LoaderFillType["None"] = 0] = "None";
  551. LoaderFillType[LoaderFillType["Scale"] = 1] = "Scale";
  552. LoaderFillType[LoaderFillType["ScaleMatchHeight"] = 2] = "ScaleMatchHeight";
  553. LoaderFillType[LoaderFillType["ScaleMatchWidth"] = 3] = "ScaleMatchWidth";
  554. LoaderFillType[LoaderFillType["ScaleFree"] = 4] = "ScaleFree";
  555. LoaderFillType[LoaderFillType["ScaleNoBorder"] = 5] = "ScaleNoBorder";
  556. })(LoaderFillType = fgui.LoaderFillType || (fgui.LoaderFillType = {}));
  557. let ListLayoutType;
  558. (function (ListLayoutType) {
  559. ListLayoutType[ListLayoutType["SingleColumn"] = 0] = "SingleColumn";
  560. ListLayoutType[ListLayoutType["SingleRow"] = 1] = "SingleRow";
  561. ListLayoutType[ListLayoutType["FlowHorizontal"] = 2] = "FlowHorizontal";
  562. ListLayoutType[ListLayoutType["FlowVertical"] = 3] = "FlowVertical";
  563. ListLayoutType[ListLayoutType["Pagination"] = 4] = "Pagination";
  564. })(ListLayoutType = fgui.ListLayoutType || (fgui.ListLayoutType = {}));
  565. let ListSelectionMode;
  566. (function (ListSelectionMode) {
  567. ListSelectionMode[ListSelectionMode["Single"] = 0] = "Single";
  568. ListSelectionMode[ListSelectionMode["Multiple"] = 1] = "Multiple";
  569. ListSelectionMode[ListSelectionMode["Multiple_SingleClick"] = 2] = "Multiple_SingleClick";
  570. ListSelectionMode[ListSelectionMode["None"] = 3] = "None";
  571. })(ListSelectionMode = fgui.ListSelectionMode || (fgui.ListSelectionMode = {}));
  572. let OverflowType;
  573. (function (OverflowType) {
  574. OverflowType[OverflowType["Visible"] = 0] = "Visible";
  575. OverflowType[OverflowType["Hidden"] = 1] = "Hidden";
  576. OverflowType[OverflowType["Scroll"] = 2] = "Scroll";
  577. })(OverflowType = fgui.OverflowType || (fgui.OverflowType = {}));
  578. let PackageItemType;
  579. (function (PackageItemType) {
  580. PackageItemType[PackageItemType["Image"] = 0] = "Image";
  581. PackageItemType[PackageItemType["MovieClip"] = 1] = "MovieClip";
  582. PackageItemType[PackageItemType["Sound"] = 2] = "Sound";
  583. PackageItemType[PackageItemType["Component"] = 3] = "Component";
  584. PackageItemType[PackageItemType["Atlas"] = 4] = "Atlas";
  585. PackageItemType[PackageItemType["Font"] = 5] = "Font";
  586. PackageItemType[PackageItemType["Swf"] = 6] = "Swf";
  587. PackageItemType[PackageItemType["Misc"] = 7] = "Misc";
  588. PackageItemType[PackageItemType["Unknown"] = 8] = "Unknown";
  589. PackageItemType[PackageItemType["Spine"] = 9] = "Spine";
  590. PackageItemType[PackageItemType["DragonBones"] = 10] = "DragonBones";
  591. })(PackageItemType = fgui.PackageItemType || (fgui.PackageItemType = {}));
  592. let ObjectType;
  593. (function (ObjectType) {
  594. ObjectType[ObjectType["Image"] = 0] = "Image";
  595. ObjectType[ObjectType["MovieClip"] = 1] = "MovieClip";
  596. ObjectType[ObjectType["Swf"] = 2] = "Swf";
  597. ObjectType[ObjectType["Graph"] = 3] = "Graph";
  598. ObjectType[ObjectType["Loader"] = 4] = "Loader";
  599. ObjectType[ObjectType["Group"] = 5] = "Group";
  600. ObjectType[ObjectType["Text"] = 6] = "Text";
  601. ObjectType[ObjectType["RichText"] = 7] = "RichText";
  602. ObjectType[ObjectType["InputText"] = 8] = "InputText";
  603. ObjectType[ObjectType["Component"] = 9] = "Component";
  604. ObjectType[ObjectType["List"] = 10] = "List";
  605. ObjectType[ObjectType["Label"] = 11] = "Label";
  606. ObjectType[ObjectType["Button"] = 12] = "Button";
  607. ObjectType[ObjectType["ComboBox"] = 13] = "ComboBox";
  608. ObjectType[ObjectType["ProgressBar"] = 14] = "ProgressBar";
  609. ObjectType[ObjectType["Slider"] = 15] = "Slider";
  610. ObjectType[ObjectType["ScrollBar"] = 16] = "ScrollBar";
  611. ObjectType[ObjectType["Tree"] = 17] = "Tree";
  612. ObjectType[ObjectType["Loader3D"] = 18] = "Loader3D";
  613. })(ObjectType = fgui.ObjectType || (fgui.ObjectType = {}));
  614. let ProgressTitleType;
  615. (function (ProgressTitleType) {
  616. ProgressTitleType[ProgressTitleType["Percent"] = 0] = "Percent";
  617. ProgressTitleType[ProgressTitleType["ValueAndMax"] = 1] = "ValueAndMax";
  618. ProgressTitleType[ProgressTitleType["Value"] = 2] = "Value";
  619. ProgressTitleType[ProgressTitleType["Max"] = 3] = "Max";
  620. })(ProgressTitleType = fgui.ProgressTitleType || (fgui.ProgressTitleType = {}));
  621. let ScrollBarDisplayType;
  622. (function (ScrollBarDisplayType) {
  623. ScrollBarDisplayType[ScrollBarDisplayType["Default"] = 0] = "Default";
  624. ScrollBarDisplayType[ScrollBarDisplayType["Visible"] = 1] = "Visible";
  625. ScrollBarDisplayType[ScrollBarDisplayType["Auto"] = 2] = "Auto";
  626. ScrollBarDisplayType[ScrollBarDisplayType["Hidden"] = 3] = "Hidden";
  627. })(ScrollBarDisplayType = fgui.ScrollBarDisplayType || (fgui.ScrollBarDisplayType = {}));
  628. let ScrollType;
  629. (function (ScrollType) {
  630. ScrollType[ScrollType["Horizontal"] = 0] = "Horizontal";
  631. ScrollType[ScrollType["Vertical"] = 1] = "Vertical";
  632. ScrollType[ScrollType["Both"] = 2] = "Both";
  633. })(ScrollType = fgui.ScrollType || (fgui.ScrollType = {}));
  634. let FlipType;
  635. (function (FlipType) {
  636. FlipType[FlipType["None"] = 0] = "None";
  637. FlipType[FlipType["Horizontal"] = 1] = "Horizontal";
  638. FlipType[FlipType["Vertical"] = 2] = "Vertical";
  639. FlipType[FlipType["Both"] = 3] = "Both";
  640. })(FlipType = fgui.FlipType || (fgui.FlipType = {}));
  641. let ChildrenRenderOrder;
  642. (function (ChildrenRenderOrder) {
  643. ChildrenRenderOrder[ChildrenRenderOrder["Ascent"] = 0] = "Ascent";
  644. ChildrenRenderOrder[ChildrenRenderOrder["Descent"] = 1] = "Descent";
  645. ChildrenRenderOrder[ChildrenRenderOrder["Arch"] = 2] = "Arch";
  646. })(ChildrenRenderOrder = fgui.ChildrenRenderOrder || (fgui.ChildrenRenderOrder = {}));
  647. let GroupLayoutType;
  648. (function (GroupLayoutType) {
  649. GroupLayoutType[GroupLayoutType["None"] = 0] = "None";
  650. GroupLayoutType[GroupLayoutType["Horizontal"] = 1] = "Horizontal";
  651. GroupLayoutType[GroupLayoutType["Vertical"] = 2] = "Vertical";
  652. })(GroupLayoutType = fgui.GroupLayoutType || (fgui.GroupLayoutType = {}));
  653. let PopupDirection;
  654. (function (PopupDirection) {
  655. PopupDirection[PopupDirection["Auto"] = 0] = "Auto";
  656. PopupDirection[PopupDirection["Up"] = 1] = "Up";
  657. PopupDirection[PopupDirection["Down"] = 2] = "Down";
  658. })(PopupDirection = fgui.PopupDirection || (fgui.PopupDirection = {}));
  659. let RelationType;
  660. (function (RelationType) {
  661. RelationType[RelationType["Left_Left"] = 0] = "Left_Left";
  662. RelationType[RelationType["Left_Center"] = 1] = "Left_Center";
  663. RelationType[RelationType["Left_Right"] = 2] = "Left_Right";
  664. RelationType[RelationType["Center_Center"] = 3] = "Center_Center";
  665. RelationType[RelationType["Right_Left"] = 4] = "Right_Left";
  666. RelationType[RelationType["Right_Center"] = 5] = "Right_Center";
  667. RelationType[RelationType["Right_Right"] = 6] = "Right_Right";
  668. RelationType[RelationType["Top_Top"] = 7] = "Top_Top";
  669. RelationType[RelationType["Top_Middle"] = 8] = "Top_Middle";
  670. RelationType[RelationType["Top_Bottom"] = 9] = "Top_Bottom";
  671. RelationType[RelationType["Middle_Middle"] = 10] = "Middle_Middle";
  672. RelationType[RelationType["Bottom_Top"] = 11] = "Bottom_Top";
  673. RelationType[RelationType["Bottom_Middle"] = 12] = "Bottom_Middle";
  674. RelationType[RelationType["Bottom_Bottom"] = 13] = "Bottom_Bottom";
  675. RelationType[RelationType["Width"] = 14] = "Width";
  676. RelationType[RelationType["Height"] = 15] = "Height";
  677. RelationType[RelationType["LeftExt_Left"] = 16] = "LeftExt_Left";
  678. RelationType[RelationType["LeftExt_Right"] = 17] = "LeftExt_Right";
  679. RelationType[RelationType["RightExt_Left"] = 18] = "RightExt_Left";
  680. RelationType[RelationType["RightExt_Right"] = 19] = "RightExt_Right";
  681. RelationType[RelationType["TopExt_Top"] = 20] = "TopExt_Top";
  682. RelationType[RelationType["TopExt_Bottom"] = 21] = "TopExt_Bottom";
  683. RelationType[RelationType["BottomExt_Top"] = 22] = "BottomExt_Top";
  684. RelationType[RelationType["BottomExt_Bottom"] = 23] = "BottomExt_Bottom";
  685. RelationType[RelationType["Size"] = 24] = "Size";
  686. })(RelationType = fgui.RelationType || (fgui.RelationType = {}));
  687. let FillMethod;
  688. (function (FillMethod) {
  689. FillMethod[FillMethod["None"] = 0] = "None";
  690. FillMethod[FillMethod["Horizontal"] = 1] = "Horizontal";
  691. FillMethod[FillMethod["Vertical"] = 2] = "Vertical";
  692. FillMethod[FillMethod["Radial90"] = 3] = "Radial90";
  693. FillMethod[FillMethod["Radial180"] = 4] = "Radial180";
  694. FillMethod[FillMethod["Radial360"] = 5] = "Radial360";
  695. })(FillMethod = fgui.FillMethod || (fgui.FillMethod = {}));
  696. let FillOrigin;
  697. (function (FillOrigin) {
  698. FillOrigin[FillOrigin["Top"] = 0] = "Top";
  699. FillOrigin[FillOrigin["Bottom"] = 1] = "Bottom";
  700. FillOrigin[FillOrigin["Left"] = 2] = "Left";
  701. FillOrigin[FillOrigin["Right"] = 3] = "Right";
  702. })(FillOrigin = fgui.FillOrigin || (fgui.FillOrigin = {}));
  703. let ObjectPropID;
  704. (function (ObjectPropID) {
  705. ObjectPropID[ObjectPropID["Text"] = 0] = "Text";
  706. ObjectPropID[ObjectPropID["Icon"] = 1] = "Icon";
  707. ObjectPropID[ObjectPropID["Color"] = 2] = "Color";
  708. ObjectPropID[ObjectPropID["OutlineColor"] = 3] = "OutlineColor";
  709. ObjectPropID[ObjectPropID["Playing"] = 4] = "Playing";
  710. ObjectPropID[ObjectPropID["Frame"] = 5] = "Frame";
  711. ObjectPropID[ObjectPropID["DeltaTime"] = 6] = "DeltaTime";
  712. ObjectPropID[ObjectPropID["TimeScale"] = 7] = "TimeScale";
  713. ObjectPropID[ObjectPropID["FontSize"] = 8] = "FontSize";
  714. ObjectPropID[ObjectPropID["Selected"] = 9] = "Selected";
  715. })(ObjectPropID = fgui.ObjectPropID || (fgui.ObjectPropID = {}));
  716. })(fgui || (fgui = {}));
  717. (function (fgui) {
  718. class GObject {
  719. constructor() {
  720. this._x = 0;
  721. this._y = 0;
  722. this._alpha = 1;
  723. this._visible = true;
  724. this._touchable = true;
  725. this._skewX = 0;
  726. this._skewY = 0;
  727. this._sortingOrder = 0;
  728. this._internalVisible = true;
  729. this.sourceWidth = 0;
  730. this.sourceHeight = 0;
  731. this.initWidth = 0;
  732. this.initHeight = 0;
  733. this.minWidth = 0;
  734. this.minHeight = 0;
  735. this.maxWidth = 0;
  736. this.maxHeight = 0;
  737. this._width = 0;
  738. this._height = 0;
  739. this._rawWidth = 0;
  740. this._rawHeight = 0;
  741. this._sizePercentInGroup = 0;
  742. this._node = new cc.Node();
  743. if (GObject._defaultGroupIndex == -1) {
  744. GObject._defaultGroupIndex = 0;
  745. let groups = cc.game.groupList;
  746. let cnt = groups.length;
  747. for (let i = 0; i < cnt; i++) {
  748. if (groups[i].toLowerCase() == fgui.UIConfig.defaultUIGroup.toLowerCase()) {
  749. GObject._defaultGroupIndex = i;
  750. break;
  751. }
  752. }
  753. }
  754. this._node['$gobj'] = this;
  755. this._node.groupIndex = GObject._defaultGroupIndex;
  756. this._node.setAnchorPoint(0, 1);
  757. this._node.on(cc.Node.EventType.ANCHOR_CHANGED, this.handleAnchorChanged, this);
  758. this._id = this._node.uuid;
  759. this._name = '';
  760. this._relations = new fgui.Relations(this);
  761. this._gears = new Array(10);
  762. this._blendMode = fgui.BlendMode.Normal;
  763. this._partner = this._node.addComponent(GObjectPartner);
  764. }
  765. get id() {
  766. return this._id;
  767. }
  768. get name() {
  769. return this._name;
  770. }
  771. set name(value) {
  772. this._name = value;
  773. }
  774. get x() {
  775. return this._x;
  776. }
  777. set x(value) {
  778. this.setPosition(value, this._y);
  779. }
  780. get y() {
  781. return this._y;
  782. }
  783. set y(value) {
  784. this.setPosition(this._x, value);
  785. }
  786. setPosition(xv, yv) {
  787. if (this._x != xv || this._y != yv) {
  788. var dx = xv - this._x;
  789. var dy = yv - this._y;
  790. this._x = xv;
  791. this._y = yv;
  792. this.handlePositionChanged();
  793. if (this instanceof fgui.GGroup)
  794. this.moveChildren(dx, dy);
  795. this.updateGear(1);
  796. if (this._parent && !(this._parent instanceof fgui.GList)) {
  797. this._parent.setBoundsChangedFlag();
  798. if (this._group)
  799. this._group.setBoundsChangedFlag(true);
  800. this._node.emit(fgui.Event.XY_CHANGED, this);
  801. }
  802. if (GObject.draggingObject == this && !sUpdateInDragging)
  803. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  804. }
  805. }
  806. get xMin() {
  807. return this._pivotAsAnchor ? this._x - this._width * this.node.anchorX : this._x;
  808. }
  809. set xMin(value) {
  810. if (this._pivotAsAnchor)
  811. this.setPosition(value + this._width * this.node.anchorX, this._y);
  812. else
  813. this.setPosition(value, this._y);
  814. }
  815. get yMin() {
  816. return this._pivotAsAnchor ? this._y - this._height * (1 - this.node.anchorY) : this._y;
  817. }
  818. set yMin(value) {
  819. if (this._pivotAsAnchor)
  820. this.setPosition(this._x, value + this._height * (1 - this.node.anchorY));
  821. else
  822. this.setPosition(this._x, value);
  823. }
  824. get pixelSnapping() {
  825. return this._pixelSnapping;
  826. }
  827. set pixelSnapping(value) {
  828. if (this._pixelSnapping != value) {
  829. this._pixelSnapping = value;
  830. this.handlePositionChanged();
  831. }
  832. }
  833. center(restraint) {
  834. var r;
  835. if (this._parent)
  836. r = this.parent;
  837. else
  838. r = this.root;
  839. this.setPosition((r.width - this._width) / 2, (r.height - this._height) / 2);
  840. if (restraint) {
  841. this.addRelation(r, fgui.RelationType.Center_Center);
  842. this.addRelation(r, fgui.RelationType.Middle_Middle);
  843. }
  844. }
  845. get width() {
  846. this.ensureSizeCorrect();
  847. if (this._relations.sizeDirty)
  848. this._relations.ensureRelationsSizeCorrect();
  849. return this._width;
  850. }
  851. set width(value) {
  852. this.setSize(value, this._rawHeight);
  853. }
  854. get height() {
  855. this.ensureSizeCorrect();
  856. if (this._relations.sizeDirty)
  857. this._relations.ensureRelationsSizeCorrect();
  858. return this._height;
  859. }
  860. set height(value) {
  861. this.setSize(this._rawWidth, value);
  862. }
  863. setSize(wv, hv, ignorePivot) {
  864. if (this._rawWidth != wv || this._rawHeight != hv) {
  865. this._rawWidth = wv;
  866. this._rawHeight = hv;
  867. if (wv < this.minWidth)
  868. wv = this.minWidth;
  869. if (hv < this.minHeight)
  870. hv = this.minHeight;
  871. if (this.maxWidth > 0 && wv > this.maxWidth)
  872. wv = this.maxWidth;
  873. if (this.maxHeight > 0 && hv > this.maxHeight)
  874. hv = this.maxHeight;
  875. var dWidth = wv - this._width;
  876. var dHeight = hv - this._height;
  877. this._width = wv;
  878. this._height = hv;
  879. this.handleSizeChanged();
  880. if ((this.node.anchorX != 0 || this.node.anchorY != 1) && !this._pivotAsAnchor && !ignorePivot)
  881. this.setPosition(this.x - this.node.anchorX * dWidth, this.y - (1 - this.node.anchorY) * dHeight);
  882. else
  883. this.handlePositionChanged();
  884. if (this instanceof fgui.GGroup)
  885. this.resizeChildren(dWidth, dHeight);
  886. this.updateGear(2);
  887. if (this._parent) {
  888. this._relations.onOwnerSizeChanged(dWidth, dHeight, this._pivotAsAnchor || !ignorePivot);
  889. this._parent.setBoundsChangedFlag();
  890. if (this._group)
  891. this._group.setBoundsChangedFlag();
  892. }
  893. this._node.emit(fgui.Event.SIZE_CHANGED, this);
  894. }
  895. }
  896. makeFullScreen() {
  897. this.setSize(fgui.GRoot.inst.width, fgui.GRoot.inst.height);
  898. }
  899. ensureSizeCorrect() { }
  900. get actualWidth() {
  901. return this.width * Math.abs(this._node.scaleX);
  902. }
  903. get actualHeight() {
  904. return this.height * Math.abs(this._node.scaleY);
  905. }
  906. get scaleX() {
  907. return this._node.scaleX;
  908. }
  909. set scaleX(value) {
  910. this.setScale(value, this._node.scaleY);
  911. }
  912. get scaleY() {
  913. return this._node.scaleY;
  914. }
  915. set scaleY(value) {
  916. this.setScale(this._node.scaleX, value);
  917. }
  918. setScale(sx, sy) {
  919. if (this._node.scaleX != sx || this._node.scaleY != sy) {
  920. this._node.setScale(sx, sy);
  921. this.updateGear(2);
  922. }
  923. }
  924. get skewX() {
  925. return this._skewX;
  926. }
  927. set skewX(value) {
  928. this.setSkew(value, this._skewY);
  929. }
  930. get skewY() {
  931. return this._skewY;
  932. }
  933. set skewY(value) {
  934. this.setSkew(this._skewX, value);
  935. }
  936. setSkew(xv, yv) {
  937. if (this._skewX != xv || this._skewY != yv) {
  938. this._skewX = xv;
  939. this._skewY = yv;
  940. this._node.skewX = xv;
  941. this._node.skewY = yv;
  942. }
  943. }
  944. get pivotX() {
  945. return this.node.anchorX;
  946. }
  947. set pivotX(value) {
  948. this.node.anchorX = value;
  949. }
  950. get pivotY() {
  951. return 1 - this.node.anchorY;
  952. }
  953. set pivotY(value) {
  954. this.node.anchorY = 1 - value;
  955. }
  956. setPivot(xv, yv, asAnchor) {
  957. if (this.node.anchorX != xv || this.node.anchorY != 1 - yv) {
  958. this._pivotAsAnchor = asAnchor;
  959. this.node.setAnchorPoint(xv, 1 - yv);
  960. }
  961. else if (this._pivotAsAnchor != asAnchor) {
  962. this._pivotAsAnchor = asAnchor;
  963. this.handlePositionChanged();
  964. }
  965. }
  966. get pivotAsAnchor() {
  967. return this._pivotAsAnchor;
  968. }
  969. get touchable() {
  970. return this._touchable;
  971. }
  972. set touchable(value) {
  973. if (this._touchable != value) {
  974. this._touchable = value;
  975. this.updateGear(3);
  976. }
  977. }
  978. get grayed() {
  979. return this._grayed;
  980. }
  981. set grayed(value) {
  982. if (this._grayed != value) {
  983. this._grayed = value;
  984. this.handleGrayedChanged();
  985. this.updateGear(3);
  986. }
  987. }
  988. get enabled() {
  989. return !this._grayed && this._touchable;
  990. }
  991. set enabled(value) {
  992. this.grayed = !value;
  993. this.touchable = value;
  994. }
  995. get rotation() {
  996. return -this._node.angle;
  997. }
  998. set rotation(value) {
  999. value = -value;
  1000. if (this._node.angle != value) {
  1001. this._node.angle = value;
  1002. this.updateGear(3);
  1003. }
  1004. }
  1005. get alpha() {
  1006. return this._alpha;
  1007. }
  1008. set alpha(value) {
  1009. if (this._alpha != value) {
  1010. this._alpha = value;
  1011. this._node.opacity = this._alpha * 255;
  1012. if (this instanceof fgui.GGroup)
  1013. this.handleAlphaChanged();
  1014. this.updateGear(3);
  1015. }
  1016. }
  1017. get visible() {
  1018. return this._visible;
  1019. }
  1020. set visible(value) {
  1021. if (this._visible != value) {
  1022. this._visible = value;
  1023. this.handleVisibleChanged();
  1024. if (this._group && this._group.excludeInvisibles)
  1025. this._group.setBoundsChangedFlag();
  1026. }
  1027. }
  1028. get _finalVisible() {
  1029. return this._visible && this._internalVisible && (!this._group || this._group._finalVisible);
  1030. }
  1031. get internalVisible3() {
  1032. return this._visible && this._internalVisible;
  1033. }
  1034. get sortingOrder() {
  1035. return this._sortingOrder;
  1036. }
  1037. set sortingOrder(value) {
  1038. if (value < 0)
  1039. value = 0;
  1040. if (this._sortingOrder != value) {
  1041. var old = this._sortingOrder;
  1042. this._sortingOrder = value;
  1043. if (this._parent)
  1044. this._parent.childSortingOrderChanged(this, old, this._sortingOrder);
  1045. }
  1046. }
  1047. requestFocus() { }
  1048. get tooltips() {
  1049. return this._tooltips;
  1050. }
  1051. set tooltips(value) {
  1052. if (this._tooltips) {
  1053. this._node.off(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1054. this._node.off(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1055. }
  1056. this._tooltips = value;
  1057. if (this._tooltips) {
  1058. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1059. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1060. }
  1061. }
  1062. get blendMode() {
  1063. return this._blendMode;
  1064. }
  1065. set blendMode(value) {
  1066. if (this._blendMode != value) {
  1067. this._blendMode = value;
  1068. fgui.BlendModeUtils.apply(this._node, value);
  1069. }
  1070. }
  1071. get onStage() {
  1072. return this._node && this._node.activeInHierarchy;
  1073. }
  1074. get resourceURL() {
  1075. if (this.packageItem)
  1076. return 'ui://' + this.packageItem.owner.id + this.packageItem.id;
  1077. else
  1078. return null;
  1079. }
  1080. set group(value) {
  1081. if (this._group != value) {
  1082. if (this._group)
  1083. this._group.setBoundsChangedFlag();
  1084. this._group = value;
  1085. if (this._group)
  1086. this._group.setBoundsChangedFlag();
  1087. }
  1088. }
  1089. get group() {
  1090. return this._group;
  1091. }
  1092. getGear(index) {
  1093. var gear = this._gears[index];
  1094. if (!gear)
  1095. this._gears[index] = gear = fgui.GearBase.create(this, index);
  1096. return gear;
  1097. }
  1098. updateGear(index) {
  1099. if (this._underConstruct || this._gearLocked)
  1100. return;
  1101. var gear = this._gears[index];
  1102. if (gear && gear.controller)
  1103. gear.updateState();
  1104. }
  1105. checkGearController(index, c) {
  1106. return this._gears[index] && this._gears[index].controller == c;
  1107. }
  1108. updateGearFromRelations(index, dx, dy) {
  1109. if (this._gears[index])
  1110. this._gears[index].updateFromRelations(dx, dy);
  1111. }
  1112. addDisplayLock() {
  1113. var gearDisplay = this._gears[0];
  1114. if (gearDisplay && gearDisplay.controller) {
  1115. var ret = gearDisplay.addLock();
  1116. this.checkGearDisplay();
  1117. return ret;
  1118. }
  1119. else
  1120. return 0;
  1121. }
  1122. releaseDisplayLock(token) {
  1123. var gearDisplay = this._gears[0];
  1124. if (gearDisplay && gearDisplay.controller) {
  1125. gearDisplay.releaseLock(token);
  1126. this.checkGearDisplay();
  1127. }
  1128. }
  1129. checkGearDisplay() {
  1130. if (this._handlingController)
  1131. return;
  1132. var connected = this._gears[0] == null || this._gears[0].connected;
  1133. if (this._gears[8])
  1134. connected = this._gears[8].evaluate(connected);
  1135. if (connected != this._internalVisible) {
  1136. this._internalVisible = connected;
  1137. this.handleVisibleChanged();
  1138. if (this._group && this._group.excludeInvisibles)
  1139. this._group.setBoundsChangedFlag();
  1140. }
  1141. }
  1142. get gearXY() {
  1143. return this.getGear(1);
  1144. }
  1145. get gearSize() {
  1146. return this.getGear(2);
  1147. }
  1148. get gearLook() {
  1149. return this.getGear(3);
  1150. }
  1151. get relations() {
  1152. return this._relations;
  1153. }
  1154. addRelation(target, relationType, usePercent) {
  1155. this._relations.add(target, relationType, usePercent);
  1156. }
  1157. removeRelation(target, relationType) {
  1158. this._relations.remove(target, relationType);
  1159. }
  1160. get node() {
  1161. return this._node;
  1162. }
  1163. get parent() {
  1164. return this._parent;
  1165. }
  1166. removeFromParent() {
  1167. if (this._parent)
  1168. this._parent.removeChild(this);
  1169. }
  1170. findParent() {
  1171. if (this._parent)
  1172. return this._parent;
  1173. let pn = this._node.parent;
  1174. while (pn) {
  1175. let gobj = pn['$gobj'];
  1176. if (gobj)
  1177. return gobj;
  1178. pn = pn.parent;
  1179. }
  1180. return null;
  1181. }
  1182. get root() {
  1183. if (this instanceof fgui.GRoot)
  1184. return this;
  1185. var p = this._parent;
  1186. while (p) {
  1187. if (p instanceof fgui.GRoot)
  1188. return p;
  1189. p = p.parent;
  1190. }
  1191. return fgui.GRoot.inst;
  1192. }
  1193. get asCom() {
  1194. return this;
  1195. }
  1196. get asButton() {
  1197. return this;
  1198. }
  1199. get asLabel() {
  1200. return this;
  1201. }
  1202. get asProgress() {
  1203. return this;
  1204. }
  1205. get asTextField() {
  1206. return this;
  1207. }
  1208. get asRichTextField() {
  1209. return this;
  1210. }
  1211. get asTextInput() {
  1212. return this;
  1213. }
  1214. get asLoader() {
  1215. return this;
  1216. }
  1217. get asList() {
  1218. return this;
  1219. }
  1220. get asTree() {
  1221. return this;
  1222. }
  1223. get asGraph() {
  1224. return this;
  1225. }
  1226. get asGroup() {
  1227. return this;
  1228. }
  1229. get asSlider() {
  1230. return this;
  1231. }
  1232. get asComboBox() {
  1233. return this;
  1234. }
  1235. get asImage() {
  1236. return this;
  1237. }
  1238. get asMovieClip() {
  1239. return this;
  1240. }
  1241. static cast(obj) {
  1242. return obj['$gobj'];
  1243. }
  1244. get text() {
  1245. return null;
  1246. }
  1247. set text(value) { }
  1248. get icon() {
  1249. return null;
  1250. }
  1251. set icon(value) { }
  1252. get treeNode() {
  1253. return this._treeNode;
  1254. }
  1255. dispose() {
  1256. let n = this._node;
  1257. if (!n)
  1258. return;
  1259. this.removeFromParent();
  1260. this._relations.dispose();
  1261. this._node = null;
  1262. n.destroy();
  1263. for (var i = 0; i < 10; i++) {
  1264. var gear = this._gears[i];
  1265. if (gear)
  1266. gear.dispose();
  1267. }
  1268. }
  1269. onEnable() { }
  1270. onDisable() { }
  1271. onUpdate() { }
  1272. onDestroy() { }
  1273. onClick(listener, target) {
  1274. this._node.on(fgui.Event.CLICK, listener, target);
  1275. }
  1276. offClick(listener, target) {
  1277. this._node.off(fgui.Event.CLICK, listener, target);
  1278. }
  1279. clearClick() {
  1280. this._node.off(fgui.Event.CLICK);
  1281. }
  1282. hasClickListener() {
  1283. return this._node.hasEventListener(fgui.Event.CLICK);
  1284. }
  1285. on(type, listener, target) {
  1286. if (type == fgui.Event.DISPLAY || type == fgui.Event.UNDISPLAY)
  1287. this._partner._emitDisplayEvents = true;
  1288. this._node.on(type, listener, target);
  1289. }
  1290. off(type, listener, target) {
  1291. this._node.off(type, listener, target);
  1292. }
  1293. get draggable() {
  1294. return this._draggable;
  1295. }
  1296. set draggable(value) {
  1297. if (this._draggable != value) {
  1298. this._draggable = value;
  1299. this.initDrag();
  1300. }
  1301. }
  1302. get dragBounds() {
  1303. return this._dragBounds;
  1304. }
  1305. set dragBounds(value) {
  1306. this._dragBounds = value;
  1307. }
  1308. startDrag(touchId) {
  1309. if (!this._node.activeInHierarchy)
  1310. return;
  1311. this.dragBegin(touchId);
  1312. }
  1313. stopDrag() {
  1314. this.dragEnd();
  1315. }
  1316. get dragging() {
  1317. return GObject.draggingObject == this;
  1318. }
  1319. localToGlobal(ax, ay, result) {
  1320. ax = ax || 0;
  1321. ay = ay || 0;
  1322. result = result || new cc.Vec2();
  1323. result.x = ax;
  1324. result.y = ay;
  1325. result.y = -result.y;
  1326. if (!this._pivotAsAnchor) {
  1327. result.x -= this.node.anchorX * this._width;
  1328. result.y += (1 - this.node.anchorY) * this._height;
  1329. }
  1330. this._node.convertToWorldSpaceAR(result, result);
  1331. result.y = fgui.GRoot.inst.height - result.y;
  1332. return result;
  1333. }
  1334. globalToLocal(ax, ay, result) {
  1335. ax = ax || 0;
  1336. ay = ay || 0;
  1337. result = result || new cc.Vec2();
  1338. result.x = ax;
  1339. result.y = fgui.GRoot.inst.height - ay;
  1340. this._node.convertToNodeSpaceAR(result, result);
  1341. if (!this._pivotAsAnchor) {
  1342. result.x += this._node.anchorX * this._width;
  1343. result.y -= (1 - this._node.anchorY) * this._height;
  1344. }
  1345. result.y = -result.y;
  1346. return result;
  1347. }
  1348. localToGlobalRect(ax, ay, aw, ah, result) {
  1349. ax = ax || 0;
  1350. ay = ay || 0;
  1351. aw = aw || 0;
  1352. ah = ah || 0;
  1353. result = result || new cc.Rect();
  1354. var pt = this.localToGlobal(ax, ay);
  1355. result.x = pt.x;
  1356. result.y = pt.y;
  1357. pt = this.localToGlobal(ax + aw, ay + ah, pt);
  1358. result.xMax = pt.x;
  1359. result.yMax = pt.y;
  1360. return result;
  1361. }
  1362. globalToLocalRect(ax, ay, aw, ah, result) {
  1363. ax = ax || 0;
  1364. ay = ay || 0;
  1365. aw = aw || 0;
  1366. ah = ah || 0;
  1367. result = result || new cc.Rect();
  1368. var pt = this.globalToLocal(ax, ay);
  1369. result.x = pt.x;
  1370. result.y = pt.y;
  1371. pt = this.globalToLocal(ax + aw, ay + ah, pt);
  1372. result.xMax = pt.x;
  1373. result.yMax = pt.y;
  1374. return result;
  1375. }
  1376. handleControllerChanged(c) {
  1377. this._handlingController = true;
  1378. for (var i = 0; i < 10; i++) {
  1379. var gear = this._gears[i];
  1380. if (gear && gear.controller == c)
  1381. gear.apply();
  1382. }
  1383. this._handlingController = false;
  1384. this.checkGearDisplay();
  1385. }
  1386. handleAnchorChanged() {
  1387. this.handlePositionChanged();
  1388. }
  1389. handlePositionChanged() {
  1390. var xv = this._x;
  1391. var yv = -this._y;
  1392. if (!this._pivotAsAnchor) {
  1393. xv += this.node.anchorX * this._width;
  1394. yv -= (1 - this.node.anchorY) * this._height;
  1395. }
  1396. if (this._pixelSnapping) {
  1397. xv = Math.round(xv);
  1398. yv = Math.round(yv);
  1399. }
  1400. this._node.setPosition(xv, yv);
  1401. }
  1402. handleSizeChanged() {
  1403. this._node.setContentSize(this._width, this._height);
  1404. }
  1405. handleGrayedChanged() {
  1406. }
  1407. handleVisibleChanged() {
  1408. this._node.active = this._finalVisible;
  1409. if (this instanceof fgui.GGroup)
  1410. this.handleVisibleChanged();
  1411. if (this._parent)
  1412. this._parent.setBoundsChangedFlag();
  1413. }
  1414. hitTest(globalPt, forTouch) {
  1415. if (forTouch == null)
  1416. forTouch = true;
  1417. if (forTouch && (this._touchDisabled || !this._touchable || !this._node.activeInHierarchy))
  1418. return null;
  1419. if (!this._hitTestPt)
  1420. this._hitTestPt = new cc.Vec2();
  1421. this.globalToLocal(globalPt.x, globalPt.y, this._hitTestPt);
  1422. if (this._pivotAsAnchor) {
  1423. this._hitTestPt.x += this.node.anchorX * this._width;
  1424. this._hitTestPt.y += (1 - this.node.anchorY) * this._height;
  1425. }
  1426. return this._hitTest(this._hitTestPt, globalPt);
  1427. }
  1428. _hitTest(pt, globalPt) {
  1429. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  1430. return this;
  1431. else
  1432. return null;
  1433. }
  1434. getProp(index) {
  1435. switch (index) {
  1436. case fgui.ObjectPropID.Text:
  1437. return this.text;
  1438. case fgui.ObjectPropID.Icon:
  1439. return this.icon;
  1440. case fgui.ObjectPropID.Color:
  1441. return null;
  1442. case fgui.ObjectPropID.OutlineColor:
  1443. return null;
  1444. case fgui.ObjectPropID.Playing:
  1445. return false;
  1446. case fgui.ObjectPropID.Frame:
  1447. return 0;
  1448. case fgui.ObjectPropID.DeltaTime:
  1449. return 0;
  1450. case fgui.ObjectPropID.TimeScale:
  1451. return 1;
  1452. case fgui.ObjectPropID.FontSize:
  1453. return 0;
  1454. case fgui.ObjectPropID.Selected:
  1455. return false;
  1456. default:
  1457. return undefined;
  1458. }
  1459. }
  1460. setProp(index, value) {
  1461. switch (index) {
  1462. case fgui.ObjectPropID.Text:
  1463. this.text = value;
  1464. break;
  1465. case fgui.ObjectPropID.Icon:
  1466. this.icon = value;
  1467. break;
  1468. }
  1469. }
  1470. constructFromResource() { }
  1471. setup_beforeAdd(buffer, beginPos) {
  1472. buffer.seek(beginPos, 0);
  1473. buffer.skip(5);
  1474. var f1;
  1475. var f2;
  1476. this._id = buffer.readS();
  1477. this._name = buffer.readS();
  1478. f1 = buffer.readInt();
  1479. f2 = buffer.readInt();
  1480. this.setPosition(f1, f2);
  1481. if (buffer.readBool()) {
  1482. this.initWidth = buffer.readInt();
  1483. this.initHeight = buffer.readInt();
  1484. this.setSize(this.initWidth, this.initHeight, true);
  1485. }
  1486. if (buffer.readBool()) {
  1487. this.minWidth = buffer.readInt();
  1488. this.maxWidth = buffer.readInt();
  1489. this.minHeight = buffer.readInt();
  1490. this.maxHeight = buffer.readInt();
  1491. }
  1492. if (buffer.readBool()) {
  1493. f1 = buffer.readFloat();
  1494. f2 = buffer.readFloat();
  1495. this.setScale(f1, f2);
  1496. }
  1497. if (buffer.readBool()) {
  1498. f1 = buffer.readFloat();
  1499. f2 = buffer.readFloat();
  1500. this.setSkew(f1, f2);
  1501. }
  1502. if (buffer.readBool()) {
  1503. f1 = buffer.readFloat();
  1504. f2 = buffer.readFloat();
  1505. this.setPivot(f1, f2, buffer.readBool());
  1506. }
  1507. f1 = buffer.readFloat();
  1508. if (f1 != 1)
  1509. this.alpha = f1;
  1510. f1 = buffer.readFloat();
  1511. if (f1 != 0)
  1512. this.rotation = f1;
  1513. if (!buffer.readBool())
  1514. this.visible = false;
  1515. if (!buffer.readBool())
  1516. this.touchable = false;
  1517. if (buffer.readBool())
  1518. this.grayed = true;
  1519. this.blendMode = buffer.readByte();
  1520. var filter = buffer.readByte();
  1521. if (filter == 1) {
  1522. }
  1523. var str = buffer.readS();
  1524. if (str != null)
  1525. this.data = str;
  1526. }
  1527. setup_afterAdd(buffer, beginPos) {
  1528. buffer.seek(beginPos, 1);
  1529. var str = buffer.readS();
  1530. if (str != null)
  1531. this.tooltips = str;
  1532. var groupId = buffer.readShort();
  1533. if (groupId >= 0)
  1534. this.group = this.parent.getChildAt(groupId);
  1535. buffer.seek(beginPos, 2);
  1536. var cnt = buffer.readShort();
  1537. for (var i = 0; i < cnt; i++) {
  1538. var nextPos = buffer.readShort();
  1539. nextPos += buffer.position;
  1540. var gear = this.getGear(buffer.readByte());
  1541. gear.setup(buffer);
  1542. buffer.position = nextPos;
  1543. }
  1544. }
  1545. onRollOver() {
  1546. this.root.showTooltips(this.tooltips);
  1547. }
  1548. onRollOut() {
  1549. this.root.hideTooltips();
  1550. }
  1551. initDrag() {
  1552. if (this._draggable) {
  1553. this.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1554. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1555. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1556. }
  1557. else {
  1558. this.off(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1559. this.off(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1560. this.off(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1561. }
  1562. }
  1563. dragBegin(touchId) {
  1564. if (GObject.draggingObject) {
  1565. let tmp = GObject.draggingObject;
  1566. tmp.stopDrag();
  1567. GObject.draggingObject = null;
  1568. tmp._node.emit(fgui.Event.DRAG_END);
  1569. }
  1570. if (touchId == undefined)
  1571. touchId = fgui.GRoot.inst.inputProcessor.getAllTouches()[0];
  1572. sGlobalDragStart.set(fgui.GRoot.inst.getTouchPosition(touchId));
  1573. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  1574. GObject.draggingObject = this;
  1575. this._dragTesting = true;
  1576. fgui.GRoot.inst.inputProcessor.addTouchMonitor(touchId, this);
  1577. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1578. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1579. }
  1580. dragEnd() {
  1581. if (GObject.draggingObject == this) {
  1582. this._dragTesting = false;
  1583. GObject.draggingObject = null;
  1584. }
  1585. sDragQuery = false;
  1586. }
  1587. onTouchBegin_0(evt) {
  1588. if (this._dragStartPos == null)
  1589. this._dragStartPos = new cc.Vec2();
  1590. this._dragStartPos.set(evt.pos);
  1591. this._dragTesting = true;
  1592. evt.captureTouch();
  1593. }
  1594. onTouchMove_0(evt) {
  1595. if (GObject.draggingObject != this && this._draggable && this._dragTesting) {
  1596. var sensitivity = fgui.UIConfig.touchDragSensitivity;
  1597. if (this._dragStartPos && Math.abs(this._dragStartPos.x - evt.pos.x) < sensitivity && Math.abs(this._dragStartPos.y - evt.pos.y) < sensitivity)
  1598. return;
  1599. this._dragTesting = false;
  1600. sDragQuery = true;
  1601. this._node.emit(fgui.Event.DRAG_START, evt);
  1602. if (sDragQuery)
  1603. this.dragBegin(evt.touchId);
  1604. }
  1605. if (GObject.draggingObject == this) {
  1606. var xx = evt.pos.x - sGlobalDragStart.x + sGlobalRect.x;
  1607. var yy = evt.pos.y - sGlobalDragStart.y + sGlobalRect.y;
  1608. if (this._dragBounds) {
  1609. var rect = fgui.GRoot.inst.localToGlobalRect(this._dragBounds.x, this._dragBounds.y, this._dragBounds.width, this._dragBounds.height, sDragHelperRect);
  1610. if (xx < rect.x)
  1611. xx = rect.x;
  1612. else if (xx + sGlobalRect.width > rect.xMax) {
  1613. xx = rect.xMax - sGlobalRect.width;
  1614. if (xx < rect.x)
  1615. xx = rect.x;
  1616. }
  1617. if (yy < rect.y)
  1618. yy = rect.y;
  1619. else if (yy + sGlobalRect.height > rect.yMax) {
  1620. yy = rect.yMax - sGlobalRect.height;
  1621. if (yy < rect.y)
  1622. yy = rect.y;
  1623. }
  1624. }
  1625. sUpdateInDragging = true;
  1626. var pt = this.parent.globalToLocal(xx, yy, sHelperPoint);
  1627. this.setPosition(Math.round(pt.x), Math.round(pt.y));
  1628. sUpdateInDragging = false;
  1629. this._node.emit(fgui.Event.DRAG_MOVE, evt);
  1630. }
  1631. }
  1632. onTouchEnd_0(evt) {
  1633. if (GObject.draggingObject == this) {
  1634. GObject.draggingObject = null;
  1635. this._node.emit(fgui.Event.DRAG_END, evt);
  1636. }
  1637. }
  1638. }
  1639. GObject._defaultGroupIndex = -1;
  1640. fgui.GObject = GObject;
  1641. var sGlobalDragStart = new cc.Vec2();
  1642. var sGlobalRect = new cc.Rect();
  1643. var sHelperPoint = new cc.Vec2();
  1644. var sDragHelperRect = new cc.Rect();
  1645. var sUpdateInDragging;
  1646. var sDragQuery = false;
  1647. class GObjectPartner extends cc.Component {
  1648. constructor() {
  1649. super(...arguments);
  1650. this._emitDisplayEvents = false;
  1651. }
  1652. callLater(callback, delay) {
  1653. if (!cc.director.getScheduler().isScheduled(callback, this))
  1654. this.scheduleOnce(callback, delay);
  1655. }
  1656. onClickLink(evt, text) {
  1657. this.node.emit(fgui.Event.LINK, text, evt);
  1658. }
  1659. onEnable() {
  1660. this.node['$gobj'].onEnable();
  1661. if (this._emitDisplayEvents)
  1662. this.node.emit(fgui.Event.DISPLAY);
  1663. }
  1664. onDisable() {
  1665. this.node['$gobj'].onDisable();
  1666. if (this._emitDisplayEvents)
  1667. this.node.emit(fgui.Event.UNDISPLAY);
  1668. }
  1669. update(dt) {
  1670. this.node['$gobj'].onUpdate(dt);
  1671. }
  1672. onDestroy() {
  1673. this.node['$gobj'].onDestroy();
  1674. }
  1675. }
  1676. fgui.GObjectPartner = GObjectPartner;
  1677. })(fgui || (fgui = {}));
  1678. (function (fgui) {
  1679. class GComponent extends fgui.GObject {
  1680. constructor() {
  1681. super();
  1682. this._sortingChildCount = 0;
  1683. this._childrenRenderOrder = fgui.ChildrenRenderOrder.Ascent;
  1684. this._apexIndex = 0;
  1685. this._node.name = 'GComponent';
  1686. this._children = new Array();
  1687. this._controllers = new Array();
  1688. this._transitions = new Array();
  1689. this._margin = new fgui.Margin();
  1690. this._alignOffset = new cc.Vec2();
  1691. this._container = new cc.Node('Container');
  1692. this._container.setAnchorPoint(0, 1);
  1693. this._node.addChild(this._container);
  1694. }
  1695. dispose() {
  1696. this._partner.unschedule(this.refresh);
  1697. var i;
  1698. var cnt;
  1699. cnt = this._transitions.length;
  1700. for (i = 0; i < cnt; ++i) {
  1701. var trans = this._transitions[i];
  1702. trans.dispose();
  1703. }
  1704. cnt = this._controllers.length;
  1705. for (i = 0; i < cnt; ++i) {
  1706. var cc = this._controllers[i];
  1707. cc.dispose();
  1708. }
  1709. if (this._scrollPane)
  1710. this._scrollPane.destroy();
  1711. this.removeFromParent();
  1712. cnt = this._children.length;
  1713. for (i = cnt - 1; i >= 0; --i) {
  1714. var obj = this._children[i];
  1715. obj._parent = null;
  1716. obj.dispose();
  1717. }
  1718. this._boundsChanged = false;
  1719. super.dispose();
  1720. }
  1721. get displayListContainer() {
  1722. return this._container;
  1723. }
  1724. addChild(child) {
  1725. this.addChildAt(child, this._children.length);
  1726. return child;
  1727. }
  1728. addChildAt(child, index) {
  1729. if (!child)
  1730. throw 'child is null';
  1731. var numChildren = this._children.length;
  1732. if (index >= 0 && index <= numChildren) {
  1733. if (child.parent == this) {
  1734. this.setChildIndex(child, index);
  1735. }
  1736. else {
  1737. child.removeFromParent();
  1738. child._parent = this;
  1739. var cnt = this._children.length;
  1740. if (child.sortingOrder != 0) {
  1741. this._sortingChildCount++;
  1742. index = this.getInsertPosForSortingChild(child);
  1743. }
  1744. else if (this._sortingChildCount > 0) {
  1745. if (index > cnt - this._sortingChildCount)
  1746. index = cnt - this._sortingChildCount;
  1747. }
  1748. if (index == cnt)
  1749. this._children.push(child);
  1750. else
  1751. this._children.splice(index, 0, child);
  1752. this.onChildAdd(child, index);
  1753. this.setBoundsChangedFlag();
  1754. }
  1755. return child;
  1756. }
  1757. else {
  1758. throw 'Invalid child index';
  1759. }
  1760. }
  1761. getInsertPosForSortingChild(target) {
  1762. var cnt = this._children.length;
  1763. var i = 0;
  1764. for (i = 0; i < cnt; i++) {
  1765. var child = this._children[i];
  1766. if (child == target)
  1767. continue;
  1768. if (target.sortingOrder < child.sortingOrder)
  1769. break;
  1770. }
  1771. return i;
  1772. }
  1773. removeChild(child, dispose) {
  1774. var childIndex = this._children.indexOf(child);
  1775. if (childIndex != -1) {
  1776. this.removeChildAt(childIndex, dispose);
  1777. }
  1778. return child;
  1779. }
  1780. removeChildAt(index, dispose) {
  1781. if (index >= 0 && index < this.numChildren) {
  1782. var child = this._children[index];
  1783. child._parent = null;
  1784. if (child.sortingOrder != 0)
  1785. this._sortingChildCount--;
  1786. this._children.splice(index, 1);
  1787. child.group = null;
  1788. this._container.removeChild(child.node);
  1789. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  1790. this._partner.callLater(this.buildNativeDisplayList);
  1791. if (dispose)
  1792. child.dispose();
  1793. else
  1794. child.node.parent = null;
  1795. this.setBoundsChangedFlag();
  1796. return child;
  1797. }
  1798. else {
  1799. throw 'Invalid child index';
  1800. }
  1801. }
  1802. removeChildren(beginIndex, endIndex, dispose) {
  1803. if (beginIndex == undefined)
  1804. beginIndex = 0;
  1805. if (endIndex == undefined)
  1806. endIndex = -1;
  1807. if (endIndex < 0 || endIndex >= this.numChildren)
  1808. endIndex = this.numChildren - 1;
  1809. for (var i = beginIndex; i <= endIndex; ++i)
  1810. this.removeChildAt(beginIndex, dispose);
  1811. }
  1812. getChildAt(index) {
  1813. if (index >= 0 && index < this.numChildren)
  1814. return this._children[index];
  1815. else
  1816. throw 'Invalid child index';
  1817. }
  1818. getChild(name) {
  1819. var cnt = this._children.length;
  1820. for (var i = 0; i < cnt; ++i) {
  1821. if (this._children[i].name == name)
  1822. return this._children[i];
  1823. }
  1824. return null;
  1825. }
  1826. getChildByPath(path) {
  1827. if (!path) {
  1828. return null;
  1829. }
  1830. var arr = path.split('.');
  1831. var cnt = arr.length;
  1832. var gcom = this;
  1833. var obj;
  1834. for (var i = 0; i < cnt; ++i) {
  1835. obj = gcom.getChild(arr[i]);
  1836. if (!obj)
  1837. break;
  1838. if (i != cnt - 1) {
  1839. if (!(obj instanceof GComponent)) {
  1840. obj = null;
  1841. break;
  1842. }
  1843. else
  1844. gcom = obj;
  1845. }
  1846. }
  1847. return obj;
  1848. }
  1849. getVisibleChild(name) {
  1850. var cnt = this._children.length;
  1851. for (var i = 0; i < cnt; ++i) {
  1852. var child = this._children[i];
  1853. if (child._finalVisible && child.name == name)
  1854. return child;
  1855. }
  1856. return null;
  1857. }
  1858. getChildInGroup(name, group) {
  1859. var cnt = this._children.length;
  1860. for (var i = 0; i < cnt; ++i) {
  1861. var child = this._children[i];
  1862. if (child.group == group && child.name == name)
  1863. return child;
  1864. }
  1865. return null;
  1866. }
  1867. getChildById(id) {
  1868. var cnt = this._children.length;
  1869. for (var i = 0; i < cnt; ++i) {
  1870. if (this._children[i]._id == id)
  1871. return this._children[i];
  1872. }
  1873. return null;
  1874. }
  1875. getChildIndex(child) {
  1876. return this._children.indexOf(child);
  1877. }
  1878. setChildIndex(child, index) {
  1879. var oldIndex = this._children.indexOf(child);
  1880. if (oldIndex == -1)
  1881. throw 'Not a child of this container';
  1882. if (child.sortingOrder != 0)
  1883. return;
  1884. var cnt = this._children.length;
  1885. if (this._sortingChildCount > 0) {
  1886. if (index > cnt - this._sortingChildCount - 1)
  1887. index = cnt - this._sortingChildCount - 1;
  1888. }
  1889. this._setChildIndex(child, oldIndex, index);
  1890. }
  1891. setChildIndexBefore(child, index) {
  1892. var oldIndex = this._children.indexOf(child);
  1893. if (oldIndex == -1)
  1894. throw 'Not a child of this container';
  1895. if (child.sortingOrder != 0)
  1896. return oldIndex;
  1897. var cnt = this._children.length;
  1898. if (this._sortingChildCount > 0) {
  1899. if (index > cnt - this._sortingChildCount - 1)
  1900. index = cnt - this._sortingChildCount - 1;
  1901. }
  1902. if (oldIndex < index)
  1903. return this._setChildIndex(child, oldIndex, index - 1);
  1904. else
  1905. return this._setChildIndex(child, oldIndex, index);
  1906. }
  1907. _setChildIndex(child, oldIndex, index) {
  1908. var cnt = this._children.length;
  1909. if (index > cnt)
  1910. index = cnt;
  1911. if (oldIndex == index)
  1912. return oldIndex;
  1913. this._children.splice(oldIndex, 1);
  1914. this._children.splice(index, 0, child);
  1915. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  1916. child.node.setSiblingIndex(index);
  1917. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  1918. child.node.setSiblingIndex(cnt - index);
  1919. else
  1920. this._partner.callLater(this.buildNativeDisplayList);
  1921. this.setBoundsChangedFlag();
  1922. return index;
  1923. }
  1924. swapChildren(child1, child2) {
  1925. var index1 = this._children.indexOf(child1);
  1926. var index2 = this._children.indexOf(child2);
  1927. if (index1 == -1 || index2 == -1)
  1928. throw 'Not a child of this container';
  1929. this.swapChildrenAt(index1, index2);
  1930. }
  1931. swapChildrenAt(index1, index2) {
  1932. var child1 = this._children[index1];
  1933. var child2 = this._children[index2];
  1934. this.setChildIndex(child1, index2);
  1935. this.setChildIndex(child2, index1);
  1936. }
  1937. get numChildren() {
  1938. return this._children.length;
  1939. }
  1940. isAncestorOf(child) {
  1941. if (child == null)
  1942. return false;
  1943. var p = child.parent;
  1944. while (p) {
  1945. if (p == this)
  1946. return true;
  1947. p = p.parent;
  1948. }
  1949. return false;
  1950. }
  1951. addController(controller) {
  1952. this._controllers.push(controller);
  1953. controller.parent = this;
  1954. this.applyController(controller);
  1955. }
  1956. getControllerAt(index) {
  1957. return this._controllers[index];
  1958. }
  1959. getController(name) {
  1960. var cnt = this._controllers.length;
  1961. for (var i = 0; i < cnt; ++i) {
  1962. var c = this._controllers[i];
  1963. if (c.name == name)
  1964. return c;
  1965. }
  1966. return null;
  1967. }
  1968. removeController(c) {
  1969. var index = this._controllers.indexOf(c);
  1970. if (index == -1)
  1971. throw 'controller not exists';
  1972. c.parent = null;
  1973. this._controllers.splice(index, 1);
  1974. var length = this._children.length;
  1975. for (var i = 0; i < length; i++) {
  1976. var child = this._children[i];
  1977. child.handleControllerChanged(c);
  1978. }
  1979. }
  1980. get controllers() {
  1981. return this._controllers;
  1982. }
  1983. onChildAdd(child, index) {
  1984. child.node.parent = this._container;
  1985. child.node.active = child._finalVisible;
  1986. if (this._buildingDisplayList)
  1987. return;
  1988. let cnt = this._children.length;
  1989. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  1990. child.node.setSiblingIndex(index);
  1991. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  1992. child.node.setSiblingIndex(cnt - index);
  1993. else
  1994. this._partner.callLater(this.buildNativeDisplayList);
  1995. }
  1996. buildNativeDisplayList(dt) {
  1997. if (!isNaN(dt)) {
  1998. let _t = this.node['$gobj'];
  1999. _t.buildNativeDisplayList();
  2000. return;
  2001. }
  2002. let cnt = this._children.length;
  2003. if (cnt == 0)
  2004. return;
  2005. let child;
  2006. switch (this._childrenRenderOrder) {
  2007. case fgui.ChildrenRenderOrder.Ascent:
  2008. {
  2009. let j = 0;
  2010. for (let i = 0; i < cnt; i++) {
  2011. child = this._children[i];
  2012. child.node.setSiblingIndex(j++);
  2013. }
  2014. }
  2015. break;
  2016. case fgui.ChildrenRenderOrder.Descent:
  2017. {
  2018. let j = 0;
  2019. for (let i = cnt - 1; i >= 0; i--) {
  2020. child = this._children[i];
  2021. child.node.setSiblingIndex(j++);
  2022. }
  2023. }
  2024. break;
  2025. case fgui.ChildrenRenderOrder.Arch:
  2026. {
  2027. let j = 0;
  2028. for (let i = 0; i < this._apexIndex; i++) {
  2029. child = this._children[i];
  2030. child.node.setSiblingIndex(j++);
  2031. }
  2032. for (let i = cnt - 1; i >= this._apexIndex; i--) {
  2033. child = this._children[i];
  2034. child.node.setSiblingIndex(j++);
  2035. }
  2036. }
  2037. break;
  2038. }
  2039. }
  2040. applyController(c) {
  2041. this._applyingController = c;
  2042. var child;
  2043. var length = this._children.length;
  2044. for (var i = 0; i < length; i++) {
  2045. child = this._children[i];
  2046. child.handleControllerChanged(c);
  2047. }
  2048. this._applyingController = null;
  2049. c.runActions();
  2050. }
  2051. applyAllControllers() {
  2052. var cnt = this._controllers.length;
  2053. for (var i = 0; i < cnt; ++i) {
  2054. this.applyController(this._controllers[i]);
  2055. }
  2056. }
  2057. adjustRadioGroupDepth(obj, c) {
  2058. var cnt = this._children.length;
  2059. var i;
  2060. var child;
  2061. var myIndex = -1, maxIndex = -1;
  2062. for (i = 0; i < cnt; i++) {
  2063. child = this._children[i];
  2064. if (child == obj) {
  2065. myIndex = i;
  2066. }
  2067. else if (child instanceof fgui.GButton && child.relatedController == c) {
  2068. if (i > maxIndex)
  2069. maxIndex = i;
  2070. }
  2071. }
  2072. if (myIndex < maxIndex) {
  2073. if (this._applyingController)
  2074. this._children[maxIndex].handleControllerChanged(this._applyingController);
  2075. this.swapChildrenAt(myIndex, maxIndex);
  2076. }
  2077. }
  2078. getTransitionAt(index) {
  2079. return this._transitions[index];
  2080. }
  2081. getTransition(transName) {
  2082. var cnt = this._transitions.length;
  2083. for (var i = 0; i < cnt; ++i) {
  2084. var trans = this._transitions[i];
  2085. if (trans.name == transName)
  2086. return trans;
  2087. }
  2088. return null;
  2089. }
  2090. isChildInView(child) {
  2091. if (this._rectMask) {
  2092. return child.x + child.width >= 0 && child.x <= this.width && child.y + child.height >= 0 && child.y <= this.height;
  2093. }
  2094. else if (this._scrollPane) {
  2095. return this._scrollPane.isChildInView(child);
  2096. }
  2097. else
  2098. return true;
  2099. }
  2100. getFirstChildInView() {
  2101. var cnt = this._children.length;
  2102. for (var i = 0; i < cnt; ++i) {
  2103. var child = this._children[i];
  2104. if (this.isChildInView(child))
  2105. return i;
  2106. }
  2107. return -1;
  2108. }
  2109. getLastChildInView() {
  2110. let index = -1;
  2111. var cnt = this._children.length;
  2112. for (var i = 0; i < cnt; ++i) {
  2113. var child = this._children[i];
  2114. if (this.isChildInView(child))
  2115. index = i;
  2116. }
  2117. return index;
  2118. }
  2119. get scrollPane() {
  2120. return this._scrollPane;
  2121. }
  2122. get opaque() {
  2123. return this._opaque;
  2124. }
  2125. set opaque(value) {
  2126. this._opaque = value;
  2127. }
  2128. get margin() {
  2129. return this._margin;
  2130. }
  2131. set margin(value) {
  2132. this._margin.copy(value);
  2133. this.handleSizeChanged();
  2134. }
  2135. get childrenRenderOrder() {
  2136. return this._childrenRenderOrder;
  2137. }
  2138. set childrenRenderOrder(value) {
  2139. if (this._childrenRenderOrder != value) {
  2140. this._childrenRenderOrder = value;
  2141. this.buildNativeDisplayList();
  2142. }
  2143. }
  2144. get apexIndex() {
  2145. return this._apexIndex;
  2146. }
  2147. set apexIndex(value) {
  2148. if (this._apexIndex != value) {
  2149. this._apexIndex = value;
  2150. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2151. this.buildNativeDisplayList();
  2152. }
  2153. }
  2154. get mask() {
  2155. return this._maskContent;
  2156. }
  2157. set mask(value) {
  2158. this.setMask(value, false);
  2159. }
  2160. setMask(value, inverted) {
  2161. if (this._maskContent) {
  2162. this._maskContent.node.off(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2163. this._maskContent.node.off(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2164. this._maskContent.node.off(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2165. this._maskContent.node.off(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2166. this._maskContent.node.off(cc.Node.EventType.ROTATION_CHANGED, this.onMaskContentChanged, this);
  2167. this._maskContent.visible = true;
  2168. }
  2169. this._maskContent = value;
  2170. if (this._maskContent) {
  2171. if (!(value instanceof fgui.GImage) && !(value instanceof fgui.GGraph))
  2172. return;
  2173. if (!this._customMask) {
  2174. let maskNode = new cc.Node('Mask');
  2175. maskNode.parent = this._node;
  2176. if (this._scrollPane)
  2177. this._container.parent.parent = maskNode;
  2178. else
  2179. this._container.parent = maskNode;
  2180. this._customMask = maskNode.addComponent(cc.Mask);
  2181. }
  2182. value.visible = false;
  2183. value.node.on(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2184. value.node.on(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2185. value.node.on(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2186. value.node.on(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2187. value.node.on(cc.Node.EventType.ROTATION_CHANGED, this.onMaskContentChanged, this);
  2188. this._customMask.inverted = inverted;
  2189. if (this._node.activeInHierarchy)
  2190. this.onMaskReady();
  2191. else
  2192. this.on(fgui.Event.DISPLAY, this.onMaskReady, this);
  2193. this.onMaskContentChanged();
  2194. if (this._scrollPane)
  2195. this._scrollPane.adjustMaskContainer();
  2196. else
  2197. this._container.setPosition(0, 0);
  2198. }
  2199. else if (this._customMask) {
  2200. if (this._scrollPane)
  2201. this._container.parent.parent = this._node;
  2202. else
  2203. this._container.parent = this._node;
  2204. this._customMask.node.destroy();
  2205. this._customMask = null;
  2206. if (this._scrollPane)
  2207. this._scrollPane.adjustMaskContainer();
  2208. else
  2209. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2210. }
  2211. }
  2212. onMaskReady() {
  2213. this.off(fgui.Event.DISPLAY, this.onMaskReady, this);
  2214. if (this._maskContent instanceof fgui.GImage) {
  2215. this._customMask.type = cc.Mask.Type.IMAGE_STENCIL;
  2216. this._customMask.alphaThreshold = 0.0001;
  2217. this._customMask.spriteFrame = this._maskContent._content.spriteFrame;
  2218. }
  2219. else if (this._maskContent instanceof fgui.GGraph) {
  2220. if (this._maskContent.type == 2)
  2221. this._customMask.type = cc.Mask.Type.ELLIPSE;
  2222. else
  2223. this._customMask.type = cc.Mask.Type.RECT;
  2224. }
  2225. }
  2226. onMaskContentChanged() {
  2227. let maskNode = this._customMask.node;
  2228. let contentNode = this._maskContent.node;
  2229. let w = contentNode.width * contentNode.scaleX;
  2230. let h = contentNode.height * contentNode.scaleY;
  2231. maskNode.setContentSize(w, h);
  2232. let left = contentNode.x - contentNode.anchorX * w;
  2233. let top = contentNode.y - contentNode.anchorY * h;
  2234. maskNode.setAnchorPoint(-left / maskNode.width, -top / maskNode.height);
  2235. maskNode.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2236. }
  2237. get _pivotCorrectX() {
  2238. return -this.pivotX * this._width + this._margin.left;
  2239. }
  2240. get _pivotCorrectY() {
  2241. return this.pivotY * this._height - this._margin.top;
  2242. }
  2243. get baseUserData() {
  2244. var buffer = this.packageItem.rawData;
  2245. buffer.seek(0, 4);
  2246. return buffer.readS();
  2247. }
  2248. setupScroll(buffer) {
  2249. this._scrollPane = this._node.addComponent(fgui.ScrollPane);
  2250. this._scrollPane.setup(buffer);
  2251. }
  2252. setupOverflow(overflow) {
  2253. if (overflow == fgui.OverflowType.Hidden)
  2254. this._rectMask = this._container.addComponent(cc.Mask);
  2255. if (!this._margin.isNone)
  2256. this.handleSizeChanged();
  2257. }
  2258. handleAnchorChanged() {
  2259. super.handleAnchorChanged();
  2260. if (this._customMask)
  2261. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2262. else if (this._scrollPane)
  2263. this._scrollPane.adjustMaskContainer();
  2264. else
  2265. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  2266. }
  2267. handleSizeChanged() {
  2268. super.handleSizeChanged();
  2269. if (this._customMask)
  2270. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2271. else if (!this._scrollPane)
  2272. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2273. if (this._scrollPane)
  2274. this._scrollPane.onOwnerSizeChanged();
  2275. else
  2276. this._container.setContentSize(this.viewWidth, this.viewHeight);
  2277. }
  2278. handleGrayedChanged() {
  2279. var c = this.getController('grayed');
  2280. if (c) {
  2281. c.selectedIndex = this.grayed ? 1 : 0;
  2282. return;
  2283. }
  2284. var v = this.grayed;
  2285. var cnt = this._children.length;
  2286. for (var i = 0; i < cnt; ++i) {
  2287. this._children[i].grayed = v;
  2288. }
  2289. }
  2290. handleControllerChanged(c) {
  2291. super.handleControllerChanged(c);
  2292. if (this._scrollPane)
  2293. this._scrollPane.handleControllerChanged(c);
  2294. }
  2295. _hitTest(pt, globalPt) {
  2296. if (this._customMask) {
  2297. s_vec2.set(globalPt);
  2298. s_vec2.y = fgui.GRoot.inst.height - globalPt.y;
  2299. let b = this._customMask['_hitTest'](s_vec2) || false;
  2300. if (!b)
  2301. return null;
  2302. }
  2303. if (this.hitArea) {
  2304. if (!this.hitArea.hitTest(pt, globalPt))
  2305. return null;
  2306. }
  2307. else if (this._rectMask) {
  2308. s_vec2.set(pt);
  2309. s_vec2.x += this._container.x;
  2310. s_vec2.y += this._container.y;
  2311. let clippingSize = this._container.getContentSize();
  2312. if (s_vec2.x < 0 || s_vec2.y < 0 || s_vec2.x >= clippingSize.width || s_vec2.y >= clippingSize.height)
  2313. return null;
  2314. }
  2315. if (this._scrollPane) {
  2316. let target = this._scrollPane.hitTest(pt, globalPt);
  2317. if (!target)
  2318. return null;
  2319. if (target != this)
  2320. return target;
  2321. }
  2322. let target = null;
  2323. let cnt = this._children.length;
  2324. for (let i = cnt - 1; i >= 0; i--) {
  2325. let child = this._children[i];
  2326. if (this._maskContent == child || child._touchDisabled)
  2327. continue;
  2328. target = child.hitTest(globalPt);
  2329. if (target)
  2330. break;
  2331. }
  2332. if (!target && this._opaque && (this.hitArea || (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)))
  2333. target = this;
  2334. return target;
  2335. }
  2336. setBoundsChangedFlag() {
  2337. if (!this._scrollPane && !this._trackBounds)
  2338. return;
  2339. if (!this._boundsChanged) {
  2340. this._boundsChanged = true;
  2341. this._partner.callLater(this.refresh);
  2342. }
  2343. }
  2344. refresh(dt) {
  2345. if (!isNaN(dt)) {
  2346. let _t = this.node['$gobj'];
  2347. _t.refresh();
  2348. return;
  2349. }
  2350. if (this._boundsChanged) {
  2351. var len = this._children.length;
  2352. if (len > 0) {
  2353. for (var i = 0; i < len; i++) {
  2354. var child = this._children[i];
  2355. child.ensureSizeCorrect();
  2356. }
  2357. }
  2358. this.updateBounds();
  2359. }
  2360. }
  2361. ensureBoundsCorrect() {
  2362. var len = this._children.length;
  2363. if (len > 0) {
  2364. for (var i = 0; i < len; i++) {
  2365. var child = this._children[i];
  2366. child.ensureSizeCorrect();
  2367. }
  2368. }
  2369. if (this._boundsChanged)
  2370. this.updateBounds();
  2371. }
  2372. updateBounds() {
  2373. var ax = 0, ay = 0, aw = 0, ah = 0;
  2374. var len = this._children.length;
  2375. if (len > 0) {
  2376. ;
  2377. (ax = Number.POSITIVE_INFINITY), (ay = Number.POSITIVE_INFINITY);
  2378. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  2379. var tmp = 0;
  2380. var i = 0;
  2381. for (var i = 0; i < len; i++) {
  2382. var child = this._children[i];
  2383. tmp = child.x;
  2384. if (tmp < ax)
  2385. ax = tmp;
  2386. tmp = child.y;
  2387. if (tmp < ay)
  2388. ay = tmp;
  2389. tmp = child.x + child.actualWidth;
  2390. if (tmp > ar)
  2391. ar = tmp;
  2392. tmp = child.y + child.actualHeight;
  2393. if (tmp > ab)
  2394. ab = tmp;
  2395. }
  2396. aw = ar - ax;
  2397. ah = ab - ay;
  2398. }
  2399. this.setBounds(ax, ay, aw, ah);
  2400. }
  2401. setBounds(ax, ay, aw, ah = 0) {
  2402. this._boundsChanged = false;
  2403. if (this._scrollPane)
  2404. this._scrollPane.setContentSize(Math.round(ax + aw), Math.round(ay + ah));
  2405. }
  2406. get viewWidth() {
  2407. if (this._scrollPane)
  2408. return this._scrollPane.viewWidth;
  2409. else
  2410. return this.width - this._margin.left - this._margin.right;
  2411. }
  2412. set viewWidth(value) {
  2413. if (this._scrollPane)
  2414. this._scrollPane.viewWidth = value;
  2415. else
  2416. this.width = value + this._margin.left + this._margin.right;
  2417. }
  2418. get viewHeight() {
  2419. if (this._scrollPane)
  2420. return this._scrollPane.viewHeight;
  2421. else
  2422. return this.height - this._margin.top - this._margin.bottom;
  2423. }
  2424. set viewHeight(value) {
  2425. if (this._scrollPane)
  2426. this._scrollPane.viewHeight = value;
  2427. else
  2428. this.height = value + this._margin.top + this._margin.bottom;
  2429. }
  2430. getSnappingPosition(xValue, yValue, resultPoint) {
  2431. if (!resultPoint)
  2432. resultPoint = new cc.Vec2();
  2433. var cnt = this._children.length;
  2434. if (cnt == 0) {
  2435. resultPoint.x = 0;
  2436. resultPoint.y = 0;
  2437. return resultPoint;
  2438. }
  2439. this.ensureBoundsCorrect();
  2440. var obj = null;
  2441. var prev = null;
  2442. var i = 0;
  2443. if (yValue != 0) {
  2444. for (; i < cnt; i++) {
  2445. obj = this._children[i];
  2446. if (yValue < obj.y) {
  2447. if (i == 0) {
  2448. yValue = 0;
  2449. break;
  2450. }
  2451. else {
  2452. prev = this._children[i - 1];
  2453. if (yValue < prev.y + prev.actualHeight / 2)
  2454. yValue = prev.y;
  2455. else
  2456. yValue = obj.y;
  2457. break;
  2458. }
  2459. }
  2460. }
  2461. if (i == cnt)
  2462. yValue = obj.y;
  2463. }
  2464. if (xValue != 0) {
  2465. if (i > 0)
  2466. i--;
  2467. for (; i < cnt; i++) {
  2468. obj = this._children[i];
  2469. if (xValue < obj.x) {
  2470. if (i == 0) {
  2471. xValue = 0;
  2472. break;
  2473. }
  2474. else {
  2475. prev = this._children[i - 1];
  2476. if (xValue < prev.x + prev.actualWidth / 2)
  2477. xValue = prev.x;
  2478. else
  2479. xValue = obj.x;
  2480. break;
  2481. }
  2482. }
  2483. }
  2484. if (i == cnt)
  2485. xValue = obj.x;
  2486. }
  2487. resultPoint.x = xValue;
  2488. resultPoint.y = yValue;
  2489. return resultPoint;
  2490. }
  2491. childSortingOrderChanged(child, oldValue, newValue = 0) {
  2492. if (newValue == 0) {
  2493. this._sortingChildCount--;
  2494. this.setChildIndex(child, this._children.length);
  2495. }
  2496. else {
  2497. if (oldValue == 0)
  2498. this._sortingChildCount++;
  2499. var oldIndex = this._children.indexOf(child);
  2500. var index = this.getInsertPosForSortingChild(child);
  2501. if (oldIndex < index)
  2502. this._setChildIndex(child, oldIndex, index - 1);
  2503. else
  2504. this._setChildIndex(child, oldIndex, index);
  2505. }
  2506. }
  2507. constructFromResource() {
  2508. this.constructFromResource2(null, 0);
  2509. }
  2510. constructFromResource2(objectPool, poolIndex) {
  2511. var contentItem = this.packageItem.getBranch();
  2512. if (!contentItem.decoded) {
  2513. contentItem.decoded = true;
  2514. fgui.TranslationHelper.translateComponent(contentItem);
  2515. }
  2516. var i;
  2517. var dataLen;
  2518. var curPos;
  2519. var nextPos;
  2520. var f1;
  2521. var f2;
  2522. var i1;
  2523. var i2;
  2524. var buffer = contentItem.rawData;
  2525. buffer.seek(0, 0);
  2526. this._underConstruct = true;
  2527. this.sourceWidth = buffer.readInt();
  2528. this.sourceHeight = buffer.readInt();
  2529. this.initWidth = this.sourceWidth;
  2530. this.initHeight = this.sourceHeight;
  2531. this.setSize(this.sourceWidth, this.sourceHeight);
  2532. if (buffer.readBool()) {
  2533. this.minWidth = buffer.readInt();
  2534. this.maxWidth = buffer.readInt();
  2535. this.minHeight = buffer.readInt();
  2536. this.maxHeight = buffer.readInt();
  2537. }
  2538. if (buffer.readBool()) {
  2539. f1 = buffer.readFloat();
  2540. f2 = buffer.readFloat();
  2541. this.setPivot(f1, f2, buffer.readBool());
  2542. }
  2543. if (buffer.readBool()) {
  2544. this._margin.top = buffer.readInt();
  2545. this._margin.bottom = buffer.readInt();
  2546. this._margin.left = buffer.readInt();
  2547. this._margin.right = buffer.readInt();
  2548. }
  2549. var overflow = buffer.readByte();
  2550. if (overflow == fgui.OverflowType.Scroll) {
  2551. var savedPos = buffer.position;
  2552. buffer.seek(0, 7);
  2553. this.setupScroll(buffer);
  2554. buffer.position = savedPos;
  2555. }
  2556. else
  2557. this.setupOverflow(overflow);
  2558. if (buffer.readBool())
  2559. buffer.skip(8);
  2560. this._buildingDisplayList = true;
  2561. buffer.seek(0, 1);
  2562. var controllerCount = buffer.readShort();
  2563. for (i = 0; i < controllerCount; i++) {
  2564. nextPos = buffer.readShort();
  2565. nextPos += buffer.position;
  2566. var controller = new fgui.Controller();
  2567. this._controllers.push(controller);
  2568. controller.parent = this;
  2569. controller.setup(buffer);
  2570. buffer.position = nextPos;
  2571. }
  2572. buffer.seek(0, 2);
  2573. var child;
  2574. var childCount = buffer.readShort();
  2575. for (i = 0; i < childCount; i++) {
  2576. dataLen = buffer.readShort();
  2577. curPos = buffer.position;
  2578. if (objectPool)
  2579. child = objectPool[poolIndex + i];
  2580. else {
  2581. buffer.seek(curPos, 0);
  2582. var type = buffer.readByte();
  2583. var src = buffer.readS();
  2584. var pkgId = buffer.readS();
  2585. var pi = null;
  2586. if (src != null) {
  2587. var pkg;
  2588. if (pkgId != null)
  2589. pkg = fgui.UIPackage.getById(pkgId);
  2590. else
  2591. pkg = contentItem.owner;
  2592. pi = pkg ? pkg.getItemById(src) : null;
  2593. }
  2594. if (pi) {
  2595. child = fgui.UIObjectFactory.newObject(pi);
  2596. child.constructFromResource();
  2597. }
  2598. else
  2599. child = fgui.UIObjectFactory.newObject(type);
  2600. }
  2601. child._underConstruct = true;
  2602. child.setup_beforeAdd(buffer, curPos);
  2603. child._parent = this;
  2604. child.node.parent = this._container;
  2605. this._children.push(child);
  2606. buffer.position = curPos + dataLen;
  2607. }
  2608. buffer.seek(0, 3);
  2609. this.relations.setup(buffer, true);
  2610. buffer.seek(0, 2);
  2611. buffer.skip(2);
  2612. for (i = 0; i < childCount; i++) {
  2613. nextPos = buffer.readShort();
  2614. nextPos += buffer.position;
  2615. buffer.seek(buffer.position, 3);
  2616. this._children[i].relations.setup(buffer, false);
  2617. buffer.position = nextPos;
  2618. }
  2619. buffer.seek(0, 2);
  2620. buffer.skip(2);
  2621. for (i = 0; i < childCount; i++) {
  2622. nextPos = buffer.readShort();
  2623. nextPos += buffer.position;
  2624. child = this._children[i];
  2625. child.setup_afterAdd(buffer, buffer.position);
  2626. child._underConstruct = false;
  2627. buffer.position = nextPos;
  2628. }
  2629. buffer.seek(0, 4);
  2630. buffer.skip(2);
  2631. this.opaque = buffer.readBool();
  2632. var maskId = buffer.readShort();
  2633. if (maskId != -1) {
  2634. this.setMask(this.getChildAt(maskId), buffer.readBool());
  2635. }
  2636. var hitTestId = buffer.readS();
  2637. i1 = buffer.readInt();
  2638. i2 = buffer.readInt();
  2639. if (hitTestId != null) {
  2640. pi = contentItem.owner.getItemById(hitTestId);
  2641. if (pi && pi.hitTestData)
  2642. this.hitArea = new fgui.PixelHitTest(pi.hitTestData, i1, i2);
  2643. }
  2644. else if (i1 != 0 && i2 != -1) {
  2645. this.hitArea = new fgui.ChildHitArea(this.getChildAt(i2));
  2646. }
  2647. buffer.seek(0, 5);
  2648. var transitionCount = buffer.readShort();
  2649. for (i = 0; i < transitionCount; i++) {
  2650. nextPos = buffer.readShort();
  2651. nextPos += buffer.position;
  2652. var trans = new fgui.Transition(this);
  2653. trans.setup(buffer);
  2654. this._transitions.push(trans);
  2655. buffer.position = nextPos;
  2656. }
  2657. this.applyAllControllers();
  2658. this._buildingDisplayList = false;
  2659. this._underConstruct = false;
  2660. this.buildNativeDisplayList();
  2661. this.setBoundsChangedFlag();
  2662. if (contentItem.objectType != fgui.ObjectType.Component)
  2663. this.constructExtension(buffer);
  2664. this.onConstruct();
  2665. }
  2666. constructExtension(buffer) { }
  2667. onConstruct() { }
  2668. setup_afterAdd(buffer, beginPos) {
  2669. super.setup_afterAdd(buffer, beginPos);
  2670. buffer.seek(beginPos, 4);
  2671. var pageController = buffer.readShort();
  2672. if (pageController != -1 && this._scrollPane)
  2673. this._scrollPane.pageController = this._parent.getControllerAt(pageController);
  2674. var cnt = buffer.readShort();
  2675. for (var i = 0; i < cnt; i++) {
  2676. var cc = this.getController(buffer.readS());
  2677. var pageId = buffer.readS();
  2678. if (cc)
  2679. cc.selectedPageId = pageId;
  2680. }
  2681. if (buffer.version >= 2) {
  2682. cnt = buffer.readShort();
  2683. for (i = 0; i < cnt; i++) {
  2684. var target = buffer.readS();
  2685. var propertyId = buffer.readShort();
  2686. var value = buffer.readS();
  2687. var obj = this.getChildByPath(target);
  2688. if (obj)
  2689. obj.setProp(propertyId, value);
  2690. }
  2691. }
  2692. }
  2693. onEnable() {
  2694. let cnt = this._transitions.length;
  2695. for (let i = 0; i < cnt; ++i)
  2696. this._transitions[i].onEnable();
  2697. }
  2698. onDisable() {
  2699. let cnt = this._transitions.length;
  2700. for (let i = 0; i < cnt; ++i)
  2701. this._transitions[i].onDisable();
  2702. }
  2703. }
  2704. fgui.GComponent = GComponent;
  2705. var s_vec2 = new cc.Vec2();
  2706. })(fgui || (fgui = {}));
  2707. (function (fgui) {
  2708. class GButton extends fgui.GComponent {
  2709. constructor() {
  2710. super();
  2711. this._node.name = "GButton";
  2712. this._mode = fgui.ButtonMode.Common;
  2713. this._title = "";
  2714. this._icon = "";
  2715. this._sound = fgui.UIConfig.buttonSound;
  2716. this._soundVolumeScale = fgui.UIConfig.buttonSoundVolumeScale;
  2717. this._changeStateOnClick = true;
  2718. this._downEffect = 0;
  2719. this._downEffectValue = 0.8;
  2720. }
  2721. get icon() {
  2722. return this._icon;
  2723. }
  2724. set icon(value) {
  2725. this._icon = value;
  2726. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  2727. if (this._iconObject)
  2728. this._iconObject.icon = value;
  2729. this.updateGear(7);
  2730. }
  2731. get selectedIcon() {
  2732. return this._selectedIcon;
  2733. }
  2734. set selectedIcon(value) {
  2735. this._selectedIcon = value;
  2736. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  2737. if (this._iconObject)
  2738. this._iconObject.icon = value;
  2739. }
  2740. get title() {
  2741. return this._title;
  2742. }
  2743. set title(value) {
  2744. this._title = value;
  2745. if (this._titleObject)
  2746. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  2747. this.updateGear(6);
  2748. }
  2749. get text() {
  2750. return this.title;
  2751. }
  2752. set text(value) {
  2753. this.title = value;
  2754. }
  2755. get selectedTitle() {
  2756. return this._selectedTitle;
  2757. }
  2758. set selectedTitle(value) {
  2759. this._selectedTitle = value;
  2760. if (this._titleObject)
  2761. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  2762. }
  2763. get titleColor() {
  2764. var tf = this.getTextField();
  2765. if (tf)
  2766. return tf.color;
  2767. else
  2768. return cc.Color.BLACK;
  2769. }
  2770. set titleColor(value) {
  2771. var tf = this.getTextField();
  2772. if (tf)
  2773. tf.color = value;
  2774. }
  2775. get titleFontSize() {
  2776. var tf = this.getTextField();
  2777. if (tf)
  2778. return tf.fontSize;
  2779. else
  2780. return 0;
  2781. }
  2782. set titleFontSize(value) {
  2783. var tf = this.getTextField();
  2784. if (tf)
  2785. tf.fontSize = value;
  2786. }
  2787. get sound() {
  2788. return this._sound;
  2789. }
  2790. set sound(val) {
  2791. this._sound = val;
  2792. }
  2793. get soundVolumeScale() {
  2794. return this._soundVolumeScale;
  2795. }
  2796. set soundVolumeScale(value) {
  2797. this._soundVolumeScale = value;
  2798. }
  2799. set selected(val) {
  2800. if (this._mode == fgui.ButtonMode.Common)
  2801. return;
  2802. if (this._selected != val) {
  2803. this._selected = val;
  2804. this.setCurrentState();
  2805. if (this._selectedTitle && this._titleObject)
  2806. this._titleObject.text = this._selected ? this._selectedTitle : this._title;
  2807. if (this._selectedIcon) {
  2808. var str = this._selected ? this._selectedIcon : this._icon;
  2809. if (this._iconObject)
  2810. this._iconObject.icon = str;
  2811. }
  2812. if (this._relatedController
  2813. && this._parent
  2814. && !this._parent._buildingDisplayList) {
  2815. if (this._selected) {
  2816. this._relatedController.selectedPageId = this._relatedPageId;
  2817. if (this._relatedController.autoRadioGroupDepth)
  2818. this._parent.adjustRadioGroupDepth(this, this._relatedController);
  2819. }
  2820. else if (this._mode == fgui.ButtonMode.Check && this._relatedController.selectedPageId == this._relatedPageId)
  2821. this._relatedController.oppositePageId = this._relatedPageId;
  2822. }
  2823. }
  2824. }
  2825. get selected() {
  2826. return this._selected;
  2827. }
  2828. get mode() {
  2829. return this._mode;
  2830. }
  2831. set mode(value) {
  2832. if (this._mode != value) {
  2833. if (value == fgui.ButtonMode.Common)
  2834. this.selected = false;
  2835. this._mode = value;
  2836. }
  2837. }
  2838. get relatedController() {
  2839. return this._relatedController;
  2840. }
  2841. set relatedController(val) {
  2842. this._relatedController = val;
  2843. }
  2844. get relatedPageId() {
  2845. return this._relatedPageId;
  2846. }
  2847. set relatedPageId(val) {
  2848. this._relatedPageId = val;
  2849. }
  2850. get changeStateOnClick() {
  2851. return this._changeStateOnClick;
  2852. }
  2853. set changeStateOnClick(value) {
  2854. this._changeStateOnClick = value;
  2855. }
  2856. get linkedPopup() {
  2857. return this._linkedPopup;
  2858. }
  2859. set linkedPopup(value) {
  2860. this._linkedPopup = value;
  2861. }
  2862. getTextField() {
  2863. if (this._titleObject instanceof fgui.GTextField)
  2864. return this._titleObject;
  2865. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof GButton))
  2866. return this._titleObject.getTextField();
  2867. else
  2868. return null;
  2869. }
  2870. fireClick() {
  2871. fgui.GRoot.inst.inputProcessor.simulateClick(this);
  2872. }
  2873. setState(val) {
  2874. if (this._buttonController)
  2875. this._buttonController.selectedPage = val;
  2876. if (this._downEffect == 1) {
  2877. var cnt = this.numChildren;
  2878. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  2879. if (!this._downColor)
  2880. this._downColor = new cc.Color();
  2881. var r = this._downEffectValue * 255;
  2882. this._downColor.r = this._downColor.g = this._downColor.b = r;
  2883. for (var i = 0; i < cnt; i++) {
  2884. var obj = this.getChildAt(i);
  2885. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  2886. obj.color = this._downColor;
  2887. }
  2888. }
  2889. else {
  2890. for (var i = 0; i < cnt; i++) {
  2891. var obj = this.getChildAt(i);
  2892. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  2893. obj.color = cc.Color.WHITE;
  2894. }
  2895. }
  2896. }
  2897. else if (this._downEffect == 2) {
  2898. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  2899. if (!this._downScaled) {
  2900. this._downScaled = true;
  2901. this.setScale(this.scaleX * this._downEffectValue, this.scaleY * this._downEffectValue);
  2902. }
  2903. }
  2904. else {
  2905. if (this._downScaled) {
  2906. this._downScaled = false;
  2907. this.setScale(this.scaleX / this._downEffectValue, this.scaleY / this._downEffectValue);
  2908. }
  2909. }
  2910. }
  2911. }
  2912. setCurrentState() {
  2913. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  2914. if (this._selected)
  2915. this.setState(GButton.SELECTED_DISABLED);
  2916. else
  2917. this.setState(GButton.DISABLED);
  2918. }
  2919. else {
  2920. if (this._selected)
  2921. this.setState(this._over ? GButton.SELECTED_OVER : GButton.DOWN);
  2922. else
  2923. this.setState(this._over ? GButton.OVER : GButton.UP);
  2924. }
  2925. }
  2926. handleControllerChanged(c) {
  2927. super.handleControllerChanged(c);
  2928. if (this._relatedController == c)
  2929. this.selected = this._relatedPageId == c.selectedPageId;
  2930. }
  2931. handleGrayedChanged() {
  2932. if (this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  2933. if (this.grayed) {
  2934. if (this._selected && this._buttonController.hasPage(GButton.SELECTED_DISABLED))
  2935. this.setState(GButton.SELECTED_DISABLED);
  2936. else
  2937. this.setState(GButton.DISABLED);
  2938. }
  2939. else if (this._selected)
  2940. this.setState(GButton.DOWN);
  2941. else
  2942. this.setState(GButton.UP);
  2943. }
  2944. else
  2945. super.handleGrayedChanged();
  2946. }
  2947. getProp(index) {
  2948. switch (index) {
  2949. case fgui.ObjectPropID.Color:
  2950. return this.titleColor;
  2951. case fgui.ObjectPropID.OutlineColor:
  2952. {
  2953. var tf = this.getTextField();
  2954. if (tf)
  2955. return tf.strokeColor;
  2956. else
  2957. return 0;
  2958. }
  2959. case fgui.ObjectPropID.FontSize:
  2960. return this.titleFontSize;
  2961. case fgui.ObjectPropID.Selected:
  2962. return this.selected;
  2963. default:
  2964. return super.getProp(index);
  2965. }
  2966. }
  2967. setProp(index, value) {
  2968. switch (index) {
  2969. case fgui.ObjectPropID.Color:
  2970. this.titleColor = value;
  2971. break;
  2972. case fgui.ObjectPropID.OutlineColor:
  2973. {
  2974. var tf = this.getTextField();
  2975. if (tf)
  2976. tf.strokeColor = value;
  2977. }
  2978. break;
  2979. case fgui.ObjectPropID.FontSize:
  2980. this.titleFontSize = value;
  2981. break;
  2982. case fgui.ObjectPropID.Selected:
  2983. this.selected = value;
  2984. break;
  2985. default:
  2986. super.setProp(index, value);
  2987. break;
  2988. }
  2989. }
  2990. constructExtension(buffer) {
  2991. buffer.seek(0, 6);
  2992. this._mode = buffer.readByte();
  2993. var str = buffer.readS();
  2994. if (str)
  2995. this._sound = str;
  2996. this._soundVolumeScale = buffer.readFloat();
  2997. this._downEffect = buffer.readByte();
  2998. this._downEffectValue = buffer.readFloat();
  2999. if (this._downEffect == 2)
  3000. this.setPivot(0.5, 0.5, this.pivotAsAnchor);
  3001. this._buttonController = this.getController("button");
  3002. this._titleObject = this.getChild("title");
  3003. this._iconObject = this.getChild("icon");
  3004. if (this._titleObject)
  3005. this._title = this._titleObject.text;
  3006. if (this._iconObject)
  3007. this._icon = this._iconObject.icon;
  3008. if (this._mode == fgui.ButtonMode.Common)
  3009. this.setState(GButton.UP);
  3010. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3011. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3012. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3013. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3014. this._node.on(fgui.Event.CLICK, this.onClick_1, this);
  3015. }
  3016. setup_afterAdd(buffer, beginPos) {
  3017. super.setup_afterAdd(buffer, beginPos);
  3018. if (!buffer.seek(beginPos, 6))
  3019. return;
  3020. if (buffer.readByte() != this.packageItem.objectType)
  3021. return;
  3022. var str;
  3023. var iv;
  3024. str = buffer.readS();
  3025. if (str != null)
  3026. this.title = str;
  3027. str = buffer.readS();
  3028. if (str != null)
  3029. this.selectedTitle = str;
  3030. str = buffer.readS();
  3031. if (str != null)
  3032. this.icon = str;
  3033. str = buffer.readS();
  3034. if (str != null)
  3035. this.selectedIcon = str;
  3036. if (buffer.readBool())
  3037. this.titleColor = buffer.readColor();
  3038. iv = buffer.readInt();
  3039. if (iv != 0)
  3040. this.titleFontSize = iv;
  3041. iv = buffer.readShort();
  3042. if (iv >= 0)
  3043. this._relatedController = this.parent.getControllerAt(iv);
  3044. this._relatedPageId = buffer.readS();
  3045. str = buffer.readS();
  3046. if (str != null)
  3047. this._sound = str;
  3048. if (buffer.readBool())
  3049. this._soundVolumeScale = buffer.readFloat();
  3050. this.selected = buffer.readBool();
  3051. }
  3052. onRollOver_1() {
  3053. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3054. return;
  3055. this._over = true;
  3056. if (this._down)
  3057. return;
  3058. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3059. return;
  3060. this.setState(this._selected ? GButton.SELECTED_OVER : GButton.OVER);
  3061. }
  3062. onRollOut_1() {
  3063. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3064. return;
  3065. this._over = false;
  3066. if (this._down)
  3067. return;
  3068. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3069. return;
  3070. this.setState(this._selected ? GButton.DOWN : GButton.UP);
  3071. }
  3072. onTouchBegin_1(evt) {
  3073. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3074. return;
  3075. this._down = true;
  3076. evt.captureTouch();
  3077. if (this._mode == fgui.ButtonMode.Common) {
  3078. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3079. this.setState(GButton.SELECTED_DISABLED);
  3080. else
  3081. this.setState(GButton.DOWN);
  3082. }
  3083. if (this._linkedPopup) {
  3084. if (this._linkedPopup instanceof fgui.Window)
  3085. this._linkedPopup.toggleStatus();
  3086. else
  3087. this.root.togglePopup(this._linkedPopup, this);
  3088. }
  3089. }
  3090. onTouchEnd_1(evt) {
  3091. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3092. return;
  3093. if (this._down) {
  3094. this._down = false;
  3095. if (this._node == null)
  3096. return;
  3097. if (this._mode == fgui.ButtonMode.Common) {
  3098. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3099. this.setState(GButton.DISABLED);
  3100. else if (this._over)
  3101. this.setState(GButton.OVER);
  3102. else
  3103. this.setState(GButton.UP);
  3104. }
  3105. else {
  3106. if (!this._over
  3107. && this._buttonController != null
  3108. && (this._buttonController.selectedPage == GButton.OVER
  3109. || this._buttonController.selectedPage == GButton.SELECTED_OVER)) {
  3110. this.setCurrentState();
  3111. }
  3112. }
  3113. }
  3114. }
  3115. onClick_1() {
  3116. if (this._sound) {
  3117. var pi = fgui.UIPackage.getItemByURL(this._sound);
  3118. if (pi) {
  3119. var sound = pi.owner.getItemAsset(pi);
  3120. if (sound)
  3121. fgui.GRoot.inst.playOneShotSound(sound, this._soundVolumeScale);
  3122. }
  3123. }
  3124. if (this._mode == fgui.ButtonMode.Check) {
  3125. if (this._changeStateOnClick) {
  3126. this.selected = !this._selected;
  3127. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3128. }
  3129. }
  3130. else if (this._mode == fgui.ButtonMode.Radio) {
  3131. if (this._changeStateOnClick && !this._selected) {
  3132. this.selected = true;
  3133. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3134. }
  3135. }
  3136. else {
  3137. if (this._relatedController)
  3138. this._relatedController.selectedPageId = this._relatedPageId;
  3139. }
  3140. }
  3141. }
  3142. GButton.UP = "up";
  3143. GButton.DOWN = "down";
  3144. GButton.OVER = "over";
  3145. GButton.SELECTED_OVER = "selectedOver";
  3146. GButton.DISABLED = "disabled";
  3147. GButton.SELECTED_DISABLED = "selectedDisabled";
  3148. fgui.GButton = GButton;
  3149. })(fgui || (fgui = {}));
  3150. (function (fgui) {
  3151. class GComboBox extends fgui.GComponent {
  3152. constructor() {
  3153. super();
  3154. this._visibleItemCount = 0;
  3155. this._selectedIndex = 0;
  3156. this._popupDirection = fgui.PopupDirection.Auto;
  3157. this._node.name = "GComboBox";
  3158. this._visibleItemCount = fgui.UIConfig.defaultComboBoxVisibleItemCount;
  3159. this._itemsUpdated = true;
  3160. this._selectedIndex = -1;
  3161. this._items = [];
  3162. this._values = [];
  3163. }
  3164. get text() {
  3165. if (this._titleObject)
  3166. return this._titleObject.text;
  3167. else
  3168. return null;
  3169. }
  3170. set text(value) {
  3171. if (this._titleObject)
  3172. this._titleObject.text = value;
  3173. this.updateGear(6);
  3174. }
  3175. get icon() {
  3176. if (this._iconObject)
  3177. return this._iconObject.icon;
  3178. else
  3179. return null;
  3180. }
  3181. set icon(value) {
  3182. if (this._iconObject)
  3183. this._iconObject.icon = value;
  3184. this.updateGear(7);
  3185. }
  3186. get titleColor() {
  3187. var tf = this.getTextField();
  3188. if (tf)
  3189. return tf.color;
  3190. else
  3191. return cc.Color.BLACK;
  3192. }
  3193. set titleColor(value) {
  3194. var tf = this.getTextField();
  3195. if (tf)
  3196. tf.color = value;
  3197. }
  3198. get titleFontSize() {
  3199. var tf = this.getTextField();
  3200. if (tf)
  3201. return tf.fontSize;
  3202. else
  3203. return 0;
  3204. }
  3205. set titleFontSize(value) {
  3206. var tf = this.getTextField();
  3207. if (tf)
  3208. tf.fontSize = value;
  3209. }
  3210. get visibleItemCount() {
  3211. return this._visibleItemCount;
  3212. }
  3213. set visibleItemCount(value) {
  3214. this._visibleItemCount = value;
  3215. }
  3216. get popupDirection() {
  3217. return this._popupDirection;
  3218. }
  3219. set popupDirection(value) {
  3220. this._popupDirection = value;
  3221. }
  3222. get items() {
  3223. return this._items;
  3224. }
  3225. set items(value) {
  3226. if (!value)
  3227. this._items.length = 0;
  3228. else
  3229. this._items = value.concat();
  3230. if (this._items.length > 0) {
  3231. if (this._selectedIndex >= this._items.length)
  3232. this._selectedIndex = this._items.length - 1;
  3233. else if (this._selectedIndex == -1)
  3234. this._selectedIndex = 0;
  3235. this.text = this._items[this._selectedIndex];
  3236. if (this._icons && this._selectedIndex < this._icons.length)
  3237. this.icon = this._icons[this._selectedIndex];
  3238. }
  3239. else {
  3240. this.text = "";
  3241. if (this._icons)
  3242. this.icon = null;
  3243. this._selectedIndex = -1;
  3244. }
  3245. this._itemsUpdated = true;
  3246. }
  3247. get icons() {
  3248. return this._icons;
  3249. }
  3250. set icons(value) {
  3251. this._icons = value;
  3252. if (this._icons && this._selectedIndex != -1 && this._selectedIndex < this._icons.length)
  3253. this.icon = this._icons[this._selectedIndex];
  3254. }
  3255. get values() {
  3256. return this._values;
  3257. }
  3258. set values(value) {
  3259. if (!value)
  3260. this._values.length = 0;
  3261. else
  3262. this._values = value.concat();
  3263. }
  3264. get selectedIndex() {
  3265. return this._selectedIndex;
  3266. }
  3267. set selectedIndex(val) {
  3268. if (this._selectedIndex == val)
  3269. return;
  3270. this._selectedIndex = val;
  3271. if (this._selectedIndex >= 0 && this._selectedIndex < this._items.length) {
  3272. this.text = this._items[this._selectedIndex];
  3273. if (this._icons && this._selectedIndex < this._icons.length)
  3274. this.icon = this._icons[this._selectedIndex];
  3275. }
  3276. else {
  3277. this.text = "";
  3278. if (this._icons)
  3279. this.icon = null;
  3280. }
  3281. this.updateSelectionController();
  3282. }
  3283. get value() {
  3284. return this._values[this._selectedIndex];
  3285. }
  3286. set value(val) {
  3287. var index = this._values.indexOf(val);
  3288. if (index == -1 && val == null)
  3289. index = this._values.indexOf("");
  3290. this.selectedIndex = index;
  3291. }
  3292. get selectionController() {
  3293. return this._selectionController;
  3294. }
  3295. set selectionController(value) {
  3296. this._selectionController = value;
  3297. }
  3298. getTextField() {
  3299. if (this._titleObject instanceof fgui.GTextField)
  3300. return this._titleObject;
  3301. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof fgui.GButton))
  3302. return this._titleObject.getTextField();
  3303. else
  3304. return null;
  3305. }
  3306. setState(val) {
  3307. if (this._buttonController)
  3308. this._buttonController.selectedPage = val;
  3309. }
  3310. getProp(index) {
  3311. switch (index) {
  3312. case fgui.ObjectPropID.Color:
  3313. return this.titleColor;
  3314. case fgui.ObjectPropID.OutlineColor:
  3315. {
  3316. var tf = this.getTextField();
  3317. if (tf)
  3318. return tf.strokeColor;
  3319. else
  3320. return 0;
  3321. }
  3322. case fgui.ObjectPropID.FontSize:
  3323. {
  3324. tf = this.getTextField();
  3325. if (tf)
  3326. return tf.fontSize;
  3327. else
  3328. return 0;
  3329. }
  3330. default:
  3331. return super.getProp(index);
  3332. }
  3333. }
  3334. setProp(index, value) {
  3335. switch (index) {
  3336. case fgui.ObjectPropID.Color:
  3337. this.titleColor = value;
  3338. break;
  3339. case fgui.ObjectPropID.OutlineColor:
  3340. {
  3341. var tf = this.getTextField();
  3342. if (tf)
  3343. tf.strokeColor = value;
  3344. }
  3345. break;
  3346. case fgui.ObjectPropID.FontSize:
  3347. {
  3348. tf = this.getTextField();
  3349. if (tf)
  3350. tf.fontSize = value;
  3351. }
  3352. break;
  3353. default:
  3354. super.setProp(index, value);
  3355. break;
  3356. }
  3357. }
  3358. constructExtension(buffer) {
  3359. var str;
  3360. this._buttonController = this.getController("button");
  3361. this._titleObject = this.getChild("title");
  3362. this._iconObject = this.getChild("icon");
  3363. str = buffer.readS();
  3364. if (str) {
  3365. let obj = fgui.UIPackage.createObjectFromURL(str);
  3366. if (!(obj instanceof fgui.GComponent)) {
  3367. console.warn("下拉框必须为元件");
  3368. return;
  3369. }
  3370. this.dropdown = obj;
  3371. this.dropdown.name = "this.dropdown";
  3372. this._list = this.dropdown.getChild("list");
  3373. if (this._list == null) {
  3374. console.warn(this.resourceURL + ": 下拉框的弹出元件里必须包含名为list的列表");
  3375. return;
  3376. }
  3377. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  3378. this._list.addRelation(this.dropdown, fgui.RelationType.Width);
  3379. this._list.removeRelation(this.dropdown, fgui.RelationType.Height);
  3380. this.dropdown.addRelation(this._list, fgui.RelationType.Height);
  3381. this.dropdown.removeRelation(this._list, fgui.RelationType.Width);
  3382. this.dropdown.on(fgui.Event.UNDISPLAY, this.onPopupClosed, this);
  3383. }
  3384. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3385. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3386. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3387. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3388. }
  3389. handleControllerChanged(c) {
  3390. super.handleControllerChanged(c);
  3391. if (this._selectionController == c)
  3392. this.selectedIndex = c.selectedIndex;
  3393. }
  3394. updateSelectionController() {
  3395. if (this._selectionController && !this._selectionController.changing
  3396. && this._selectedIndex < this._selectionController.pageCount) {
  3397. var c = this._selectionController;
  3398. this._selectionController = null;
  3399. c.selectedIndex = this._selectedIndex;
  3400. this._selectionController = c;
  3401. }
  3402. }
  3403. dispose() {
  3404. if (this.dropdown) {
  3405. this.dropdown.dispose();
  3406. this.dropdown = null;
  3407. }
  3408. super.dispose();
  3409. }
  3410. setup_afterAdd(buffer, beginPos) {
  3411. super.setup_afterAdd(buffer, beginPos);
  3412. if (!buffer.seek(beginPos, 6))
  3413. return;
  3414. if (buffer.readByte() != this.packageItem.objectType)
  3415. return;
  3416. var i;
  3417. var iv;
  3418. var nextPos;
  3419. var str;
  3420. var itemCount = buffer.readShort();
  3421. for (i = 0; i < itemCount; i++) {
  3422. nextPos = buffer.readShort();
  3423. nextPos += buffer.position;
  3424. this._items[i] = buffer.readS();
  3425. this._values[i] = buffer.readS();
  3426. str = buffer.readS();
  3427. if (str != null) {
  3428. if (this._icons == null)
  3429. this._icons = new Array();
  3430. this._icons[i] = str;
  3431. }
  3432. buffer.position = nextPos;
  3433. }
  3434. str = buffer.readS();
  3435. if (str != null) {
  3436. this.text = str;
  3437. this._selectedIndex = this._items.indexOf(str);
  3438. }
  3439. else if (this._items.length > 0) {
  3440. this._selectedIndex = 0;
  3441. this.text = this._items[0];
  3442. }
  3443. else
  3444. this._selectedIndex = -1;
  3445. str = buffer.readS();
  3446. if (str != null)
  3447. this.icon = str;
  3448. if (buffer.readBool())
  3449. this.titleColor = buffer.readColor();
  3450. iv = buffer.readInt();
  3451. if (iv > 0)
  3452. this._visibleItemCount = iv;
  3453. this._popupDirection = buffer.readByte();
  3454. iv = buffer.readShort();
  3455. if (iv >= 0)
  3456. this._selectionController = this.parent.getControllerAt(iv);
  3457. }
  3458. showDropdown() {
  3459. if (this._itemsUpdated) {
  3460. this._itemsUpdated = false;
  3461. this._list.removeChildrenToPool();
  3462. var cnt = this._items.length;
  3463. for (var i = 0; i < cnt; i++) {
  3464. var item = this._list.addItemFromPool();
  3465. item.name = i < this._values.length ? this._values[i] : "";
  3466. item.text = this._items[i];
  3467. item.icon = (this._icons && i < this._icons.length) ? this._icons[i] : null;
  3468. }
  3469. this._list.resizeToFit(this._visibleItemCount);
  3470. }
  3471. this._list.selectedIndex = -1;
  3472. this.dropdown.width = this.width;
  3473. this._list.ensureBoundsCorrect();
  3474. this.root.togglePopup(this.dropdown, this, this._popupDirection);
  3475. if (this.dropdown.parent)
  3476. this.setState(fgui.GButton.DOWN);
  3477. }
  3478. onPopupClosed() {
  3479. if (this._over)
  3480. this.setState(fgui.GButton.OVER);
  3481. else
  3482. this.setState(fgui.GButton.UP);
  3483. }
  3484. onClickItem(itemObject) {
  3485. let _t = this;
  3486. let index = this._list.getChildIndex(itemObject);
  3487. this._partner.callLater(function (dt) {
  3488. _t.onClickItem2(index);
  3489. }, 0.1);
  3490. }
  3491. onClickItem2(index) {
  3492. if (this.dropdown.parent instanceof fgui.GRoot)
  3493. this.dropdown.parent.hidePopup();
  3494. this._selectedIndex = -1;
  3495. this.selectedIndex = index;
  3496. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3497. }
  3498. onRollOver_1() {
  3499. this._over = true;
  3500. if (this._down || this.dropdown && this.dropdown.parent)
  3501. return;
  3502. this.setState(fgui.GButton.OVER);
  3503. }
  3504. onRollOut_1() {
  3505. this._over = false;
  3506. if (this._down || this.dropdown && this.dropdown.parent)
  3507. return;
  3508. this.setState(fgui.GButton.UP);
  3509. }
  3510. onTouchBegin_1(evt) {
  3511. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3512. return;
  3513. if ((evt.initiator instanceof fgui.GTextInput) && evt.initiator.editable)
  3514. return;
  3515. this._down = true;
  3516. evt.captureTouch();
  3517. if (this.dropdown)
  3518. this.showDropdown();
  3519. }
  3520. onTouchEnd_1(evt) {
  3521. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3522. return;
  3523. if (this._down) {
  3524. this._down = false;
  3525. if (this.dropdown && !this.dropdown.parent) {
  3526. if (this._over)
  3527. this.setState(fgui.GButton.OVER);
  3528. else
  3529. this.setState(fgui.GButton.UP);
  3530. }
  3531. }
  3532. }
  3533. }
  3534. fgui.GComboBox = GComboBox;
  3535. })(fgui || (fgui = {}));
  3536. (function (fgui) {
  3537. class GGraph extends fgui.GObject {
  3538. constructor() {
  3539. super();
  3540. this._type = 0;
  3541. this._lineSize = 0;
  3542. this._node.name = "GGraph";
  3543. this._lineSize = 1;
  3544. this._lineColor = new cc.Color();
  3545. this._fillColor = new cc.Color(255, 255, 255, 255);
  3546. this._content = this._node.addComponent(cc.Graphics);
  3547. }
  3548. drawRect(lineSize, lineColor, fillColor, corner) {
  3549. this._type = 1;
  3550. this._lineSize = lineSize;
  3551. this._lineColor.set(lineColor);
  3552. this._fillColor.set(fillColor);
  3553. this._cornerRadius = corner;
  3554. this.updateGraph();
  3555. }
  3556. drawEllipse(lineSize, lineColor, fillColor) {
  3557. this._type = 2;
  3558. this._lineSize = lineSize;
  3559. this._lineColor.set(lineColor);
  3560. this._fillColor.set(fillColor);
  3561. this.updateGraph();
  3562. }
  3563. drawRegularPolygon(lineSize, lineColor, fillColor, sides, startAngle, distances) {
  3564. this._type = 4;
  3565. this._lineSize = lineSize;
  3566. this._lineColor.set(lineColor);
  3567. this._fillColor.set(fillColor);
  3568. this._sides = sides;
  3569. this._startAngle = startAngle || 0;
  3570. this._distances = distances;
  3571. this.updateGraph();
  3572. }
  3573. drawPolygon(lineSize, lineColor, fillColor, points) {
  3574. this._type = 3;
  3575. this._lineSize = lineSize;
  3576. this._lineColor.set(lineColor);
  3577. this._fillColor.set(fillColor);
  3578. this._polygonPoints = points;
  3579. this.updateGraph();
  3580. }
  3581. get distances() {
  3582. return this._distances;
  3583. }
  3584. set distances(value) {
  3585. this._distances = value;
  3586. if (this._type == 3)
  3587. this.updateGraph();
  3588. }
  3589. clearGraphics() {
  3590. this._type = 0;
  3591. if (this._hasContent) {
  3592. this._content.clear();
  3593. this._hasContent = false;
  3594. }
  3595. }
  3596. get type() {
  3597. return this._type;
  3598. }
  3599. get color() {
  3600. return this._fillColor;
  3601. }
  3602. set color(value) {
  3603. this._fillColor.set(value);
  3604. if (this._type != 0)
  3605. this.updateGraph();
  3606. }
  3607. updateGraph() {
  3608. let ctx = this._content;
  3609. if (this._hasContent) {
  3610. this._hasContent = false;
  3611. ctx.clear();
  3612. }
  3613. var w = this._width;
  3614. var h = this._height;
  3615. if (w == 0 || h == 0)
  3616. return;
  3617. var px = -this.pivotX * this._width;
  3618. var py = this.pivotY * this._height;
  3619. let ls = this._lineSize / 2;
  3620. ctx.lineWidth = this._lineSize;
  3621. ctx.strokeColor = this._lineColor;
  3622. ctx.fillColor = this._fillColor;
  3623. if (this._type == 1) {
  3624. if (this._cornerRadius) {
  3625. ctx.roundRect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize, this._cornerRadius[0]);
  3626. }
  3627. else
  3628. ctx.rect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize);
  3629. }
  3630. else if (this._type == 2) {
  3631. ctx.ellipse(w / 2 + px, -h / 2 + py, w / 2 - ls, h / 2 - ls);
  3632. }
  3633. else if (this._type == 3) {
  3634. this.drawPath(ctx, this._polygonPoints, px, py);
  3635. }
  3636. else if (this._type == 4) {
  3637. if (!this._polygonPoints)
  3638. this._polygonPoints = [];
  3639. var radius = Math.min(w, h) / 2 - ls;
  3640. this._polygonPoints.length = 0;
  3641. var angle = cc.misc.degreesToRadians(this._startAngle);
  3642. var deltaAngle = 2 * Math.PI / this._sides;
  3643. var dist;
  3644. for (var i = 0; i < this._sides; i++) {
  3645. if (this._distances) {
  3646. dist = this._distances[i];
  3647. if (isNaN(dist))
  3648. dist = 1;
  3649. }
  3650. else
  3651. dist = 1;
  3652. var xv = radius + radius * dist * Math.cos(angle);
  3653. var yv = radius + radius * dist * Math.sin(angle);
  3654. this._polygonPoints.push(xv, yv);
  3655. angle += deltaAngle;
  3656. }
  3657. this.drawPath(ctx, this._polygonPoints, px, py);
  3658. }
  3659. if (ls != 0)
  3660. ctx.stroke();
  3661. if (this._fillColor.a != 0)
  3662. ctx.fill();
  3663. this._hasContent = true;
  3664. }
  3665. drawPath(ctx, points, px, py) {
  3666. var cnt = points.length;
  3667. ctx.moveTo(points[0] + px, -points[1] + py);
  3668. for (var i = 2; i < cnt; i += 2)
  3669. ctx.lineTo(points[i] + px, -points[i + 1] + py);
  3670. ctx.lineTo(points[0] + px, -points[1] + py);
  3671. }
  3672. handleSizeChanged() {
  3673. super.handleSizeChanged();
  3674. if (this._type != 0)
  3675. this.updateGraph();
  3676. }
  3677. handleAnchorChanged() {
  3678. super.handleAnchorChanged();
  3679. if (this._type != 0)
  3680. this.updateGraph();
  3681. }
  3682. getProp(index) {
  3683. if (index == fgui.ObjectPropID.Color)
  3684. return this.color;
  3685. else
  3686. return super.getProp(index);
  3687. }
  3688. setProp(index, value) {
  3689. if (index == fgui.ObjectPropID.Color)
  3690. this.color = value;
  3691. else
  3692. super.setProp(index, value);
  3693. }
  3694. _hitTest(pt) {
  3695. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height) {
  3696. if (this._type == 3) {
  3697. let points = this._polygonPoints;
  3698. let len = points.length / 2;
  3699. let i;
  3700. let j = len - 1;
  3701. let oddNodes = false;
  3702. let w = this._width;
  3703. let h = this._height;
  3704. for (i = 0; i < len; ++i) {
  3705. let ix = points[i * 2];
  3706. let iy = points[i * 2 + 1];
  3707. let jx = points[j * 2];
  3708. let jy = points[j * 2 + 1];
  3709. if ((iy < pt.y && jy >= pt.y || jy < pt.y && iy >= pt.y) && (ix <= pt.x || jx <= pt.x)) {
  3710. if (ix + (pt.y - iy) / (jy - iy) * (jx - ix) < pt.x)
  3711. oddNodes = !oddNodes;
  3712. }
  3713. j = i;
  3714. }
  3715. return oddNodes ? this : null;
  3716. }
  3717. else
  3718. return this;
  3719. }
  3720. else
  3721. return null;
  3722. }
  3723. setup_beforeAdd(buffer, beginPos) {
  3724. super.setup_beforeAdd(buffer, beginPos);
  3725. buffer.seek(beginPos, 5);
  3726. this._type = buffer.readByte();
  3727. if (this._type != 0) {
  3728. var i;
  3729. var cnt;
  3730. this._lineSize = buffer.readInt();
  3731. this._lineColor.set(buffer.readColor(true));
  3732. this._fillColor.set(buffer.readColor(true));
  3733. if (buffer.readBool()) {
  3734. this._cornerRadius = new Array(4);
  3735. for (i = 0; i < 4; i++)
  3736. this._cornerRadius[i] = buffer.readFloat();
  3737. }
  3738. if (this._type == 3) {
  3739. cnt = buffer.readShort();
  3740. this._polygonPoints = [];
  3741. this._polygonPoints.length = cnt;
  3742. for (i = 0; i < cnt; i++)
  3743. this._polygonPoints[i] = buffer.readFloat();
  3744. }
  3745. else if (this._type == 4) {
  3746. this._sides = buffer.readShort();
  3747. this._startAngle = buffer.readFloat();
  3748. cnt = buffer.readShort();
  3749. if (cnt > 0) {
  3750. this._distances = [];
  3751. for (i = 0; i < cnt; i++)
  3752. this._distances[i] = buffer.readFloat();
  3753. }
  3754. }
  3755. this.updateGraph();
  3756. }
  3757. }
  3758. }
  3759. fgui.GGraph = GGraph;
  3760. })(fgui || (fgui = {}));
  3761. (function (fgui) {
  3762. class GGroup extends fgui.GObject {
  3763. constructor() {
  3764. super();
  3765. this._layout = 0;
  3766. this._lineGap = 0;
  3767. this._columnGap = 0;
  3768. this._mainGridIndex = -1;
  3769. this._mainGridMinSize = 50;
  3770. this._mainChildIndex = -1;
  3771. this._totalSize = 0;
  3772. this._numChildren = 0;
  3773. this._updating = 0;
  3774. this._node.name = "GGroup";
  3775. this._touchDisabled = true;
  3776. }
  3777. dispose() {
  3778. this._boundsChanged = false;
  3779. super.dispose();
  3780. }
  3781. get layout() {
  3782. return this._layout;
  3783. }
  3784. set layout(value) {
  3785. if (this._layout != value) {
  3786. this._layout = value;
  3787. this.setBoundsChangedFlag();
  3788. }
  3789. }
  3790. get lineGap() {
  3791. return this._lineGap;
  3792. }
  3793. set lineGap(value) {
  3794. if (this._lineGap != value) {
  3795. this._lineGap = value;
  3796. this.setBoundsChangedFlag(true);
  3797. }
  3798. }
  3799. get columnGap() {
  3800. return this._columnGap;
  3801. }
  3802. set columnGap(value) {
  3803. if (this._columnGap != value) {
  3804. this._columnGap = value;
  3805. this.setBoundsChangedFlag(true);
  3806. }
  3807. }
  3808. get excludeInvisibles() {
  3809. return this._excludeInvisibles;
  3810. }
  3811. set excludeInvisibles(value) {
  3812. if (this._excludeInvisibles != value) {
  3813. this._excludeInvisibles = value;
  3814. this.setBoundsChangedFlag();
  3815. }
  3816. }
  3817. get autoSizeDisabled() {
  3818. return this._autoSizeDisabled;
  3819. }
  3820. set autoSizeDisabled(value) {
  3821. this._autoSizeDisabled = value;
  3822. }
  3823. get mainGridMinSize() {
  3824. return this._mainGridMinSize;
  3825. }
  3826. set mainGridMinSize(value) {
  3827. if (this._mainGridMinSize != value) {
  3828. this._mainGridMinSize = value;
  3829. this.setBoundsChangedFlag();
  3830. }
  3831. }
  3832. get mainGridIndex() {
  3833. return this._mainGridIndex;
  3834. }
  3835. set mainGridIndex(value) {
  3836. if (this._mainGridIndex != value) {
  3837. this._mainGridIndex = value;
  3838. this.setBoundsChangedFlag();
  3839. }
  3840. }
  3841. setBoundsChangedFlag(positionChangedOnly = false) {
  3842. if (this._updating == 0 && this._parent) {
  3843. if (!positionChangedOnly)
  3844. this._percentReady = false;
  3845. if (!this._boundsChanged) {
  3846. this._boundsChanged = true;
  3847. if (this._layout != fgui.GroupLayoutType.None)
  3848. this._partner.callLater(this._ensureBoundsCorrect);
  3849. }
  3850. }
  3851. }
  3852. _ensureBoundsCorrect() {
  3853. let _t = (this.node["$gobj"]);
  3854. _t.ensureBoundsCorrect();
  3855. }
  3856. ensureSizeCorrect() {
  3857. if (this._parent == null || !this._boundsChanged || this._layout == 0)
  3858. return;
  3859. this._boundsChanged = false;
  3860. if (this._autoSizeDisabled)
  3861. this.resizeChildren(0, 0);
  3862. else {
  3863. this.handleLayout();
  3864. this.updateBounds();
  3865. }
  3866. }
  3867. ensureBoundsCorrect() {
  3868. if (this._parent == null || !this._boundsChanged)
  3869. return;
  3870. this._boundsChanged = false;
  3871. if (this._layout == 0)
  3872. this.updateBounds();
  3873. else {
  3874. if (this._autoSizeDisabled)
  3875. this.resizeChildren(0, 0);
  3876. else {
  3877. this.handleLayout();
  3878. this.updateBounds();
  3879. }
  3880. }
  3881. }
  3882. updateBounds() {
  3883. this._partner.unschedule(this._ensureBoundsCorrect);
  3884. var cnt = this._parent.numChildren;
  3885. var i;
  3886. var child;
  3887. var ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  3888. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  3889. var tmp;
  3890. var empty = true;
  3891. for (i = 0; i < cnt; i++) {
  3892. child = this._parent.getChildAt(i);
  3893. if (child.group != this || this._excludeInvisibles && !child.internalVisible3)
  3894. continue;
  3895. tmp = child.xMin;
  3896. if (tmp < ax)
  3897. ax = tmp;
  3898. tmp = child.yMin;
  3899. if (tmp < ay)
  3900. ay = tmp;
  3901. tmp = child.xMin + child.width;
  3902. if (tmp > ar)
  3903. ar = tmp;
  3904. tmp = child.yMin + child.height;
  3905. if (tmp > ab)
  3906. ab = tmp;
  3907. empty = false;
  3908. }
  3909. var w = 0, h = 0;
  3910. if (!empty) {
  3911. this._updating |= 1;
  3912. this.setPosition(ax, ay);
  3913. this._updating &= 2;
  3914. w = ar - ax;
  3915. h = ab - ay;
  3916. }
  3917. if ((this._updating & 2) == 0) {
  3918. this._updating |= 2;
  3919. this.setSize(w, h);
  3920. this._updating &= 1;
  3921. }
  3922. else {
  3923. this._updating &= 1;
  3924. this.resizeChildren(this._width - w, this._height - h);
  3925. }
  3926. }
  3927. handleLayout() {
  3928. this._updating |= 1;
  3929. var child;
  3930. var i;
  3931. var cnt;
  3932. if (this._layout == fgui.GroupLayoutType.Horizontal) {
  3933. var curX = this.x;
  3934. cnt = this._parent.numChildren;
  3935. for (i = 0; i < cnt; i++) {
  3936. child = this._parent.getChildAt(i);
  3937. if (child.group != this)
  3938. continue;
  3939. if (this._excludeInvisibles && !child.internalVisible3)
  3940. continue;
  3941. child.xMin = curX;
  3942. if (child.width != 0)
  3943. curX += child.width + this._columnGap;
  3944. }
  3945. }
  3946. else if (this._layout == fgui.GroupLayoutType.Vertical) {
  3947. var curY = this.y;
  3948. cnt = this._parent.numChildren;
  3949. for (i = 0; i < cnt; i++) {
  3950. child = this._parent.getChildAt(i);
  3951. if (child.group != this)
  3952. continue;
  3953. if (this._excludeInvisibles && !child.internalVisible3)
  3954. continue;
  3955. child.yMin = curY;
  3956. if (child.height != 0)
  3957. curY += child.height + this._lineGap;
  3958. }
  3959. }
  3960. this._updating &= 2;
  3961. }
  3962. moveChildren(dx, dy) {
  3963. if ((this._updating & 1) != 0 || this._parent == null)
  3964. return;
  3965. this._updating |= 1;
  3966. var cnt = this._parent.numChildren;
  3967. var i;
  3968. var child;
  3969. for (i = 0; i < cnt; i++) {
  3970. child = this._parent.getChildAt(i);
  3971. if (child.group == this) {
  3972. child.setPosition(child.x + dx, child.y + dy);
  3973. }
  3974. }
  3975. this._updating &= 2;
  3976. }
  3977. resizeChildren(dw, dh) {
  3978. if (this._layout == fgui.GroupLayoutType.None || (this._updating & 2) != 0 || this._parent == null)
  3979. return;
  3980. this._updating |= 2;
  3981. if (this._boundsChanged) {
  3982. this._boundsChanged = false;
  3983. if (!this._autoSizeDisabled) {
  3984. this.updateBounds();
  3985. return;
  3986. }
  3987. }
  3988. var cnt = this._parent.numChildren;
  3989. var i;
  3990. var child;
  3991. if (!this._percentReady) {
  3992. this._percentReady = true;
  3993. this._numChildren = 0;
  3994. this._totalSize = 0;
  3995. this._mainChildIndex = -1;
  3996. var j = 0;
  3997. for (i = 0; i < cnt; i++) {
  3998. child = this._parent.getChildAt(i);
  3999. if (child.group != this)
  4000. continue;
  4001. if (!this._excludeInvisibles || child.internalVisible3) {
  4002. if (j == this._mainGridIndex)
  4003. this._mainChildIndex = i;
  4004. this._numChildren++;
  4005. if (this._layout == 1)
  4006. this._totalSize += child.width;
  4007. else
  4008. this._totalSize += child.height;
  4009. }
  4010. j++;
  4011. }
  4012. if (this._mainChildIndex != -1) {
  4013. if (this._layout == 1) {
  4014. child = this._parent.getChildAt(this._mainChildIndex);
  4015. this._totalSize += this._mainGridMinSize - child.width;
  4016. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4017. }
  4018. else {
  4019. child = this._parent.getChildAt(this._mainChildIndex);
  4020. this._totalSize += this._mainGridMinSize - child.height;
  4021. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4022. }
  4023. }
  4024. for (i = 0; i < cnt; i++) {
  4025. child = this._parent.getChildAt(i);
  4026. if (child.group != this)
  4027. continue;
  4028. if (i == this._mainChildIndex)
  4029. continue;
  4030. if (this._totalSize > 0)
  4031. child._sizePercentInGroup = (this._layout == 1 ? child.width : child.height) / this._totalSize;
  4032. else
  4033. child._sizePercentInGroup = 0;
  4034. }
  4035. }
  4036. var remainSize = 0;
  4037. var remainPercent = 1;
  4038. var priorHandled = false;
  4039. if (this._layout == 1) {
  4040. remainSize = this.width - (this._numChildren - 1) * this._columnGap;
  4041. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4042. child = this._parent.getChildAt(this._mainChildIndex);
  4043. child.setSize(remainSize - (this._totalSize - this._mainGridMinSize), child._rawHeight + dh, true);
  4044. remainSize -= child.width;
  4045. remainPercent -= child._sizePercentInGroup;
  4046. priorHandled = true;
  4047. }
  4048. var curX = this.x;
  4049. for (i = 0; i < cnt; i++) {
  4050. child = this._parent.getChildAt(i);
  4051. if (child.group != this)
  4052. continue;
  4053. if (this._excludeInvisibles && !child.internalVisible3) {
  4054. child.setSize(child._rawWidth, child._rawHeight + dh, true);
  4055. continue;
  4056. }
  4057. if (!priorHandled || i != this._mainChildIndex) {
  4058. child.setSize(Math.round(child._sizePercentInGroup / remainPercent * remainSize), child._rawHeight + dh, true);
  4059. remainPercent -= child._sizePercentInGroup;
  4060. remainSize -= child.width;
  4061. }
  4062. child.xMin = curX;
  4063. if (child.width != 0)
  4064. curX += child.width + this._columnGap;
  4065. }
  4066. }
  4067. else {
  4068. remainSize = this.height - (this._numChildren - 1) * this._lineGap;
  4069. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4070. child = this._parent.getChildAt(this._mainChildIndex);
  4071. child.setSize(child._rawWidth + dw, remainSize - (this._totalSize - this._mainGridMinSize), true);
  4072. remainSize -= child.height;
  4073. remainPercent -= child._sizePercentInGroup;
  4074. priorHandled = true;
  4075. }
  4076. var curY = this.y;
  4077. for (i = 0; i < cnt; i++) {
  4078. child = this._parent.getChildAt(i);
  4079. if (child.group != this)
  4080. continue;
  4081. if (this._excludeInvisibles && !child.internalVisible3) {
  4082. child.setSize(child._rawWidth + dw, child._rawHeight, true);
  4083. continue;
  4084. }
  4085. if (!priorHandled || i != this._mainChildIndex) {
  4086. child.setSize(child._rawWidth + dw, Math.round(child._sizePercentInGroup / remainPercent * remainSize), true);
  4087. remainPercent -= child._sizePercentInGroup;
  4088. remainSize -= child.height;
  4089. }
  4090. child.yMin = curY;
  4091. if (child.height != 0)
  4092. curY += child.height + this._lineGap;
  4093. }
  4094. }
  4095. this._updating &= 1;
  4096. }
  4097. handleAlphaChanged() {
  4098. if (this._underConstruct)
  4099. return;
  4100. var cnt = this._parent.numChildren;
  4101. for (var i = 0; i < cnt; i++) {
  4102. var child = this._parent.getChildAt(i);
  4103. if (child.group == this)
  4104. child.alpha = this.alpha;
  4105. }
  4106. }
  4107. handleVisibleChanged() {
  4108. if (!this._parent)
  4109. return;
  4110. var cnt = this._parent.numChildren;
  4111. for (var i = 0; i < cnt; i++) {
  4112. var child = this._parent.getChildAt(i);
  4113. if (child.group == this)
  4114. child.handleVisibleChanged();
  4115. }
  4116. }
  4117. setup_beforeAdd(buffer, beginPos) {
  4118. super.setup_beforeAdd(buffer, beginPos);
  4119. buffer.seek(beginPos, 5);
  4120. this._layout = buffer.readByte();
  4121. this._lineGap = buffer.readInt();
  4122. this._columnGap = buffer.readInt();
  4123. if (buffer.version >= 2) {
  4124. this._excludeInvisibles = buffer.readBool();
  4125. this._autoSizeDisabled = buffer.readBool();
  4126. this._mainChildIndex = buffer.readInt();
  4127. }
  4128. }
  4129. setup_afterAdd(buffer, beginPos) {
  4130. super.setup_afterAdd(buffer, beginPos);
  4131. if (!this.visible)
  4132. this.handleVisibleChanged();
  4133. }
  4134. }
  4135. fgui.GGroup = GGroup;
  4136. })(fgui || (fgui = {}));
  4137. (function (fgui) {
  4138. class GImage extends fgui.GObject {
  4139. constructor() {
  4140. super();
  4141. this._node.name = 'GImage';
  4142. this._touchDisabled = true;
  4143. this._content = this._node.addComponent(fgui.Image);
  4144. this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  4145. this._content.trim = false;
  4146. }
  4147. get color() {
  4148. return this._node.color;
  4149. }
  4150. set color(value) {
  4151. this._node.color = value;
  4152. this.updateGear(4);
  4153. }
  4154. get flip() {
  4155. return this._content.flip;
  4156. }
  4157. set flip(value) {
  4158. this._content.flip = value;
  4159. }
  4160. get fillMethod() {
  4161. return this._content.fillMethod;
  4162. }
  4163. set fillMethod(value) {
  4164. this._content.fillMethod = value;
  4165. }
  4166. get fillOrigin() {
  4167. return this._content.fillOrigin;
  4168. }
  4169. set fillOrigin(value) {
  4170. this._content.fillOrigin = value;
  4171. }
  4172. get fillClockwise() {
  4173. return this._content.fillClockwise;
  4174. }
  4175. set fillClockwise(value) {
  4176. this._content.fillClockwise = value;
  4177. }
  4178. get fillAmount() {
  4179. return this._content.fillAmount;
  4180. }
  4181. set fillAmount(value) {
  4182. this._content.fillAmount = value;
  4183. }
  4184. constructFromResource() {
  4185. var contentItem = this.packageItem.getBranch();
  4186. this.sourceWidth = contentItem.width;
  4187. this.sourceHeight = contentItem.height;
  4188. this.initWidth = this.sourceWidth;
  4189. this.initHeight = this.sourceHeight;
  4190. this.setSize(this.sourceWidth, this.sourceHeight);
  4191. contentItem = contentItem.getHighResolution();
  4192. contentItem.load();
  4193. if (contentItem.scale9Grid)
  4194. this._content.type = cc.Sprite.Type.SLICED;
  4195. else if (contentItem.scaleByTile)
  4196. this._content.type = cc.Sprite.Type.TILED;
  4197. contentItem.owner.getItemAssetAsync(contentItem, this.onLoaded.bind(this));
  4198. }
  4199. onLoaded(err, packageItem) {
  4200. if (!cc.isValid(this._node))
  4201. return;
  4202. if (err) {
  4203. console.warn(err);
  4204. return;
  4205. }
  4206. this._content.spriteFrame = packageItem.asset;
  4207. }
  4208. handleGrayedChanged() {
  4209. this._content.grayed = this._grayed;
  4210. }
  4211. getProp(index) {
  4212. if (index == fgui.ObjectPropID.Color)
  4213. return this.color;
  4214. else
  4215. return super.getProp(index);
  4216. }
  4217. setProp(index, value) {
  4218. if (index == fgui.ObjectPropID.Color)
  4219. this.color = value;
  4220. else
  4221. super.setProp(index, value);
  4222. }
  4223. setup_beforeAdd(buffer, beginPos) {
  4224. super.setup_beforeAdd(buffer, beginPos);
  4225. buffer.seek(beginPos, 5);
  4226. if (buffer.readBool())
  4227. this.color = buffer.readColor();
  4228. this._content.flip = buffer.readByte();
  4229. this._content.fillMethod = buffer.readByte();
  4230. if (this._content.fillMethod != 0) {
  4231. this._content.fillOrigin = buffer.readByte();
  4232. this._content.fillClockwise = buffer.readBool();
  4233. this._content.fillAmount = buffer.readFloat();
  4234. }
  4235. }
  4236. }
  4237. fgui.GImage = GImage;
  4238. })(fgui || (fgui = {}));
  4239. (function (fgui) {
  4240. class GLabel extends fgui.GComponent {
  4241. constructor() {
  4242. super();
  4243. this._node.name = "GLabel";
  4244. }
  4245. get icon() {
  4246. if (this._iconObject)
  4247. return this._iconObject.icon;
  4248. }
  4249. set icon(value) {
  4250. if (this._iconObject)
  4251. this._iconObject.icon = value;
  4252. this.updateGear(7);
  4253. }
  4254. get title() {
  4255. if (this._titleObject)
  4256. return this._titleObject.text;
  4257. else
  4258. return null;
  4259. }
  4260. set title(value) {
  4261. if (this._titleObject)
  4262. this._titleObject.text = value;
  4263. this.updateGear(6);
  4264. }
  4265. get text() {
  4266. return this.title;
  4267. }
  4268. set text(value) {
  4269. this.title = value;
  4270. }
  4271. get titleColor() {
  4272. var tf = this.getTextField();
  4273. if (tf)
  4274. return tf.color;
  4275. else
  4276. return cc.Color.WHITE;
  4277. }
  4278. set titleColor(value) {
  4279. var tf = this.getTextField();
  4280. if (tf)
  4281. tf.color = value;
  4282. this.updateGear(4);
  4283. }
  4284. get titleFontSize() {
  4285. var tf = this.getTextField();
  4286. if (tf)
  4287. return tf.fontSize;
  4288. else
  4289. return 0;
  4290. }
  4291. set titleFontSize(value) {
  4292. var tf = this.getTextField();
  4293. if (tf)
  4294. tf.fontSize = value;
  4295. }
  4296. set editable(val) {
  4297. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4298. this._titleObject.editable = val;
  4299. }
  4300. get editable() {
  4301. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4302. return this._titleObject.editable;
  4303. else
  4304. return false;
  4305. }
  4306. getTextField() {
  4307. if (this._titleObject instanceof fgui.GTextField)
  4308. return this._titleObject;
  4309. else if ((this._titleObject instanceof GLabel) || (this._titleObject instanceof fgui.GButton))
  4310. return this._titleObject.getTextField();
  4311. else
  4312. return null;
  4313. }
  4314. getProp(index) {
  4315. switch (index) {
  4316. case fgui.ObjectPropID.Color:
  4317. return this.titleColor;
  4318. case fgui.ObjectPropID.OutlineColor:
  4319. {
  4320. var tf = this.getTextField();
  4321. if (tf)
  4322. return tf.strokeColor;
  4323. else
  4324. return 0;
  4325. }
  4326. case fgui.ObjectPropID.FontSize:
  4327. return this.titleFontSize;
  4328. default:
  4329. return super.getProp(index);
  4330. }
  4331. }
  4332. setProp(index, value) {
  4333. switch (index) {
  4334. case fgui.ObjectPropID.Color:
  4335. this.titleColor = value;
  4336. break;
  4337. case fgui.ObjectPropID.OutlineColor:
  4338. {
  4339. var tf = this.getTextField();
  4340. if (tf)
  4341. tf.strokeColor = value;
  4342. }
  4343. break;
  4344. case fgui.ObjectPropID.FontSize:
  4345. this.titleFontSize = value;
  4346. break;
  4347. default:
  4348. super.setProp(index, value);
  4349. break;
  4350. }
  4351. }
  4352. constructExtension(buffer) {
  4353. this._titleObject = this.getChild("title");
  4354. this._iconObject = this.getChild("icon");
  4355. }
  4356. setup_afterAdd(buffer, beginPos) {
  4357. super.setup_afterAdd(buffer, beginPos);
  4358. if (!buffer.seek(beginPos, 6))
  4359. return;
  4360. if (buffer.readByte() != this.packageItem.objectType)
  4361. return;
  4362. var str;
  4363. str = buffer.readS();
  4364. if (str != null)
  4365. this.title = str;
  4366. str = buffer.readS();
  4367. if (str != null)
  4368. this.icon = str;
  4369. if (buffer.readBool())
  4370. this.titleColor = buffer.readColor();
  4371. var iv = buffer.readInt();
  4372. if (iv != 0)
  4373. this.titleFontSize = iv;
  4374. if (buffer.readBool()) {
  4375. var input = this.getTextField();
  4376. if (input instanceof fgui.GTextInput) {
  4377. str = buffer.readS();
  4378. if (str != null)
  4379. input.promptText = str;
  4380. str = buffer.readS();
  4381. if (str != null)
  4382. input.restrict = str;
  4383. iv = buffer.readInt();
  4384. if (iv != 0)
  4385. input.maxLength = iv;
  4386. iv = buffer.readInt();
  4387. if (iv != 0) {
  4388. }
  4389. if (buffer.readBool())
  4390. input.password = true;
  4391. }
  4392. else
  4393. buffer.skip(13);
  4394. }
  4395. }
  4396. }
  4397. fgui.GLabel = GLabel;
  4398. })(fgui || (fgui = {}));
  4399. (function (fgui) {
  4400. class GList extends fgui.GComponent {
  4401. constructor() {
  4402. super();
  4403. this.scrollItemToViewOnClick = true;
  4404. this.foldInvisibleItems = false;
  4405. this._lineCount = 0;
  4406. this._columnCount = 0;
  4407. this._lineGap = 0;
  4408. this._columnGap = 0;
  4409. this._lastSelectedIndex = 0;
  4410. this._numItems = 0;
  4411. this._realNumItems = 0;
  4412. this._firstIndex = 0;
  4413. this._curLineItemCount = 0;
  4414. this._curLineItemCount2 = 0;
  4415. this._virtualListChanged = 0;
  4416. this.itemInfoVer = 0;
  4417. this.isAsyncCreateItem = false;
  4418. this._node.name = 'GList';
  4419. this._trackBounds = true;
  4420. this._pool = new fgui.GObjectPool();
  4421. this._layout = fgui.ListLayoutType.SingleColumn;
  4422. this._autoResizeItem = true;
  4423. this._lastSelectedIndex = -1;
  4424. this._selectionMode = fgui.ListSelectionMode.Single;
  4425. this.opaque = true;
  4426. this._align = fgui.AlignType.Left;
  4427. this._verticalAlign = fgui.VertAlignType.Top;
  4428. this._asyncListOperationRunner = this._node.addComponent(fgui.AsyncListOperationRunner);
  4429. this.on(fgui.Event.LIST_ITEM_CREATED_REFRESH, this._onItemCreated, this);
  4430. }
  4431. dispose() {
  4432. this._partner.unschedule(this._refreshVirtualList);
  4433. this._pool.clear();
  4434. super.dispose();
  4435. }
  4436. onDisable() {
  4437. super.onDisable();
  4438. }
  4439. _onItemCreated() {
  4440. this._refreshVirtualList();
  4441. this._partner.unschedule(this._refreshVirtualList);
  4442. }
  4443. get layout() {
  4444. return this._layout;
  4445. }
  4446. set layout(value) {
  4447. if (this._layout != value) {
  4448. this._layout = value;
  4449. this.setBoundsChangedFlag();
  4450. if (this._virtual)
  4451. this.setVirtualListChangedFlag(true);
  4452. }
  4453. }
  4454. get lineCount() {
  4455. return this._lineCount;
  4456. }
  4457. set lineCount(value) {
  4458. if (this._lineCount != value) {
  4459. this._lineCount = value;
  4460. this.setBoundsChangedFlag();
  4461. if (this._virtual)
  4462. this.setVirtualListChangedFlag(true);
  4463. }
  4464. }
  4465. get columnCount() {
  4466. return this._columnCount;
  4467. }
  4468. set columnCount(value) {
  4469. if (this._columnCount != value) {
  4470. this._columnCount = value;
  4471. this.setBoundsChangedFlag();
  4472. if (this._virtual)
  4473. this.setVirtualListChangedFlag(true);
  4474. }
  4475. }
  4476. get lineGap() {
  4477. return this._lineGap;
  4478. }
  4479. set lineGap(value) {
  4480. if (this._lineGap != value) {
  4481. this._lineGap = value;
  4482. this.setBoundsChangedFlag();
  4483. if (this._virtual)
  4484. this.setVirtualListChangedFlag(true);
  4485. }
  4486. }
  4487. get columnGap() {
  4488. return this._columnGap;
  4489. }
  4490. set columnGap(value) {
  4491. if (this._columnGap != value) {
  4492. this._columnGap = value;
  4493. this.setBoundsChangedFlag();
  4494. if (this._virtual)
  4495. this.setVirtualListChangedFlag(true);
  4496. }
  4497. }
  4498. get align() {
  4499. return this._align;
  4500. }
  4501. set align(value) {
  4502. if (this._align != value) {
  4503. this._align = value;
  4504. this.setBoundsChangedFlag();
  4505. if (this._virtual)
  4506. this.setVirtualListChangedFlag(true);
  4507. }
  4508. }
  4509. get verticalAlign() {
  4510. return this._verticalAlign;
  4511. }
  4512. set verticalAlign(value) {
  4513. if (this._verticalAlign != value) {
  4514. this._verticalAlign = value;
  4515. this.setBoundsChangedFlag();
  4516. if (this._virtual)
  4517. this.setVirtualListChangedFlag(true);
  4518. }
  4519. }
  4520. get virtualItemSize() {
  4521. return this._itemSize;
  4522. }
  4523. set virtualItemSize(value) {
  4524. if (this._virtual) {
  4525. if (this._itemSize == null)
  4526. this._itemSize = new cc.Size(0, 0);
  4527. this._itemSize.width = value.width;
  4528. this._itemSize.height = value.height;
  4529. this.setVirtualListChangedFlag(true);
  4530. }
  4531. }
  4532. get defaultItem() {
  4533. return this._defaultItem;
  4534. }
  4535. set defaultItem(val) {
  4536. this._defaultItem = val;
  4537. }
  4538. get autoResizeItem() {
  4539. return this._autoResizeItem;
  4540. }
  4541. set autoResizeItem(value) {
  4542. if (this._autoResizeItem != value) {
  4543. this._autoResizeItem = value;
  4544. this.setBoundsChangedFlag();
  4545. if (this._virtual)
  4546. this.setVirtualListChangedFlag(true);
  4547. }
  4548. }
  4549. get selectionMode() {
  4550. return this._selectionMode;
  4551. }
  4552. set selectionMode(value) {
  4553. this._selectionMode = value;
  4554. }
  4555. get selectionController() {
  4556. return this._selectionController;
  4557. }
  4558. set selectionController(value) {
  4559. this._selectionController = value;
  4560. }
  4561. get itemPool() {
  4562. return this._pool;
  4563. }
  4564. getFromPool(url) {
  4565. if (!url)
  4566. url = this._defaultItem;
  4567. var obj = this._pool.getObject(url);
  4568. if (obj)
  4569. obj.visible = true;
  4570. return obj;
  4571. }
  4572. returnToPool(obj) {
  4573. this._pool.returnObject(obj);
  4574. }
  4575. addChildAt(child, index) {
  4576. super.addChildAt(child, index);
  4577. if (child instanceof fgui.GButton) {
  4578. child.selected = false;
  4579. child.changeStateOnClick = false;
  4580. }
  4581. child.on(fgui.Event.CLICK, this.onClickItem, this);
  4582. return child;
  4583. }
  4584. addItem(url) {
  4585. if (!url)
  4586. url = this._defaultItem;
  4587. return this.addChild(fgui.UIPackage.createObjectFromURL(url));
  4588. }
  4589. addItemFromPool(url) {
  4590. return this.addChild(this.getFromPool(url));
  4591. }
  4592. removeChildAt(index, dispose) {
  4593. var child = super.removeChildAt(index, dispose);
  4594. child.off(fgui.Event.CLICK, this.onClickItem, this);
  4595. return child;
  4596. }
  4597. removeChildToPoolAt(index) {
  4598. var child = super.removeChildAt(index);
  4599. this.returnToPool(child);
  4600. }
  4601. removeChildToPool(child) {
  4602. super.removeChild(child);
  4603. this.returnToPool(child);
  4604. }
  4605. removeChildrenToPool(beginIndex, endIndex) {
  4606. if (beginIndex == undefined)
  4607. beginIndex = 0;
  4608. if (endIndex == undefined)
  4609. endIndex = -1;
  4610. if (endIndex < 0 || endIndex >= this._children.length)
  4611. endIndex = this._children.length - 1;
  4612. for (var i = beginIndex; i <= endIndex; ++i)
  4613. this.removeChildToPoolAt(beginIndex);
  4614. }
  4615. get selectedIndex() {
  4616. var i;
  4617. if (this._virtual) {
  4618. for (i = 0; i < this._realNumItems; i++) {
  4619. var ii = this._virtualItems[i];
  4620. if ((ii.obj instanceof fgui.GButton && ii.obj.selected) || (!ii.obj && ii.selected)) {
  4621. if (this._loop)
  4622. return i % this._numItems;
  4623. else
  4624. return i;
  4625. }
  4626. }
  4627. }
  4628. else {
  4629. var cnt = this._children.length;
  4630. for (i = 0; i < cnt; i++) {
  4631. var obj = this._children[i];
  4632. if (obj instanceof fgui.GButton && obj.selected)
  4633. return i;
  4634. }
  4635. }
  4636. return -1;
  4637. }
  4638. set selectedIndex(value) {
  4639. if (value >= 0 && value < this.numItems) {
  4640. if (this._selectionMode != fgui.ListSelectionMode.Single)
  4641. this.clearSelection();
  4642. this.addSelection(value);
  4643. }
  4644. else
  4645. this.clearSelection();
  4646. }
  4647. getSelection(result) {
  4648. if (!result)
  4649. result = new Array();
  4650. var i;
  4651. if (this._virtual) {
  4652. for (i = 0; i < this._realNumItems; i++) {
  4653. var ii = this._virtualItems[i];
  4654. if ((ii.obj instanceof fgui.GButton && ii.obj.selected) || (!ii.obj && ii.selected)) {
  4655. var j = i;
  4656. if (this._loop) {
  4657. j = i % this._numItems;
  4658. if (result.indexOf(j) != -1)
  4659. continue;
  4660. }
  4661. result.push(j);
  4662. }
  4663. }
  4664. }
  4665. else {
  4666. var cnt = this._children.length;
  4667. for (i = 0; i < cnt; i++) {
  4668. var obj = this._children[i];
  4669. if (obj instanceof fgui.GButton && obj.selected)
  4670. result.push(i);
  4671. }
  4672. }
  4673. return result;
  4674. }
  4675. addSelection(index, scrollItToView) {
  4676. if (this._selectionMode == fgui.ListSelectionMode.None)
  4677. return;
  4678. this.checkVirtualList();
  4679. if (this._selectionMode == fgui.ListSelectionMode.Single)
  4680. this.clearSelection();
  4681. if (scrollItToView)
  4682. this.scrollToView(index);
  4683. this._lastSelectedIndex = index;
  4684. var obj;
  4685. if (this._virtual) {
  4686. var ii = this._virtualItems[index];
  4687. if (ii.obj)
  4688. obj = ii.obj;
  4689. ii.selected = true;
  4690. }
  4691. else
  4692. obj = this.getChildAt(index);
  4693. if (obj instanceof fgui.GButton && !obj.selected) {
  4694. obj.selected = true;
  4695. this.updateSelectionController(index);
  4696. }
  4697. }
  4698. removeSelection(index) {
  4699. if (this._selectionMode == fgui.ListSelectionMode.None)
  4700. return;
  4701. var obj;
  4702. if (this._virtual) {
  4703. var ii = this._virtualItems[index];
  4704. if (ii.obj)
  4705. obj = ii.obj;
  4706. ii.selected = false;
  4707. }
  4708. else
  4709. obj = this.getChildAt(index);
  4710. if (obj instanceof fgui.GButton)
  4711. obj.selected = false;
  4712. }
  4713. clearSelection() {
  4714. var i;
  4715. if (this._virtual) {
  4716. for (i = 0; i < this._realNumItems; i++) {
  4717. var ii = this._virtualItems[i];
  4718. if (ii.obj instanceof fgui.GButton)
  4719. ii.obj.selected = false;
  4720. ii.selected = false;
  4721. }
  4722. }
  4723. else {
  4724. var cnt = this._children.length;
  4725. for (i = 0; i < cnt; i++) {
  4726. var obj = this._children[i];
  4727. if (obj instanceof fgui.GButton)
  4728. obj.selected = false;
  4729. }
  4730. }
  4731. }
  4732. clearSelectionExcept(g) {
  4733. var i;
  4734. if (this._virtual) {
  4735. for (i = 0; i < this._realNumItems; i++) {
  4736. var ii = this._virtualItems[i];
  4737. if (ii.obj != g) {
  4738. if (ii.obj instanceof fgui.GButton)
  4739. ii.obj.selected = false;
  4740. ii.selected = false;
  4741. }
  4742. }
  4743. }
  4744. else {
  4745. var cnt = this._children.length;
  4746. for (i = 0; i < cnt; i++) {
  4747. var obj = this._children[i];
  4748. if (obj instanceof fgui.GButton && obj != g)
  4749. obj.selected = false;
  4750. }
  4751. }
  4752. }
  4753. selectAll() {
  4754. this.checkVirtualList();
  4755. var last = -1;
  4756. var i;
  4757. if (this._virtual) {
  4758. for (i = 0; i < this._realNumItems; i++) {
  4759. var ii = this._virtualItems[i];
  4760. if (ii.obj instanceof fgui.GButton && !ii.obj.selected) {
  4761. ii.obj.selected = true;
  4762. last = i;
  4763. }
  4764. ii.selected = true;
  4765. }
  4766. }
  4767. else {
  4768. var cnt = this._children.length;
  4769. for (i = 0; i < cnt; i++) {
  4770. var obj = this._children[i];
  4771. if (obj instanceof fgui.GButton && !obj.selected) {
  4772. obj.selected = true;
  4773. last = i;
  4774. }
  4775. }
  4776. }
  4777. if (last != -1)
  4778. this.updateSelectionController(last);
  4779. }
  4780. selectNone() {
  4781. this.clearSelection();
  4782. }
  4783. selectReverse() {
  4784. this.checkVirtualList();
  4785. var last = -1;
  4786. var i;
  4787. if (this._virtual) {
  4788. for (i = 0; i < this._realNumItems; i++) {
  4789. var ii = this._virtualItems[i];
  4790. if (ii.obj instanceof fgui.GButton) {
  4791. ii.obj.selected = !ii.obj.selected;
  4792. if (ii.obj.selected)
  4793. last = i;
  4794. }
  4795. ii.selected = !ii.selected;
  4796. }
  4797. }
  4798. else {
  4799. var cnt = this._children.length;
  4800. for (i = 0; i < cnt; i++) {
  4801. var obj = this._children[i];
  4802. if (obj instanceof fgui.GButton) {
  4803. obj.selected = !obj.selected;
  4804. if (obj.selected)
  4805. last = i;
  4806. }
  4807. }
  4808. }
  4809. if (last != -1)
  4810. this.updateSelectionController(last);
  4811. }
  4812. handleArrowKey(dir) {
  4813. var index = this.selectedIndex;
  4814. if (index == -1)
  4815. return;
  4816. switch (dir) {
  4817. case 1:
  4818. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  4819. index--;
  4820. if (index >= 0) {
  4821. this.clearSelection();
  4822. this.addSelection(index, true);
  4823. }
  4824. }
  4825. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  4826. var current = this._children[index];
  4827. var k = 0;
  4828. for (var i = index - 1; i >= 0; i--) {
  4829. var obj = this._children[i];
  4830. if (obj.y != current.y) {
  4831. current = obj;
  4832. break;
  4833. }
  4834. k++;
  4835. }
  4836. for (; i >= 0; i--) {
  4837. obj = this._children[i];
  4838. if (obj.y != current.y) {
  4839. this.clearSelection();
  4840. this.addSelection(i + k + 1, true);
  4841. break;
  4842. }
  4843. }
  4844. }
  4845. break;
  4846. case 3:
  4847. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  4848. index++;
  4849. if (index < this._children.length) {
  4850. this.clearSelection();
  4851. this.addSelection(index, true);
  4852. }
  4853. }
  4854. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  4855. current = this._children[index];
  4856. k = 0;
  4857. var cnt = this._children.length;
  4858. for (i = index + 1; i < cnt; i++) {
  4859. obj = this._children[i];
  4860. if (obj.x != current.x) {
  4861. current = obj;
  4862. break;
  4863. }
  4864. k++;
  4865. }
  4866. for (; i < cnt; i++) {
  4867. obj = this._children[i];
  4868. if (obj.x != current.x) {
  4869. this.clearSelection();
  4870. this.addSelection(i - k - 1, true);
  4871. break;
  4872. }
  4873. }
  4874. }
  4875. break;
  4876. case 5:
  4877. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  4878. index++;
  4879. if (index < this._children.length) {
  4880. this.clearSelection();
  4881. this.addSelection(index, true);
  4882. }
  4883. }
  4884. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  4885. current = this._children[index];
  4886. k = 0;
  4887. cnt = this._children.length;
  4888. for (i = index + 1; i < cnt; i++) {
  4889. obj = this._children[i];
  4890. if (obj.y != current.y) {
  4891. current = obj;
  4892. break;
  4893. }
  4894. k++;
  4895. }
  4896. for (; i < cnt; i++) {
  4897. obj = this._children[i];
  4898. if (obj.y != current.y) {
  4899. this.clearSelection();
  4900. this.addSelection(i - k - 1, true);
  4901. break;
  4902. }
  4903. }
  4904. }
  4905. break;
  4906. case 7:
  4907. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  4908. index--;
  4909. if (index >= 0) {
  4910. this.clearSelection();
  4911. this.addSelection(index, true);
  4912. }
  4913. }
  4914. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  4915. current = this._children[index];
  4916. k = 0;
  4917. for (i = index - 1; i >= 0; i--) {
  4918. obj = this._children[i];
  4919. if (obj.x != current.x) {
  4920. current = obj;
  4921. break;
  4922. }
  4923. k++;
  4924. }
  4925. for (; i >= 0; i--) {
  4926. obj = this._children[i];
  4927. if (obj.x != current.x) {
  4928. this.clearSelection();
  4929. this.addSelection(i + k + 1, true);
  4930. break;
  4931. }
  4932. }
  4933. }
  4934. break;
  4935. }
  4936. }
  4937. onClickItem(evt) {
  4938. if (this._scrollPane && this._scrollPane.isDragged)
  4939. return;
  4940. var item = fgui.GObject.cast(evt.currentTarget);
  4941. this.setSelectionOnEvent(item, evt);
  4942. if (this._scrollPane && this.scrollItemToViewOnClick)
  4943. this._scrollPane.scrollToView(item, true);
  4944. this.dispatchItemEvent(item, evt);
  4945. }
  4946. dispatchItemEvent(item, evt) {
  4947. this._node.emit(fgui.Event.CLICK_ITEM, item, evt);
  4948. }
  4949. setSelectionOnEvent(item, evt) {
  4950. if (!(item instanceof fgui.GButton) || this._selectionMode == fgui.ListSelectionMode.None)
  4951. return;
  4952. var dontChangeLastIndex = false;
  4953. var index = this.childIndexToItemIndex(this.getChildIndex(item));
  4954. if (this._selectionMode == fgui.ListSelectionMode.Single) {
  4955. if (!item.selected) {
  4956. this.clearSelectionExcept(item);
  4957. item.selected = true;
  4958. }
  4959. }
  4960. else {
  4961. if (evt.isShiftDown) {
  4962. if (!item.selected) {
  4963. if (this._lastSelectedIndex != -1) {
  4964. var min = Math.min(this._lastSelectedIndex, index);
  4965. var max = Math.max(this._lastSelectedIndex, index);
  4966. max = Math.min(max, this.numItems - 1);
  4967. var i;
  4968. if (this._virtual) {
  4969. for (i = min; i <= max; i++) {
  4970. var ii = this._virtualItems[i];
  4971. if (ii.obj instanceof fgui.GButton)
  4972. ii.obj.selected = true;
  4973. ii.selected = true;
  4974. }
  4975. }
  4976. else {
  4977. for (i = min; i <= max; i++) {
  4978. var obj = this.getChildAt(i);
  4979. if (obj instanceof fgui.GButton)
  4980. obj.selected = true;
  4981. }
  4982. }
  4983. dontChangeLastIndex = true;
  4984. }
  4985. else {
  4986. item.selected = true;
  4987. }
  4988. }
  4989. }
  4990. else if (evt.isCtrlDown || this._selectionMode == fgui.ListSelectionMode.Multiple_SingleClick) {
  4991. item.selected = !item.selected;
  4992. }
  4993. else {
  4994. if (!item.selected) {
  4995. this.clearSelectionExcept(item);
  4996. item.selected = true;
  4997. }
  4998. else
  4999. this.clearSelectionExcept(item);
  5000. }
  5001. }
  5002. if (!dontChangeLastIndex)
  5003. this._lastSelectedIndex = index;
  5004. if (item.selected)
  5005. this.updateSelectionController(index);
  5006. }
  5007. resizeToFit(itemCount = Number.POSITIVE_INFINITY, minSize = 0) {
  5008. this.ensureBoundsCorrect();
  5009. var curCount = this.numItems;
  5010. if (itemCount > curCount)
  5011. itemCount = curCount;
  5012. if (this._virtual) {
  5013. var lineCount = Math.ceil(itemCount / this._curLineItemCount);
  5014. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5015. this.viewHeight = lineCount * this._itemSize.height + Math.max(0, lineCount - 1) * this._lineGap;
  5016. else
  5017. this.viewWidth = lineCount * this._itemSize.width + Math.max(0, lineCount - 1) * this._columnGap;
  5018. }
  5019. else if (itemCount == 0) {
  5020. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5021. this.viewHeight = minSize;
  5022. else
  5023. this.viewWidth = minSize;
  5024. }
  5025. else {
  5026. var i = itemCount - 1;
  5027. var obj = null;
  5028. while (i >= 0) {
  5029. obj = this.getChildAt(i);
  5030. if (!this.foldInvisibleItems || obj.visible)
  5031. break;
  5032. i--;
  5033. }
  5034. if (i < 0) {
  5035. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5036. this.viewHeight = minSize;
  5037. else
  5038. this.viewWidth = minSize;
  5039. }
  5040. else {
  5041. var size = 0;
  5042. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5043. size = obj.y + obj.height;
  5044. if (size < minSize)
  5045. size = minSize;
  5046. this.viewHeight = size;
  5047. }
  5048. else {
  5049. size = obj.x + obj.width;
  5050. if (size < minSize)
  5051. size = minSize;
  5052. this.viewWidth = size;
  5053. }
  5054. }
  5055. }
  5056. }
  5057. getMaxItemWidth() {
  5058. var cnt = this._children.length;
  5059. var max = 0;
  5060. for (var i = 0; i < cnt; i++) {
  5061. var child = this.getChildAt(i);
  5062. if (child.width > max)
  5063. max = child.width;
  5064. }
  5065. return max;
  5066. }
  5067. handleSizeChanged() {
  5068. super.handleSizeChanged();
  5069. this.setBoundsChangedFlag();
  5070. if (this._virtual)
  5071. this.setVirtualListChangedFlag(true);
  5072. }
  5073. handleControllerChanged(c) {
  5074. super.handleControllerChanged(c);
  5075. if (this._selectionController == c)
  5076. this.selectedIndex = c.selectedIndex;
  5077. }
  5078. updateSelectionController(index) {
  5079. if (this._selectionController && !this._selectionController.changing && index < this._selectionController.pageCount) {
  5080. var c = this._selectionController;
  5081. this._selectionController = null;
  5082. c.selectedIndex = index;
  5083. this._selectionController = c;
  5084. }
  5085. }
  5086. getSnappingPosition(xValue, yValue, resultPoint) {
  5087. if (this._virtual) {
  5088. resultPoint = resultPoint || new cc.Vec2();
  5089. var saved;
  5090. var index;
  5091. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5092. saved = yValue;
  5093. s_n = yValue;
  5094. index = this.getIndexOnPos1(false);
  5095. yValue = s_n;
  5096. if (index < this._virtualItems.length && saved - yValue > this._virtualItems[index].height / 2 && index < this._realNumItems)
  5097. yValue += this._virtualItems[index].height + this._lineGap;
  5098. }
  5099. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5100. saved = xValue;
  5101. s_n = xValue;
  5102. index = this.getIndexOnPos2(false);
  5103. xValue = s_n;
  5104. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5105. xValue += this._virtualItems[index].width + this._columnGap;
  5106. }
  5107. else {
  5108. saved = xValue;
  5109. s_n = xValue;
  5110. index = this.getIndexOnPos3(false);
  5111. xValue = s_n;
  5112. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5113. xValue += this._virtualItems[index].width + this._columnGap;
  5114. }
  5115. resultPoint.x = xValue;
  5116. resultPoint.y = yValue;
  5117. return resultPoint;
  5118. }
  5119. else {
  5120. return super.getSnappingPosition(xValue, yValue, resultPoint);
  5121. }
  5122. }
  5123. scrollToView(index, ani, setFirst) {
  5124. if (this._virtual) {
  5125. if (this._numItems == 0)
  5126. return;
  5127. this.checkVirtualList();
  5128. if (index >= this._virtualItems.length)
  5129. throw 'Invalid child index: ' + index + '>' + this._virtualItems.length;
  5130. if (this._loop)
  5131. index = Math.floor(this._firstIndex / this._numItems) * this._numItems + index;
  5132. var rect;
  5133. var ii = this._virtualItems[index];
  5134. var pos = 0;
  5135. var i;
  5136. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5137. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5138. pos += this._virtualItems[i].height + this._lineGap;
  5139. rect = new cc.Rect(0, pos, this._itemSize.width, ii.height);
  5140. }
  5141. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5142. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5143. pos += this._virtualItems[i].width + this._columnGap;
  5144. rect = new cc.Rect(pos, 0, ii.width, this._itemSize.height);
  5145. }
  5146. else {
  5147. var page = index / (this._curLineItemCount * this._curLineItemCount2);
  5148. 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);
  5149. }
  5150. if (this._scrollPane)
  5151. this._scrollPane.scrollToView(rect, ani, setFirst);
  5152. }
  5153. else {
  5154. var obj = this.getChildAt(index);
  5155. if (obj) {
  5156. if (this._scrollPane)
  5157. this._scrollPane.scrollToView(obj, ani, setFirst);
  5158. else if (this.parent && this.parent.scrollPane)
  5159. this.parent.scrollPane.scrollToView(obj, ani, setFirst);
  5160. }
  5161. }
  5162. }
  5163. getFirstChildInView() {
  5164. return this.childIndexToItemIndex(super.getFirstChildInView());
  5165. }
  5166. getLastChildInView() {
  5167. return this.childIndexToItemIndex(super.getLastChildInView());
  5168. }
  5169. childIndexToItemIndex(index) {
  5170. if (!this._virtual)
  5171. return index;
  5172. if (this._layout == fgui.ListLayoutType.Pagination) {
  5173. for (var i = this._firstIndex; i < this._realNumItems; i++) {
  5174. if (this._virtualItems[i].obj) {
  5175. index--;
  5176. if (index < 0)
  5177. return i;
  5178. }
  5179. }
  5180. return index;
  5181. }
  5182. else {
  5183. index += this._firstIndex;
  5184. if (this._loop && this._numItems > 0)
  5185. index = index % this._numItems;
  5186. return index;
  5187. }
  5188. }
  5189. itemIndexToChildIndex(index) {
  5190. if (!this._virtual)
  5191. return index;
  5192. if (this._layout == fgui.ListLayoutType.Pagination) {
  5193. return this.getChildIndex(this._virtualItems[index].obj);
  5194. }
  5195. else {
  5196. if (this._loop && this._numItems > 0) {
  5197. var j = this._firstIndex % this._numItems;
  5198. if (index >= j)
  5199. index = index - j;
  5200. else
  5201. index = this._numItems - j + index;
  5202. }
  5203. else
  5204. index -= this._firstIndex;
  5205. return index;
  5206. }
  5207. }
  5208. setVirtual() {
  5209. this._setVirtual(false);
  5210. }
  5211. setVirtualAndLoop() {
  5212. this._setVirtual(true);
  5213. }
  5214. _setVirtual(loop) {
  5215. if (!this._virtual) {
  5216. if (!this._scrollPane)
  5217. throw 'Virtual list must be scrollable!';
  5218. if (loop) {
  5219. if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.FlowVertical)
  5220. throw 'Loop list is not supported for FlowHorizontal or FlowVertical layout!';
  5221. this._scrollPane.bouncebackEffect = false;
  5222. }
  5223. this._virtual = true;
  5224. this._loop = loop;
  5225. this._virtualItems = new Array();
  5226. this.removeChildrenToPool();
  5227. if (this._itemSize == null) {
  5228. this._itemSize = new cc.Size(0, 0);
  5229. var obj = this.getFromPool(null);
  5230. if (!obj) {
  5231. throw 'Virtual List must have a default list item resource.';
  5232. }
  5233. else {
  5234. this._itemSize.width = obj.width;
  5235. this._itemSize.height = obj.height;
  5236. }
  5237. this.returnToPool(obj);
  5238. }
  5239. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5240. this._scrollPane.scrollStep = this._itemSize.height;
  5241. if (this._loop)
  5242. this._scrollPane._loop = 2;
  5243. }
  5244. else {
  5245. this._scrollPane.scrollStep = this._itemSize.width;
  5246. if (this._loop)
  5247. this._scrollPane._loop = 1;
  5248. }
  5249. this._node.on(fgui.Event.SCROLL, this.__scrolled, this);
  5250. this.setVirtualListChangedFlag(true);
  5251. }
  5252. }
  5253. get numItems() {
  5254. if (this._virtual)
  5255. return this._numItems;
  5256. else
  5257. return this._children.length;
  5258. }
  5259. set numItems(value) {
  5260. this._asyncListOperationRunner.isFirstCreate = true;
  5261. if (this._virtual) {
  5262. if (this.itemRenderer == null)
  5263. throw 'Set itemRenderer first!';
  5264. this._numItems = value;
  5265. if (this._loop)
  5266. this._realNumItems = this._numItems * 6;
  5267. else
  5268. this._realNumItems = this._numItems;
  5269. var oldCount = this._virtualItems.length;
  5270. if (this._realNumItems > oldCount) {
  5271. for (i = oldCount; i < this._realNumItems; i++) {
  5272. var ii = {
  5273. width: this._itemSize.width,
  5274. height: this._itemSize.height,
  5275. updateFlag: 0,
  5276. };
  5277. this._virtualItems.push(ii);
  5278. }
  5279. }
  5280. else {
  5281. for (i = this._realNumItems; i < oldCount; i++)
  5282. this._virtualItems[i].selected = false;
  5283. }
  5284. if (this._virtualListChanged != 0)
  5285. this._partner.unschedule(this._refreshVirtualList);
  5286. this._refreshVirtualList();
  5287. }
  5288. else {
  5289. var cnt = this._children.length;
  5290. if (value > cnt) {
  5291. for (var i = cnt; i < value; i++) {
  5292. if (this.itemProvider == null)
  5293. this.addItemFromPool();
  5294. else
  5295. this.addItemFromPool(this.itemProvider(i));
  5296. }
  5297. }
  5298. else {
  5299. this.removeChildrenToPool(value, cnt);
  5300. }
  5301. if (this.itemRenderer != null) {
  5302. for (i = 0; i < value; i++)
  5303. this.itemRenderer(i, this.getChildAt(i));
  5304. }
  5305. }
  5306. }
  5307. refreshVirtualList() {
  5308. this.setVirtualListChangedFlag(false);
  5309. }
  5310. checkVirtualList() {
  5311. if (this._virtualListChanged != 0) {
  5312. this._refreshVirtualList();
  5313. this._partner.unschedule(this._refreshVirtualList);
  5314. }
  5315. }
  5316. setVirtualListChangedFlag(layoutChanged) {
  5317. if (layoutChanged)
  5318. this._virtualListChanged = 2;
  5319. else if (this._virtualListChanged == 0)
  5320. this._virtualListChanged = 1;
  5321. this._partner.callLater(this._refreshVirtualList);
  5322. }
  5323. _refreshVirtualList(dt) {
  5324. if (!isNaN(dt)) {
  5325. let _t = this.node['$gobj'];
  5326. _t._refreshVirtualList();
  5327. return;
  5328. }
  5329. var layoutChanged = this._virtualListChanged == 2;
  5330. this._virtualListChanged = 0;
  5331. this._eventLocked = true;
  5332. if (layoutChanged) {
  5333. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.SingleRow)
  5334. this._curLineItemCount = 1;
  5335. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5336. if (this._columnCount > 0)
  5337. this._curLineItemCount = this._columnCount;
  5338. else {
  5339. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5340. if (this._curLineItemCount <= 0)
  5341. this._curLineItemCount = 1;
  5342. }
  5343. }
  5344. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5345. if (this._lineCount > 0)
  5346. this._curLineItemCount = this._lineCount;
  5347. else {
  5348. this._curLineItemCount = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5349. if (this._curLineItemCount <= 0)
  5350. this._curLineItemCount = 1;
  5351. }
  5352. }
  5353. else {
  5354. if (this._columnCount > 0)
  5355. this._curLineItemCount = this._columnCount;
  5356. else {
  5357. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5358. if (this._curLineItemCount <= 0)
  5359. this._curLineItemCount = 1;
  5360. }
  5361. if (this._lineCount > 0)
  5362. this._curLineItemCount2 = this._lineCount;
  5363. else {
  5364. this._curLineItemCount2 = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5365. if (this._curLineItemCount2 <= 0)
  5366. this._curLineItemCount2 = 1;
  5367. }
  5368. }
  5369. }
  5370. var ch = 0, cw = 0;
  5371. if (this._realNumItems > 0) {
  5372. var i;
  5373. var len = Math.ceil(this._realNumItems / this._curLineItemCount) * this._curLineItemCount;
  5374. var len2 = Math.min(this._curLineItemCount, this._realNumItems);
  5375. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5376. for (i = 0; i < len; i += this._curLineItemCount)
  5377. ch += this._virtualItems[i].height + this._lineGap;
  5378. if (ch > 0)
  5379. ch -= this._lineGap;
  5380. if (this._autoResizeItem)
  5381. cw = this._scrollPane.viewWidth;
  5382. else {
  5383. for (i = 0; i < len2; i++)
  5384. cw += this._virtualItems[i].width + this._columnGap;
  5385. if (cw > 0)
  5386. cw -= this._columnGap;
  5387. }
  5388. }
  5389. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5390. for (i = 0; i < len; i += this._curLineItemCount)
  5391. cw += this._virtualItems[i].width + this._columnGap;
  5392. if (cw > 0)
  5393. cw -= this._columnGap;
  5394. if (this._autoResizeItem)
  5395. ch = this._scrollPane.viewHeight;
  5396. else {
  5397. for (i = 0; i < len2; i++)
  5398. ch += this._virtualItems[i].height + this._lineGap;
  5399. if (ch > 0)
  5400. ch -= this._lineGap;
  5401. }
  5402. }
  5403. else {
  5404. var pageCount = Math.ceil(len / (this._curLineItemCount * this._curLineItemCount2));
  5405. cw = pageCount * this.viewWidth;
  5406. ch = this.viewHeight;
  5407. }
  5408. }
  5409. this.handleAlign(cw, ch);
  5410. this._scrollPane.setContentSize(cw, ch);
  5411. this._eventLocked = false;
  5412. this.handleScroll(true);
  5413. }
  5414. __scrolled(evt) {
  5415. this.handleScroll(false);
  5416. }
  5417. getIndexOnPos1(forceUpdate) {
  5418. if (this._realNumItems < this._curLineItemCount) {
  5419. s_n = 0;
  5420. return 0;
  5421. }
  5422. var i;
  5423. var pos2;
  5424. var pos3;
  5425. if (this.numChildren > 0 && !forceUpdate) {
  5426. pos2 = this.getChildAt(0).y;
  5427. if (pos2 > s_n) {
  5428. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  5429. pos2 -= this._virtualItems[i].height + this._lineGap;
  5430. if (pos2 <= s_n) {
  5431. s_n = pos2;
  5432. return i;
  5433. }
  5434. }
  5435. s_n = 0;
  5436. return 0;
  5437. }
  5438. else {
  5439. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  5440. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  5441. if (pos3 > s_n) {
  5442. s_n = pos2;
  5443. return i;
  5444. }
  5445. pos2 = pos3;
  5446. }
  5447. s_n = pos2;
  5448. return this._realNumItems - this._curLineItemCount;
  5449. }
  5450. }
  5451. else {
  5452. pos2 = 0;
  5453. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  5454. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  5455. if (pos3 > s_n) {
  5456. s_n = pos2;
  5457. return i;
  5458. }
  5459. pos2 = pos3;
  5460. }
  5461. s_n = pos2;
  5462. return this._realNumItems - this._curLineItemCount;
  5463. }
  5464. }
  5465. getIndexOnPos2(forceUpdate) {
  5466. if (this._realNumItems < this._curLineItemCount) {
  5467. s_n = 0;
  5468. return 0;
  5469. }
  5470. var i;
  5471. var pos2;
  5472. var pos3;
  5473. if (this.numChildren > 0 && !forceUpdate) {
  5474. pos2 = this.getChildAt(0).x;
  5475. if (pos2 > s_n) {
  5476. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  5477. pos2 -= this._virtualItems[i].width + this._columnGap;
  5478. if (pos2 <= s_n) {
  5479. s_n = pos2;
  5480. return i;
  5481. }
  5482. }
  5483. s_n = 0;
  5484. return 0;
  5485. }
  5486. else {
  5487. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  5488. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  5489. if (pos3 > s_n) {
  5490. s_n = pos2;
  5491. return i;
  5492. }
  5493. pos2 = pos3;
  5494. }
  5495. s_n = pos2;
  5496. return this._realNumItems - this._curLineItemCount;
  5497. }
  5498. }
  5499. else {
  5500. pos2 = 0;
  5501. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  5502. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  5503. if (pos3 > s_n) {
  5504. s_n = pos2;
  5505. return i;
  5506. }
  5507. pos2 = pos3;
  5508. }
  5509. s_n = pos2;
  5510. return this._realNumItems - this._curLineItemCount;
  5511. }
  5512. }
  5513. getIndexOnPos3(forceUpdate) {
  5514. if (this._realNumItems < this._curLineItemCount) {
  5515. s_n = 0;
  5516. return 0;
  5517. }
  5518. var viewWidth = this.viewWidth;
  5519. var page = Math.floor(s_n / viewWidth);
  5520. var startIndex = page * (this._curLineItemCount * this._curLineItemCount2);
  5521. var pos2 = page * viewWidth;
  5522. var i;
  5523. var pos3;
  5524. for (i = 0; i < this._curLineItemCount; i++) {
  5525. pos3 = pos2 + this._virtualItems[startIndex + i].width + this._columnGap;
  5526. if (pos3 > s_n) {
  5527. s_n = pos2;
  5528. return startIndex + i;
  5529. }
  5530. pos2 = pos3;
  5531. }
  5532. s_n = pos2;
  5533. return startIndex + this._curLineItemCount - 1;
  5534. }
  5535. handleScroll(forceUpdate) {
  5536. if (this._eventLocked)
  5537. return;
  5538. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5539. var enterCounter = 0;
  5540. while (this.handleScroll1(forceUpdate)) {
  5541. enterCounter++;
  5542. forceUpdate = false;
  5543. if (enterCounter > 20) {
  5544. console.log('FairyGUI: list will never be filled as the item renderer function always returns a different size.');
  5545. break;
  5546. }
  5547. }
  5548. this.handleScroll1(false);
  5549. this.handleArchOrder1();
  5550. }
  5551. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5552. enterCounter = 0;
  5553. while (this.handleScroll2(forceUpdate)) {
  5554. enterCounter++;
  5555. forceUpdate = false;
  5556. if (enterCounter > 20) {
  5557. console.log('FairyGUI: list will never be filled as the item renderer function always returns a different size.');
  5558. break;
  5559. }
  5560. }
  5561. this.handleScroll2(false);
  5562. this.handleArchOrder2();
  5563. }
  5564. else {
  5565. this.handleScroll3(forceUpdate);
  5566. }
  5567. this._boundsChanged = false;
  5568. }
  5569. handleScroll1(forceUpdate) {
  5570. var pos = this._scrollPane.scrollingPosY;
  5571. var max = pos + this._scrollPane.viewHeight;
  5572. var end = max == this._scrollPane.contentHeight;
  5573. s_n = pos;
  5574. var newFirstIndex = this.getIndexOnPos1(forceUpdate);
  5575. pos = s_n;
  5576. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  5577. return false;
  5578. }
  5579. var oldFirstIndex = this._firstIndex;
  5580. this._firstIndex = newFirstIndex;
  5581. var curIndex = newFirstIndex;
  5582. var forward = oldFirstIndex > newFirstIndex;
  5583. var childCount = this.numChildren;
  5584. var lastIndex = oldFirstIndex + childCount - 1;
  5585. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  5586. var curX = 0, curY = pos;
  5587. var needRender;
  5588. var deltaSize = 0;
  5589. var firstItemDeltaSize = 0;
  5590. var url = this.defaultItem;
  5591. var ii, ii2;
  5592. var i, j;
  5593. var partSize = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  5594. this.itemInfoVer++;
  5595. while (curIndex < this._realNumItems && (end || curY < max)) {
  5596. ii = this._virtualItems[curIndex];
  5597. if (!ii.obj || forceUpdate) {
  5598. if (this.itemProvider != null) {
  5599. url = this.itemProvider(curIndex % this._numItems);
  5600. if (url == null)
  5601. url = this._defaultItem;
  5602. url = fgui.UIPackage.normalizeURL(url);
  5603. }
  5604. if (ii.obj && ii.obj.resourceURL != url) {
  5605. if (ii.obj instanceof fgui.GButton)
  5606. ii.selected = ii.obj.selected;
  5607. this.removeChildToPool(ii.obj);
  5608. ii.obj = null;
  5609. }
  5610. }
  5611. if (!ii.obj) {
  5612. if (forward) {
  5613. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  5614. ii2 = this._virtualItems[j];
  5615. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  5616. if (ii2.obj instanceof fgui.GButton)
  5617. ii2.selected = ii2.obj.selected;
  5618. ii.obj = ii2.obj;
  5619. ii2.obj = null;
  5620. if (j == reuseIndex)
  5621. reuseIndex--;
  5622. break;
  5623. }
  5624. }
  5625. }
  5626. else {
  5627. for (j = reuseIndex; j <= lastIndex; j++) {
  5628. ii2 = this._virtualItems[j];
  5629. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  5630. if (ii2.obj instanceof fgui.GButton)
  5631. ii2.selected = ii2.obj.selected;
  5632. ii.obj = ii2.obj;
  5633. ii2.obj = null;
  5634. if (j == reuseIndex)
  5635. reuseIndex++;
  5636. break;
  5637. }
  5638. }
  5639. }
  5640. if (ii.obj) {
  5641. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  5642. }
  5643. else {
  5644. if (this.isAsyncCreateItem) {
  5645. ii.obj = this._pool.getObjectFromPool(url);
  5646. if (!ii.obj) {
  5647. this._asyncListOperationRunner.createObj(url);
  5648. break;
  5649. }
  5650. }
  5651. else {
  5652. ii.obj = this._pool.getObject(url);
  5653. }
  5654. if (forward)
  5655. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  5656. else
  5657. this.addChild(ii.obj);
  5658. }
  5659. if (ii.obj instanceof fgui.GButton)
  5660. ii.obj.selected = ii.selected;
  5661. needRender = true;
  5662. }
  5663. else
  5664. needRender = forceUpdate;
  5665. if (needRender) {
  5666. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleColumn || this._columnCount > 0))
  5667. ii.obj.setSize(partSize, ii.obj.height, true);
  5668. this.itemRenderer(curIndex % this._numItems, ii.obj);
  5669. if (curIndex % this._curLineItemCount == 0) {
  5670. deltaSize += Math.ceil(ii.obj.height) - ii.height;
  5671. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  5672. firstItemDeltaSize = Math.ceil(ii.obj.height) - ii.height;
  5673. }
  5674. }
  5675. ii.width = Math.ceil(ii.obj.width);
  5676. ii.height = Math.ceil(ii.obj.height);
  5677. }
  5678. ii.updateFlag = this.itemInfoVer;
  5679. ii.obj.setPosition(curX, curY);
  5680. if (curIndex == newFirstIndex)
  5681. max += ii.height;
  5682. curX += ii.width + this._columnGap;
  5683. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  5684. curX = 0;
  5685. curY += ii.height + this._lineGap;
  5686. }
  5687. curIndex++;
  5688. }
  5689. for (i = 0; i < childCount; i++) {
  5690. ii = this._virtualItems[oldFirstIndex + i];
  5691. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  5692. if (ii.obj instanceof fgui.GButton)
  5693. ii.selected = ii.obj.selected;
  5694. this.removeChildToPool(ii.obj);
  5695. ii.obj = null;
  5696. }
  5697. }
  5698. childCount = this._children.length;
  5699. for (i = 0; i < childCount; i++) {
  5700. let obj = this._virtualItems[newFirstIndex + i].obj;
  5701. if (this._children[i] != obj)
  5702. this.setChildIndex(obj, i);
  5703. }
  5704. if (deltaSize != 0 || firstItemDeltaSize != 0)
  5705. this._scrollPane.changeContentSizeOnScrolling(0, deltaSize, 0, firstItemDeltaSize);
  5706. if (curIndex > 0 && this.numChildren > 0 && this._container.y <= 0 && this.getChildAt(0).y > -this._container.y)
  5707. return true;
  5708. else
  5709. return false;
  5710. }
  5711. handleScroll2(forceUpdate) {
  5712. var pos = this._scrollPane.scrollingPosX;
  5713. var max = pos + this._scrollPane.viewWidth;
  5714. var end = pos == this._scrollPane.contentWidth;
  5715. s_n = pos;
  5716. var newFirstIndex = this.getIndexOnPos2(forceUpdate);
  5717. pos = s_n;
  5718. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  5719. return false;
  5720. }
  5721. var oldFirstIndex = this._firstIndex;
  5722. this._firstIndex = newFirstIndex;
  5723. var curIndex = newFirstIndex;
  5724. var forward = oldFirstIndex > newFirstIndex;
  5725. var childCount = this.numChildren;
  5726. var lastIndex = oldFirstIndex + childCount - 1;
  5727. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  5728. var curX = pos, curY = 0;
  5729. var needRender;
  5730. var deltaSize = 0;
  5731. var firstItemDeltaSize = 0;
  5732. var url = this.defaultItem;
  5733. var ii, ii2;
  5734. var i, j;
  5735. var partSize = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  5736. this.itemInfoVer++;
  5737. while (curIndex < this._realNumItems && (end || curX < max)) {
  5738. ii = this._virtualItems[curIndex];
  5739. if (!ii.obj || forceUpdate) {
  5740. if (this.itemProvider != null) {
  5741. url = this.itemProvider(curIndex % this._numItems);
  5742. if (url == null)
  5743. url = this._defaultItem;
  5744. url = fgui.UIPackage.normalizeURL(url);
  5745. }
  5746. if (ii.obj && ii.obj.resourceURL != url) {
  5747. if (ii.obj instanceof fgui.GButton)
  5748. ii.selected = ii.obj.selected;
  5749. this.removeChildToPool(ii.obj);
  5750. ii.obj = null;
  5751. }
  5752. }
  5753. if (!ii.obj) {
  5754. if (forward) {
  5755. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  5756. ii2 = this._virtualItems[j];
  5757. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  5758. if (ii2.obj instanceof fgui.GButton)
  5759. ii2.selected = ii2.obj.selected;
  5760. ii.obj = ii2.obj;
  5761. ii2.obj = null;
  5762. if (j == reuseIndex)
  5763. reuseIndex--;
  5764. break;
  5765. }
  5766. }
  5767. }
  5768. else {
  5769. for (j = reuseIndex; j <= lastIndex; j++) {
  5770. ii2 = this._virtualItems[j];
  5771. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  5772. if (ii2.obj instanceof fgui.GButton)
  5773. ii2.selected = ii2.obj.selected;
  5774. ii.obj = ii2.obj;
  5775. ii2.obj = null;
  5776. if (j == reuseIndex)
  5777. reuseIndex++;
  5778. break;
  5779. }
  5780. }
  5781. }
  5782. if (ii.obj) {
  5783. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  5784. }
  5785. else {
  5786. if (this.isAsyncCreateItem) {
  5787. ii.obj = this._pool.getObjectFromPool(url);
  5788. if (!ii.obj) {
  5789. this._asyncListOperationRunner.createObj(url);
  5790. break;
  5791. }
  5792. }
  5793. else {
  5794. ii.obj = this._pool.getObject(url);
  5795. }
  5796. if (forward)
  5797. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  5798. else
  5799. this.addChild(ii.obj);
  5800. }
  5801. if (ii.obj instanceof fgui.GButton)
  5802. ii.obj.selected = ii.selected;
  5803. needRender = true;
  5804. }
  5805. else
  5806. needRender = forceUpdate;
  5807. if (needRender) {
  5808. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleRow || this._lineCount > 0))
  5809. ii.obj.setSize(ii.obj.width, partSize, true);
  5810. this.itemRenderer(curIndex % this._numItems, ii.obj);
  5811. if (curIndex % this._curLineItemCount == 0) {
  5812. deltaSize += Math.ceil(ii.obj.width) - ii.width;
  5813. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  5814. firstItemDeltaSize = Math.ceil(ii.obj.width) - ii.width;
  5815. }
  5816. }
  5817. ii.width = Math.ceil(ii.obj.width);
  5818. ii.height = Math.ceil(ii.obj.height);
  5819. }
  5820. ii.updateFlag = this.itemInfoVer;
  5821. ii.obj.setPosition(curX, curY);
  5822. if (curIndex == newFirstIndex)
  5823. max += ii.width;
  5824. curY += ii.height + this._lineGap;
  5825. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  5826. curY = 0;
  5827. curX += ii.width + this._columnGap;
  5828. }
  5829. curIndex++;
  5830. }
  5831. for (i = 0; i < childCount; i++) {
  5832. ii = this._virtualItems[oldFirstIndex + i];
  5833. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  5834. if (ii.obj instanceof fgui.GButton)
  5835. ii.selected = ii.obj.selected;
  5836. this.removeChildToPool(ii.obj);
  5837. ii.obj = null;
  5838. }
  5839. }
  5840. childCount = this._children.length;
  5841. for (i = 0; i < childCount; i++) {
  5842. let obj = this._virtualItems[newFirstIndex + i].obj;
  5843. if (this._children[i] != obj)
  5844. this.setChildIndex(obj, i);
  5845. }
  5846. if (deltaSize != 0 || firstItemDeltaSize != 0)
  5847. this._scrollPane.changeContentSizeOnScrolling(deltaSize, 0, firstItemDeltaSize, 0);
  5848. if (curIndex > 0 && this.numChildren > 0 && this._container.x <= 0 && this.getChildAt(0).x > -this._container.x)
  5849. return true;
  5850. else
  5851. return false;
  5852. }
  5853. handleScroll3(forceUpdate) {
  5854. var pos = this._scrollPane.scrollingPosX;
  5855. s_n = pos;
  5856. var newFirstIndex = this.getIndexOnPos3(forceUpdate);
  5857. pos = s_n;
  5858. if (newFirstIndex == this._firstIndex && !forceUpdate)
  5859. return;
  5860. var oldFirstIndex = this._firstIndex;
  5861. this._firstIndex = newFirstIndex;
  5862. var reuseIndex = oldFirstIndex;
  5863. var virtualItemCount = this._virtualItems.length;
  5864. var pageSize = this._curLineItemCount * this._curLineItemCount2;
  5865. var startCol = newFirstIndex % this._curLineItemCount;
  5866. var viewWidth = this.viewWidth;
  5867. var page = Math.floor(newFirstIndex / pageSize);
  5868. var startIndex = page * pageSize;
  5869. var lastIndex = startIndex + pageSize * 2;
  5870. var needRender;
  5871. var i;
  5872. var ii, ii2;
  5873. var col;
  5874. var url = this._defaultItem;
  5875. var partWidth = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  5876. var partHeight = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount2 - 1)) / this._curLineItemCount2;
  5877. this.itemInfoVer++;
  5878. for (i = startIndex; i < lastIndex; i++) {
  5879. if (i >= this._realNumItems)
  5880. continue;
  5881. col = i % this._curLineItemCount;
  5882. if (i - startIndex < pageSize) {
  5883. if (col < startCol)
  5884. continue;
  5885. }
  5886. else {
  5887. if (col > startCol)
  5888. continue;
  5889. }
  5890. ii = this._virtualItems[i];
  5891. ii.updateFlag = this.itemInfoVer;
  5892. }
  5893. var lastObj = null;
  5894. var insertIndex = 0;
  5895. for (i = startIndex; i < lastIndex; i++) {
  5896. if (i >= this._realNumItems)
  5897. continue;
  5898. ii = this._virtualItems[i];
  5899. if (ii.updateFlag != this.itemInfoVer)
  5900. continue;
  5901. if (!ii.obj) {
  5902. while (reuseIndex < virtualItemCount) {
  5903. ii2 = this._virtualItems[reuseIndex];
  5904. if (ii2.obj && ii2.updateFlag != this.itemInfoVer) {
  5905. if (ii2.obj instanceof fgui.GButton)
  5906. ii2.selected = ii2.obj.selected;
  5907. ii.obj = ii2.obj;
  5908. ii2.obj = null;
  5909. break;
  5910. }
  5911. reuseIndex++;
  5912. }
  5913. if (insertIndex == -1)
  5914. insertIndex = this.getChildIndex(lastObj) + 1;
  5915. if (!ii.obj) {
  5916. if (this.itemProvider != null) {
  5917. url = this.itemProvider(i % this._numItems);
  5918. if (url == null)
  5919. url = this._defaultItem;
  5920. url = fgui.UIPackage.normalizeURL(url);
  5921. }
  5922. if (this.isAsyncCreateItem) {
  5923. ii.obj = this._pool.getObjectFromPool(url);
  5924. if (!ii.obj) {
  5925. this._asyncListOperationRunner.createObj(url);
  5926. break;
  5927. }
  5928. }
  5929. else {
  5930. ii.obj = this._pool.getObject(url);
  5931. }
  5932. this.addChildAt(ii.obj, insertIndex);
  5933. }
  5934. else {
  5935. insertIndex = this.setChildIndexBefore(ii.obj, insertIndex);
  5936. }
  5937. insertIndex++;
  5938. if (ii.obj instanceof fgui.GButton)
  5939. ii.obj.selected = ii.selected;
  5940. needRender = true;
  5941. }
  5942. else {
  5943. needRender = forceUpdate;
  5944. insertIndex = -1;
  5945. lastObj = ii.obj;
  5946. }
  5947. if (needRender) {
  5948. if (this._autoResizeItem) {
  5949. if (this._curLineItemCount == this._columnCount && this._curLineItemCount2 == this._lineCount)
  5950. ii.obj.setSize(partWidth, partHeight, true);
  5951. else if (this._curLineItemCount == this._columnCount)
  5952. ii.obj.setSize(partWidth, ii.obj.height, true);
  5953. else if (this._curLineItemCount2 == this._lineCount)
  5954. ii.obj.setSize(ii.obj.width, partHeight, true);
  5955. }
  5956. this.itemRenderer(i % this._numItems, ii.obj);
  5957. ii.width = Math.ceil(ii.obj.width);
  5958. ii.height = Math.ceil(ii.obj.height);
  5959. }
  5960. }
  5961. var borderX = (startIndex / pageSize) * viewWidth;
  5962. var xx = borderX;
  5963. var yy = 0;
  5964. var lineHeight = 0;
  5965. for (i = startIndex; i < lastIndex; i++) {
  5966. if (i >= this._realNumItems)
  5967. continue;
  5968. ii = this._virtualItems[i];
  5969. if (ii.updateFlag == this.itemInfoVer)
  5970. ii.obj.setPosition(xx, yy);
  5971. if (ii.height > lineHeight)
  5972. lineHeight = ii.height;
  5973. if (i % this._curLineItemCount == this._curLineItemCount - 1) {
  5974. xx = borderX;
  5975. yy += lineHeight + this._lineGap;
  5976. lineHeight = 0;
  5977. if (i == startIndex + pageSize - 1) {
  5978. borderX += viewWidth;
  5979. xx = borderX;
  5980. yy = 0;
  5981. }
  5982. }
  5983. else
  5984. xx += ii.width + this._columnGap;
  5985. }
  5986. for (i = reuseIndex; i < virtualItemCount; i++) {
  5987. ii = this._virtualItems[i];
  5988. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  5989. if (ii.obj instanceof fgui.GButton)
  5990. ii.selected = ii.obj.selected;
  5991. this.removeChildToPool(ii.obj);
  5992. ii.obj = null;
  5993. }
  5994. }
  5995. }
  5996. handleArchOrder1() {
  5997. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  5998. var mid = this._scrollPane.posY + this.viewHeight / 2;
  5999. var minDist = Number.POSITIVE_INFINITY;
  6000. var dist = 0;
  6001. var apexIndex = 0;
  6002. var cnt = this.numChildren;
  6003. for (var i = 0; i < cnt; i++) {
  6004. var obj = this.getChildAt(i);
  6005. if (!this.foldInvisibleItems || obj.visible) {
  6006. dist = Math.abs(mid - obj.y - obj.height / 2);
  6007. if (dist < minDist) {
  6008. minDist = dist;
  6009. apexIndex = i;
  6010. }
  6011. }
  6012. }
  6013. this.apexIndex = apexIndex;
  6014. }
  6015. }
  6016. handleArchOrder2() {
  6017. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6018. var mid = this._scrollPane.posX + this.viewWidth / 2;
  6019. var minDist = Number.POSITIVE_INFINITY;
  6020. var dist = 0;
  6021. var apexIndex = 0;
  6022. var cnt = this.numChildren;
  6023. for (var i = 0; i < cnt; i++) {
  6024. var obj = this.getChildAt(i);
  6025. if (!this.foldInvisibleItems || obj.visible) {
  6026. dist = Math.abs(mid - obj.x - obj.width / 2);
  6027. if (dist < minDist) {
  6028. minDist = dist;
  6029. apexIndex = i;
  6030. }
  6031. }
  6032. }
  6033. this.apexIndex = apexIndex;
  6034. }
  6035. }
  6036. handleAlign(contentWidth, contentHeight) {
  6037. var newOffsetX = 0;
  6038. var newOffsetY = 0;
  6039. if (contentHeight < this.viewHeight) {
  6040. if (this._verticalAlign == fgui.VertAlignType.Middle)
  6041. newOffsetY = Math.floor((this.viewHeight - contentHeight) / 2);
  6042. else if (this._verticalAlign == fgui.VertAlignType.Bottom)
  6043. newOffsetY = this.viewHeight - contentHeight;
  6044. }
  6045. if (contentWidth < this.viewWidth) {
  6046. if (this._align == fgui.AlignType.Center)
  6047. newOffsetX = Math.floor((this.viewWidth - contentWidth) / 2);
  6048. else if (this._align == fgui.AlignType.Right)
  6049. newOffsetX = this.viewWidth - contentWidth;
  6050. }
  6051. if (newOffsetX != this._alignOffset.x || newOffsetY != this._alignOffset.y) {
  6052. this._alignOffset.x = newOffsetX;
  6053. this._alignOffset.y = newOffsetY;
  6054. if (this._scrollPane)
  6055. this._scrollPane.adjustMaskContainer();
  6056. else
  6057. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  6058. }
  6059. }
  6060. updateBounds() {
  6061. if (this._virtual)
  6062. return;
  6063. var i;
  6064. var child;
  6065. var curX = 0;
  6066. var curY = 0;
  6067. var maxWidth = 0;
  6068. var maxHeight = 0;
  6069. var cw = 0, ch = 0;
  6070. var j = 0;
  6071. var page = 0;
  6072. var k = 0;
  6073. var cnt = this._children.length;
  6074. var viewWidth = this.viewWidth;
  6075. var viewHeight = this.viewHeight;
  6076. var lineSize = 0;
  6077. var lineStart = 0;
  6078. var ratio = 0;
  6079. if (this._layout == fgui.ListLayoutType.SingleColumn) {
  6080. for (i = 0; i < cnt; i++) {
  6081. child = this.getChildAt(i);
  6082. if (this.foldInvisibleItems && !child.visible)
  6083. continue;
  6084. if (curY != 0)
  6085. curY += this._lineGap;
  6086. child.y = curY;
  6087. if (this._autoResizeItem)
  6088. child.setSize(viewWidth, child.height, true);
  6089. curY += Math.ceil(child.height);
  6090. if (child.width > maxWidth)
  6091. maxWidth = child.width;
  6092. }
  6093. ch = curY;
  6094. if (ch <= viewHeight && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.vtScrollBar) {
  6095. viewWidth += this._scrollPane.vtScrollBar.width;
  6096. for (i = 0; i < cnt; i++) {
  6097. child = this.getChildAt(i);
  6098. if (this.foldInvisibleItems && !child.visible)
  6099. continue;
  6100. child.setSize(viewWidth, child.height, true);
  6101. if (child.width > maxWidth)
  6102. maxWidth = child.width;
  6103. }
  6104. }
  6105. cw = Math.ceil(maxWidth);
  6106. }
  6107. else if (this._layout == fgui.ListLayoutType.SingleRow) {
  6108. for (i = 0; i < cnt; i++) {
  6109. child = this.getChildAt(i);
  6110. if (this.foldInvisibleItems && !child.visible)
  6111. continue;
  6112. if (curX != 0)
  6113. curX += this._columnGap;
  6114. child.x = curX;
  6115. if (this._autoResizeItem)
  6116. child.setSize(child.width, viewHeight, true);
  6117. curX += Math.ceil(child.width);
  6118. if (child.height > maxHeight)
  6119. maxHeight = child.height;
  6120. }
  6121. cw = curX;
  6122. if (cw <= viewWidth && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.hzScrollBar) {
  6123. viewHeight += this._scrollPane.hzScrollBar.height;
  6124. for (i = 0; i < cnt; i++) {
  6125. child = this.getChildAt(i);
  6126. if (this.foldInvisibleItems && !child.visible)
  6127. continue;
  6128. child.setSize(child.width, viewHeight, true);
  6129. if (child.height > maxHeight)
  6130. maxHeight = child.height;
  6131. }
  6132. }
  6133. ch = Math.ceil(maxHeight);
  6134. }
  6135. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6136. if (this._autoResizeItem && this._columnCount > 0) {
  6137. for (i = 0; i < cnt; i++) {
  6138. child = this.getChildAt(i);
  6139. if (this.foldInvisibleItems && !child.visible)
  6140. continue;
  6141. lineSize += child.sourceWidth;
  6142. j++;
  6143. if (j == this._columnCount || i == cnt - 1) {
  6144. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6145. curX = 0;
  6146. for (j = lineStart; j <= i; j++) {
  6147. child = this.getChildAt(j);
  6148. if (this.foldInvisibleItems && !child.visible)
  6149. continue;
  6150. child.setPosition(curX, curY);
  6151. if (j < i) {
  6152. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), child.height, true);
  6153. curX += Math.ceil(child.width) + this._columnGap;
  6154. }
  6155. else {
  6156. child.setSize(viewWidth - curX, child.height, true);
  6157. }
  6158. if (child.height > maxHeight)
  6159. maxHeight = child.height;
  6160. }
  6161. curY += Math.ceil(maxHeight) + this._lineGap;
  6162. maxHeight = 0;
  6163. j = 0;
  6164. lineStart = i + 1;
  6165. lineSize = 0;
  6166. }
  6167. }
  6168. ch = curY + Math.ceil(maxHeight);
  6169. cw = viewWidth;
  6170. }
  6171. else {
  6172. for (i = 0; i < cnt; i++) {
  6173. child = this.getChildAt(i);
  6174. if (this.foldInvisibleItems && !child.visible)
  6175. continue;
  6176. if (curX != 0)
  6177. curX += this._columnGap;
  6178. if ((this._columnCount != 0 && j >= this._columnCount) || (this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0)) {
  6179. curX = 0;
  6180. curY += Math.ceil(maxHeight) + this._lineGap;
  6181. maxHeight = 0;
  6182. j = 0;
  6183. }
  6184. child.setPosition(curX, curY);
  6185. curX += Math.ceil(child.width);
  6186. if (curX > maxWidth)
  6187. maxWidth = curX;
  6188. if (child.height > maxHeight)
  6189. maxHeight = child.height;
  6190. j++;
  6191. }
  6192. ch = curY + Math.ceil(maxHeight);
  6193. cw = Math.ceil(maxWidth);
  6194. }
  6195. }
  6196. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  6197. if (this._autoResizeItem && this._lineCount > 0) {
  6198. for (i = 0; i < cnt; i++) {
  6199. child = this.getChildAt(i);
  6200. if (this.foldInvisibleItems && !child.visible)
  6201. continue;
  6202. lineSize += child.sourceHeight;
  6203. j++;
  6204. if (j == this._lineCount || i == cnt - 1) {
  6205. ratio = (viewHeight - lineSize - (j - 1) * this._lineGap) / lineSize;
  6206. curY = 0;
  6207. for (j = lineStart; j <= i; j++) {
  6208. child = this.getChildAt(j);
  6209. if (this.foldInvisibleItems && !child.visible)
  6210. continue;
  6211. child.setPosition(curX, curY);
  6212. if (j < i) {
  6213. child.setSize(child.width, child.sourceHeight + Math.round(child.sourceHeight * ratio), true);
  6214. curY += Math.ceil(child.height) + this._lineGap;
  6215. }
  6216. else {
  6217. child.setSize(child.width, viewHeight - curY, true);
  6218. }
  6219. if (child.width > maxWidth)
  6220. maxWidth = child.width;
  6221. }
  6222. curX += Math.ceil(maxWidth) + this._columnGap;
  6223. maxWidth = 0;
  6224. j = 0;
  6225. lineStart = i + 1;
  6226. lineSize = 0;
  6227. }
  6228. }
  6229. cw = curX + Math.ceil(maxWidth);
  6230. ch = viewHeight;
  6231. }
  6232. else {
  6233. for (i = 0; i < cnt; i++) {
  6234. child = this.getChildAt(i);
  6235. if (this.foldInvisibleItems && !child.visible)
  6236. continue;
  6237. if (curY != 0)
  6238. curY += this._lineGap;
  6239. if ((this._lineCount != 0 && j >= this._lineCount) || (this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0)) {
  6240. curY = 0;
  6241. curX += Math.ceil(maxWidth) + this._columnGap;
  6242. maxWidth = 0;
  6243. j = 0;
  6244. }
  6245. child.setPosition(curX, curY);
  6246. curY += Math.ceil(child.height);
  6247. if (curY > maxHeight)
  6248. maxHeight = curY;
  6249. if (child.width > maxWidth)
  6250. maxWidth = child.width;
  6251. j++;
  6252. }
  6253. cw = curX + Math.ceil(maxWidth);
  6254. ch = Math.ceil(maxHeight);
  6255. }
  6256. }
  6257. else {
  6258. var eachHeight;
  6259. if (this._autoResizeItem && this._lineCount > 0)
  6260. eachHeight = Math.floor((viewHeight - (this._lineCount - 1) * this._lineGap) / this._lineCount);
  6261. if (this._autoResizeItem && this._columnCount > 0) {
  6262. for (i = 0; i < cnt; i++) {
  6263. child = this.getChildAt(i);
  6264. if (this.foldInvisibleItems && !child.visible)
  6265. continue;
  6266. if (j == 0 && ((this._lineCount != 0 && k >= this._lineCount) || (this._lineCount == 0 && curY + (this._lineCount > 0 ? eachHeight : child.height) > viewHeight))) {
  6267. page++;
  6268. curY = 0;
  6269. k = 0;
  6270. }
  6271. lineSize += child.sourceWidth;
  6272. j++;
  6273. if (j == this._columnCount || i == cnt - 1) {
  6274. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6275. curX = 0;
  6276. for (j = lineStart; j <= i; j++) {
  6277. child = this.getChildAt(j);
  6278. if (this.foldInvisibleItems && !child.visible)
  6279. continue;
  6280. child.setPosition(page * viewWidth + curX, curY);
  6281. if (j < i) {
  6282. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), this._lineCount > 0 ? eachHeight : child.height, true);
  6283. curX += Math.ceil(child.width) + this._columnGap;
  6284. }
  6285. else {
  6286. child.setSize(viewWidth - curX, this._lineCount > 0 ? eachHeight : child.height, true);
  6287. }
  6288. if (child.height > maxHeight)
  6289. maxHeight = child.height;
  6290. }
  6291. curY += Math.ceil(maxHeight) + this._lineGap;
  6292. maxHeight = 0;
  6293. j = 0;
  6294. lineStart = i + 1;
  6295. lineSize = 0;
  6296. k++;
  6297. }
  6298. }
  6299. }
  6300. else {
  6301. for (i = 0; i < cnt; i++) {
  6302. child = this.getChildAt(i);
  6303. if (this.foldInvisibleItems && !child.visible)
  6304. continue;
  6305. if (curX != 0)
  6306. curX += this._columnGap;
  6307. if (this._autoResizeItem && this._lineCount > 0)
  6308. child.setSize(child.width, eachHeight, true);
  6309. if ((this._columnCount != 0 && j >= this._columnCount) || (this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0)) {
  6310. curX = 0;
  6311. curY += Math.ceil(maxHeight) + this._lineGap;
  6312. maxHeight = 0;
  6313. j = 0;
  6314. k++;
  6315. if ((this._lineCount != 0 && k >= this._lineCount) || (this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0)) {
  6316. page++;
  6317. curY = 0;
  6318. k = 0;
  6319. }
  6320. }
  6321. child.setPosition(page * viewWidth + curX, curY);
  6322. curX += Math.ceil(child.width);
  6323. if (curX > maxWidth)
  6324. maxWidth = curX;
  6325. if (child.height > maxHeight)
  6326. maxHeight = child.height;
  6327. j++;
  6328. }
  6329. }
  6330. ch = page > 0 ? viewHeight : curY + Math.ceil(maxHeight);
  6331. cw = (page + 1) * viewWidth;
  6332. }
  6333. this.handleAlign(cw, ch);
  6334. this.setBounds(0, 0, cw, ch);
  6335. }
  6336. setup_beforeAdd(buffer, beginPos) {
  6337. super.setup_beforeAdd(buffer, beginPos);
  6338. buffer.seek(beginPos, 5);
  6339. this._layout = buffer.readByte();
  6340. this._selectionMode = buffer.readByte();
  6341. this._align = buffer.readByte();
  6342. this._verticalAlign = buffer.readByte();
  6343. this._lineGap = buffer.readShort();
  6344. this._columnGap = buffer.readShort();
  6345. this._lineCount = buffer.readShort();
  6346. this._columnCount = buffer.readShort();
  6347. this._autoResizeItem = buffer.readBool();
  6348. this._childrenRenderOrder = buffer.readByte();
  6349. this._apexIndex = buffer.readShort();
  6350. if (buffer.readBool()) {
  6351. this._margin.top = buffer.readInt();
  6352. this._margin.bottom = buffer.readInt();
  6353. this._margin.left = buffer.readInt();
  6354. this._margin.right = buffer.readInt();
  6355. }
  6356. var overflow = buffer.readByte();
  6357. if (overflow == fgui.OverflowType.Scroll) {
  6358. var savedPos = buffer.position;
  6359. buffer.seek(beginPos, 7);
  6360. this.setupScroll(buffer);
  6361. buffer.position = savedPos;
  6362. }
  6363. else
  6364. this.setupOverflow(overflow);
  6365. if (buffer.readBool())
  6366. buffer.skip(8);
  6367. if (buffer.version >= 2) {
  6368. this.scrollItemToViewOnClick = buffer.readBool();
  6369. this.foldInvisibleItems = buffer.readBool();
  6370. }
  6371. buffer.seek(beginPos, 8);
  6372. this._defaultItem = buffer.readS();
  6373. this.readItems(buffer);
  6374. }
  6375. readItems(buffer) {
  6376. var cnt;
  6377. var i;
  6378. var nextPos;
  6379. var str;
  6380. cnt = buffer.readShort();
  6381. for (i = 0; i < cnt; i++) {
  6382. nextPos = buffer.readShort();
  6383. nextPos += buffer.position;
  6384. str = buffer.readS();
  6385. if (str == null) {
  6386. str = this.defaultItem;
  6387. if (!str) {
  6388. buffer.position = nextPos;
  6389. continue;
  6390. }
  6391. }
  6392. var obj = this.getFromPool(str);
  6393. if (obj) {
  6394. this.addChild(obj);
  6395. this.setupItem(buffer, obj);
  6396. }
  6397. buffer.position = nextPos;
  6398. }
  6399. }
  6400. setupItem(buffer, obj) {
  6401. var str;
  6402. str = buffer.readS();
  6403. if (str != null)
  6404. obj.text = str;
  6405. str = buffer.readS();
  6406. if (str != null && obj instanceof fgui.GButton)
  6407. obj.selectedTitle = str;
  6408. str = buffer.readS();
  6409. if (str != null)
  6410. obj.icon = str;
  6411. str = buffer.readS();
  6412. if (str != null && obj instanceof fgui.GButton)
  6413. obj.selectedIcon = str;
  6414. str = buffer.readS();
  6415. if (str != null)
  6416. obj.name = str;
  6417. var cnt;
  6418. var i;
  6419. if (obj instanceof fgui.GComponent) {
  6420. cnt = buffer.readShort();
  6421. for (i = 0; i < cnt; i++) {
  6422. var cc = obj.getController(buffer.readS());
  6423. str = buffer.readS();
  6424. if (cc)
  6425. cc.selectedPageId = str;
  6426. }
  6427. if (buffer.version >= 2) {
  6428. cnt = buffer.readShort();
  6429. for (i = 0; i < cnt; i++) {
  6430. var target = buffer.readS();
  6431. var propertyId = buffer.readShort();
  6432. var value = buffer.readS();
  6433. var obj2 = obj.getChildByPath(target);
  6434. if (obj2)
  6435. obj2.setProp(propertyId, value);
  6436. }
  6437. }
  6438. }
  6439. }
  6440. setup_afterAdd(buffer, beginPos) {
  6441. super.setup_afterAdd(buffer, beginPos);
  6442. buffer.seek(beginPos, 6);
  6443. var i = buffer.readShort();
  6444. if (i != -1)
  6445. this._selectionController = this.parent.getControllerAt(i);
  6446. }
  6447. }
  6448. fgui.GList = GList;
  6449. var s_n = 0;
  6450. })(fgui || (fgui = {}));
  6451. (function (fgui) {
  6452. class GObjectPool {
  6453. constructor() {
  6454. this._count = 0;
  6455. this._pool = {};
  6456. }
  6457. clear() {
  6458. for (var i1 in this._pool) {
  6459. var arr = this._pool[i1];
  6460. var cnt = arr.length;
  6461. for (var i = 0; i < cnt; i++)
  6462. arr[i].dispose();
  6463. }
  6464. this._pool = {};
  6465. this._count = 0;
  6466. }
  6467. get count() {
  6468. return this._count;
  6469. }
  6470. getObject(url) {
  6471. url = fgui.UIPackage.normalizeURL(url);
  6472. if (url == null)
  6473. return null;
  6474. var arr = this._pool[url];
  6475. if (arr && arr.length) {
  6476. this._count--;
  6477. return arr.shift();
  6478. }
  6479. var child = fgui.UIPackage.createObjectFromURL(url);
  6480. return child;
  6481. }
  6482. getObjectFromPool(url) {
  6483. url = fgui.UIPackage.normalizeURL(url);
  6484. if (url == null)
  6485. return null;
  6486. var arr = this._pool[url];
  6487. if (arr && arr.length) {
  6488. this._count--;
  6489. return arr.shift();
  6490. }
  6491. return null;
  6492. }
  6493. returnObject(obj) {
  6494. var url = obj.resourceURL;
  6495. if (!url)
  6496. return;
  6497. var arr = this._pool[url];
  6498. if (arr == null) {
  6499. arr = new Array();
  6500. this._pool[url] = arr;
  6501. }
  6502. this._count++;
  6503. arr.push(obj);
  6504. }
  6505. }
  6506. fgui.GObjectPool = GObjectPool;
  6507. })(fgui || (fgui = {}));
  6508. (function (fgui) {
  6509. class GLoader extends fgui.GObject {
  6510. constructor() {
  6511. super();
  6512. this._frame = 0;
  6513. this._node.name = 'GLoader';
  6514. this._playing = true;
  6515. this._url = '';
  6516. this._fill = fgui.LoaderFillType.None;
  6517. this._align = fgui.AlignType.Left;
  6518. this._verticalAlign = fgui.VertAlignType.Top;
  6519. this._showErrorSign = true;
  6520. this._color = new cc.Color(255, 255, 255, 255);
  6521. this._container = new cc.Node('Image');
  6522. this._container.setAnchorPoint(0, 1);
  6523. this._node.addChild(this._container);
  6524. this._content = this._container.addComponent(fgui.MovieClip);
  6525. this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  6526. this._content.trim = false;
  6527. this._content.setPlaySettings();
  6528. }
  6529. dispose() {
  6530. if (this._contentItem == null) {
  6531. this.freeExternal(this._content.spriteFrame);
  6532. }
  6533. if (this._content2)
  6534. this._content2.dispose();
  6535. this._container.destroy();
  6536. super.dispose();
  6537. }
  6538. get url() {
  6539. return this._url;
  6540. }
  6541. set url(value) {
  6542. if (this._url == value)
  6543. return;
  6544. this._url = value;
  6545. this.loadContent();
  6546. this.updateGear(7);
  6547. }
  6548. get icon() {
  6549. return this._url;
  6550. }
  6551. set icon(value) {
  6552. this.url = value;
  6553. }
  6554. get align() {
  6555. return this._align;
  6556. }
  6557. set align(value) {
  6558. if (this._align != value) {
  6559. this._align = value;
  6560. this.updateLayout();
  6561. }
  6562. }
  6563. get verticalAlign() {
  6564. return this._verticalAlign;
  6565. }
  6566. set verticalAlign(value) {
  6567. if (this._verticalAlign != value) {
  6568. this._verticalAlign = value;
  6569. this.updateLayout();
  6570. }
  6571. }
  6572. get fill() {
  6573. return this._fill;
  6574. }
  6575. set fill(value) {
  6576. if (this._fill != value) {
  6577. this._fill = value;
  6578. this.updateLayout();
  6579. }
  6580. }
  6581. get shrinkOnly() {
  6582. return this._shrinkOnly;
  6583. }
  6584. set shrinkOnly(value) {
  6585. if (this._shrinkOnly != value) {
  6586. this._shrinkOnly = value;
  6587. this.updateLayout();
  6588. }
  6589. }
  6590. get autoSize() {
  6591. return this._autoSize;
  6592. }
  6593. set autoSize(value) {
  6594. if (this._autoSize != value) {
  6595. this._autoSize = value;
  6596. this.updateLayout();
  6597. }
  6598. }
  6599. get playing() {
  6600. return this._playing;
  6601. }
  6602. set playing(value) {
  6603. if (this._playing != value) {
  6604. this._playing = value;
  6605. if (this._content instanceof fgui.MovieClip)
  6606. this._content.playing = value;
  6607. this.updateGear(5);
  6608. }
  6609. }
  6610. get frame() {
  6611. return this._frame;
  6612. }
  6613. set frame(value) {
  6614. if (this._frame != value) {
  6615. this._frame = value;
  6616. if (this._content instanceof fgui.MovieClip)
  6617. this._content.frame = value;
  6618. this.updateGear(5);
  6619. }
  6620. }
  6621. get color() {
  6622. return this._color;
  6623. }
  6624. set color(value) {
  6625. this._color.set(value);
  6626. this.updateGear(4);
  6627. this._container.color = value;
  6628. }
  6629. get fillMethod() {
  6630. return this._content.fillMethod;
  6631. }
  6632. set fillMethod(value) {
  6633. this._content.fillMethod = value;
  6634. }
  6635. get fillOrigin() {
  6636. return this._content.fillOrigin;
  6637. }
  6638. set fillOrigin(value) {
  6639. this._content.fillOrigin = value;
  6640. }
  6641. get fillClockwise() {
  6642. return this._content.fillClockwise;
  6643. }
  6644. set fillClockwise(value) {
  6645. this._content.fillClockwise = value;
  6646. }
  6647. get fillAmount() {
  6648. return this._content.fillAmount;
  6649. }
  6650. set fillAmount(value) {
  6651. this._content.fillAmount = value;
  6652. }
  6653. get showErrorSign() {
  6654. return this._showErrorSign;
  6655. }
  6656. set showErrorSign(value) {
  6657. this._showErrorSign = value;
  6658. }
  6659. get component() {
  6660. return this._content2;
  6661. }
  6662. get texture() {
  6663. return this._content.spriteFrame;
  6664. }
  6665. set texture(value) {
  6666. this.url = null;
  6667. this._content.spriteFrame = value;
  6668. this._content.type = cc.Sprite.Type.SIMPLE;
  6669. if (value != null) {
  6670. this.sourceWidth = value.getRect().width;
  6671. this.sourceHeight = value.getRect().height;
  6672. }
  6673. else {
  6674. this.sourceWidth = this.sourceHeight = 0;
  6675. }
  6676. this.updateLayout();
  6677. }
  6678. loadContent() {
  6679. this.clearContent();
  6680. if (!this._url)
  6681. return;
  6682. if (fgui.ToolSet.startsWith(this._url, 'ui://'))
  6683. this.loadFromPackage(this._url);
  6684. else
  6685. this.loadExternal();
  6686. }
  6687. loadFromPackage(itemURL) {
  6688. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  6689. if (this._contentItem) {
  6690. this._contentItem = this._contentItem.getBranch();
  6691. this.sourceWidth = this._contentItem.width;
  6692. this.sourceHeight = this._contentItem.height;
  6693. this._contentItem = this._contentItem.getHighResolution();
  6694. this._contentItem.load();
  6695. if (this._autoSize)
  6696. this.setSize(this.sourceWidth, this.sourceHeight);
  6697. if (this._contentItem.type == fgui.PackageItemType.Image) {
  6698. this._contentItem.owner.getItemAssetAsync(this._contentItem, this.onLoadedItem.bind(this, itemURL));
  6699. }
  6700. else if (this._contentItem.type == fgui.PackageItemType.MovieClip) {
  6701. this._content.interval = this._contentItem.interval;
  6702. this._content.swing = this._contentItem.swing;
  6703. this._content.repeatDelay = this._contentItem.repeatDelay;
  6704. this._content.frames = this._contentItem.frames;
  6705. this.updateLayout();
  6706. }
  6707. else if (this._contentItem.type == fgui.PackageItemType.Component) {
  6708. var obj = fgui.UIPackage.createObjectFromURL(itemURL);
  6709. if (!obj)
  6710. this.setErrorState();
  6711. else if (!(obj instanceof fgui.GComponent)) {
  6712. obj.dispose();
  6713. this.setErrorState();
  6714. }
  6715. else {
  6716. this._content2 = obj;
  6717. this._container.addChild(this._content2.node);
  6718. this.updateLayout();
  6719. }
  6720. }
  6721. else
  6722. this.setErrorState();
  6723. }
  6724. else
  6725. this.setErrorState();
  6726. }
  6727. loadExternal() {
  6728. if (fgui.ToolSet.startsWith(this._url, 'http://') || fgui.ToolSet.startsWith(this._url, 'https://') || fgui.ToolSet.startsWith(this._url, '/'))
  6729. cc.assetManager.loadRemote(this._url, this.onLoaded.bind(this, this._url));
  6730. else
  6731. cc.resources.load(this._url, cc.Asset, this.onLoaded.bind(this, this._url));
  6732. }
  6733. onLoaded(url, err, asset) {
  6734. if (!this._url || !cc.isValid(this._node))
  6735. return;
  6736. if (this._url != url) {
  6737. return;
  6738. }
  6739. if (err) {
  6740. console.warn(err);
  6741. return;
  6742. }
  6743. if (asset instanceof cc.SpriteFrame)
  6744. this.onExternalLoadSuccess(asset);
  6745. else if (asset instanceof cc.Texture2D)
  6746. this.onExternalLoadSuccess(new cc.SpriteFrame(asset));
  6747. }
  6748. onLoadedItem(url, err, packageItem) {
  6749. if (!this._url || !cc.isValid(this._node))
  6750. return;
  6751. if (this._url != url) {
  6752. return;
  6753. }
  6754. if (err) {
  6755. console.warn(err);
  6756. return;
  6757. }
  6758. this.onExternalLoadSuccess(packageItem.asset);
  6759. }
  6760. freeExternal(texture) {
  6761. }
  6762. onExternalLoadSuccess(texture) {
  6763. this._content.spriteFrame = texture;
  6764. this._content.type = cc.Sprite.Type.SIMPLE;
  6765. if (this._content.fillMethod == 0) {
  6766. if (this._contentItem) {
  6767. if (this._contentItem.scale9Grid)
  6768. this._content.type = cc.Sprite.Type.SLICED;
  6769. else if (this._contentItem.scaleByTile)
  6770. this._content.type = cc.Sprite.Type.TILED;
  6771. else
  6772. this._content.type = cc.Sprite.Type.SIMPLE;
  6773. }
  6774. }
  6775. this.sourceWidth = texture.getRect().width;
  6776. this.sourceHeight = texture.getRect().height;
  6777. if (this._autoSize)
  6778. this.setSize(this.sourceWidth, this.sourceHeight);
  6779. this.updateLayout();
  6780. }
  6781. onExternalLoadFailed() {
  6782. this.setErrorState();
  6783. }
  6784. setErrorState() {
  6785. if (!this._showErrorSign)
  6786. return;
  6787. if (this._errorSign == null) {
  6788. if (fgui.UIConfig.loaderErrorSign != null) {
  6789. this._errorSign = GLoader._errorSignPool.getObject(fgui.UIConfig.loaderErrorSign);
  6790. }
  6791. }
  6792. if (this._errorSign) {
  6793. this._errorSign.setSize(this.width, this.height);
  6794. this._container.addChild(this._errorSign.node);
  6795. }
  6796. }
  6797. clearErrorState() {
  6798. if (this._errorSign) {
  6799. this._container.removeChild(this._errorSign.node);
  6800. GLoader._errorSignPool.returnObject(this._errorSign);
  6801. this._errorSign = null;
  6802. }
  6803. }
  6804. updateLayout() {
  6805. if (this._content2 == null && this._content == null) {
  6806. if (this._autoSize) {
  6807. this._updatingLayout = true;
  6808. this.setSize(50, 30);
  6809. this._updatingLayout = false;
  6810. }
  6811. return;
  6812. }
  6813. let cw = this.sourceWidth;
  6814. let ch = this.sourceHeight;
  6815. let pivotCorrectX = -this.pivotX * this._width;
  6816. let pivotCorrectY = this.pivotY * this._height;
  6817. if (this._autoSize) {
  6818. this._updatingLayout = true;
  6819. if (cw == 0)
  6820. cw = 50;
  6821. if (ch == 0)
  6822. ch = 30;
  6823. this.setSize(cw, ch);
  6824. this._updatingLayout = false;
  6825. this._container.setContentSize(this._width, this._height);
  6826. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  6827. if (this._content2) {
  6828. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  6829. this._content2.setScale(1, 1);
  6830. }
  6831. if (cw == this._width && ch == this._height)
  6832. return;
  6833. }
  6834. var sx = 1, sy = 1;
  6835. if (this._fill != fgui.LoaderFillType.None) {
  6836. sx = this.width / this.sourceWidth;
  6837. sy = this.height / this.sourceHeight;
  6838. if (sx != 1 || sy != 1) {
  6839. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  6840. sx = sy;
  6841. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  6842. sy = sx;
  6843. else if (this._fill == fgui.LoaderFillType.Scale) {
  6844. if (sx > sy)
  6845. sx = sy;
  6846. else
  6847. sy = sx;
  6848. }
  6849. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  6850. if (sx > sy)
  6851. sy = sx;
  6852. else
  6853. sx = sy;
  6854. }
  6855. if (this._shrinkOnly) {
  6856. if (sx > 1)
  6857. sx = 1;
  6858. if (sy > 1)
  6859. sy = 1;
  6860. }
  6861. cw = this.sourceWidth * sx;
  6862. ch = this.sourceHeight * sy;
  6863. }
  6864. }
  6865. this._container.setContentSize(cw, ch);
  6866. if (this._content2) {
  6867. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  6868. this._content2.setScale(sx, sy);
  6869. }
  6870. var nx, ny;
  6871. if (this._align == fgui.AlignType.Left)
  6872. nx = 0;
  6873. else if (this._align == fgui.AlignType.Center)
  6874. nx = Math.floor((this._width - cw) / 2);
  6875. else
  6876. nx = this._width - cw;
  6877. if (this._verticalAlign == fgui.VertAlignType.Top)
  6878. ny = 0;
  6879. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  6880. ny = Math.floor((this._height - ch) / 2);
  6881. else
  6882. ny = this._height - ch;
  6883. ny = -ny;
  6884. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  6885. }
  6886. clearContent() {
  6887. this.clearErrorState();
  6888. if (!this._contentItem) {
  6889. var texture = this._content.spriteFrame;
  6890. this.freeExternal(texture);
  6891. }
  6892. if (this._content2) {
  6893. this._container.removeChild(this._content2.node);
  6894. this._content2.dispose();
  6895. this._content2 = null;
  6896. }
  6897. this._content.frames = null;
  6898. this._content.spriteFrame = null;
  6899. this._contentItem = null;
  6900. }
  6901. handleSizeChanged() {
  6902. super.handleSizeChanged();
  6903. if (!this._updatingLayout)
  6904. this.updateLayout();
  6905. }
  6906. handleAnchorChanged() {
  6907. super.handleAnchorChanged();
  6908. if (!this._updatingLayout)
  6909. this.updateLayout();
  6910. }
  6911. handleGrayedChanged() {
  6912. this._content.grayed = this._grayed;
  6913. }
  6914. _hitTest(pt, globalPt) {
  6915. if (this._content2) {
  6916. let obj = this._content2.hitTest(globalPt);
  6917. if (obj)
  6918. return obj;
  6919. }
  6920. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  6921. return this;
  6922. else
  6923. return null;
  6924. }
  6925. getProp(index) {
  6926. switch (index) {
  6927. case fgui.ObjectPropID.Color:
  6928. return this.color;
  6929. case fgui.ObjectPropID.Playing:
  6930. return this.playing;
  6931. case fgui.ObjectPropID.Frame:
  6932. return this.frame;
  6933. case fgui.ObjectPropID.TimeScale:
  6934. return this._content.timeScale;
  6935. default:
  6936. return super.getProp(index);
  6937. }
  6938. }
  6939. setProp(index, value) {
  6940. switch (index) {
  6941. case fgui.ObjectPropID.Color:
  6942. this.color = value;
  6943. break;
  6944. case fgui.ObjectPropID.Playing:
  6945. this.playing = value;
  6946. break;
  6947. case fgui.ObjectPropID.Frame:
  6948. this.frame = value;
  6949. break;
  6950. case fgui.ObjectPropID.TimeScale:
  6951. this._content.timeScale = value;
  6952. break;
  6953. case fgui.ObjectPropID.DeltaTime:
  6954. this._content.advance(value);
  6955. break;
  6956. default:
  6957. super.setProp(index, value);
  6958. break;
  6959. }
  6960. }
  6961. setup_beforeAdd(buffer, beginPos) {
  6962. super.setup_beforeAdd(buffer, beginPos);
  6963. buffer.seek(beginPos, 5);
  6964. this._url = buffer.readS();
  6965. this._align = buffer.readByte();
  6966. this._verticalAlign = buffer.readByte();
  6967. this._fill = buffer.readByte();
  6968. this._shrinkOnly = buffer.readBool();
  6969. this._autoSize = buffer.readBool();
  6970. this._showErrorSign = buffer.readBool();
  6971. this._playing = buffer.readBool();
  6972. this._frame = buffer.readInt();
  6973. if (buffer.readBool())
  6974. this.color = buffer.readColor();
  6975. this._content.fillMethod = buffer.readByte();
  6976. if (this._content.fillMethod != 0) {
  6977. this._content.fillOrigin = buffer.readByte();
  6978. this._content.fillClockwise = buffer.readBool();
  6979. this._content.fillAmount = buffer.readFloat();
  6980. }
  6981. if (this._url)
  6982. this.loadContent();
  6983. }
  6984. }
  6985. GLoader._errorSignPool = new fgui.GObjectPool();
  6986. fgui.GLoader = GLoader;
  6987. })(fgui || (fgui = {}));
  6988. (function (fgui) {
  6989. class GLoader3D extends fgui.GObject {
  6990. constructor() {
  6991. super();
  6992. this._frame = 0;
  6993. this._premultipliedAlpha = false;
  6994. this._node.name = 'GLoader3D';
  6995. this._playing = true;
  6996. this._url = '';
  6997. this._fill = fgui.LoaderFillType.None;
  6998. this._align = fgui.AlignType.Left;
  6999. this._verticalAlign = fgui.VertAlignType.Top;
  7000. this._color = new cc.Color(255, 255, 255, 255);
  7001. this._container = new cc.Node('Wrapper');
  7002. this._container.setAnchorPoint(0, 1);
  7003. this._node.addChild(this._container);
  7004. }
  7005. dispose() {
  7006. super.dispose();
  7007. }
  7008. get url() {
  7009. return this._url;
  7010. }
  7011. set url(value) {
  7012. if (this._url == value)
  7013. return;
  7014. this._url = value;
  7015. this.loadContent();
  7016. this.updateGear(7);
  7017. }
  7018. get icon() {
  7019. return this._url;
  7020. }
  7021. set icon(value) {
  7022. this.url = value;
  7023. }
  7024. get align() {
  7025. return this._align;
  7026. }
  7027. set align(value) {
  7028. if (this._align != value) {
  7029. this._align = value;
  7030. this.updateLayout();
  7031. }
  7032. }
  7033. get verticalAlign() {
  7034. return this._verticalAlign;
  7035. }
  7036. set verticalAlign(value) {
  7037. if (this._verticalAlign != value) {
  7038. this._verticalAlign = value;
  7039. this.updateLayout();
  7040. }
  7041. }
  7042. get fill() {
  7043. return this._fill;
  7044. }
  7045. set fill(value) {
  7046. if (this._fill != value) {
  7047. this._fill = value;
  7048. this.updateLayout();
  7049. }
  7050. }
  7051. get shrinkOnly() {
  7052. return this._shrinkOnly;
  7053. }
  7054. set shrinkOnly(value) {
  7055. if (this._shrinkOnly != value) {
  7056. this._shrinkOnly = value;
  7057. this.updateLayout();
  7058. }
  7059. }
  7060. get autoSize() {
  7061. return this._autoSize;
  7062. }
  7063. set autoSize(value) {
  7064. if (this._autoSize != value) {
  7065. this._autoSize = value;
  7066. this.updateLayout();
  7067. }
  7068. }
  7069. get playing() {
  7070. return this._playing;
  7071. }
  7072. set playing(value) {
  7073. if (this._playing != value) {
  7074. this._playing = value;
  7075. this.updateGear(5);
  7076. this.onChange();
  7077. }
  7078. }
  7079. get frame() {
  7080. return this._frame;
  7081. }
  7082. set frame(value) {
  7083. if (this._frame != value) {
  7084. this._frame = value;
  7085. this.updateGear(5);
  7086. this.onChange();
  7087. }
  7088. }
  7089. get animationName() {
  7090. return this._animationName;
  7091. }
  7092. set animationName(value) {
  7093. if (this._animationName != value) {
  7094. this._animationName = value;
  7095. this.onChange();
  7096. }
  7097. }
  7098. get skinName() {
  7099. return this._skinName;
  7100. }
  7101. set skinName(value) {
  7102. if (this._skinName != value) {
  7103. this._skinName = value;
  7104. this.onChange();
  7105. }
  7106. }
  7107. get loop() {
  7108. return this._loop;
  7109. }
  7110. set loop(value) {
  7111. if (this._loop != value) {
  7112. this._loop = value;
  7113. this.onChange();
  7114. }
  7115. }
  7116. get color() {
  7117. return this._color;
  7118. }
  7119. set color(value) {
  7120. this._color.set(value);
  7121. this.updateGear(4);
  7122. if (this._content)
  7123. this._content.node.color = value;
  7124. }
  7125. get content() {
  7126. return this._content;
  7127. }
  7128. loadContent() {
  7129. this.clearContent();
  7130. if (!this._url)
  7131. return;
  7132. if (fgui.ToolSet.startsWith(this._url, 'ui://'))
  7133. this.loadFromPackage(this._url);
  7134. else
  7135. this.loadExternal();
  7136. }
  7137. loadFromPackage(itemURL) {
  7138. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7139. if (this._contentItem) {
  7140. this._contentItem = this._contentItem.getBranch();
  7141. this.sourceWidth = this._contentItem.width;
  7142. this.sourceHeight = this._contentItem.height;
  7143. this._contentItem = this._contentItem.getHighResolution();
  7144. if (this._autoSize)
  7145. this.setSize(this.sourceWidth, this.sourceHeight);
  7146. if (this._contentItem.type == fgui.PackageItemType.Spine || this._contentItem.type == fgui.PackageItemType.DragonBones)
  7147. this._contentItem.owner.getItemAssetAsync(this._contentItem, this.onLoaded.bind(this));
  7148. }
  7149. }
  7150. onLoaded(err, item) {
  7151. if (!this._node) {
  7152. return;
  7153. }
  7154. if (!cc.isValid(this._node))
  7155. return;
  7156. if (this._contentItem != item)
  7157. return;
  7158. if (err)
  7159. console.warn(err);
  7160. if (!this._contentItem.asset)
  7161. return;
  7162. if (this._contentItem.type == fgui.PackageItemType.Spine)
  7163. this.setSpine(this._contentItem.asset, this._contentItem.skeletonAnchor);
  7164. else if (this._contentItem.type == fgui.PackageItemType.DragonBones)
  7165. this.setDragonBones(this._contentItem.asset, this._contentItem.atlasAsset, this._contentItem.skeletonAnchor);
  7166. }
  7167. setSpine(asset, anchor, pma) {
  7168. this.url = null;
  7169. this.clearContent();
  7170. let node = new cc.Node();
  7171. node.color = this._color;
  7172. this._container.addChild(node);
  7173. if (!anchor) {
  7174. let skeleton = asset.getRuntimeData();
  7175. anchor = new cc.Vec2(skeleton.x + skeleton.width, skeleton.y + skeleton.height);
  7176. this.sourceWidth = skeleton.width;
  7177. this.sourceHeight = skeleton.height;
  7178. if (this._autoSize)
  7179. this.setSize(this.sourceWidth, this.sourceHeight);
  7180. }
  7181. node.setPosition(anchor.x, -anchor.y);
  7182. this._content = node.addComponent(sp.Skeleton);
  7183. this._content.premultipliedAlpha = this._premultipliedAlpha;
  7184. if (!asset.textures) {
  7185. console.warn('骨骼动画加载错误 textures是空');
  7186. }
  7187. this._content.skeletonData = asset;
  7188. this._contentAsset = asset;
  7189. this.onChangeSpine();
  7190. this.updateLayout();
  7191. }
  7192. setDragonBones(asset, atlasAsset, anchor, pma) {
  7193. this.url = null;
  7194. this.clearContent();
  7195. let node = new cc.Node();
  7196. node.color = this._color;
  7197. this._container.addChild(node);
  7198. node.setPosition(anchor.x, -anchor.y);
  7199. this._content = node.addComponent(dragonBones.ArmatureDisplay);
  7200. this._content.premultipliedAlpha = this._premultipliedAlpha;
  7201. this._content.dragonAsset = asset;
  7202. this._content.dragonAtlasAsset = atlasAsset;
  7203. this._contentAsset = asset;
  7204. let armatureKey = asset['init'](dragonBones.CCFactory.getInstance(), atlasAsset['_uuid']);
  7205. let dragonBonesData = this._content['_factory'].getDragonBonesData(armatureKey);
  7206. this._content.armatureName = dragonBonesData.armatureNames[0];
  7207. this.onChangeDragonBones();
  7208. this.updateLayout();
  7209. }
  7210. set premultipliedAlpha(value) {
  7211. this._premultipliedAlpha = value;
  7212. }
  7213. onChange() {
  7214. this.onChangeSpine();
  7215. this.onChangeDragonBones();
  7216. }
  7217. onChangeSpine() {
  7218. if (!(this._content instanceof sp.Skeleton))
  7219. return;
  7220. if (this._animationName) {
  7221. let trackEntry = this._content.getCurrent(0);
  7222. if (!trackEntry || trackEntry.animation.name != this._animationName || (trackEntry.isComplete() && !trackEntry.loop)) {
  7223. this._content.defaultAnimation = this._animationName;
  7224. trackEntry = this._content.setAnimation(0, this._animationName, this._loop);
  7225. }
  7226. if (this._playing)
  7227. this._content.paused = false;
  7228. else {
  7229. this._content.paused = true;
  7230. trackEntry.trackTime = fgui.ToolSet.lerp(0, trackEntry.animationEnd - trackEntry.animationStart, this._frame / 100);
  7231. }
  7232. }
  7233. else
  7234. this._content.clearTrack(0);
  7235. let skin = this._skinName || this._content.skeletonData.getRuntimeData().skins[0].name;
  7236. if (this._content['_skeleton'].skin != skin)
  7237. this._content.setSkin(skin);
  7238. }
  7239. onChangeDragonBones() {
  7240. if (!(this._content instanceof dragonBones.ArmatureDisplay))
  7241. return;
  7242. if (this._animationName) {
  7243. if (this._playing)
  7244. this._content.playAnimation(this._animationName, this._loop ? 0 : 1);
  7245. else
  7246. this._content.armature().animation.gotoAndStopByFrame(this._animationName, this._frame);
  7247. }
  7248. else
  7249. this._content.armature().animation.reset();
  7250. }
  7251. loadExternal() {
  7252. if (fgui.ToolSet.startsWith(this._url, 'http://') || fgui.ToolSet.startsWith(this._url, 'https://') || fgui.ToolSet.startsWith(this._url, '/'))
  7253. cc.assetManager.loadRemote(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7254. else
  7255. cc.resources.load(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7256. }
  7257. onLoaded2(err, asset) {
  7258. if (!this._url || !cc.isValid(this._node))
  7259. return;
  7260. if (err)
  7261. console.warn(err);
  7262. if (!this._node) {
  7263. return;
  7264. }
  7265. if (!asset)
  7266. return;
  7267. asset.addRef();
  7268. this.setSpine(asset);
  7269. }
  7270. updateLayout() {
  7271. let cw = this.sourceWidth;
  7272. let ch = this.sourceHeight;
  7273. let pivotCorrectX = -this.pivotX * this._width;
  7274. let pivotCorrectY = this.pivotY * this._height;
  7275. if (this._autoSize) {
  7276. this._updatingLayout = true;
  7277. if (cw == 0)
  7278. cw = 50;
  7279. if (ch == 0)
  7280. ch = 30;
  7281. this.setSize(cw, ch);
  7282. this._updatingLayout = false;
  7283. if (cw == this._width && ch == this._height) {
  7284. this._container.setScale(1, 1);
  7285. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  7286. return;
  7287. }
  7288. }
  7289. var sx = 1, sy = 1;
  7290. if (this._fill != fgui.LoaderFillType.None) {
  7291. sx = this.width / this.sourceWidth;
  7292. sy = this.height / this.sourceHeight;
  7293. if (sx != 1 || sy != 1) {
  7294. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7295. sx = sy;
  7296. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7297. sy = sx;
  7298. else if (this._fill == fgui.LoaderFillType.Scale) {
  7299. if (sx > sy)
  7300. sx = sy;
  7301. else
  7302. sy = sx;
  7303. }
  7304. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7305. if (sx > sy)
  7306. sy = sx;
  7307. else
  7308. sx = sy;
  7309. }
  7310. if (this._shrinkOnly) {
  7311. if (sx > 1)
  7312. sx = 1;
  7313. if (sy > 1)
  7314. sy = 1;
  7315. }
  7316. cw = this.sourceWidth * sx;
  7317. ch = this.sourceHeight * sy;
  7318. }
  7319. }
  7320. this._container.setScale(sx, sy);
  7321. var nx, ny;
  7322. if (this._align == fgui.AlignType.Left)
  7323. nx = 0;
  7324. else if (this._align == fgui.AlignType.Center)
  7325. nx = Math.floor((this._width - cw) / 2);
  7326. else
  7327. nx = this._width - cw;
  7328. if (this._verticalAlign == fgui.VertAlignType.Top)
  7329. ny = 0;
  7330. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  7331. ny = Math.floor((this._height - ch) / 2);
  7332. else
  7333. ny = this._height - ch;
  7334. ny = -ny;
  7335. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  7336. }
  7337. clearContent() {
  7338. this._contentItem = null;
  7339. if (this._content) {
  7340. if (this._contentAsset) {
  7341. this._contentAsset = null;
  7342. }
  7343. this._content.node.destroy();
  7344. this._content = null;
  7345. }
  7346. }
  7347. handleSizeChanged() {
  7348. super.handleSizeChanged();
  7349. if (!this._updatingLayout)
  7350. this.updateLayout();
  7351. }
  7352. handleAnchorChanged() {
  7353. super.handleAnchorChanged();
  7354. if (!this._updatingLayout)
  7355. this.updateLayout();
  7356. }
  7357. handleGrayedChanged() { }
  7358. getProp(index) {
  7359. switch (index) {
  7360. case fgui.ObjectPropID.Color:
  7361. return this.color;
  7362. case fgui.ObjectPropID.Playing:
  7363. return this.playing;
  7364. case fgui.ObjectPropID.Frame:
  7365. return this.frame;
  7366. case fgui.ObjectPropID.TimeScale:
  7367. return 1;
  7368. default:
  7369. return super.getProp(index);
  7370. }
  7371. }
  7372. setProp(index, value) {
  7373. switch (index) {
  7374. case fgui.ObjectPropID.Color:
  7375. this.color = value;
  7376. break;
  7377. case fgui.ObjectPropID.Playing:
  7378. this.playing = value;
  7379. break;
  7380. case fgui.ObjectPropID.Frame:
  7381. this.frame = value;
  7382. break;
  7383. case fgui.ObjectPropID.TimeScale:
  7384. break;
  7385. case fgui.ObjectPropID.DeltaTime:
  7386. break;
  7387. default:
  7388. super.setProp(index, value);
  7389. break;
  7390. }
  7391. }
  7392. setup_beforeAdd(buffer, beginPos) {
  7393. super.setup_beforeAdd(buffer, beginPos);
  7394. buffer.seek(beginPos, 5);
  7395. this._url = buffer.readS();
  7396. this._align = buffer.readByte();
  7397. this._verticalAlign = buffer.readByte();
  7398. this._fill = buffer.readByte();
  7399. this._shrinkOnly = buffer.readBool();
  7400. this._autoSize = buffer.readBool();
  7401. this._animationName = buffer.readS();
  7402. this._skinName = buffer.readS();
  7403. this._playing = buffer.readBool();
  7404. this._frame = buffer.readInt();
  7405. this._loop = buffer.readBool();
  7406. if (buffer.readBool())
  7407. this.color = buffer.readColor();
  7408. if (this._url)
  7409. this.loadContent();
  7410. }
  7411. }
  7412. fgui.GLoader3D = GLoader3D;
  7413. })(fgui || (fgui = {}));
  7414. (function (fgui) {
  7415. class GMovieClip extends fgui.GObject {
  7416. constructor() {
  7417. super();
  7418. this._node.name = "GMovieClip";
  7419. this._touchDisabled = true;
  7420. this._content = this._node.addComponent(fgui.MovieClip);
  7421. this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  7422. this._content.trim = false;
  7423. this._content.setPlaySettings();
  7424. }
  7425. get color() {
  7426. return this._node.color;
  7427. }
  7428. set color(value) {
  7429. this._node.color = value;
  7430. this.updateGear(4);
  7431. }
  7432. get playing() {
  7433. return this._content.playing;
  7434. }
  7435. set playing(value) {
  7436. if (this._content.playing != value) {
  7437. this._content.playing = value;
  7438. this.updateGear(5);
  7439. }
  7440. }
  7441. get frame() {
  7442. return this._content.frame;
  7443. }
  7444. set frame(value) {
  7445. if (this._content.frame != value) {
  7446. this._content.frame = value;
  7447. this.updateGear(5);
  7448. }
  7449. }
  7450. get timeScale() {
  7451. return this._content.timeScale;
  7452. }
  7453. set timeScale(value) {
  7454. this._content.timeScale = value;
  7455. }
  7456. rewind() {
  7457. this._content.rewind();
  7458. }
  7459. syncStatus(anotherMc) {
  7460. this._content.syncStatus(anotherMc._content);
  7461. }
  7462. advance(timeInMiniseconds) {
  7463. this._content.advance(timeInMiniseconds);
  7464. }
  7465. setPlaySettings(start, end, times, endAt, endCallback, callbackObj) {
  7466. this._content.setPlaySettings(start, end, times, endAt, endCallback, callbackObj);
  7467. }
  7468. handleGrayedChanged() {
  7469. this._content.grayed = this._grayed;
  7470. }
  7471. handleSizeChanged() {
  7472. super.handleSizeChanged();
  7473. this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  7474. }
  7475. getProp(index) {
  7476. switch (index) {
  7477. case fgui.ObjectPropID.Color:
  7478. return this.color;
  7479. case fgui.ObjectPropID.Playing:
  7480. return this.playing;
  7481. case fgui.ObjectPropID.Frame:
  7482. return this.frame;
  7483. case fgui.ObjectPropID.TimeScale:
  7484. return this.timeScale;
  7485. default:
  7486. return super.getProp(index);
  7487. }
  7488. }
  7489. setProp(index, value) {
  7490. switch (index) {
  7491. case fgui.ObjectPropID.Color:
  7492. this.color = value;
  7493. break;
  7494. case fgui.ObjectPropID.Playing:
  7495. this.playing = value;
  7496. break;
  7497. case fgui.ObjectPropID.Frame:
  7498. this.frame = value;
  7499. break;
  7500. case fgui.ObjectPropID.TimeScale:
  7501. this.timeScale = value;
  7502. break;
  7503. case fgui.ObjectPropID.DeltaTime:
  7504. this.advance(value);
  7505. break;
  7506. default:
  7507. super.setProp(index, value);
  7508. break;
  7509. }
  7510. }
  7511. constructFromResource() {
  7512. var contentItem = this.packageItem.getBranch();
  7513. this.sourceWidth = contentItem.width;
  7514. this.sourceHeight = contentItem.height;
  7515. this.initWidth = this.sourceWidth;
  7516. this.initHeight = this.sourceHeight;
  7517. this.setSize(this.sourceWidth, this.sourceHeight);
  7518. contentItem = contentItem.getHighResolution();
  7519. contentItem.load();
  7520. this._content.interval = contentItem.interval;
  7521. this._content.swing = contentItem.swing;
  7522. this._content.repeatDelay = contentItem.repeatDelay;
  7523. this._content.frames = contentItem.frames;
  7524. this._content.smoothing = contentItem.smoothing;
  7525. }
  7526. setup_beforeAdd(buffer, beginPos) {
  7527. super.setup_beforeAdd(buffer, beginPos);
  7528. buffer.seek(beginPos, 5);
  7529. if (buffer.readBool())
  7530. this.color = buffer.readColor();
  7531. buffer.readByte();
  7532. this._content.frame = buffer.readInt();
  7533. this._content.playing = buffer.readBool();
  7534. }
  7535. }
  7536. fgui.GMovieClip = GMovieClip;
  7537. })(fgui || (fgui = {}));
  7538. (function (fgui) {
  7539. class GProgressBar extends fgui.GComponent {
  7540. constructor() {
  7541. super();
  7542. this._min = 0;
  7543. this._max = 0;
  7544. this._value = 0;
  7545. this._barMaxWidth = 0;
  7546. this._barMaxHeight = 0;
  7547. this._barMaxWidthDelta = 0;
  7548. this._barMaxHeightDelta = 0;
  7549. this._barStartX = 0;
  7550. this._barStartY = 0;
  7551. this._node.name = 'GProgressBar';
  7552. this._titleType = fgui.ProgressTitleType.Percent;
  7553. this._value = 50;
  7554. this._max = 100;
  7555. }
  7556. onDestroy() {
  7557. var tweener = fgui.GTween.getTween(this, this.update);
  7558. if (tweener) {
  7559. tweener.kill();
  7560. }
  7561. super.onDestroy();
  7562. }
  7563. get titleType() {
  7564. return this._titleType;
  7565. }
  7566. set titleType(value) {
  7567. if (this._titleType != value) {
  7568. this._titleType = value;
  7569. this.update(this._value);
  7570. }
  7571. }
  7572. get min() {
  7573. return this._min;
  7574. }
  7575. set min(value) {
  7576. if (this._min != value) {
  7577. this._min = value;
  7578. this.update(this._value);
  7579. }
  7580. }
  7581. get max() {
  7582. return this._max;
  7583. }
  7584. set max(value) {
  7585. if (this._max != value) {
  7586. this._max = value;
  7587. this.update(this._value);
  7588. }
  7589. }
  7590. get value() {
  7591. return this._value;
  7592. }
  7593. set value(value) {
  7594. if (this._value != value) {
  7595. fgui.GTween.kill(this, false, this.update);
  7596. this._value = value;
  7597. this.update(value);
  7598. }
  7599. }
  7600. tweenValue(value, duration) {
  7601. var oldValule;
  7602. var tweener = fgui.GTween.getTween(this, this.update);
  7603. if (tweener) {
  7604. oldValule = tweener.value.x;
  7605. tweener.kill();
  7606. }
  7607. else
  7608. oldValule = this._value;
  7609. this._value = value;
  7610. return fgui.GTween.to(oldValule, this._value, duration).setTarget(this, this.update).setEase(fgui.EaseType.Linear);
  7611. }
  7612. update(newValue) {
  7613. var percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  7614. if (this._titleObject) {
  7615. switch (this._titleType) {
  7616. case fgui.ProgressTitleType.Percent:
  7617. this._titleObject.text = Math.floor(percent * 100) + '%';
  7618. break;
  7619. case fgui.ProgressTitleType.ValueAndMax:
  7620. this._titleObject.text = Math.floor(newValue) + '/' + Math.floor(this._max);
  7621. break;
  7622. case fgui.ProgressTitleType.Value:
  7623. this._titleObject.text = '' + Math.floor(newValue);
  7624. break;
  7625. case fgui.ProgressTitleType.Max:
  7626. this._titleObject.text = '' + Math.floor(this._max);
  7627. break;
  7628. }
  7629. }
  7630. var fullWidth = this.width - this._barMaxWidthDelta;
  7631. var fullHeight = this.height - this._barMaxHeightDelta;
  7632. if (!this._reverse) {
  7633. if (this._barObjectH) {
  7634. if (!this.setFillAmount(this._barObjectH, percent))
  7635. this._barObjectH.width = Math.round(fullWidth * percent);
  7636. }
  7637. if (this._barObjectV) {
  7638. if (!this.setFillAmount(this._barObjectV, percent))
  7639. this._barObjectV.height = Math.round(fullHeight * percent);
  7640. }
  7641. }
  7642. else {
  7643. if (this._barObjectH) {
  7644. if (!this.setFillAmount(this._barObjectH, 1 - percent)) {
  7645. this._barObjectH.width = Math.round(fullWidth * percent);
  7646. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  7647. }
  7648. }
  7649. if (this._barObjectV) {
  7650. if (!this.setFillAmount(this._barObjectV, 1 - percent)) {
  7651. this._barObjectV.height = Math.round(fullHeight * percent);
  7652. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  7653. }
  7654. }
  7655. }
  7656. if (this._aniObject)
  7657. this._aniObject.setProp(fgui.ObjectPropID.Frame, Math.floor(percent * 100));
  7658. }
  7659. setFillAmount(bar, percent) {
  7660. if ((bar instanceof fgui.GImage || bar instanceof fgui.GLoader) && bar.fillMethod != fgui.FillMethod.None) {
  7661. bar.fillAmount = percent;
  7662. return true;
  7663. }
  7664. else
  7665. return false;
  7666. }
  7667. constructExtension(buffer) {
  7668. buffer.seek(0, 6);
  7669. this._titleType = buffer.readByte();
  7670. this._reverse = buffer.readBool();
  7671. this._titleObject = this.getChild('title');
  7672. this._barObjectH = this.getChild('bar');
  7673. this._barObjectV = this.getChild('bar_v');
  7674. this._aniObject = this.getChild('ani');
  7675. if (this._barObjectH) {
  7676. this._barMaxWidth = this._barObjectH.width;
  7677. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  7678. this._barStartX = this._barObjectH.x;
  7679. }
  7680. if (this._barObjectV) {
  7681. this._barMaxHeight = this._barObjectV.height;
  7682. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  7683. this._barStartY = this._barObjectV.y;
  7684. }
  7685. }
  7686. handleSizeChanged() {
  7687. super.handleSizeChanged();
  7688. if (this._barObjectH)
  7689. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  7690. if (this._barObjectV)
  7691. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  7692. if (!this._underConstruct)
  7693. this.update(this._value);
  7694. }
  7695. setup_afterAdd(buffer, beginPos) {
  7696. super.setup_afterAdd(buffer, beginPos);
  7697. if (!buffer.seek(beginPos, 6)) {
  7698. this.update(this._value);
  7699. return;
  7700. }
  7701. if (buffer.readByte() != this.packageItem.objectType) {
  7702. this.update(this._value);
  7703. return;
  7704. }
  7705. this._value = buffer.readInt();
  7706. this._max = buffer.readInt();
  7707. if (buffer.version >= 2)
  7708. this._min = buffer.readInt();
  7709. this.update(this._value);
  7710. }
  7711. }
  7712. fgui.GProgressBar = GProgressBar;
  7713. })(fgui || (fgui = {}));
  7714. (function (fgui) {
  7715. class GTextField extends fgui.GObject {
  7716. constructor() {
  7717. super();
  7718. this._fontSize = 0;
  7719. this._leading = 0;
  7720. this._node.name = 'GTextField';
  7721. this._touchDisabled = true;
  7722. this._text = '';
  7723. this._color = new cc.Color(255, 255, 255, 255);
  7724. this.createRenderer();
  7725. this.fontSize = 12;
  7726. this.leading = 3;
  7727. this.singleLine = false;
  7728. this._sizeDirty = false;
  7729. this._node.on(cc.Node.EventType.SIZE_CHANGED, this.onLabelSizeChanged, this);
  7730. }
  7731. createRenderer() {
  7732. this._label = this._node.addComponent(cc.Label);
  7733. this.autoSize = fgui.AutoSizeType.Both;
  7734. }
  7735. set text(value) {
  7736. this._text = value;
  7737. if (this._text == null)
  7738. this._text = '';
  7739. this.updateGear(6);
  7740. this.markSizeChanged();
  7741. this.updateText();
  7742. }
  7743. get text() {
  7744. return this._text;
  7745. }
  7746. get font() {
  7747. return this._font;
  7748. }
  7749. set font(value) {
  7750. if (this._font != value || !value) {
  7751. this._font = value;
  7752. this.markSizeChanged();
  7753. let newFont = value ? value : fgui.UIConfig.defaultFont;
  7754. if (fgui.ToolSet.startsWith(newFont, 'ui://')) {
  7755. var pi = fgui.UIPackage.getItemByURL(newFont);
  7756. if (pi)
  7757. newFont = pi.owner.getItemAsset(pi);
  7758. else
  7759. newFont = fgui.UIConfig.defaultFont;
  7760. }
  7761. this._realFont = newFont;
  7762. this.updateFont();
  7763. }
  7764. }
  7765. get fontSize() {
  7766. return this._fontSize;
  7767. }
  7768. set fontSize(value) {
  7769. if (value < 0)
  7770. return;
  7771. if (this._fontSize != value) {
  7772. this._fontSize = value;
  7773. this.markSizeChanged();
  7774. this.updateFontSize();
  7775. }
  7776. }
  7777. get color() {
  7778. return this._color;
  7779. }
  7780. set color(value) {
  7781. this._color.set(value);
  7782. this.updateGear(4);
  7783. this.updateFontColor();
  7784. }
  7785. get align() {
  7786. return this._label ? this._label.horizontalAlign : 0;
  7787. }
  7788. set align(value) {
  7789. if (this._label)
  7790. this._label.horizontalAlign = value;
  7791. }
  7792. get verticalAlign() {
  7793. return this._label ? this._label.verticalAlign : 0;
  7794. }
  7795. set verticalAlign(value) {
  7796. if (this._label)
  7797. this._label.verticalAlign = value;
  7798. }
  7799. get leading() {
  7800. return this._leading;
  7801. }
  7802. set leading(value) {
  7803. if (this._leading != value) {
  7804. this._leading = value;
  7805. this.markSizeChanged();
  7806. this.updateFontSize();
  7807. }
  7808. }
  7809. get letterSpacing() {
  7810. return this._label ? this._label.spacingX : 0;
  7811. }
  7812. set letterSpacing(value) {
  7813. if (this._label && this._label.spacingX != value) {
  7814. this.markSizeChanged();
  7815. this._label.spacingX = value;
  7816. }
  7817. }
  7818. get underline() {
  7819. return this._label ? this._label.enableUnderline : false;
  7820. }
  7821. set underline(value) {
  7822. if (this._label)
  7823. this._label.enableUnderline = value;
  7824. }
  7825. get bold() {
  7826. return this._label ? this._label.enableBold : false;
  7827. }
  7828. set bold(value) {
  7829. if (this._label)
  7830. this._label.enableBold = value;
  7831. }
  7832. get italic() {
  7833. return this._label ? this._label.enableItalic : false;
  7834. }
  7835. set italic(value) {
  7836. if (this._label)
  7837. this._label.enableItalic = value;
  7838. }
  7839. get singleLine() {
  7840. return this._label ? !this._label.enableWrapText : false;
  7841. }
  7842. set singleLine(value) {
  7843. if (this._label)
  7844. this._label.enableWrapText = !value;
  7845. }
  7846. get stroke() {
  7847. return this._outline && this._outline.enabled ? this._outline.width : 0;
  7848. }
  7849. set stroke(value) {
  7850. if (value == 0) {
  7851. if (this._outline)
  7852. this._outline.enabled = false;
  7853. }
  7854. else {
  7855. if (!this._outline) {
  7856. this._outline = this._node.addComponent(cc.LabelOutline);
  7857. this.updateStrokeColor();
  7858. }
  7859. else
  7860. this._outline.enabled = true;
  7861. this._outline.width = value;
  7862. }
  7863. }
  7864. get strokeColor() {
  7865. return this._strokeColor;
  7866. }
  7867. set strokeColor(value) {
  7868. if (!this._strokeColor)
  7869. this._strokeColor = new cc.Color();
  7870. this._strokeColor.set(value);
  7871. this.updateGear(4);
  7872. this.updateStrokeColor();
  7873. }
  7874. get shadowOffset() {
  7875. return this._shadowOffset;
  7876. }
  7877. set shadowOffset(value) {
  7878. if (!this._shadowOffset)
  7879. this._shadowOffset = new cc.Vec2();
  7880. this._shadowOffset.set(value);
  7881. if (this._shadowOffset.x != 0 || this._shadowOffset.y != 0) {
  7882. if (!this._shadow) {
  7883. this._shadow = this._node.addComponent(cc.LabelShadow);
  7884. this.updateShadowColor();
  7885. }
  7886. else
  7887. this._shadow.enabled = true;
  7888. this._shadow.offset.x = value.x;
  7889. this._shadow.offset.y = -value.y;
  7890. }
  7891. else if (this._shadow)
  7892. this._shadow.enabled = false;
  7893. }
  7894. get shadowColor() {
  7895. return this._shadowColor;
  7896. }
  7897. set shadowColor(value) {
  7898. if (!this._shadowColor)
  7899. this._shadowColor = new cc.Color();
  7900. this._shadowColor.set(value);
  7901. this.updateShadowColor();
  7902. }
  7903. set ubbEnabled(value) {
  7904. if (this._ubbEnabled != value) {
  7905. this._ubbEnabled = value;
  7906. this.markSizeChanged();
  7907. this.updateText();
  7908. }
  7909. }
  7910. get ubbEnabled() {
  7911. return this._ubbEnabled;
  7912. }
  7913. set autoSize(value) {
  7914. if (this._autoSize != value) {
  7915. this._autoSize = value;
  7916. this.markSizeChanged();
  7917. this.updateOverflow();
  7918. }
  7919. }
  7920. get autoSize() {
  7921. return this._autoSize;
  7922. }
  7923. parseTemplate(template) {
  7924. var pos1 = 0, pos2, pos3;
  7925. var tag;
  7926. var value;
  7927. var result = '';
  7928. while ((pos2 = template.indexOf('{', pos1)) != -1) {
  7929. if (pos2 > 0 && template.charCodeAt(pos2 - 1) == 92) {
  7930. result += template.substring(pos1, pos2 - 1);
  7931. result += '{';
  7932. pos1 = pos2 + 1;
  7933. continue;
  7934. }
  7935. result += template.substring(pos1, pos2);
  7936. pos1 = pos2;
  7937. pos2 = template.indexOf('}', pos1);
  7938. if (pos2 == -1)
  7939. break;
  7940. if (pos2 == pos1 + 1) {
  7941. result += template.substr(pos1, 2);
  7942. pos1 = pos2 + 1;
  7943. continue;
  7944. }
  7945. tag = template.substring(pos1 + 1, pos2);
  7946. pos3 = tag.indexOf('=');
  7947. if (pos3 != -1) {
  7948. value = this._templateVars[tag.substring(0, pos3)];
  7949. if (value == null)
  7950. result += tag.substring(pos3 + 1);
  7951. else
  7952. result += value;
  7953. }
  7954. else {
  7955. value = this._templateVars[tag];
  7956. if (value != null)
  7957. result += value;
  7958. }
  7959. pos1 = pos2 + 1;
  7960. }
  7961. if (pos1 < template.length)
  7962. result += template.substr(pos1);
  7963. return result;
  7964. }
  7965. get templateVars() {
  7966. return this._templateVars;
  7967. }
  7968. set templateVars(value) {
  7969. if (this._templateVars == null && value == null)
  7970. return;
  7971. this._templateVars = value;
  7972. this.flushVars();
  7973. }
  7974. setVar(name, value) {
  7975. if (!this._templateVars)
  7976. this._templateVars = {};
  7977. this._templateVars[name] = value;
  7978. return this;
  7979. }
  7980. flushVars() {
  7981. this.markSizeChanged();
  7982. this.updateText();
  7983. }
  7984. get textWidth() {
  7985. this.ensureSizeCorrect();
  7986. return this._node.width;
  7987. }
  7988. ensureSizeCorrect() {
  7989. if (this._sizeDirty) {
  7990. if (this._label['_forceUpdateRenderData'])
  7991. this._label['_forceUpdateRenderData']();
  7992. else
  7993. this._label['_updateRenderData'](true);
  7994. this._sizeDirty = false;
  7995. }
  7996. }
  7997. updateText() {
  7998. var text2 = this._text;
  7999. if (this._templateVars)
  8000. text2 = this.parseTemplate(text2);
  8001. if (this._ubbEnabled)
  8002. text2 = fgui.UBBParser.inst.parse(text2, true);
  8003. this._label.string = text2;
  8004. }
  8005. assignFont(label, value) {
  8006. if (value instanceof cc.Font)
  8007. label.font = value;
  8008. else {
  8009. let font = fgui.getFontByName(value);
  8010. if (!font) {
  8011. label.fontFamily = value;
  8012. label.useSystemFont = true;
  8013. }
  8014. else
  8015. label.font = font;
  8016. }
  8017. }
  8018. assignFontColor(label, value) {
  8019. let font = label.font;
  8020. if (font instanceof cc.BitmapFont && !font._fntConfig.canTint)
  8021. value = cc.Color.WHITE;
  8022. if (this._grayed)
  8023. value = fgui.ToolSet.toGrayed(value);
  8024. label.node.color = value;
  8025. }
  8026. updateFont() {
  8027. this.assignFont(this._label, this._realFont);
  8028. }
  8029. updateFontColor() {
  8030. this.assignFontColor(this._label, this._color);
  8031. }
  8032. updateStrokeColor() {
  8033. if (!this._outline)
  8034. return;
  8035. if (!this._strokeColor)
  8036. this._strokeColor = new cc.Color();
  8037. if (this._grayed)
  8038. this._outline.color = fgui.ToolSet.toGrayed(this._strokeColor);
  8039. else
  8040. this._outline.color = this._strokeColor;
  8041. }
  8042. updateShadowColor() {
  8043. if (!this._shadow)
  8044. return;
  8045. if (!this._shadowColor)
  8046. this._shadowColor = new cc.Color();
  8047. if (this._grayed)
  8048. this._shadow.color = fgui.ToolSet.toGrayed(this._shadowColor);
  8049. else
  8050. this._shadow.color = this._shadowColor;
  8051. }
  8052. updateFontSize() {
  8053. let font = this._label.font;
  8054. if (font instanceof cc.BitmapFont) {
  8055. let fntConfig = font._fntConfig;
  8056. if (fntConfig.resizable)
  8057. this._label.fontSize = this._fontSize;
  8058. else
  8059. this._label.fontSize = fntConfig.fontSize;
  8060. this._label.lineHeight = fntConfig.fontSize + ((this._leading + 4) * fntConfig.fontSize) / this._label.fontSize;
  8061. }
  8062. else {
  8063. this._label.fontSize = this._fontSize;
  8064. this._label.lineHeight = this._fontSize + this._leading;
  8065. }
  8066. }
  8067. updateOverflow() {
  8068. if (this._autoSize == fgui.AutoSizeType.Both)
  8069. this._label.overflow = cc.Label.Overflow.NONE;
  8070. else if (this._autoSize == fgui.AutoSizeType.Height) {
  8071. this._label.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
  8072. this._node.width = this._width;
  8073. }
  8074. else if (this._autoSize == fgui.AutoSizeType.Shrink) {
  8075. this._label.overflow = cc.Label.Overflow.SHRINK;
  8076. this._node.setContentSize(this._width, this._height);
  8077. }
  8078. else {
  8079. this._label.overflow = cc.Label.Overflow.CLAMP;
  8080. this._node.setContentSize(this._width, this._height);
  8081. }
  8082. }
  8083. markSizeChanged() {
  8084. if (this._underConstruct)
  8085. return;
  8086. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8087. if (!this._sizeDirty) {
  8088. this._node.emit(fgui.Event.SIZE_DELAY_CHANGE, this);
  8089. this._sizeDirty = true;
  8090. }
  8091. }
  8092. }
  8093. onLabelSizeChanged() {
  8094. this._sizeDirty = false;
  8095. if (this._underConstruct)
  8096. return;
  8097. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8098. this._updatingSize = true;
  8099. this.setSize(this._node.width, this._node.height);
  8100. this._updatingSize = false;
  8101. }
  8102. }
  8103. handleSizeChanged() {
  8104. if (this._updatingSize)
  8105. return;
  8106. if (this._autoSize == fgui.AutoSizeType.None || this._autoSize == fgui.AutoSizeType.Shrink) {
  8107. this._node.setContentSize(this._width, this._height);
  8108. }
  8109. else if (this._autoSize == fgui.AutoSizeType.Height)
  8110. this._node.width = this._width;
  8111. }
  8112. handleGrayedChanged() {
  8113. this.updateFontColor();
  8114. this.updateStrokeColor();
  8115. }
  8116. getProp(index) {
  8117. switch (index) {
  8118. case fgui.ObjectPropID.Color:
  8119. return this.color;
  8120. case fgui.ObjectPropID.OutlineColor:
  8121. return this.strokeColor;
  8122. case fgui.ObjectPropID.FontSize:
  8123. return this.fontSize;
  8124. default:
  8125. return super.getProp(index);
  8126. }
  8127. }
  8128. setProp(index, value) {
  8129. switch (index) {
  8130. case fgui.ObjectPropID.Color:
  8131. this.color = value;
  8132. break;
  8133. case fgui.ObjectPropID.OutlineColor:
  8134. this.strokeColor = value;
  8135. break;
  8136. case fgui.ObjectPropID.FontSize:
  8137. this.fontSize = value;
  8138. break;
  8139. default:
  8140. super.setProp(index, value);
  8141. break;
  8142. }
  8143. }
  8144. setup_beforeAdd(buffer, beginPos) {
  8145. super.setup_beforeAdd(buffer, beginPos);
  8146. buffer.seek(beginPos, 5);
  8147. this.font = buffer.readS();
  8148. this.fontSize = buffer.readShort();
  8149. this.color = buffer.readColor();
  8150. this.align = buffer.readByte();
  8151. this.verticalAlign = buffer.readByte();
  8152. this.leading = buffer.readShort();
  8153. this.letterSpacing = buffer.readShort();
  8154. this._ubbEnabled = buffer.readBool();
  8155. this.autoSize = buffer.readByte();
  8156. this.underline = buffer.readBool();
  8157. this.italic = buffer.readBool();
  8158. this.bold = buffer.readBool();
  8159. this.singleLine = buffer.readBool();
  8160. if (buffer.readBool()) {
  8161. this.strokeColor = buffer.readColor();
  8162. this.stroke = buffer.readFloat();
  8163. }
  8164. if (buffer.readBool()) {
  8165. this.shadowColor = buffer.readColor();
  8166. let f1 = buffer.readFloat();
  8167. let f2 = buffer.readFloat();
  8168. this.shadowOffset = new cc.Vec2(f1, f2);
  8169. }
  8170. if (buffer.readBool())
  8171. this._templateVars = {};
  8172. }
  8173. setup_afterAdd(buffer, beginPos) {
  8174. super.setup_afterAdd(buffer, beginPos);
  8175. buffer.seek(beginPos, 6);
  8176. var str = buffer.readS();
  8177. if (str != null)
  8178. this.text = str;
  8179. }
  8180. }
  8181. fgui.GTextField = GTextField;
  8182. })(fgui || (fgui = {}));
  8183. (function (fgui) {
  8184. class RichTextImageAtlas extends cc.SpriteAtlas {
  8185. getSpriteFrame(key) {
  8186. let pi = fgui.UIPackage.getItemByURL(key);
  8187. if (pi) {
  8188. pi.owner.getItemAssetSync(pi);
  8189. if (pi.type == fgui.PackageItemType.Image)
  8190. return pi.asset;
  8191. else if (pi.type == fgui.PackageItemType.MovieClip)
  8192. return pi.frames[0].texture;
  8193. }
  8194. return super.getSpriteFrame(key);
  8195. }
  8196. }
  8197. fgui.RichTextImageAtlas = RichTextImageAtlas;
  8198. class GRichTextField extends fgui.GTextField {
  8199. constructor() {
  8200. super();
  8201. this._node.name = 'GRichTextField';
  8202. this._touchDisabled = false;
  8203. this.linkUnderline = fgui.UIConfig.linkUnderline;
  8204. }
  8205. createRenderer() {
  8206. this._richText = this._node.addComponent(cc.RichText);
  8207. this._richText.handleTouchEvent = false;
  8208. this.autoSize = fgui.AutoSizeType.None;
  8209. this._richText.imageAtlas = GRichTextField.imageAtlas;
  8210. }
  8211. get align() {
  8212. return this._richText.horizontalAlign;
  8213. }
  8214. set align(value) {
  8215. this._richText.horizontalAlign = value;
  8216. }
  8217. get underline() {
  8218. return this._underline;
  8219. }
  8220. set underline(value) {
  8221. if (this._underline != value) {
  8222. this._underline = value;
  8223. this.updateText();
  8224. }
  8225. }
  8226. get bold() {
  8227. return this._bold;
  8228. }
  8229. set bold(value) {
  8230. if (this._bold != value) {
  8231. this._bold = value;
  8232. this.updateText();
  8233. }
  8234. }
  8235. get italic() {
  8236. return this._italics;
  8237. }
  8238. set italic(value) {
  8239. if (this._italics != value) {
  8240. this._italics = value;
  8241. this.updateText();
  8242. }
  8243. }
  8244. markSizeChanged() {
  8245. }
  8246. updateText() {
  8247. var text2 = this._text;
  8248. if (this._templateVars)
  8249. text2 = this.parseTemplate(text2);
  8250. if (this._ubbEnabled) {
  8251. fgui.UBBParser.inst.linkUnderline = this.linkUnderline;
  8252. fgui.UBBParser.inst.linkColor = this.linkColor;
  8253. text2 = fgui.UBBParser.inst.parse(text2);
  8254. }
  8255. if (this._bold)
  8256. text2 = '<b>' + text2 + '</b>';
  8257. if (this._italics)
  8258. text2 = '<i>' + text2 + '</i>';
  8259. if (this._underline)
  8260. text2 = '<u>' + text2 + '</u>';
  8261. let c = this._color;
  8262. if (this._grayed)
  8263. c = fgui.ToolSet.toGrayed(c);
  8264. text2 = '<color=' + c.toHEX('#rrggbb') + '>' + text2 + '</color>';
  8265. if (this._outline) {
  8266. let outlineColor = this.strokeColor.toHEX();
  8267. let outlineWidth = this.stroke;
  8268. text2 = '<outline color=' + outlineColor + ' width=' + outlineWidth.toString() + '>' + text2 + '</outline>';
  8269. }
  8270. if (this._autoSize == fgui.AutoSizeType.Both) {
  8271. if (this._richText.maxWidth != 0)
  8272. this._richText.maxWidth = 0;
  8273. this._richText.string = text2;
  8274. if (this.maxWidth != 0 && this._node.width > this.maxWidth)
  8275. this._richText.maxWidth = this.maxWidth;
  8276. }
  8277. else
  8278. this._richText.string = text2;
  8279. }
  8280. updateFont() {
  8281. this.assignFont(this._richText, this._realFont);
  8282. this.updateText();
  8283. }
  8284. updateFontColor() {
  8285. this.assignFontColor(this._richText, this._color);
  8286. this.updateText();
  8287. }
  8288. updateFontSize() {
  8289. let fontSize = this._fontSize;
  8290. let font = this._richText.font;
  8291. if (font instanceof cc.BitmapFont) {
  8292. if (!font._fntConfig.resizable)
  8293. fontSize = font._fntConfig.fontSize;
  8294. }
  8295. this._richText.fontSize = fontSize;
  8296. this._richText.lineHeight = fontSize + this._leading;
  8297. }
  8298. updateOverflow() {
  8299. if (this._autoSize == fgui.AutoSizeType.Both)
  8300. this._richText.maxWidth = 0;
  8301. else
  8302. this._richText.maxWidth = this._width;
  8303. }
  8304. handleSizeChanged() {
  8305. if (this._updatingSize)
  8306. return;
  8307. if (this._autoSize != fgui.AutoSizeType.Both)
  8308. this._richText.maxWidth = this._width;
  8309. }
  8310. }
  8311. GRichTextField.imageAtlas = new RichTextImageAtlas();
  8312. fgui.GRichTextField = GRichTextField;
  8313. })(fgui || (fgui = {}));
  8314. (function (fgui) {
  8315. class GRoot extends fgui.GComponent {
  8316. constructor() {
  8317. super();
  8318. this._node.name = 'GRoot';
  8319. this.opaque = false;
  8320. this._volumeScale = 1;
  8321. this._popupStack = new Array();
  8322. this._justClosedPopups = new Array();
  8323. this._modalLayer = new fgui.GGraph();
  8324. this._modalLayer.setSize(this.width, this.height);
  8325. this._modalLayer.drawRect(0, cc.Color.TRANSPARENT, fgui.UIConfig.modalLayerColor);
  8326. this._modalLayer.addRelation(this, fgui.RelationType.Size);
  8327. this._thisOnResized = this.onWinResize.bind(this);
  8328. this._inputProcessor = this.node.addComponent(fgui.InputProcessor);
  8329. this._inputProcessor._captureCallback = this.onTouchBegin_1;
  8330. if (CC_EDITOR) {
  8331. ;
  8332. cc.engine.on('design-resolution-changed', this._thisOnResized);
  8333. }
  8334. else {
  8335. ;
  8336. cc.view.on('canvas-resize', this._thisOnResized);
  8337. }
  8338. this.onWinResize();
  8339. }
  8340. static get inst() {
  8341. if (!GRoot._inst)
  8342. throw 'Call GRoot.create first!';
  8343. return GRoot._inst;
  8344. }
  8345. static create() {
  8346. GRoot._inst = new GRoot();
  8347. GRoot._inst.node.parent = cc.director.getScene();
  8348. return GRoot._inst;
  8349. }
  8350. onDestroy() {
  8351. if (CC_EDITOR) {
  8352. ;
  8353. cc.engine.off('design-resolution-changed', this._thisOnResized);
  8354. }
  8355. else {
  8356. ;
  8357. cc.view.off('canvas-resize', this._thisOnResized);
  8358. }
  8359. if (this == GRoot._inst)
  8360. GRoot._inst = null;
  8361. }
  8362. getTouchPosition(touchId) {
  8363. return this._inputProcessor.getTouchPosition(touchId);
  8364. }
  8365. get touchTarget() {
  8366. return this._inputProcessor.getTouchTarget();
  8367. }
  8368. get inputProcessor() {
  8369. return this._inputProcessor;
  8370. }
  8371. showWindow(win) {
  8372. this.addChild(win);
  8373. win.requestFocus();
  8374. if (win.x > this.width)
  8375. win.x = this.width - win.width;
  8376. else if (win.x + win.width < 0)
  8377. win.x = 0;
  8378. if (win.y > this.height)
  8379. win.y = this.height - win.height;
  8380. else if (win.y + win.height < 0)
  8381. win.y = 0;
  8382. this.adjustModalLayer();
  8383. }
  8384. hideWindow(win) {
  8385. win.hide();
  8386. }
  8387. hideWindowImmediately(win) {
  8388. if (win.parent == this)
  8389. this.removeChild(win);
  8390. this.adjustModalLayer();
  8391. }
  8392. bringToFront(win) {
  8393. var cnt = this.numChildren;
  8394. var i;
  8395. if (this._modalLayer.parent && !win.modal)
  8396. i = this.getChildIndex(this._modalLayer) - 1;
  8397. else
  8398. i = cnt - 1;
  8399. for (; i >= 0; i--) {
  8400. var g = this.getChildAt(i);
  8401. if (g == win)
  8402. return;
  8403. if (g instanceof fgui.Window)
  8404. break;
  8405. }
  8406. if (i >= 0)
  8407. this.setChildIndex(win, i);
  8408. }
  8409. showModalWait(msg) {
  8410. if (fgui.UIConfig.globalModalWaiting != null) {
  8411. if (this._modalWaitPane == null)
  8412. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.globalModalWaiting);
  8413. this._modalWaitPane.setSize(this.width, this.height);
  8414. this._modalWaitPane.addRelation(this, fgui.RelationType.Size);
  8415. this.addChild(this._modalWaitPane);
  8416. this._modalWaitPane.text = msg;
  8417. }
  8418. }
  8419. closeModalWait() {
  8420. if (this._modalWaitPane && this._modalWaitPane.parent)
  8421. this.removeChild(this._modalWaitPane);
  8422. }
  8423. closeAllExceptModals() {
  8424. var arr = this._children.slice();
  8425. var cnt = arr.length;
  8426. for (var i = 0; i < cnt; i++) {
  8427. var g = arr[i];
  8428. if (g instanceof fgui.Window && !g.modal)
  8429. g.hide();
  8430. }
  8431. }
  8432. closeAllWindows() {
  8433. var arr = this._children.slice();
  8434. var cnt = arr.length;
  8435. for (var i = 0; i < cnt; i++) {
  8436. var g = arr[i];
  8437. if (g instanceof fgui.Window)
  8438. g.hide();
  8439. }
  8440. }
  8441. getTopWindow() {
  8442. var cnt = this.numChildren;
  8443. for (var i = cnt - 1; i >= 0; i--) {
  8444. var g = this.getChildAt(i);
  8445. if (g instanceof fgui.Window) {
  8446. return g;
  8447. }
  8448. }
  8449. return null;
  8450. }
  8451. get modalLayer() {
  8452. return this._modalLayer;
  8453. }
  8454. get hasModalWindow() {
  8455. return this._modalLayer.parent != null;
  8456. }
  8457. get modalWaiting() {
  8458. return this._modalWaitPane && this._modalWaitPane.node.activeInHierarchy;
  8459. }
  8460. getPopupPosition(popup, target, dir, result) {
  8461. let pos = result || new cc.Vec2();
  8462. var sizeW = 0, sizeH = 0;
  8463. if (target) {
  8464. pos = target.localToGlobal();
  8465. let pos2 = target.localToGlobal(target.width, target.height);
  8466. sizeW = pos2.x - pos.x;
  8467. sizeH = pos2.y - pos.y;
  8468. }
  8469. else {
  8470. pos = this.getTouchPosition();
  8471. pos = this.globalToLocal(pos.x, pos.y);
  8472. }
  8473. if (pos.x + popup.width > this.width)
  8474. pos.x = pos.x - (popup.width - (this.width - pos.x));
  8475. pos.y += sizeH;
  8476. if (((dir === undefined || dir === fgui.PopupDirection.Auto) && pos.y + popup.height > this.height) || dir === false || dir === fgui.PopupDirection.Up) {
  8477. pos.y = pos.y - sizeH - popup.height - 1;
  8478. if (pos.y < 0) {
  8479. pos.y = 0;
  8480. }
  8481. }
  8482. if (pos.y + popup.height > this.height) {
  8483. pos.y = pos.y - sizeH - popup.height - 1;
  8484. if (pos.y < 0) {
  8485. pos.y = 0;
  8486. }
  8487. }
  8488. return pos;
  8489. }
  8490. showPopup(popup, target, dir, parent) {
  8491. if (this._popupStack.length > 0) {
  8492. var k = this._popupStack.indexOf(popup);
  8493. if (k != -1) {
  8494. for (var i = this._popupStack.length - 1; i >= k; i--)
  8495. this.removeChild(this._popupStack.pop());
  8496. }
  8497. }
  8498. this._popupStack.push(popup);
  8499. if (target) {
  8500. var p = target;
  8501. while (p) {
  8502. if (p.parent == this) {
  8503. if (popup.sortingOrder < p.sortingOrder) {
  8504. popup.sortingOrder = p.sortingOrder;
  8505. }
  8506. break;
  8507. }
  8508. p = p.parent;
  8509. }
  8510. }
  8511. parent = parent || this;
  8512. parent.addChild(popup);
  8513. this.adjustModalLayer();
  8514. let pt = this.getPopupPosition(popup, target, dir, null);
  8515. let parentGrobalPos = parent.localToGlobal();
  8516. pt.x = pt.x - parentGrobalPos.x;
  8517. pt.y = pt.y - parentGrobalPos.y;
  8518. popup.setPosition(pt.x, pt.y);
  8519. }
  8520. togglePopup(popup, target, dir) {
  8521. if (this._justClosedPopups.indexOf(popup) != -1)
  8522. return;
  8523. this.showPopup(popup, target, dir);
  8524. }
  8525. hidePopup(popup) {
  8526. if (popup) {
  8527. var k = this._popupStack.indexOf(popup);
  8528. if (k != -1) {
  8529. for (var i = this._popupStack.length - 1; i >= k; i--)
  8530. this.closePopup(this._popupStack.pop());
  8531. }
  8532. }
  8533. else {
  8534. var cnt = this._popupStack.length;
  8535. for (i = cnt - 1; i >= 0; i--)
  8536. this.closePopup(this._popupStack[i]);
  8537. this._popupStack.length = 0;
  8538. }
  8539. }
  8540. get hasAnyPopup() {
  8541. return this._popupStack.length != 0;
  8542. }
  8543. closePopup(target) {
  8544. if (target.parent) {
  8545. if (target instanceof fgui.Window)
  8546. target.hide();
  8547. else
  8548. target.parent.removeChild(target);
  8549. }
  8550. }
  8551. showTooltips(msg) {
  8552. if (this._defaultTooltipWin == null) {
  8553. var resourceURL = fgui.UIConfig.tooltipsWin;
  8554. if (!resourceURL) {
  8555. console.warn('UIConfig.tooltipsWin not defined');
  8556. return;
  8557. }
  8558. this._defaultTooltipWin = fgui.UIPackage.createObjectFromURL(resourceURL);
  8559. }
  8560. this._defaultTooltipWin.text = msg;
  8561. this.showTooltipsWin(this._defaultTooltipWin);
  8562. }
  8563. showTooltipsWin(tooltipWin) {
  8564. this.hideTooltips();
  8565. this._tooltipWin = tooltipWin;
  8566. let pt = this.getTouchPosition();
  8567. pt.x += 10;
  8568. pt.y += 20;
  8569. this.globalToLocal(pt.x, pt.y, pt);
  8570. if (pt.x + this._tooltipWin.width > this.width) {
  8571. pt.x = pt.x - this._tooltipWin.width - 1;
  8572. if (pt.x < 0)
  8573. pt.x = 10;
  8574. }
  8575. if (pt.y + this._tooltipWin.height > this.height) {
  8576. pt.y = pt.y - this._tooltipWin.height - 1;
  8577. if (pt.y < 0)
  8578. pt.y = 10;
  8579. }
  8580. this._tooltipWin.setPosition(pt.x, pt.y);
  8581. this.addChild(this._tooltipWin);
  8582. }
  8583. hideTooltips() {
  8584. if (this._tooltipWin) {
  8585. if (this._tooltipWin.parent)
  8586. this.removeChild(this._tooltipWin);
  8587. this._tooltipWin = null;
  8588. }
  8589. }
  8590. get volumeScale() {
  8591. return this._volumeScale;
  8592. }
  8593. set volumeScale(value) {
  8594. this._volumeScale = value;
  8595. }
  8596. playOneShotSound(clip, volumeScale) {
  8597. if (volumeScale === undefined)
  8598. volumeScale = 1;
  8599. cc.audioEngine.play(clip, false, this._volumeScale * volumeScale);
  8600. }
  8601. adjustModalLayer() {
  8602. var cnt = this.numChildren;
  8603. if (this._modalWaitPane && this._modalWaitPane.parent)
  8604. this.setChildIndex(this._modalWaitPane, cnt - 1);
  8605. for (var i = cnt - 1; i >= 0; i--) {
  8606. var g = this.getChildAt(i);
  8607. if (g instanceof fgui.Window && g.modal) {
  8608. if (this._modalLayer.parent == null)
  8609. this.addChildAt(this._modalLayer, i);
  8610. else
  8611. this.setChildIndexBefore(this._modalLayer, i);
  8612. return;
  8613. }
  8614. }
  8615. if (this._modalLayer.parent)
  8616. this.removeChild(this._modalLayer);
  8617. }
  8618. onTouchBegin_1(evt) {
  8619. if (this._tooltipWin)
  8620. this.hideTooltips();
  8621. this._justClosedPopups.length = 0;
  8622. if (this._popupStack.length > 0) {
  8623. let mc = evt.initiator;
  8624. while (mc && mc != this) {
  8625. let pindex = this._popupStack.indexOf(mc);
  8626. if (pindex != -1) {
  8627. for (let i = this._popupStack.length - 1; i > pindex; i--) {
  8628. var popup = this._popupStack.pop();
  8629. this.closePopup(popup);
  8630. this._justClosedPopups.push(popup);
  8631. }
  8632. return;
  8633. }
  8634. mc = mc.findParent();
  8635. }
  8636. let cnt = this._popupStack.length;
  8637. for (let i = cnt - 1; i >= 0; i--) {
  8638. popup = this._popupStack[i];
  8639. this.closePopup(popup);
  8640. this._justClosedPopups.push(popup);
  8641. }
  8642. this._popupStack.length = 0;
  8643. }
  8644. }
  8645. onWinResize() {
  8646. let size = cc.view.getCanvasSize();
  8647. size.width /= cc.view.getScaleX();
  8648. size.height /= cc.view.getScaleY();
  8649. let pos = cc.view.getViewportRect().origin;
  8650. pos.x = pos.x / cc.view.getScaleX();
  8651. pos.y = pos.y / cc.view.getScaleY();
  8652. this.setSize(size.width, size.height);
  8653. this._node.setPosition(-pos.x, this._height - pos.y);
  8654. this.updateContentScaleLevel();
  8655. }
  8656. handlePositionChanged() {
  8657. }
  8658. updateContentScaleLevel() {
  8659. var ss = Math.max(cc.view.getScaleX(), cc.view.getScaleY());
  8660. if (ss >= 3.5)
  8661. GRoot.contentScaleLevel = 3;
  8662. else if (ss >= 2.5)
  8663. GRoot.contentScaleLevel = 2;
  8664. else if (ss >= 1.5)
  8665. GRoot.contentScaleLevel = 1;
  8666. else
  8667. GRoot.contentScaleLevel = 0;
  8668. }
  8669. }
  8670. GRoot.contentScaleLevel = 0;
  8671. fgui.GRoot = GRoot;
  8672. })(fgui || (fgui = {}));
  8673. (function (fgui) {
  8674. class GScrollBar extends fgui.GComponent {
  8675. constructor() {
  8676. super();
  8677. this._node.name = "GScrollBar";
  8678. this._dragOffset = new cc.Vec2();
  8679. this._scrollPerc = 0;
  8680. }
  8681. setScrollPane(target, vertical) {
  8682. this._target = target;
  8683. this._vertical = vertical;
  8684. }
  8685. setDisplayPerc(value) {
  8686. if (this._vertical) {
  8687. if (!this._fixedGripSize)
  8688. this._grip.height = Math.floor(value * this._bar.height);
  8689. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  8690. }
  8691. else {
  8692. if (!this._fixedGripSize)
  8693. this._grip.width = Math.floor(value * this._bar.width);
  8694. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  8695. }
  8696. this._grip.visible = value != 0 && value != 1;
  8697. }
  8698. setScrollPerc(val) {
  8699. this._scrollPerc = val;
  8700. if (this._vertical)
  8701. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  8702. else
  8703. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  8704. }
  8705. get minSize() {
  8706. if (this._vertical)
  8707. return (this._arrowButton1 ? this._arrowButton1.height : 0) + (this._arrowButton2 ? this._arrowButton2.height : 0);
  8708. else
  8709. return (this._arrowButton1 ? this._arrowButton1.width : 0) + (this._arrowButton2 ? this._arrowButton2.width : 0);
  8710. }
  8711. get gripDragging() {
  8712. return this._gripDragging;
  8713. }
  8714. constructExtension(buffer) {
  8715. buffer.seek(0, 6);
  8716. this._fixedGripSize = buffer.readBool();
  8717. this._grip = this.getChild("grip");
  8718. if (!this._grip) {
  8719. console.warn("需要定义grip");
  8720. return;
  8721. }
  8722. this._bar = this.getChild("bar");
  8723. if (!this._bar) {
  8724. console.warn("需要定义bar");
  8725. return;
  8726. }
  8727. this._arrowButton1 = this.getChild("arrow1");
  8728. this._arrowButton2 = this.getChild("arrow2");
  8729. this._grip.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchDown, this);
  8730. this._grip.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  8731. this._grip.on(fgui.Event.TOUCH_END, this.onGripTouchEnd, this);
  8732. if (this._arrowButton1)
  8733. this._arrowButton1.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow1, this);
  8734. if (this._arrowButton2)
  8735. this._arrowButton2.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow2, this);
  8736. this.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  8737. }
  8738. onGripTouchDown(evt) {
  8739. evt.stopPropagation();
  8740. evt.captureTouch();
  8741. this._gripDragging = true;
  8742. this._target.updateScrollBarVisible();
  8743. this.globalToLocal(evt.pos.x, evt.pos.y, this._dragOffset);
  8744. this._dragOffset.x -= this._grip.x;
  8745. this._dragOffset.y -= this._grip.y;
  8746. }
  8747. onGripTouchMove(evt) {
  8748. if (!this.onStage)
  8749. return;
  8750. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  8751. if (this._vertical) {
  8752. var curY = pt.y - this._dragOffset.y;
  8753. this._target.setPercY((curY - this._bar.y) / (this._bar.height - this._grip.height), false);
  8754. }
  8755. else {
  8756. var curX = pt.x - this._dragOffset.x;
  8757. this._target.setPercX((curX - this._bar.x) / (this._bar.width - this._grip.width), false);
  8758. }
  8759. }
  8760. onGripTouchEnd(evt) {
  8761. if (!this.onStage)
  8762. return;
  8763. this._gripDragging = false;
  8764. this._target.updateScrollBarVisible();
  8765. }
  8766. onClickArrow1(evt) {
  8767. evt.stopPropagation();
  8768. if (this._vertical)
  8769. this._target.scrollUp();
  8770. else
  8771. this._target.scrollLeft();
  8772. }
  8773. onClickArrow2(evt) {
  8774. evt.stopPropagation();
  8775. if (this._vertical)
  8776. this._target.scrollDown();
  8777. else
  8778. this._target.scrollRight();
  8779. }
  8780. onBarTouchBegin(evt) {
  8781. var pt = this._grip.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  8782. if (this._vertical) {
  8783. if (pt.y < 0)
  8784. this._target.scrollUp(4);
  8785. else
  8786. this._target.scrollDown(4);
  8787. }
  8788. else {
  8789. if (pt.x < 0)
  8790. this._target.scrollLeft(4);
  8791. else
  8792. this._target.scrollRight(4);
  8793. }
  8794. }
  8795. }
  8796. fgui.GScrollBar = GScrollBar;
  8797. var s_vec2 = new cc.Vec2();
  8798. })(fgui || (fgui = {}));
  8799. (function (fgui) {
  8800. class GSlider extends fgui.GComponent {
  8801. constructor() {
  8802. super();
  8803. this._min = 0;
  8804. this._max = 0;
  8805. this._value = 0;
  8806. this._barMaxWidth = 0;
  8807. this._barMaxHeight = 0;
  8808. this._barMaxWidthDelta = 0;
  8809. this._barMaxHeightDelta = 0;
  8810. this._clickPercent = 0;
  8811. this._barStartX = 0;
  8812. this._barStartY = 0;
  8813. this.changeOnClick = true;
  8814. this.canDrag = true;
  8815. this.availableValue = -1;
  8816. this._node.name = 'GSlider';
  8817. this._titleType = fgui.ProgressTitleType.Percent;
  8818. this._value = 50;
  8819. this._max = 100;
  8820. this._clickPos = new cc.Vec2();
  8821. }
  8822. get titleType() {
  8823. return this._titleType;
  8824. }
  8825. set titleType(value) {
  8826. this._titleType = value;
  8827. }
  8828. get wholeNumbers() {
  8829. return this._wholeNumbers;
  8830. }
  8831. set wholeNumbers(value) {
  8832. if (this._wholeNumbers != value) {
  8833. this._wholeNumbers = value;
  8834. this.update();
  8835. }
  8836. }
  8837. get min() {
  8838. return this._min;
  8839. }
  8840. set min(value) {
  8841. if (this._min != value) {
  8842. this._min = value;
  8843. this.update();
  8844. }
  8845. }
  8846. get max() {
  8847. return this._max;
  8848. }
  8849. set max(value) {
  8850. if (this._max != value) {
  8851. this._max = value;
  8852. this.update();
  8853. }
  8854. }
  8855. get value() {
  8856. return this._value;
  8857. }
  8858. set value(value) {
  8859. if (this._value != value) {
  8860. this._value = value;
  8861. this.update();
  8862. }
  8863. }
  8864. update() {
  8865. this.updateWithPercent((this._value - this._min) / (this._max - this._min));
  8866. }
  8867. updateWithPercent(percent, manual) {
  8868. if (isNaN(percent)) {
  8869. percent = 0;
  8870. }
  8871. percent = fgui.ToolSet.clamp01(percent);
  8872. if (manual) {
  8873. var newValue = fgui.ToolSet.clamp(this._min + (this._max - this._min) * percent, this._min, this._max);
  8874. if (this.availableValue != -1) {
  8875. if (this._wholeNumbers) {
  8876. newValue = Math.round(newValue);
  8877. }
  8878. if (newValue > this.availableValue) {
  8879. newValue = this.availableValue;
  8880. }
  8881. console.log('newValue:', newValue);
  8882. }
  8883. if (this._wholeNumbers) {
  8884. newValue = Math.round(newValue);
  8885. percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  8886. }
  8887. if (newValue != this._value) {
  8888. this._value = newValue;
  8889. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  8890. }
  8891. }
  8892. if (this._titleObject) {
  8893. switch (this._titleType) {
  8894. case fgui.ProgressTitleType.Percent:
  8895. this._titleObject.text = Math.floor(percent * 100) + '%';
  8896. break;
  8897. case fgui.ProgressTitleType.ValueAndMax:
  8898. this._titleObject.text = this._value + '/' + this._max;
  8899. break;
  8900. case fgui.ProgressTitleType.Value:
  8901. this._titleObject.text = '' + this._value;
  8902. break;
  8903. case fgui.ProgressTitleType.Max:
  8904. this._titleObject.text = '' + this._max;
  8905. break;
  8906. }
  8907. }
  8908. var fullWidth = this.width - this._barMaxWidthDelta;
  8909. var fullHeight = this.height - this._barMaxHeightDelta;
  8910. if (!this._reverse) {
  8911. if (this._barObjectH)
  8912. this._barObjectH.width = Math.round(fullWidth * percent);
  8913. if (this._barObjectV)
  8914. this._barObjectV.height = Math.round(fullHeight * percent);
  8915. }
  8916. else {
  8917. if (this._barObjectH) {
  8918. this._barObjectH.width = Math.round(fullWidth * percent);
  8919. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  8920. }
  8921. if (this._barObjectV) {
  8922. this._barObjectV.height = Math.round(fullHeight * percent);
  8923. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  8924. }
  8925. }
  8926. }
  8927. constructExtension(buffer) {
  8928. buffer.seek(0, 6);
  8929. this._titleType = buffer.readByte();
  8930. this._reverse = buffer.readBool();
  8931. if (buffer.version >= 2) {
  8932. this._wholeNumbers = buffer.readBool();
  8933. this.changeOnClick = buffer.readBool();
  8934. }
  8935. this._titleObject = this.getChild('title');
  8936. this._barObjectH = this.getChild('bar');
  8937. this._barObjectV = this.getChild('bar_v');
  8938. this._gripObject = this.getChild('grip');
  8939. if (this._barObjectH) {
  8940. this._barMaxWidth = this._barObjectH.width;
  8941. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  8942. this._barStartX = this._barObjectH.x;
  8943. }
  8944. if (this._barObjectV) {
  8945. this._barMaxHeight = this._barObjectV.height;
  8946. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  8947. this._barStartY = this._barObjectV.y;
  8948. }
  8949. if (this._gripObject) {
  8950. this._gripObject.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchBegin, this);
  8951. this._gripObject.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  8952. }
  8953. this._node.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  8954. }
  8955. handleSizeChanged() {
  8956. super.handleSizeChanged();
  8957. if (this._barObjectH)
  8958. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  8959. if (this._barObjectV)
  8960. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  8961. if (!this._underConstruct)
  8962. this.update();
  8963. }
  8964. setup_afterAdd(buffer, beginPos) {
  8965. super.setup_afterAdd(buffer, beginPos);
  8966. if (!buffer.seek(beginPos, 6)) {
  8967. this.update();
  8968. return;
  8969. }
  8970. if (buffer.readByte() != this.packageItem.objectType) {
  8971. this.update();
  8972. return;
  8973. }
  8974. this._value = buffer.readInt();
  8975. this._max = buffer.readInt();
  8976. if (buffer.version >= 2)
  8977. this._min = buffer.readInt();
  8978. this.update();
  8979. }
  8980. onGripTouchBegin(evt) {
  8981. this.canDrag = true;
  8982. evt.stopPropagation();
  8983. evt.captureTouch();
  8984. this._clickPos = this.globalToLocal(evt.pos.x, evt.pos.y);
  8985. this._clickPercent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  8986. }
  8987. onGripTouchMove(evt) {
  8988. if (!this.canDrag) {
  8989. return;
  8990. }
  8991. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  8992. var deltaX = pt.x - this._clickPos.x;
  8993. var deltaY = pt.y - this._clickPos.y;
  8994. if (this._reverse) {
  8995. deltaX = -deltaX;
  8996. deltaY = -deltaY;
  8997. }
  8998. var percent;
  8999. if (this._barObjectH)
  9000. percent = this._clickPercent + deltaX / this._barMaxWidth;
  9001. else
  9002. percent = this._clickPercent + deltaY / this._barMaxHeight;
  9003. this.updateWithPercent(percent, true);
  9004. }
  9005. onBarTouchBegin(evt) {
  9006. if (!this.changeOnClick)
  9007. return;
  9008. var pt = this._gripObject.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9009. var percent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9010. var delta = 0;
  9011. if (this._barObjectH != null)
  9012. delta = (pt.x - this._gripObject.width / 2) / this._barMaxWidth;
  9013. if (this._barObjectV != null)
  9014. delta = (pt.y - this._gripObject.height / 2) / this._barMaxHeight;
  9015. if (this._reverse)
  9016. percent -= delta;
  9017. else
  9018. percent += delta;
  9019. this.updateWithPercent(percent, true);
  9020. }
  9021. }
  9022. fgui.GSlider = GSlider;
  9023. var s_vec2 = new cc.Vec2();
  9024. })(fgui || (fgui = {}));
  9025. (function (fgui) {
  9026. class GTextInput extends fgui.GTextField {
  9027. constructor() {
  9028. super();
  9029. this._node.name = "GTextInput";
  9030. this._touchDisabled = false;
  9031. }
  9032. createRenderer() {
  9033. this._editBox = this._node.addComponent(MyEditBox);
  9034. this._editBox.maxLength = -1;
  9035. this._editBox["_updateTextLabel"]();
  9036. this._node.on('text-changed', this.onTextChanged, this);
  9037. this.on(fgui.Event.TOUCH_END, this.onTouchEnd1, this);
  9038. this.autoSize = fgui.AutoSizeType.None;
  9039. }
  9040. set editable(val) {
  9041. this._editBox.enabled = val;
  9042. }
  9043. get editable() {
  9044. return this._editBox.enabled;
  9045. }
  9046. set maxLength(val) {
  9047. if (val == 0)
  9048. val = -1;
  9049. this._editBox.maxLength = val;
  9050. }
  9051. get maxLength() {
  9052. return this._editBox.maxLength;
  9053. }
  9054. set promptText(val) {
  9055. this._promptText = val;
  9056. let newCreate = !this._editBox.placeholderLabel;
  9057. this._editBox["_updatePlaceholderLabel"]();
  9058. if (newCreate)
  9059. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  9060. this._editBox.placeholderLabel.string = fgui.UBBParser.inst.parse(this._promptText, true);
  9061. if (fgui.UBBParser.inst.lastColor) {
  9062. let c = this._editBox.placeholderLabel.node.color;
  9063. if (!c)
  9064. c = new cc.Color();
  9065. c.fromHEX(fgui.UBBParser.inst.lastColor);
  9066. this.assignFontColor(this._editBox.placeholderLabel, c);
  9067. }
  9068. else
  9069. this.assignFontColor(this._editBox.placeholderLabel, this._color);
  9070. if (fgui.UBBParser.inst.lastSize)
  9071. this._editBox.placeholderLabel.fontSize = parseInt(fgui.UBBParser.inst.lastSize);
  9072. else
  9073. this._editBox.placeholderLabel.fontSize = this._fontSize;
  9074. }
  9075. get promptText() {
  9076. return this._promptText;
  9077. }
  9078. set restrict(value) {
  9079. }
  9080. get restrict() {
  9081. return "";
  9082. }
  9083. get password() {
  9084. return this._editBox.inputFlag == cc.EditBox.InputFlag.PASSWORD;
  9085. ;
  9086. }
  9087. set password(val) {
  9088. this._editBox.inputFlag = val ? cc.EditBox.InputFlag.PASSWORD : cc.EditBox.InputFlag.DEFAULT;
  9089. }
  9090. get align() {
  9091. return this._editBox.textLabel.horizontalAlign;
  9092. }
  9093. set align(value) {
  9094. this._editBox.textLabel.horizontalAlign = value;
  9095. if (this._editBox.placeholderLabel) {
  9096. this._editBox.placeholderLabel.horizontalAlign = value;
  9097. }
  9098. }
  9099. get verticalAlign() {
  9100. return this._editBox.textLabel.verticalAlign;
  9101. }
  9102. set verticalAlign(value) {
  9103. this._editBox.textLabel.verticalAlign = value;
  9104. if (this._editBox.placeholderLabel) {
  9105. this._editBox.placeholderLabel.verticalAlign = value;
  9106. }
  9107. }
  9108. get singleLine() {
  9109. return this._editBox.inputMode != cc.EditBox.InputMode.ANY;
  9110. }
  9111. set singleLine(value) {
  9112. this._editBox.inputMode = value ? cc.EditBox.InputMode.SINGLE_LINE : cc.EditBox.InputMode.ANY;
  9113. }
  9114. requestFocus() {
  9115. this._editBox.focus();
  9116. }
  9117. markSizeChanged() {
  9118. }
  9119. updateText() {
  9120. var text2 = this._text;
  9121. if (this._templateVars)
  9122. text2 = this.parseTemplate(text2);
  9123. if (this._ubbEnabled)
  9124. text2 = fgui.UBBParser.inst.parse(fgui.ToolSet.encodeHTML(text2), true);
  9125. this._editBox.string = text2;
  9126. }
  9127. updateFont() {
  9128. this.assignFont(this._editBox.textLabel, this._realFont);
  9129. if (this._editBox.placeholderLabel)
  9130. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  9131. }
  9132. updateFontColor() {
  9133. this.assignFontColor(this._editBox.textLabel, this._color);
  9134. }
  9135. updateFontSize() {
  9136. this._editBox.textLabel.fontSize = this._fontSize;
  9137. this._editBox.textLabel.lineHeight = this._fontSize + this._leading;
  9138. if (this._editBox.placeholderLabel)
  9139. this._editBox.placeholderLabel.fontSize = this._editBox.textLabel.fontSize;
  9140. }
  9141. updateOverflow() {
  9142. }
  9143. onTextChanged() {
  9144. this._text = this._editBox.string;
  9145. }
  9146. onTouchEnd1(evt) {
  9147. this._editBox.openKeyboard(evt.touch);
  9148. }
  9149. setup_beforeAdd(buffer, beginPos) {
  9150. super.setup_beforeAdd(buffer, beginPos);
  9151. buffer.seek(beginPos, 4);
  9152. var str = buffer.readS();
  9153. if (str != null)
  9154. this.promptText = str;
  9155. str = buffer.readS();
  9156. if (str != null)
  9157. this.restrict = str;
  9158. var iv = buffer.readInt();
  9159. if (iv != 0)
  9160. this.maxLength = iv;
  9161. iv = buffer.readInt();
  9162. if (iv != 0) {
  9163. }
  9164. if (buffer.readBool())
  9165. this.password = true;
  9166. if (this._editBox.placeholderLabel) {
  9167. let hAlign = this._editBox.textLabel.horizontalAlign;
  9168. this._editBox.placeholderLabel.horizontalAlign = hAlign;
  9169. let vAlign = this._editBox.textLabel.verticalAlign;
  9170. this._editBox.placeholderLabel.verticalAlign = vAlign;
  9171. }
  9172. }
  9173. }
  9174. fgui.GTextInput = GTextInput;
  9175. class MyEditBox extends cc.EditBox {
  9176. _registerEvent() {
  9177. }
  9178. _syncSize() {
  9179. let size = this.node.getContentSize();
  9180. let impl = this["_impl"];
  9181. impl.setSize(size.width, size.height);
  9182. if (this.textLabel)
  9183. this.textLabel.node.setContentSize(size.width, size.height);
  9184. if (this.placeholderLabel)
  9185. this.placeholderLabel.node.setContentSize(size.width, size.height);
  9186. }
  9187. openKeyboard(touch) {
  9188. let impl = this["_impl"];
  9189. if (impl) {
  9190. impl.beginEditing();
  9191. }
  9192. }
  9193. }
  9194. })(fgui || (fgui = {}));
  9195. (function (fgui) {
  9196. class GTree extends fgui.GList {
  9197. constructor() {
  9198. super();
  9199. this._indent = 15;
  9200. this._rootNode = new fgui.GTreeNode(true);
  9201. this._rootNode._setTree(this);
  9202. this._rootNode.expanded = true;
  9203. }
  9204. get rootNode() {
  9205. return this._rootNode;
  9206. }
  9207. get indent() {
  9208. return this._indent;
  9209. }
  9210. set indent(value) {
  9211. this._indent = value;
  9212. }
  9213. get clickToExpand() {
  9214. return this._clickToExpand;
  9215. }
  9216. set clickToExpand(value) {
  9217. this._clickToExpand = value;
  9218. }
  9219. getSelectedNode() {
  9220. if (this.selectedIndex != -1)
  9221. return this.getChildAt(this.selectedIndex)._treeNode;
  9222. else
  9223. return null;
  9224. }
  9225. getSelectedNodes(result) {
  9226. if (!result)
  9227. result = new Array();
  9228. s_list.length = 0;
  9229. super.getSelection(s_list);
  9230. var cnt = s_list.length;
  9231. var ret = new Array();
  9232. for (var i = 0; i < cnt; i++) {
  9233. var node = this.getChildAt(s_list[i])._treeNode;
  9234. ret.push(node);
  9235. }
  9236. return ret;
  9237. }
  9238. selectNode(node, scrollItToView) {
  9239. var parentNode = node.parent;
  9240. while (parentNode && parentNode != this._rootNode) {
  9241. parentNode.expanded = true;
  9242. parentNode = parentNode.parent;
  9243. }
  9244. if (!node._cell)
  9245. return;
  9246. this.addSelection(this.getChildIndex(node._cell), scrollItToView);
  9247. }
  9248. unselectNode(node) {
  9249. if (!node._cell)
  9250. return;
  9251. this.removeSelection(this.getChildIndex(node._cell));
  9252. }
  9253. expandAll(folderNode) {
  9254. if (!folderNode)
  9255. folderNode = this._rootNode;
  9256. folderNode.expanded = true;
  9257. var cnt = folderNode.numChildren;
  9258. for (var i = 0; i < cnt; i++) {
  9259. var node = folderNode.getChildAt(i);
  9260. if (node.isFolder)
  9261. this.expandAll(node);
  9262. }
  9263. }
  9264. collapseAll(folderNode) {
  9265. if (!folderNode)
  9266. folderNode = this._rootNode;
  9267. if (folderNode != this._rootNode)
  9268. folderNode.expanded = false;
  9269. var cnt = folderNode.numChildren;
  9270. for (var i = 0; i < cnt; i++) {
  9271. var node = folderNode.getChildAt(i);
  9272. if (node.isFolder)
  9273. this.collapseAll(node);
  9274. }
  9275. }
  9276. createCell(node) {
  9277. var child = this.getFromPool(node._resURL);
  9278. if (!(child instanceof fgui.GComponent))
  9279. throw new Error("cannot create tree node object.");
  9280. child._treeNode = node;
  9281. node._cell = child;
  9282. var indentObj = child.getChild("indent");
  9283. if (indentObj)
  9284. indentObj.width = (node.level - 1) * this._indent;
  9285. var cc;
  9286. cc = child.getController("expanded");
  9287. if (cc) {
  9288. cc.on(fgui.Event.STATUS_CHANGED, this.__expandedStateChanged, this);
  9289. cc.selectedIndex = node.expanded ? 1 : 0;
  9290. }
  9291. cc = child.getController("leaf");
  9292. if (cc)
  9293. cc.selectedIndex = node.isFolder ? 0 : 1;
  9294. if (node.isFolder)
  9295. node._cell.on(fgui.Event.TOUCH_BEGIN, this.__cellMouseDown, this);
  9296. if (this.treeNodeRender)
  9297. this.treeNodeRender(node, child);
  9298. }
  9299. _afterInserted(node) {
  9300. if (!node._cell)
  9301. this.createCell(node);
  9302. var index = this.getInsertIndexForNode(node);
  9303. this.addChildAt(node._cell, index);
  9304. if (this.treeNodeRender)
  9305. this.treeNodeRender(node, node._cell);
  9306. if (node.isFolder && node.expanded)
  9307. this.checkChildren(node, index);
  9308. }
  9309. getInsertIndexForNode(node) {
  9310. var prevNode = node.getPrevSibling();
  9311. if (prevNode == null)
  9312. prevNode = node.parent;
  9313. var insertIndex = this.getChildIndex(prevNode._cell) + 1;
  9314. var myLevel = node.level;
  9315. var cnt = this.numChildren;
  9316. for (var i = insertIndex; i < cnt; i++) {
  9317. var testNode = this.getChildAt(i)._treeNode;
  9318. if (testNode.level <= myLevel)
  9319. break;
  9320. insertIndex++;
  9321. }
  9322. return insertIndex;
  9323. }
  9324. _afterRemoved(node) {
  9325. this.removeNode(node);
  9326. }
  9327. _afterExpanded(node) {
  9328. if (node == this._rootNode) {
  9329. this.checkChildren(this._rootNode, 0);
  9330. return;
  9331. }
  9332. if (this.treeNodeWillExpand != null)
  9333. this.treeNodeWillExpand(node, true);
  9334. if (node._cell == null)
  9335. return;
  9336. if (this.treeNodeRender)
  9337. this.treeNodeRender(node, node._cell);
  9338. var cc = node._cell.getController("expanded");
  9339. if (cc)
  9340. cc.selectedIndex = 1;
  9341. if (node._cell.parent)
  9342. this.checkChildren(node, this.getChildIndex(node._cell));
  9343. }
  9344. _afterCollapsed(node) {
  9345. if (node == this._rootNode) {
  9346. this.checkChildren(this._rootNode, 0);
  9347. return;
  9348. }
  9349. if (this.treeNodeWillExpand)
  9350. this.treeNodeWillExpand(node, false);
  9351. if (node._cell == null)
  9352. return;
  9353. if (this.treeNodeRender)
  9354. this.treeNodeRender(node, node._cell);
  9355. var cc = node._cell.getController("expanded");
  9356. if (cc)
  9357. cc.selectedIndex = 0;
  9358. if (node._cell.parent)
  9359. this.hideFolderNode(node);
  9360. }
  9361. _afterMoved(node) {
  9362. var startIndex = this.getChildIndex(node._cell);
  9363. var endIndex;
  9364. if (node.isFolder)
  9365. endIndex = this.getFolderEndIndex(startIndex, node.level);
  9366. else
  9367. endIndex = startIndex + 1;
  9368. var insertIndex = this.getInsertIndexForNode(node);
  9369. var i;
  9370. var cnt = endIndex - startIndex;
  9371. var obj;
  9372. if (insertIndex < startIndex) {
  9373. for (i = 0; i < cnt; i++) {
  9374. obj = this.getChildAt(startIndex + i);
  9375. this.setChildIndex(obj, insertIndex + i);
  9376. }
  9377. }
  9378. else {
  9379. for (i = 0; i < cnt; i++) {
  9380. obj = this.getChildAt(startIndex);
  9381. this.setChildIndex(obj, insertIndex);
  9382. }
  9383. }
  9384. }
  9385. getFolderEndIndex(startIndex, level) {
  9386. var cnt = this.numChildren;
  9387. for (var i = startIndex + 1; i < cnt; i++) {
  9388. var node = this.getChildAt(i)._treeNode;
  9389. if (node.level <= level)
  9390. return i;
  9391. }
  9392. return cnt;
  9393. }
  9394. checkChildren(folderNode, index) {
  9395. var cnt = folderNode.numChildren;
  9396. for (var i = 0; i < cnt; i++) {
  9397. index++;
  9398. var node = folderNode.getChildAt(i);
  9399. if (node._cell == null)
  9400. this.createCell(node);
  9401. if (!node._cell.parent)
  9402. this.addChildAt(node._cell, index);
  9403. if (node.isFolder && node.expanded)
  9404. index = this.checkChildren(node, index);
  9405. }
  9406. return index;
  9407. }
  9408. hideFolderNode(folderNode) {
  9409. var cnt = folderNode.numChildren;
  9410. for (var i = 0; i < cnt; i++) {
  9411. var node = folderNode.getChildAt(i);
  9412. if (node._cell)
  9413. this.removeChild(node._cell);
  9414. if (node.isFolder && node.expanded)
  9415. this.hideFolderNode(node);
  9416. }
  9417. }
  9418. removeNode(node) {
  9419. if (node._cell) {
  9420. if (node._cell.parent)
  9421. this.removeChild(node._cell);
  9422. this.returnToPool(node._cell);
  9423. node._cell._treeNode = null;
  9424. node._cell = null;
  9425. }
  9426. if (node.isFolder) {
  9427. var cnt = node.numChildren;
  9428. for (var i = 0; i < cnt; i++) {
  9429. var node2 = node.getChildAt(i);
  9430. this.removeNode(node2);
  9431. }
  9432. }
  9433. }
  9434. __cellMouseDown(evt) {
  9435. var node = fgui.GObject.cast(evt.currentTarget)._treeNode;
  9436. this._expandedStatusInEvt = node.expanded;
  9437. }
  9438. __expandedStateChanged(cc) {
  9439. var node = cc.parent._treeNode;
  9440. node.expanded = cc.selectedIndex == 1;
  9441. }
  9442. dispatchItemEvent(item, evt) {
  9443. if (this._clickToExpand != 0) {
  9444. var node = item._treeNode;
  9445. if (node && this._expandedStatusInEvt == node.expanded) {
  9446. if (this._clickToExpand == 2) {
  9447. }
  9448. else
  9449. node.expanded = !node.expanded;
  9450. }
  9451. }
  9452. super.dispatchItemEvent(item, evt);
  9453. }
  9454. setup_beforeAdd(buffer, beginPos) {
  9455. super.setup_beforeAdd(buffer, beginPos);
  9456. buffer.seek(beginPos, 9);
  9457. this._indent = buffer.readInt();
  9458. this._clickToExpand = buffer.readByte();
  9459. }
  9460. readItems(buffer) {
  9461. var cnt;
  9462. var i;
  9463. var nextPos;
  9464. var str;
  9465. var isFolder;
  9466. var lastNode;
  9467. var level;
  9468. var prevLevel = 0;
  9469. cnt = buffer.readShort();
  9470. for (i = 0; i < cnt; i++) {
  9471. nextPos = buffer.readShort();
  9472. nextPos += buffer.position;
  9473. str = buffer.readS();
  9474. if (str == null) {
  9475. str = this.defaultItem;
  9476. if (!str) {
  9477. buffer.position = nextPos;
  9478. continue;
  9479. }
  9480. }
  9481. isFolder = buffer.readBool();
  9482. level = buffer.readByte();
  9483. var node = new fgui.GTreeNode(isFolder, str);
  9484. node.expanded = true;
  9485. if (i == 0)
  9486. this._rootNode.addChild(node);
  9487. else {
  9488. if (level > prevLevel)
  9489. lastNode.addChild(node);
  9490. else if (level < prevLevel) {
  9491. for (var j = level; j <= prevLevel; j++)
  9492. lastNode = lastNode.parent;
  9493. lastNode.addChild(node);
  9494. }
  9495. else
  9496. lastNode.parent.addChild(node);
  9497. }
  9498. lastNode = node;
  9499. prevLevel = level;
  9500. this.setupItem(buffer, node.cell);
  9501. buffer.position = nextPos;
  9502. }
  9503. }
  9504. }
  9505. fgui.GTree = GTree;
  9506. var s_list = new Array();
  9507. })(fgui || (fgui = {}));
  9508. (function (fgui) {
  9509. class GTreeNode {
  9510. constructor(hasChild, resURL) {
  9511. this._level = 0;
  9512. this._resURL = resURL;
  9513. if (hasChild)
  9514. this._children = new Array();
  9515. }
  9516. set expanded(value) {
  9517. if (this._children == null)
  9518. return;
  9519. if (this._expanded != value) {
  9520. this._expanded = value;
  9521. if (this._tree) {
  9522. if (this._expanded)
  9523. this._tree._afterExpanded(this);
  9524. else
  9525. this._tree._afterCollapsed(this);
  9526. }
  9527. }
  9528. }
  9529. get expanded() {
  9530. return this._expanded;
  9531. }
  9532. get isFolder() {
  9533. return this._children != null;
  9534. }
  9535. get parent() {
  9536. return this._parent;
  9537. }
  9538. get text() {
  9539. if (this._cell)
  9540. return this._cell.text;
  9541. else
  9542. return null;
  9543. }
  9544. set text(value) {
  9545. if (this._cell)
  9546. this._cell.text = value;
  9547. }
  9548. get icon() {
  9549. if (this._cell)
  9550. return this._cell.icon;
  9551. else
  9552. return null;
  9553. }
  9554. set icon(value) {
  9555. if (this._cell)
  9556. this._cell.icon = value;
  9557. }
  9558. get cell() {
  9559. return this._cell;
  9560. }
  9561. get level() {
  9562. return this._level;
  9563. }
  9564. _setLevel(value) {
  9565. this._level = value;
  9566. }
  9567. addChild(child) {
  9568. this.addChildAt(child, this._children.length);
  9569. return child;
  9570. }
  9571. addChildAt(child, index) {
  9572. if (!child)
  9573. throw new Error("child is null");
  9574. var numChildren = this._children.length;
  9575. if (index >= 0 && index <= numChildren) {
  9576. if (child._parent == this) {
  9577. this.setChildIndex(child, index);
  9578. }
  9579. else {
  9580. if (child._parent)
  9581. child._parent.removeChild(child);
  9582. var cnt = this._children.length;
  9583. if (index == cnt)
  9584. this._children.push(child);
  9585. else
  9586. this._children.splice(index, 0, child);
  9587. child._parent = this;
  9588. child._level = this._level + 1;
  9589. child._setTree(this._tree);
  9590. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  9591. this._tree._afterInserted(child);
  9592. }
  9593. return child;
  9594. }
  9595. else {
  9596. throw new RangeError("Invalid child index");
  9597. }
  9598. }
  9599. removeChild(child) {
  9600. var childIndex = this._children.indexOf(child);
  9601. if (childIndex != -1) {
  9602. this.removeChildAt(childIndex);
  9603. }
  9604. return child;
  9605. }
  9606. removeChildAt(index) {
  9607. if (index >= 0 && index < this.numChildren) {
  9608. var child = this._children[index];
  9609. this._children.splice(index, 1);
  9610. child._parent = null;
  9611. if (this._tree) {
  9612. child._setTree(null);
  9613. this._tree._afterRemoved(child);
  9614. }
  9615. return child;
  9616. }
  9617. else {
  9618. throw "Invalid child index";
  9619. }
  9620. }
  9621. removeChildren(beginIndex, endIndex) {
  9622. beginIndex = beginIndex || 0;
  9623. if (endIndex == null)
  9624. endIndex = -1;
  9625. if (endIndex < 0 || endIndex >= this.numChildren)
  9626. endIndex = this.numChildren - 1;
  9627. for (var i = beginIndex; i <= endIndex; ++i)
  9628. this.removeChildAt(beginIndex);
  9629. }
  9630. getChildAt(index) {
  9631. if (index >= 0 && index < this.numChildren)
  9632. return this._children[index];
  9633. else
  9634. throw "Invalid child index";
  9635. }
  9636. getChildIndex(child) {
  9637. return this._children.indexOf(child);
  9638. }
  9639. getPrevSibling() {
  9640. if (this._parent == null)
  9641. return null;
  9642. var i = this._parent._children.indexOf(this);
  9643. if (i <= 0)
  9644. return null;
  9645. return this._parent._children[i - 1];
  9646. }
  9647. getNextSibling() {
  9648. if (this._parent == null)
  9649. return null;
  9650. var i = this._parent._children.indexOf(this);
  9651. if (i < 0 || i >= this._parent._children.length - 1)
  9652. return null;
  9653. return this._parent._children[i + 1];
  9654. }
  9655. setChildIndex(child, index) {
  9656. var oldIndex = this._children.indexOf(child);
  9657. if (oldIndex == -1)
  9658. throw "Not a child of this container";
  9659. var cnt = this._children.length;
  9660. if (index < 0)
  9661. index = 0;
  9662. else if (index > cnt)
  9663. index = cnt;
  9664. if (oldIndex == index)
  9665. return;
  9666. this._children.splice(oldIndex, 1);
  9667. this._children.splice(index, 0, child);
  9668. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  9669. this._tree._afterMoved(child);
  9670. }
  9671. swapChildren(child1, child2) {
  9672. var index1 = this._children.indexOf(child1);
  9673. var index2 = this._children.indexOf(child2);
  9674. if (index1 == -1 || index2 == -1)
  9675. throw "Not a child of this container";
  9676. this.swapChildrenAt(index1, index2);
  9677. }
  9678. swapChildrenAt(index1, index2) {
  9679. var child1 = this._children[index1];
  9680. var child2 = this._children[index2];
  9681. this.setChildIndex(child1, index2);
  9682. this.setChildIndex(child2, index1);
  9683. }
  9684. get numChildren() {
  9685. return this._children.length;
  9686. }
  9687. expandToRoot() {
  9688. var p = this;
  9689. while (p) {
  9690. p.expanded = true;
  9691. p = p.parent;
  9692. }
  9693. }
  9694. get tree() {
  9695. return this._tree;
  9696. }
  9697. _setTree(value) {
  9698. this._tree = value;
  9699. if (this._tree && this._tree.treeNodeWillExpand && this._expanded)
  9700. this._tree.treeNodeWillExpand(this, true);
  9701. if (this._children) {
  9702. var cnt = this._children.length;
  9703. for (var i = 0; i < cnt; i++) {
  9704. var node = this._children[i];
  9705. node._level = this._level + 1;
  9706. node._setTree(value);
  9707. }
  9708. }
  9709. }
  9710. }
  9711. fgui.GTreeNode = GTreeNode;
  9712. })(fgui || (fgui = {}));
  9713. (function (fgui) {
  9714. class Margin {
  9715. constructor() {
  9716. this.left = 0;
  9717. this.right = 0;
  9718. this.top = 0;
  9719. this.bottom = 0;
  9720. }
  9721. copy(source) {
  9722. this.top = source.top;
  9723. this.bottom = source.bottom;
  9724. this.left = source.left;
  9725. this.right = source.right;
  9726. }
  9727. isNone() {
  9728. return this.left == 0 && this.right == 0 && this.top == 0 && this.bottom == 0;
  9729. }
  9730. }
  9731. fgui.Margin = Margin;
  9732. })(fgui || (fgui = {}));
  9733. (function (fgui) {
  9734. class PackageItem {
  9735. constructor() {
  9736. this.width = 0;
  9737. this.height = 0;
  9738. }
  9739. load() {
  9740. return this.owner.getItemAsset(this);
  9741. }
  9742. getBranch() {
  9743. if (this.branches && this.owner._branchIndex != -1) {
  9744. var itemId = this.branches[this.owner._branchIndex];
  9745. if (itemId)
  9746. return this.owner.getItemById(itemId);
  9747. }
  9748. return this;
  9749. }
  9750. getHighResolution() {
  9751. if (this.highResolution && fgui.GRoot.contentScaleLevel > 0) {
  9752. var itemId = this.highResolution[fgui.GRoot.contentScaleLevel - 1];
  9753. if (itemId)
  9754. return this.owner.getItemById(itemId);
  9755. }
  9756. return this;
  9757. }
  9758. toString() {
  9759. return this.name;
  9760. }
  9761. }
  9762. fgui.PackageItem = PackageItem;
  9763. })(fgui || (fgui = {}));
  9764. (function (fgui) {
  9765. class PopupMenu {
  9766. constructor(url) {
  9767. if (!url) {
  9768. url = fgui.UIConfig.popupMenu;
  9769. if (!url)
  9770. throw "UIConfig.popupMenu not defined";
  9771. }
  9772. this._contentPane = fgui.UIPackage.createObjectFromURL(url);
  9773. this._contentPane.on(fgui.Event.DISPLAY, this.onDisplay, this);
  9774. this._list = (this._contentPane.getChild("list"));
  9775. this._list.removeChildrenToPool();
  9776. this._list.addRelation(this._contentPane, fgui.RelationType.Width);
  9777. this._list.removeRelation(this._contentPane, fgui.RelationType.Height);
  9778. this._contentPane.addRelation(this._list, fgui.RelationType.Height);
  9779. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  9780. }
  9781. dispose() {
  9782. this._contentPane.dispose();
  9783. }
  9784. addItem(caption, callback) {
  9785. var item = this._list.addItemFromPool();
  9786. item.title = caption;
  9787. item.data = callback;
  9788. item.grayed = false;
  9789. var c = item.getController("checked");
  9790. if (c)
  9791. c.selectedIndex = 0;
  9792. return item;
  9793. }
  9794. addItemAt(caption, index, callback) {
  9795. var item = this._list.getFromPool();
  9796. this._list.addChildAt(item, index);
  9797. item.title = caption;
  9798. item.data = callback;
  9799. item.grayed = false;
  9800. var c = item.getController("checked");
  9801. if (c)
  9802. c.selectedIndex = 0;
  9803. return item;
  9804. }
  9805. addSeperator() {
  9806. if (fgui.UIConfig.popupMenu_seperator == null)
  9807. throw "UIConfig.popupMenu_seperator not defined";
  9808. this.list.addItemFromPool(fgui.UIConfig.popupMenu_seperator);
  9809. }
  9810. getItemName(index) {
  9811. var item = this._list.getChildAt(index);
  9812. return item.name;
  9813. }
  9814. setItemText(name, caption) {
  9815. var item = this._list.getChild(name);
  9816. item.title = caption;
  9817. }
  9818. setItemVisible(name, visible) {
  9819. var item = this._list.getChild(name);
  9820. if (item.visible != visible) {
  9821. item.visible = visible;
  9822. this._list.setBoundsChangedFlag();
  9823. }
  9824. }
  9825. setItemGrayed(name, grayed) {
  9826. var item = this._list.getChild(name);
  9827. item.grayed = grayed;
  9828. }
  9829. setItemCheckable(name, checkable) {
  9830. var item = this._list.getChild(name);
  9831. var c = item.getController("checked");
  9832. if (c) {
  9833. if (checkable) {
  9834. if (c.selectedIndex == 0)
  9835. c.selectedIndex = 1;
  9836. }
  9837. else
  9838. c.selectedIndex = 0;
  9839. }
  9840. }
  9841. setItemChecked(name, checked) {
  9842. var item = this._list.getChild(name);
  9843. var c = item.getController("checked");
  9844. if (c)
  9845. c.selectedIndex = checked ? 2 : 1;
  9846. }
  9847. isItemChecked(name) {
  9848. var item = this._list.getChild(name);
  9849. var c = item.getController("checked");
  9850. if (c)
  9851. return c.selectedIndex == 2;
  9852. else
  9853. return false;
  9854. }
  9855. removeItem(name) {
  9856. var item = this._list.getChild(name);
  9857. if (item) {
  9858. var index = this._list.getChildIndex(item);
  9859. this._list.removeChildToPoolAt(index);
  9860. return true;
  9861. }
  9862. else
  9863. return false;
  9864. }
  9865. clearItems() {
  9866. this._list.removeChildrenToPool();
  9867. }
  9868. get itemCount() {
  9869. return this._list.numChildren;
  9870. }
  9871. get contentPane() {
  9872. return this._contentPane;
  9873. }
  9874. get list() {
  9875. return this._list;
  9876. }
  9877. show(target = null, dir) {
  9878. var r = target != null ? target.root : fgui.GRoot.inst;
  9879. r.showPopup(this.contentPane, (target instanceof fgui.GRoot) ? null : target, dir);
  9880. }
  9881. onClickItem(item, evt) {
  9882. let _this = this;
  9883. this._list._partner.callLater(function (dt) {
  9884. _this.onClickItem2(item, evt);
  9885. }, 0.1);
  9886. }
  9887. onClickItem2(item, evt) {
  9888. if (!(item instanceof fgui.GButton))
  9889. return;
  9890. if (item.grayed) {
  9891. this._list.selectedIndex = -1;
  9892. return;
  9893. }
  9894. var c = item.getController("checked");
  9895. if (c && c.selectedIndex != 0) {
  9896. if (c.selectedIndex == 1)
  9897. c.selectedIndex = 2;
  9898. else
  9899. c.selectedIndex = 1;
  9900. }
  9901. var r = (this._contentPane.parent);
  9902. r.hidePopup(this.contentPane);
  9903. if (item.data instanceof Function)
  9904. item.data(item, evt);
  9905. }
  9906. onDisplay() {
  9907. this._list.selectedIndex = -1;
  9908. this._list.resizeToFit(100000, 10);
  9909. }
  9910. }
  9911. fgui.PopupMenu = PopupMenu;
  9912. })(fgui || (fgui = {}));
  9913. (function (fgui) {
  9914. class RelationItem {
  9915. constructor(owner) {
  9916. this._owner = owner;
  9917. this._defs = new Array();
  9918. }
  9919. get owner() {
  9920. return this._owner;
  9921. }
  9922. set target(value) {
  9923. if (this._target != value) {
  9924. if (this._target)
  9925. this.releaseRefTarget(this._target);
  9926. this._target = value;
  9927. if (this._target)
  9928. this.addRefTarget(this._target);
  9929. }
  9930. }
  9931. get target() {
  9932. return this._target;
  9933. }
  9934. add(relationType, usePercent) {
  9935. if (relationType == fgui.RelationType.Size) {
  9936. this.add(fgui.RelationType.Width, usePercent);
  9937. this.add(fgui.RelationType.Height, usePercent);
  9938. return;
  9939. }
  9940. var length = this._defs.length;
  9941. for (var i = 0; i < length; i++) {
  9942. var def = this._defs[i];
  9943. if (def.type == relationType)
  9944. return;
  9945. }
  9946. this.internalAdd(relationType, usePercent);
  9947. }
  9948. internalAdd(relationType, usePercent) {
  9949. if (relationType == fgui.RelationType.Size) {
  9950. this.internalAdd(fgui.RelationType.Width, usePercent);
  9951. this.internalAdd(fgui.RelationType.Height, usePercent);
  9952. return;
  9953. }
  9954. var info = new RelationDef();
  9955. info.percent = usePercent;
  9956. info.type = relationType;
  9957. info.axis = relationType <= fgui.RelationType.Right_Right || relationType == fgui.RelationType.Width || (relationType >= fgui.RelationType.LeftExt_Left && relationType <= fgui.RelationType.RightExt_Right) ? 0 : 1;
  9958. this._defs.push(info);
  9959. }
  9960. remove(relationType) {
  9961. if (relationType == fgui.RelationType.Size) {
  9962. this.remove(fgui.RelationType.Width);
  9963. this.remove(fgui.RelationType.Height);
  9964. return;
  9965. }
  9966. var dc = this._defs.length;
  9967. for (var k = 0; k < dc; k++) {
  9968. if (this._defs[k].type == relationType) {
  9969. this._defs.splice(k, 1);
  9970. break;
  9971. }
  9972. }
  9973. }
  9974. copyFrom(source) {
  9975. this.target = source.target;
  9976. this._defs.length = 0;
  9977. var length = source._defs.length;
  9978. for (var i = 0; i < length; i++) {
  9979. var info = source._defs[i];
  9980. var info2 = new RelationDef();
  9981. info2.copyFrom(info);
  9982. this._defs.push(info2);
  9983. }
  9984. }
  9985. dispose() {
  9986. if (this._target) {
  9987. this.releaseRefTarget(this._target);
  9988. this._target = null;
  9989. }
  9990. }
  9991. get isEmpty() {
  9992. return this._defs.length == 0;
  9993. }
  9994. applyOnSelfResized(dWidth, dHeight, applyPivot) {
  9995. var ox = this._owner.x;
  9996. var oy = this._owner.y;
  9997. var length = this._defs.length;
  9998. for (var i = 0; i < length; i++) {
  9999. var info = this._defs[i];
  10000. switch (info.type) {
  10001. case fgui.RelationType.Center_Center:
  10002. this._owner.x -= (0.5 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10003. break;
  10004. case fgui.RelationType.Right_Center:
  10005. case fgui.RelationType.Right_Left:
  10006. case fgui.RelationType.Right_Right:
  10007. this._owner.x -= (1 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10008. break;
  10009. case fgui.RelationType.Middle_Middle:
  10010. this._owner.y -= (0.5 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10011. break;
  10012. case fgui.RelationType.Bottom_Middle:
  10013. case fgui.RelationType.Bottom_Top:
  10014. case fgui.RelationType.Bottom_Bottom:
  10015. this._owner.y -= (1 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10016. break;
  10017. }
  10018. }
  10019. if (ox != this._owner.x || oy != this._owner.y) {
  10020. ox = this._owner.x - ox;
  10021. oy = this._owner.y - oy;
  10022. this._owner.updateGearFromRelations(1, ox, oy);
  10023. if (this._owner.parent) {
  10024. var len = this._owner.parent._transitions.length;
  10025. if (len > 0) {
  10026. for (var i = 0; i < len; ++i) {
  10027. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  10028. }
  10029. }
  10030. }
  10031. }
  10032. }
  10033. applyOnXYChanged(info, dx, dy) {
  10034. var tmp;
  10035. switch (info.type) {
  10036. case fgui.RelationType.Left_Left:
  10037. case fgui.RelationType.Left_Center:
  10038. case fgui.RelationType.Left_Right:
  10039. case fgui.RelationType.Center_Center:
  10040. case fgui.RelationType.Right_Left:
  10041. case fgui.RelationType.Right_Center:
  10042. case fgui.RelationType.Right_Right:
  10043. this._owner.x += dx;
  10044. break;
  10045. case fgui.RelationType.Top_Top:
  10046. case fgui.RelationType.Top_Middle:
  10047. case fgui.RelationType.Top_Bottom:
  10048. case fgui.RelationType.Middle_Middle:
  10049. case fgui.RelationType.Bottom_Top:
  10050. case fgui.RelationType.Bottom_Middle:
  10051. case fgui.RelationType.Bottom_Bottom:
  10052. this._owner.y += dy;
  10053. break;
  10054. case fgui.RelationType.Width:
  10055. case fgui.RelationType.Height:
  10056. break;
  10057. case fgui.RelationType.LeftExt_Left:
  10058. case fgui.RelationType.LeftExt_Right:
  10059. if (this._owner != this._target.parent) {
  10060. tmp = this._owner.xMin;
  10061. this._owner.width = this._owner._rawWidth - dx;
  10062. this._owner.xMin = tmp + dx;
  10063. }
  10064. else
  10065. this._owner.width = this._owner._rawWidth - dx;
  10066. break;
  10067. case fgui.RelationType.RightExt_Left:
  10068. case fgui.RelationType.RightExt_Right:
  10069. if (this._owner != this._target.parent) {
  10070. tmp = this._owner.xMin;
  10071. this._owner.width = this._owner._rawWidth + dx;
  10072. this._owner.xMin = tmp;
  10073. }
  10074. else
  10075. this._owner.width = this._owner._rawWidth + dx;
  10076. break;
  10077. case fgui.RelationType.TopExt_Top:
  10078. case fgui.RelationType.TopExt_Bottom:
  10079. if (this._owner != this._target.parent) {
  10080. tmp = this._owner.yMin;
  10081. this._owner.height = this._owner._rawHeight - dy;
  10082. this._owner.yMin = tmp + dy;
  10083. }
  10084. else
  10085. this._owner.height = this._owner._rawHeight - dy;
  10086. break;
  10087. case fgui.RelationType.BottomExt_Top:
  10088. case fgui.RelationType.BottomExt_Bottom:
  10089. if (this._owner != this._target.parent) {
  10090. tmp = this._owner.yMin;
  10091. this._owner.height = this._owner._rawHeight + dy;
  10092. this._owner.yMin = tmp;
  10093. }
  10094. else
  10095. this._owner.height = this._owner._rawHeight + dy;
  10096. break;
  10097. }
  10098. }
  10099. applyOnSizeChanged(info) {
  10100. var pos = 0, pivot = 0, delta = 0;
  10101. var v, tmp;
  10102. if (info.axis == 0) {
  10103. if (this._target != this._owner.parent) {
  10104. pos = this._target.x;
  10105. if (this._target.pivotAsAnchor)
  10106. pivot = this._target.pivotX;
  10107. }
  10108. if (info.percent) {
  10109. if (this._targetWidth != 0)
  10110. delta = this._target._width / this._targetWidth;
  10111. }
  10112. else
  10113. delta = this._target._width - this._targetWidth;
  10114. }
  10115. else {
  10116. if (this._target != this._owner.parent) {
  10117. pos = this._target.y;
  10118. if (this._target.pivotAsAnchor)
  10119. pivot = this._target.pivotY;
  10120. }
  10121. if (info.percent) {
  10122. if (this._targetHeight != 0)
  10123. delta = this._target._height / this._targetHeight;
  10124. }
  10125. else
  10126. delta = this._target._height - this._targetHeight;
  10127. }
  10128. switch (info.type) {
  10129. case fgui.RelationType.Left_Left:
  10130. if (info.percent)
  10131. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  10132. else if (pivot != 0)
  10133. this._owner.x += delta * -pivot;
  10134. break;
  10135. case fgui.RelationType.Left_Center:
  10136. if (info.percent)
  10137. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  10138. else
  10139. this._owner.x += delta * (0.5 - pivot);
  10140. break;
  10141. case fgui.RelationType.Left_Right:
  10142. if (info.percent)
  10143. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  10144. else
  10145. this._owner.x += delta * (1 - pivot);
  10146. break;
  10147. case fgui.RelationType.Center_Center:
  10148. if (info.percent)
  10149. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth * 0.5 - pos) * delta - this._owner._rawWidth * 0.5;
  10150. else
  10151. this._owner.x += delta * (0.5 - pivot);
  10152. break;
  10153. case fgui.RelationType.Right_Left:
  10154. if (info.percent)
  10155. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  10156. else if (pivot != 0)
  10157. this._owner.x += delta * -pivot;
  10158. break;
  10159. case fgui.RelationType.Right_Center:
  10160. if (info.percent)
  10161. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  10162. else
  10163. this._owner.x += delta * (0.5 - pivot);
  10164. break;
  10165. case fgui.RelationType.Right_Right:
  10166. if (info.percent)
  10167. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  10168. else
  10169. this._owner.x += delta * (1 - pivot);
  10170. break;
  10171. case fgui.RelationType.Top_Top:
  10172. if (info.percent)
  10173. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  10174. else if (pivot != 0)
  10175. this._owner.y += delta * -pivot;
  10176. break;
  10177. case fgui.RelationType.Top_Middle:
  10178. if (info.percent)
  10179. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  10180. else
  10181. this._owner.y += delta * (0.5 - pivot);
  10182. break;
  10183. case fgui.RelationType.Top_Bottom:
  10184. if (info.percent)
  10185. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  10186. else
  10187. this._owner.y += delta * (1 - pivot);
  10188. break;
  10189. case fgui.RelationType.Middle_Middle:
  10190. if (info.percent)
  10191. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight * 0.5 - pos) * delta - this._owner._rawHeight * 0.5;
  10192. else
  10193. this._owner.y += delta * (0.5 - pivot);
  10194. break;
  10195. case fgui.RelationType.Bottom_Top:
  10196. if (info.percent)
  10197. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  10198. else if (pivot != 0)
  10199. this._owner.y += delta * -pivot;
  10200. break;
  10201. case fgui.RelationType.Bottom_Middle:
  10202. if (info.percent)
  10203. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  10204. else
  10205. this._owner.y += delta * (0.5 - pivot);
  10206. break;
  10207. case fgui.RelationType.Bottom_Bottom:
  10208. if (info.percent)
  10209. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  10210. else
  10211. this._owner.y += delta * (1 - pivot);
  10212. break;
  10213. case fgui.RelationType.Width:
  10214. if (this._owner._underConstruct && this._owner == this._target.parent)
  10215. v = this._owner.sourceWidth - this._target.initWidth;
  10216. else
  10217. v = this._owner._rawWidth - this._targetWidth;
  10218. if (info.percent)
  10219. v = v * delta;
  10220. if (this._target == this._owner.parent) {
  10221. if (this._owner.pivotAsAnchor) {
  10222. tmp = this._owner.xMin;
  10223. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  10224. this._owner.xMin = tmp;
  10225. }
  10226. else
  10227. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  10228. }
  10229. else
  10230. this._owner.width = this._target._width + v;
  10231. break;
  10232. case fgui.RelationType.Height:
  10233. if (this._owner._underConstruct && this._owner == this._target.parent)
  10234. v = this._owner.sourceHeight - this._target.initHeight;
  10235. else
  10236. v = this._owner._rawHeight - this._targetHeight;
  10237. if (info.percent)
  10238. v = v * delta;
  10239. if (this._target == this._owner.parent) {
  10240. if (this._owner.pivotAsAnchor) {
  10241. tmp = this._owner.yMin;
  10242. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  10243. this._owner.yMin = tmp;
  10244. }
  10245. else
  10246. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  10247. }
  10248. else
  10249. this._owner.height = this._target._height + v;
  10250. break;
  10251. case fgui.RelationType.LeftExt_Left:
  10252. tmp = this._owner.xMin;
  10253. if (info.percent)
  10254. v = pos + (tmp - pos) * delta - tmp;
  10255. else
  10256. v = delta * -pivot;
  10257. this._owner.width = this._owner._rawWidth - v;
  10258. this._owner.xMin = tmp + v;
  10259. break;
  10260. case fgui.RelationType.LeftExt_Right:
  10261. tmp = this._owner.xMin;
  10262. if (info.percent)
  10263. v = pos + (tmp - pos) * delta - tmp;
  10264. else
  10265. v = delta * (1 - pivot);
  10266. this._owner.width = this._owner._rawWidth - v;
  10267. this._owner.xMin = tmp + v;
  10268. break;
  10269. case fgui.RelationType.RightExt_Left:
  10270. tmp = this._owner.xMin;
  10271. if (info.percent)
  10272. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  10273. else
  10274. v = delta * -pivot;
  10275. this._owner.width = this._owner._rawWidth + v;
  10276. this._owner.xMin = tmp;
  10277. break;
  10278. case fgui.RelationType.RightExt_Right:
  10279. tmp = this._owner.xMin;
  10280. if (info.percent) {
  10281. if (this._owner == this._target.parent) {
  10282. if (this._owner._underConstruct)
  10283. this._owner.width = pos + this._target._width - this._target._width * pivot + (this._owner.sourceWidth - pos - this._target.initWidth + this._target.initWidth * pivot) * delta;
  10284. else
  10285. this._owner.width = pos + (this._owner._rawWidth - pos) * delta;
  10286. }
  10287. else {
  10288. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  10289. this._owner.width = this._owner._rawWidth + v;
  10290. this._owner.xMin = tmp;
  10291. }
  10292. }
  10293. else {
  10294. if (this._owner == this._target.parent) {
  10295. if (this._owner._underConstruct)
  10296. this._owner.width = this._owner.sourceWidth + (this._target._width - this._target.initWidth) * (1 - pivot);
  10297. else
  10298. this._owner.width = this._owner._rawWidth + delta * (1 - pivot);
  10299. }
  10300. else {
  10301. v = delta * (1 - pivot);
  10302. this._owner.width = this._owner._rawWidth + v;
  10303. this._owner.xMin = tmp;
  10304. }
  10305. }
  10306. break;
  10307. case fgui.RelationType.TopExt_Top:
  10308. tmp = this._owner.yMin;
  10309. if (info.percent)
  10310. v = pos + (tmp - pos) * delta - tmp;
  10311. else
  10312. v = delta * -pivot;
  10313. this._owner.height = this._owner._rawHeight - v;
  10314. this._owner.yMin = tmp + v;
  10315. break;
  10316. case fgui.RelationType.TopExt_Bottom:
  10317. tmp = this._owner.yMin;
  10318. if (info.percent)
  10319. v = pos + (tmp - pos) * delta - tmp;
  10320. else
  10321. v = delta * (1 - pivot);
  10322. this._owner.height = this._owner._rawHeight - v;
  10323. this._owner.yMin = tmp + v;
  10324. break;
  10325. case fgui.RelationType.BottomExt_Top:
  10326. tmp = this._owner.yMin;
  10327. if (info.percent)
  10328. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  10329. else
  10330. v = delta * -pivot;
  10331. this._owner.height = this._owner._rawHeight + v;
  10332. this._owner.yMin = tmp;
  10333. break;
  10334. case fgui.RelationType.BottomExt_Bottom:
  10335. tmp = this._owner.yMin;
  10336. if (info.percent) {
  10337. if (this._owner == this._target.parent) {
  10338. if (this._owner._underConstruct)
  10339. this._owner.height = pos + this._target._height - this._target._height * pivot + (this._owner.sourceHeight - pos - this._target.initHeight + this._target.initHeight * pivot) * delta;
  10340. else
  10341. this._owner.height = pos + (this._owner._rawHeight - pos) * delta;
  10342. }
  10343. else {
  10344. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  10345. this._owner.height = this._owner._rawHeight + v;
  10346. this._owner.yMin = tmp;
  10347. }
  10348. }
  10349. else {
  10350. if (this._owner == this._target.parent) {
  10351. if (this._owner._underConstruct)
  10352. this._owner.height = this._owner.sourceHeight + (this._target._height - this._target.initHeight) * (1 - pivot);
  10353. else
  10354. this._owner.height = this._owner._rawHeight + delta * (1 - pivot);
  10355. }
  10356. else {
  10357. v = delta * (1 - pivot);
  10358. this._owner.height = this._owner._rawHeight + v;
  10359. this._owner.yMin = tmp;
  10360. }
  10361. }
  10362. break;
  10363. }
  10364. }
  10365. addRefTarget(target) {
  10366. if (target != this._owner.parent)
  10367. target.on(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  10368. target.on(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  10369. target.on(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  10370. this._targetX = this._target.x;
  10371. this._targetY = this._target.y;
  10372. this._targetWidth = this._target._width;
  10373. this._targetHeight = this._target._height;
  10374. }
  10375. releaseRefTarget(target) {
  10376. if (!target.node)
  10377. return;
  10378. target.off(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  10379. target.off(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  10380. target.off(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  10381. }
  10382. __targetXYChanged(evt) {
  10383. if (this._owner.relations.handling != null || (this._owner.group != null && this._owner.group._updating)) {
  10384. this._targetX = this._target.x;
  10385. this._targetY = this._target.y;
  10386. return;
  10387. }
  10388. this._owner.relations.handling = this._target;
  10389. var ox = this._owner.x;
  10390. var oy = this._owner.y;
  10391. var dx = this._target.x - this._targetX;
  10392. var dy = this._target.y - this._targetY;
  10393. var length = this._defs.length;
  10394. for (var i = 0; i < length; i++) {
  10395. var info = this._defs[i];
  10396. this.applyOnXYChanged(info, dx, dy);
  10397. }
  10398. this._targetX = this._target.x;
  10399. this._targetY = this._target.y;
  10400. if (ox != this._owner.x || oy != this._owner.y) {
  10401. ox = this._owner.x - ox;
  10402. oy = this._owner.y - oy;
  10403. this._owner.updateGearFromRelations(1, ox, oy);
  10404. if (this._owner.parent) {
  10405. var len = this._owner.parent._transitions.length;
  10406. if (len > 0) {
  10407. for (var i = 0; i < len; ++i) {
  10408. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  10409. }
  10410. }
  10411. }
  10412. }
  10413. this._owner.relations.handling = null;
  10414. }
  10415. __targetSizeChanged(evt) {
  10416. if (this._owner.relations.handling != null)
  10417. return;
  10418. let underConstruct = this._owner._underConstruct;
  10419. if (!this._owner._underConstruct) {
  10420. this._owner._underConstruct = this._target._underConstruct;
  10421. }
  10422. this._owner.relations.handling = this._target;
  10423. var ox = this._owner.x;
  10424. var oy = this._owner.y;
  10425. var ow = this._owner._rawWidth;
  10426. var oh = this._owner._rawHeight;
  10427. var length = this._defs.length;
  10428. for (var i = 0; i < length; i++) {
  10429. var info = this._defs[i];
  10430. this.applyOnSizeChanged(info);
  10431. }
  10432. this._targetWidth = this._target._width;
  10433. this._targetHeight = this._target._height;
  10434. if (ox != this._owner.x || oy != this._owner.y) {
  10435. ox = this._owner.x - ox;
  10436. oy = this._owner.y - oy;
  10437. this._owner.updateGearFromRelations(1, ox, oy);
  10438. if (this._owner.parent) {
  10439. var len = this._owner.parent._transitions.length;
  10440. if (len > 0) {
  10441. for (var i = 0; i < len; ++i) {
  10442. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  10443. }
  10444. }
  10445. }
  10446. }
  10447. if (ow != this._owner._rawWidth || oh != this._owner._rawHeight) {
  10448. ow = this._owner._rawWidth - ow;
  10449. oh = this._owner._rawHeight - oh;
  10450. this._owner.updateGearFromRelations(2, ow, oh);
  10451. }
  10452. this._owner._underConstruct = underConstruct;
  10453. this._owner.relations.handling = null;
  10454. }
  10455. __targetSizeWillChange(evt) {
  10456. this._owner.relations.sizeDirty = true;
  10457. }
  10458. }
  10459. fgui.RelationItem = RelationItem;
  10460. class RelationDef {
  10461. constructor() { }
  10462. copyFrom(source) {
  10463. this.percent = source.percent;
  10464. this.type = source.type;
  10465. this.axis = source.axis;
  10466. }
  10467. }
  10468. fgui.RelationDef = RelationDef;
  10469. })(fgui || (fgui = {}));
  10470. (function (fgui) {
  10471. class Relations {
  10472. constructor(owner) {
  10473. this._owner = owner;
  10474. this._items = new Array();
  10475. }
  10476. add(target, relationType, usePercent) {
  10477. var length = this._items.length;
  10478. for (var i = 0; i < length; i++) {
  10479. var item = this._items[i];
  10480. if (item.target == target) {
  10481. item.add(relationType, usePercent);
  10482. return;
  10483. }
  10484. }
  10485. var newItem = new fgui.RelationItem(this._owner);
  10486. newItem.target = target;
  10487. newItem.add(relationType, usePercent);
  10488. this._items.push(newItem);
  10489. }
  10490. remove(target, relationType) {
  10491. relationType = relationType || 0;
  10492. var cnt = this._items.length;
  10493. var i = 0;
  10494. while (i < cnt) {
  10495. var item = this._items[i];
  10496. if (item.target == target) {
  10497. item.remove(relationType);
  10498. if (item.isEmpty) {
  10499. item.dispose();
  10500. this._items.splice(i, 1);
  10501. cnt--;
  10502. }
  10503. else
  10504. i++;
  10505. }
  10506. else
  10507. i++;
  10508. }
  10509. }
  10510. contains(target) {
  10511. var length = this._items.length;
  10512. for (var i = 0; i < length; i++) {
  10513. var item = this._items[i];
  10514. if (item.target == target)
  10515. return true;
  10516. }
  10517. return false;
  10518. }
  10519. clearFor(target) {
  10520. var cnt = this._items.length;
  10521. var i = 0;
  10522. while (i < cnt) {
  10523. var item = this._items[i];
  10524. if (item.target == target) {
  10525. item.dispose();
  10526. this._items.splice(i, 1);
  10527. cnt--;
  10528. }
  10529. else
  10530. i++;
  10531. }
  10532. }
  10533. clearAll() {
  10534. var length = this._items.length;
  10535. for (var i = 0; i < length; i++) {
  10536. var item = this._items[i];
  10537. item.dispose();
  10538. }
  10539. this._items.length = 0;
  10540. }
  10541. copyFrom(source) {
  10542. this.clearAll();
  10543. var arr = source._items;
  10544. var length = arr.length;
  10545. for (var i = 0; i < length; i++) {
  10546. var ri = arr[i];
  10547. var item = new fgui.RelationItem(this._owner);
  10548. item.copyFrom(ri);
  10549. this._items.push(item);
  10550. }
  10551. }
  10552. dispose() {
  10553. this.clearAll();
  10554. }
  10555. onOwnerSizeChanged(dWidth, dHeight, applyPivot) {
  10556. if (this._items.length == 0)
  10557. return;
  10558. var length = this._items.length;
  10559. for (var i = 0; i < length; i++) {
  10560. var item = this._items[i];
  10561. item.applyOnSelfResized(dWidth, dHeight, applyPivot);
  10562. }
  10563. }
  10564. ensureRelationsSizeCorrect() {
  10565. if (this._items.length == 0)
  10566. return;
  10567. this.sizeDirty = false;
  10568. var length = this._items.length;
  10569. for (var i = 0; i < length; i++) {
  10570. var item = this._items[i];
  10571. item.target.ensureSizeCorrect();
  10572. }
  10573. }
  10574. get empty() {
  10575. return this._items.length == 0;
  10576. }
  10577. setup(buffer, parentToChild) {
  10578. var cnt = buffer.readByte();
  10579. var target;
  10580. for (var i = 0; i < cnt; i++) {
  10581. var targetIndex = buffer.readShort();
  10582. if (targetIndex == -1)
  10583. target = this._owner.parent;
  10584. else if (parentToChild)
  10585. target = this._owner.getChildAt(targetIndex);
  10586. else
  10587. target = this._owner.parent.getChildAt(targetIndex);
  10588. var newItem = new fgui.RelationItem(this._owner);
  10589. newItem.target = target;
  10590. this._items.push(newItem);
  10591. var cnt2 = buffer.readByte();
  10592. for (var j = 0; j < cnt2; j++) {
  10593. var rt = buffer.readByte();
  10594. var usePercent = buffer.readBool();
  10595. newItem.internalAdd(rt, usePercent);
  10596. }
  10597. }
  10598. }
  10599. }
  10600. fgui.Relations = Relations;
  10601. })(fgui || (fgui = {}));
  10602. (function (fgui) {
  10603. class ScrollPane extends cc.Component {
  10604. constructor() {
  10605. super(...arguments);
  10606. this._aniFlag = 0;
  10607. this._scrollTime = 0;
  10608. }
  10609. setup(buffer) {
  10610. const o = (this._owner = this.node['$gobj']);
  10611. this._maskContainer = new cc.Node('ScrollPane');
  10612. this._maskContainer.setAnchorPoint(0, 1);
  10613. this._maskContainer.parent = o.node;
  10614. this._container = o._container;
  10615. this._container.parent = this._maskContainer;
  10616. this._scrollBarMargin = new fgui.Margin();
  10617. this._mouseWheelEnabled = true;
  10618. this._xPos = 0;
  10619. this._yPos = 0;
  10620. this._aniFlag = 0;
  10621. this._tweening = 0;
  10622. this._footerLockedSize = 0;
  10623. this._headerLockedSize = 0;
  10624. this._viewSize = new cc.Vec2();
  10625. this._contentSize = new cc.Vec2();
  10626. this._pageSize = new cc.Vec2(1, 1);
  10627. this._overlapSize = new cc.Vec2();
  10628. this._tweenTime = new cc.Vec2();
  10629. this._tweenStart = new cc.Vec2();
  10630. this._tweenDuration = new cc.Vec2();
  10631. this._tweenChange = new cc.Vec2();
  10632. this._velocity = new cc.Vec2();
  10633. this._containerPos = new cc.Vec2();
  10634. this._beginTouchPos = new cc.Vec2();
  10635. this._lastTouchPos = new cc.Vec2();
  10636. this._lastTouchGlobalPos = new cc.Vec2();
  10637. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  10638. this._mouseWheelStep = this._scrollStep * 2;
  10639. this._decelerationRate = fgui.UIConfig.defaultScrollDecelerationRate;
  10640. o.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin, this);
  10641. o.on(fgui.Event.TOUCH_MOVE, this.onTouchMove, this);
  10642. o.on(fgui.Event.TOUCH_END, this.onTouchEnd, this);
  10643. o.on(fgui.Event.MOUSE_WHEEL, this.onMouseWheel, this);
  10644. this._scrollType = buffer.readByte();
  10645. var scrollBarDisplay = buffer.readByte();
  10646. var flags = buffer.readInt();
  10647. if (buffer.readBool()) {
  10648. this._scrollBarMargin.top = buffer.readInt();
  10649. this._scrollBarMargin.bottom = buffer.readInt();
  10650. this._scrollBarMargin.left = buffer.readInt();
  10651. this._scrollBarMargin.right = buffer.readInt();
  10652. }
  10653. var vtScrollBarRes = buffer.readS();
  10654. var hzScrollBarRes = buffer.readS();
  10655. var headerRes = buffer.readS();
  10656. var footerRes = buffer.readS();
  10657. if ((flags & 1) != 0)
  10658. this._displayOnLeft = true;
  10659. if ((flags & 2) != 0)
  10660. this._snapToItem = true;
  10661. if ((flags & 4) != 0)
  10662. this._displayInDemand = true;
  10663. if ((flags & 8) != 0)
  10664. this._pageMode = true;
  10665. if (flags & 16)
  10666. this._touchEffect = true;
  10667. else if (flags & 32)
  10668. this._touchEffect = false;
  10669. else
  10670. this._touchEffect = fgui.UIConfig.defaultScrollTouchEffect;
  10671. if (flags & 64)
  10672. this._bouncebackEffect = true;
  10673. else if (flags & 128)
  10674. this._bouncebackEffect = false;
  10675. else
  10676. this._bouncebackEffect = fgui.UIConfig.defaultScrollBounceEffect;
  10677. if ((flags & 256) != 0)
  10678. this._inertiaDisabled = true;
  10679. if ((flags & 512) == 0)
  10680. this._maskContainer.addComponent(cc.Mask);
  10681. if ((flags & 1024) != 0)
  10682. this._floating = true;
  10683. if ((flags & 2048) != 0)
  10684. this._dontClipMargin = true;
  10685. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Default)
  10686. scrollBarDisplay = fgui.UIConfig.defaultScrollBarDisplay;
  10687. if (scrollBarDisplay != fgui.ScrollBarDisplayType.Hidden) {
  10688. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) {
  10689. var res = vtScrollBarRes ? vtScrollBarRes : fgui.UIConfig.verticalScrollBar;
  10690. if (res) {
  10691. this._vtScrollBar = fgui.UIPackage.createObjectFromURL(res);
  10692. if (!this._vtScrollBar)
  10693. throw 'cannot create scrollbar from ' + res;
  10694. this._vtScrollBar.setScrollPane(this, true);
  10695. this._vtScrollBar.node.parent = o.node;
  10696. }
  10697. }
  10698. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Horizontal) {
  10699. var res = hzScrollBarRes ? hzScrollBarRes : fgui.UIConfig.horizontalScrollBar;
  10700. if (res) {
  10701. this._hzScrollBar = fgui.UIPackage.createObjectFromURL(res);
  10702. if (!this._hzScrollBar)
  10703. throw 'cannot create scrollbar from ' + res;
  10704. this._hzScrollBar.setScrollPane(this, false);
  10705. this._hzScrollBar.node.parent = o.node;
  10706. }
  10707. }
  10708. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Auto)
  10709. this._scrollBarDisplayAuto = true;
  10710. if (this._scrollBarDisplayAuto) {
  10711. if (this._vtScrollBar)
  10712. this._vtScrollBar.node.active = false;
  10713. if (this._hzScrollBar)
  10714. this._hzScrollBar.node.active = false;
  10715. o.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  10716. o.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  10717. }
  10718. }
  10719. if (headerRes) {
  10720. this._header = fgui.UIPackage.createObjectFromURL(headerRes);
  10721. if (this._header == null)
  10722. throw 'cannot create scrollPane header from ' + headerRes;
  10723. else
  10724. this._maskContainer.insertChild(this._header.node, 0);
  10725. }
  10726. if (footerRes) {
  10727. this._footer = fgui.UIPackage.createObjectFromURL(footerRes);
  10728. if (this._footer == null)
  10729. throw 'cannot create scrollPane footer from ' + footerRes;
  10730. else
  10731. this._maskContainer.insertChild(this._footer.node, 0);
  10732. }
  10733. this._refreshBarAxis = this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical ? 'y' : 'x';
  10734. this.setSize(o.width, o.height);
  10735. }
  10736. onDisable() {
  10737. this.unschedule(this.refresh);
  10738. }
  10739. onDestroy() {
  10740. delete this._pageController;
  10741. if (this._hzScrollBar)
  10742. this._hzScrollBar.dispose();
  10743. if (this._vtScrollBar)
  10744. this._vtScrollBar.dispose();
  10745. if (this._header)
  10746. this._header.dispose();
  10747. if (this._footer)
  10748. this._footer.dispose();
  10749. }
  10750. hitTest(pt, globalPt) {
  10751. let target;
  10752. if (this._vtScrollBar) {
  10753. target = this._vtScrollBar.hitTest(globalPt);
  10754. if (target)
  10755. return target;
  10756. }
  10757. if (this._hzScrollBar) {
  10758. target = this._hzScrollBar.hitTest(globalPt);
  10759. if (target)
  10760. return target;
  10761. }
  10762. if (this._header && this._header.node.activeInHierarchy) {
  10763. target = this._header.hitTest(globalPt);
  10764. if (target)
  10765. return target;
  10766. }
  10767. if (this._footer && this._footer.node.activeInHierarchy) {
  10768. target = this._footer.hitTest(globalPt);
  10769. if (target)
  10770. return target;
  10771. }
  10772. if (pt.x >= this._owner.margin.left && pt.y >= this._owner.margin.top && pt.x < this._owner.margin.left + this._viewSize.x && pt.y < this._owner.margin.top + this._viewSize.y)
  10773. return this._owner;
  10774. else
  10775. return null;
  10776. }
  10777. get owner() {
  10778. return this._owner;
  10779. }
  10780. get hzScrollBar() {
  10781. return this._hzScrollBar;
  10782. }
  10783. get vtScrollBar() {
  10784. return this._vtScrollBar;
  10785. }
  10786. get header() {
  10787. return this._header;
  10788. }
  10789. get footer() {
  10790. return this._footer;
  10791. }
  10792. get bouncebackEffect() {
  10793. return this._bouncebackEffect;
  10794. }
  10795. set bouncebackEffect(sc) {
  10796. this._bouncebackEffect = sc;
  10797. }
  10798. get touchEffect() {
  10799. return this._touchEffect;
  10800. }
  10801. set touchEffect(sc) {
  10802. this._touchEffect = sc;
  10803. }
  10804. set scrollStep(val) {
  10805. this._scrollStep = val;
  10806. if (this._scrollStep == 0)
  10807. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  10808. this._mouseWheelStep = this._scrollStep * 2;
  10809. }
  10810. get decelerationRate() {
  10811. return this._decelerationRate;
  10812. }
  10813. set decelerationRate(val) {
  10814. this._decelerationRate = val;
  10815. }
  10816. get scrollStep() {
  10817. return this._scrollStep;
  10818. }
  10819. get snapToItem() {
  10820. return this._snapToItem;
  10821. }
  10822. set snapToItem(value) {
  10823. this._snapToItem = value;
  10824. }
  10825. get mouseWheelEnabled() {
  10826. return this._mouseWheelEnabled;
  10827. }
  10828. set mouseWheelEnabled(value) {
  10829. this._mouseWheelEnabled = value;
  10830. }
  10831. get isDragged() {
  10832. return this._dragged;
  10833. }
  10834. get percX() {
  10835. return this._overlapSize.x == 0 ? 0 : this._xPos / this._overlapSize.x;
  10836. }
  10837. set percX(value) {
  10838. this.setPercX(value, false);
  10839. }
  10840. setPercX(value, ani, tweenTime = 0) {
  10841. this._scrollTime = tweenTime;
  10842. this._owner.ensureBoundsCorrect();
  10843. this.setPosX(this._overlapSize.x * fgui.ToolSet.clamp01(value), ani);
  10844. }
  10845. get percY() {
  10846. return this._overlapSize.y == 0 ? 0 : this._yPos / this._overlapSize.y;
  10847. }
  10848. set percY(value) {
  10849. this.setPercY(value, false);
  10850. }
  10851. setPercY(value, ani, tweenTime = 0) {
  10852. this._scrollTime = tweenTime;
  10853. this._owner.ensureBoundsCorrect();
  10854. this.setPosY(this._overlapSize.y * fgui.ToolSet.clamp01(value), ani);
  10855. }
  10856. get posX() {
  10857. return this._xPos;
  10858. }
  10859. set posX(value) {
  10860. this.setPosX(value, false);
  10861. }
  10862. setPosX(value, ani) {
  10863. if (this._tweening != 0) {
  10864. this.killTween();
  10865. }
  10866. this._owner.ensureBoundsCorrect();
  10867. if (this._loop == 1)
  10868. value = this.loopCheckingNewPos(value, 'x');
  10869. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.x);
  10870. if (value != this._xPos) {
  10871. this._xPos = value;
  10872. this.posChanged(ani);
  10873. }
  10874. }
  10875. get posY() {
  10876. return this._yPos;
  10877. }
  10878. set posY(value) {
  10879. this.setPosY(value, false);
  10880. }
  10881. setPosY(value, ani) {
  10882. if (this._tweening != 0) {
  10883. this.killTween();
  10884. }
  10885. this._owner.ensureBoundsCorrect();
  10886. if (this._loop == 1)
  10887. value = this.loopCheckingNewPos(value, 'y');
  10888. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.y);
  10889. if (value != this._yPos) {
  10890. this._yPos = value;
  10891. this.posChanged(ani);
  10892. }
  10893. }
  10894. get contentWidth() {
  10895. return this._contentSize.x;
  10896. }
  10897. get contentHeight() {
  10898. return this._contentSize.y;
  10899. }
  10900. get viewWidth() {
  10901. return this._viewSize.x;
  10902. }
  10903. set viewWidth(value) {
  10904. value = value + this._owner.margin.left + this._owner.margin.right;
  10905. if (this._vtScrollBar && !this._floating)
  10906. value += this._vtScrollBar.width;
  10907. this._owner.width = value;
  10908. }
  10909. get viewHeight() {
  10910. return this._viewSize.y;
  10911. }
  10912. set viewHeight(value) {
  10913. value = value + this._owner.margin.top + this._owner.margin.bottom;
  10914. if (this._hzScrollBar && !this._floating)
  10915. value += this._hzScrollBar.height;
  10916. this._owner.height = value;
  10917. }
  10918. get currentPageX() {
  10919. if (!this._pageMode)
  10920. return 0;
  10921. var page = Math.floor(this._xPos / this._pageSize.x);
  10922. if (this._xPos - page * this._pageSize.x > this._pageSize.x * 0.5)
  10923. page++;
  10924. return page;
  10925. }
  10926. set currentPageX(value) {
  10927. this.setCurrentPageX(value, false);
  10928. }
  10929. get currentPageY() {
  10930. if (!this._pageMode)
  10931. return 0;
  10932. var page = Math.floor(this._yPos / this._pageSize.y);
  10933. if (this._yPos - page * this._pageSize.y > this._pageSize.y * 0.5)
  10934. page++;
  10935. return page;
  10936. }
  10937. set currentPageY(value) {
  10938. this.setCurrentPageY(value, false);
  10939. }
  10940. setCurrentPageX(value, ani) {
  10941. if (!this._pageMode)
  10942. return;
  10943. this._owner.ensureBoundsCorrect();
  10944. if (this._overlapSize.x > 0)
  10945. this.setPosX(value * this._pageSize.x, ani);
  10946. }
  10947. setCurrentPageY(value, ani) {
  10948. if (!this._pageMode)
  10949. return;
  10950. this._owner.ensureBoundsCorrect();
  10951. if (this._overlapSize.y > 0)
  10952. this.setPosY(value * this._pageSize.y, ani);
  10953. }
  10954. get isBottomMost() {
  10955. return this._yPos == this._overlapSize.y || this._overlapSize.y == 0;
  10956. }
  10957. get isRightMost() {
  10958. return this._xPos == this._overlapSize.x || this._overlapSize.x == 0;
  10959. }
  10960. get pageController() {
  10961. return this._pageController;
  10962. }
  10963. set pageController(value) {
  10964. this._pageController = value;
  10965. }
  10966. get scrollingPosX() {
  10967. return fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  10968. }
  10969. get scrollingPosY() {
  10970. return fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  10971. }
  10972. scrollTop(ani) {
  10973. this.setPercY(0, ani);
  10974. }
  10975. scrollBottom(ani) {
  10976. this.setPercY(1, ani);
  10977. }
  10978. scrollUp(ratio, ani) {
  10979. if (ratio == undefined)
  10980. ratio = 1;
  10981. if (this._pageMode)
  10982. this.setPosY(this._yPos - this._pageSize.y * ratio, ani);
  10983. else
  10984. this.setPosY(this._yPos - this._scrollStep * ratio, ani);
  10985. }
  10986. scrollDown(ratio, ani) {
  10987. if (ratio == undefined)
  10988. ratio = 1;
  10989. if (this._pageMode)
  10990. this.setPosY(this._yPos + this._pageSize.y * ratio, ani);
  10991. else
  10992. this.setPosY(this._yPos + this._scrollStep * ratio, ani);
  10993. }
  10994. scrollLeft(ratio, ani) {
  10995. if (ratio == undefined)
  10996. ratio = 1;
  10997. if (this._pageMode)
  10998. this.setPosX(this._xPos - this._pageSize.x * ratio, ani);
  10999. else
  11000. this.setPosX(this._xPos - this._scrollStep * ratio, ani);
  11001. }
  11002. scrollRight(ratio, ani) {
  11003. if (ratio == undefined)
  11004. ratio = 1;
  11005. if (this._pageMode)
  11006. this.setPosX(this._xPos + this._pageSize.x * ratio, ani);
  11007. else
  11008. this.setPosX(this._xPos + this._scrollStep * ratio, ani);
  11009. }
  11010. scrollToView(target, ani, setFirst, tweenTime = 0) {
  11011. this._scrollTime = tweenTime;
  11012. this._owner.ensureBoundsCorrect();
  11013. if (this._needRefresh)
  11014. this.refresh();
  11015. var rect;
  11016. if (target instanceof fgui.GObject) {
  11017. if (target.parent != this._owner) {
  11018. target.parent.localToGlobalRect(target.x, target.y, target.width, target.height, s_rect);
  11019. rect = this._owner.globalToLocalRect(s_rect.x, s_rect.y, s_rect.width, s_rect.height, s_rect);
  11020. }
  11021. else {
  11022. rect = s_rect;
  11023. rect.x = target.x;
  11024. rect.y = target.y;
  11025. rect.width = target.width;
  11026. rect.height = target.height;
  11027. }
  11028. }
  11029. else
  11030. rect = target;
  11031. if (this._overlapSize.y > 0) {
  11032. var bottom = this._yPos + this._viewSize.y;
  11033. if (setFirst || rect.y <= this._yPos || rect.height >= this._viewSize.y) {
  11034. if (this._pageMode)
  11035. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  11036. else
  11037. this.setPosY(rect.y, ani);
  11038. }
  11039. else if (rect.y + rect.height > bottom) {
  11040. if (this._pageMode)
  11041. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  11042. else if (rect.height <= this._viewSize.y / 2)
  11043. this.setPosY(rect.y + rect.height * 2 - this._viewSize.y, ani);
  11044. else
  11045. this.setPosY(rect.y + rect.height - this._viewSize.y, ani);
  11046. }
  11047. }
  11048. if (this._overlapSize.x > 0) {
  11049. var right = this._xPos + this._viewSize.x;
  11050. if (setFirst || rect.x <= this._xPos || rect.width >= this._viewSize.x) {
  11051. if (this._pageMode)
  11052. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  11053. else
  11054. this.setPosX(rect.x, ani);
  11055. }
  11056. else if (rect.x + rect.width > right) {
  11057. if (this._pageMode)
  11058. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  11059. else if (rect.width <= this._viewSize.x / 2)
  11060. this.setPosX(rect.x + rect.width * 2 - this._viewSize.x, ani);
  11061. else
  11062. this.setPosX(rect.x + rect.width - this._viewSize.x, ani);
  11063. }
  11064. }
  11065. if (!ani && this._needRefresh)
  11066. this.refresh();
  11067. }
  11068. isChildInView(obj) {
  11069. if (this._overlapSize.y > 0) {
  11070. var dist = obj.y + -this._container.y;
  11071. if (dist <= -obj.height || dist >= this._viewSize.y)
  11072. return false;
  11073. }
  11074. if (this._overlapSize.x > 0) {
  11075. dist = obj.x + this._container.x;
  11076. if (dist <= -obj.width || dist >= this._viewSize.x)
  11077. return false;
  11078. }
  11079. return true;
  11080. }
  11081. cancelDragging() {
  11082. if (ScrollPane.draggingPane == this)
  11083. ScrollPane.draggingPane = null;
  11084. _gestureFlag = 0;
  11085. this._dragged = false;
  11086. }
  11087. lockHeader(size) {
  11088. if (this._headerLockedSize == size)
  11089. return;
  11090. let cx = this._container.x;
  11091. let cy = -this._container.y;
  11092. let cr = this._refreshBarAxis == 'x' ? cx : cy;
  11093. this._headerLockedSize = size;
  11094. if (!this._refreshEventDispatching && cr >= 0) {
  11095. this._tweenStart.x = cx;
  11096. this._tweenStart.y = cy;
  11097. this._tweenChange.set(cc.Vec2.ZERO);
  11098. this._tweenChange[this._refreshBarAxis] = this._headerLockedSize - this._tweenStart[this._refreshBarAxis];
  11099. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  11100. this.startTween(2);
  11101. }
  11102. }
  11103. lockFooter(size) {
  11104. if (this._footerLockedSize == size)
  11105. return;
  11106. let cx = this._container.x;
  11107. let cy = -this._container.y;
  11108. let cr = this._refreshBarAxis == 'x' ? cx : cy;
  11109. this._footerLockedSize = size;
  11110. if (!this._refreshEventDispatching && cr <= -this._overlapSize[this._refreshBarAxis]) {
  11111. this._tweenStart.x = cx;
  11112. this._tweenStart.y = cy;
  11113. this._tweenChange.set(cc.Vec2.ZERO);
  11114. var max = this._overlapSize[this._refreshBarAxis];
  11115. if (max == 0)
  11116. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  11117. else
  11118. max += this._footerLockedSize;
  11119. this._tweenChange[this._refreshBarAxis] = -max - this._tweenStart[this._refreshBarAxis];
  11120. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  11121. this.startTween(2);
  11122. }
  11123. }
  11124. onOwnerSizeChanged() {
  11125. this.setSize(this._owner.width, this._owner.height);
  11126. this.posChanged(false);
  11127. }
  11128. handleControllerChanged(c) {
  11129. if (this._pageController == c) {
  11130. if (this._scrollType == fgui.ScrollType.Horizontal)
  11131. this.setCurrentPageX(c.selectedIndex, true);
  11132. else
  11133. this.setCurrentPageY(c.selectedIndex, true);
  11134. }
  11135. }
  11136. updatePageController() {
  11137. if (this._pageController && !this._pageController.changing) {
  11138. var index;
  11139. if (this._scrollType == fgui.ScrollType.Horizontal)
  11140. index = this.currentPageX;
  11141. else
  11142. index = this.currentPageY;
  11143. if (index < this._pageController.pageCount) {
  11144. var c = this._pageController;
  11145. this._pageController = null;
  11146. c.selectedIndex = index;
  11147. this._pageController = c;
  11148. }
  11149. }
  11150. }
  11151. adjustMaskContainer() {
  11152. var mx = 0;
  11153. if (this._displayOnLeft && this._vtScrollBar && !this._floating)
  11154. mx = this._vtScrollBar.width;
  11155. const o = this._owner;
  11156. if (this._dontClipMargin)
  11157. this._maskContainer.setAnchorPoint((o.margin.left + o._alignOffset.x) / o.width, 1 - (o.margin.top + o._alignOffset.y) / o.height);
  11158. else
  11159. this._maskContainer.setAnchorPoint(o._alignOffset.x / this._viewSize.x, 1 - o._alignOffset.y / this._viewSize.y);
  11160. if (o._customMask)
  11161. this._maskContainer.setPosition(mx + o._alignOffset.x, -o._alignOffset.y);
  11162. else
  11163. this._maskContainer.setPosition(o._pivotCorrectX + mx + o._alignOffset.x, o._pivotCorrectY - o._alignOffset.y);
  11164. }
  11165. setSize(aWidth, aHeight) {
  11166. if (this._hzScrollBar) {
  11167. this._hzScrollBar.y = aHeight - this._hzScrollBar.height;
  11168. if (this._vtScrollBar) {
  11169. this._hzScrollBar.width = aWidth - this._vtScrollBar.width - this._scrollBarMargin.left - this._scrollBarMargin.right;
  11170. if (this._displayOnLeft)
  11171. this._hzScrollBar.x = this._scrollBarMargin.left + this._vtScrollBar.width;
  11172. else
  11173. this._hzScrollBar.x = this._scrollBarMargin.left;
  11174. }
  11175. else {
  11176. this._hzScrollBar.width = aWidth - this._scrollBarMargin.left - this._scrollBarMargin.right;
  11177. this._hzScrollBar.x = this._scrollBarMargin.left;
  11178. }
  11179. }
  11180. if (this._vtScrollBar) {
  11181. if (!this._displayOnLeft)
  11182. this._vtScrollBar.x = aWidth - this._vtScrollBar.width;
  11183. if (this._hzScrollBar)
  11184. this._vtScrollBar.height = aHeight - this._hzScrollBar.height - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  11185. else
  11186. this._vtScrollBar.height = aHeight - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  11187. this._vtScrollBar.y = this._scrollBarMargin.top;
  11188. }
  11189. this._viewSize.x = aWidth;
  11190. this._viewSize.y = aHeight;
  11191. if (this._hzScrollBar && !this._floating)
  11192. this._viewSize.y -= this._hzScrollBar.height;
  11193. if (this._vtScrollBar && !this._floating)
  11194. this._viewSize.x -= this._vtScrollBar.width;
  11195. this._viewSize.x -= this._owner.margin.left + this._owner.margin.right;
  11196. this._viewSize.y -= this._owner.margin.top + this._owner.margin.bottom;
  11197. this._viewSize.x = Math.max(1, this._viewSize.x);
  11198. this._viewSize.y = Math.max(1, this._viewSize.y);
  11199. this._pageSize.x = this._viewSize.x;
  11200. this._pageSize.y = this._viewSize.y;
  11201. this.adjustMaskContainer();
  11202. this.handleSizeChanged();
  11203. }
  11204. setContentSize(aWidth, aHeight) {
  11205. if (this._contentSize.x == aWidth && this._contentSize.y == aHeight)
  11206. return;
  11207. this._contentSize.x = aWidth;
  11208. this._contentSize.y = aHeight;
  11209. this.handleSizeChanged();
  11210. }
  11211. changeContentSizeOnScrolling(deltaWidth, deltaHeight, deltaPosX, deltaPosY) {
  11212. var isRightmost = this._xPos == this._overlapSize.x;
  11213. var isBottom = this._yPos == this._overlapSize.y;
  11214. this._contentSize.x += deltaWidth;
  11215. this._contentSize.y += deltaHeight;
  11216. this.handleSizeChanged();
  11217. if (this._tweening == 1) {
  11218. if (deltaWidth != 0 && isRightmost && this._tweenChange.x < 0) {
  11219. this._xPos = this._overlapSize.x;
  11220. this._tweenChange.x = -this._xPos - this._tweenStart.x;
  11221. }
  11222. if (deltaHeight != 0 && isBottom && this._tweenChange.y < 0) {
  11223. this._yPos = this._overlapSize.y;
  11224. this._tweenChange.y = -this._yPos - this._tweenStart.y;
  11225. }
  11226. }
  11227. else if (this._tweening == 2) {
  11228. if (deltaPosX != 0) {
  11229. this._container.x -= deltaPosX;
  11230. this._tweenStart.x -= deltaPosX;
  11231. this._xPos = -this._container.x;
  11232. }
  11233. if (deltaPosY != 0) {
  11234. this._container.y += deltaPosY;
  11235. this._tweenStart.y -= deltaPosY;
  11236. this._yPos = -(-this._container.y);
  11237. }
  11238. }
  11239. else if (this._dragged) {
  11240. if (deltaPosX != 0) {
  11241. this._container.x -= deltaPosX;
  11242. this._containerPos.x -= deltaPosX;
  11243. this._xPos = -this._container.x;
  11244. }
  11245. if (deltaPosY != 0) {
  11246. this._container.y += deltaPosY;
  11247. this._containerPos.y -= deltaPosY;
  11248. this._yPos = -(-this._container.y);
  11249. }
  11250. }
  11251. else {
  11252. if (deltaWidth != 0 && isRightmost) {
  11253. this._xPos = this._overlapSize.x;
  11254. this._container.x = -this._xPos;
  11255. }
  11256. if (deltaHeight != 0 && isBottom) {
  11257. this._yPos = this._overlapSize.y;
  11258. this._container.y = this._yPos;
  11259. }
  11260. }
  11261. if (this._pageMode)
  11262. this.updatePageController();
  11263. }
  11264. handleSizeChanged() {
  11265. if (this._displayInDemand) {
  11266. this._vScrollNone = this._contentSize.y <= this._viewSize.y;
  11267. this._hScrollNone = this._contentSize.x <= this._viewSize.x;
  11268. }
  11269. if (this._vtScrollBar) {
  11270. if (this._contentSize.y == 0)
  11271. this._vtScrollBar.setDisplayPerc(0);
  11272. else
  11273. this._vtScrollBar.setDisplayPerc(Math.min(1, this._viewSize.y / this._contentSize.y));
  11274. }
  11275. if (this._hzScrollBar) {
  11276. if (this._contentSize.x == 0)
  11277. this._hzScrollBar.setDisplayPerc(0);
  11278. else
  11279. this._hzScrollBar.setDisplayPerc(Math.min(1, this._viewSize.x / this._contentSize.x));
  11280. }
  11281. this.updateScrollBarVisible();
  11282. var maskWidth = this._viewSize.x;
  11283. var maskHeight = this._viewSize.y;
  11284. if (this._vScrollNone && this._vtScrollBar)
  11285. maskWidth += this._vtScrollBar.width;
  11286. if (this._hScrollNone && this._hzScrollBar)
  11287. maskHeight += this._hzScrollBar.height;
  11288. if (this._dontClipMargin) {
  11289. maskWidth += this._owner.margin.left + this._owner.margin.right;
  11290. maskHeight += this._owner.margin.top + this._owner.margin.bottom;
  11291. }
  11292. this._maskContainer.setContentSize(maskWidth, maskHeight);
  11293. if (this._vtScrollBar)
  11294. this._vtScrollBar.handlePositionChanged();
  11295. if (this._hzScrollBar)
  11296. this._hzScrollBar.handlePositionChanged();
  11297. if (this._header)
  11298. this._header.handlePositionChanged();
  11299. if (this._footer)
  11300. this._footer.handlePositionChanged();
  11301. if (this._scrollType == fgui.ScrollType.Horizontal || this._scrollType == fgui.ScrollType.Both)
  11302. this._overlapSize.x = Math.ceil(Math.max(0, this._contentSize.x - this._viewSize.x));
  11303. else
  11304. this._overlapSize.x = 0;
  11305. if (this._scrollType == fgui.ScrollType.Vertical || this._scrollType == fgui.ScrollType.Both)
  11306. this._overlapSize.y = Math.ceil(Math.max(0, this._contentSize.y - this._viewSize.y));
  11307. else
  11308. this._overlapSize.y = 0;
  11309. this._xPos = fgui.ToolSet.clamp(this._xPos, 0, this._overlapSize.x);
  11310. this._yPos = fgui.ToolSet.clamp(this._yPos, 0, this._overlapSize.y);
  11311. var max = this._overlapSize[this._refreshBarAxis];
  11312. if (max == 0)
  11313. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  11314. else
  11315. max += this._footerLockedSize;
  11316. if (this._refreshBarAxis == 'x')
  11317. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -max, this._headerLockedSize), -fgui.ToolSet.clamp(-this._container.y, -this._overlapSize.y, 0));
  11318. else
  11319. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -this._overlapSize.x, 0), -fgui.ToolSet.clamp(-this._container.y, -max, this._headerLockedSize));
  11320. if (this._header) {
  11321. if (this._refreshBarAxis == 'x')
  11322. this._header.height = this._viewSize.y;
  11323. else
  11324. this._header.width = this._viewSize.x;
  11325. }
  11326. if (this._footer) {
  11327. if (this._refreshBarAxis == 'y')
  11328. this._footer.height = this._viewSize.y;
  11329. else
  11330. this._footer.width = this._viewSize.x;
  11331. }
  11332. this.updateScrollBarPos();
  11333. if (this._pageMode)
  11334. this.updatePageController();
  11335. }
  11336. posChanged(ani) {
  11337. if (this._aniFlag == 0)
  11338. this._aniFlag = ani ? 1 : -1;
  11339. else if (this._aniFlag == 1 && !ani)
  11340. this._aniFlag = -1;
  11341. this._needRefresh = true;
  11342. if (!cc.director.getScheduler().isScheduled(this.refresh, this))
  11343. this.scheduleOnce(this.refresh);
  11344. }
  11345. refresh(dt) {
  11346. this._needRefresh = false;
  11347. this.unschedule(this.refresh);
  11348. if (this._pageMode || this._snapToItem) {
  11349. sEndPos.x = -this._xPos;
  11350. sEndPos.y = -this._yPos;
  11351. this.alignPosition(sEndPos, false);
  11352. this._xPos = -sEndPos.x;
  11353. this._yPos = -sEndPos.y;
  11354. }
  11355. this.refresh2();
  11356. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  11357. if (this._needRefresh) {
  11358. this._needRefresh = false;
  11359. this.unschedule(this.refresh);
  11360. this.refresh2();
  11361. }
  11362. this.updateScrollBarPos();
  11363. this._aniFlag = 0;
  11364. }
  11365. refresh2() {
  11366. if (this._aniFlag == 1 && !this._dragged) {
  11367. var posX;
  11368. var posY;
  11369. if (this._overlapSize.x > 0)
  11370. posX = -Math.floor(this._xPos);
  11371. else {
  11372. if (this._container.x != 0)
  11373. this._container.x = 0;
  11374. posX = 0;
  11375. }
  11376. if (this._overlapSize.y > 0)
  11377. posY = -Math.floor(this._yPos);
  11378. else {
  11379. if (this._container.y != 0)
  11380. this._container.y = 0;
  11381. posY = 0;
  11382. }
  11383. if (posX != this._container.x || posY != -this._container.y) {
  11384. this._tweenDuration.x = this._tweenDuration.y = this._scrollTime == 0 ? TWEEN_TIME_GO : this._scrollTime;
  11385. this._scrollTime = 0;
  11386. this._tweenStart.x = this._container.x;
  11387. this._tweenStart.y = -this._container.y;
  11388. this._tweenChange.x = posX - this._tweenStart.x;
  11389. this._tweenChange.y = posY - this._tweenStart.y;
  11390. this.startTween(1);
  11391. }
  11392. else if (this._tweening != 0)
  11393. this.killTween();
  11394. }
  11395. else {
  11396. if (this._tweening != 0)
  11397. this.killTween();
  11398. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  11399. this.loopCheckingCurrent();
  11400. }
  11401. if (this._pageMode)
  11402. this.updatePageController();
  11403. }
  11404. onTouchBegin(evt) {
  11405. if (!this._touchEffect)
  11406. return;
  11407. evt.captureTouch();
  11408. if (this._tweening != 0) {
  11409. this.killTween();
  11410. fgui.GRoot.inst.inputProcessor.cancelClick(evt.touchId);
  11411. this._dragged = true;
  11412. }
  11413. else
  11414. this._dragged = false;
  11415. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  11416. this._containerPos.x = this._container.x;
  11417. this._containerPos.y = -this._container.y;
  11418. this._beginTouchPos.set(pt);
  11419. this._lastTouchPos.set(pt);
  11420. this._lastTouchGlobalPos.set(evt.pos);
  11421. this._isHoldAreaDone = false;
  11422. this._velocity.set(cc.Vec2.ZERO);
  11423. this._velocityScale = 1;
  11424. this._lastMoveTime = fgui.ToolSet.getTime();
  11425. }
  11426. onTouchMove(evt) {
  11427. if (!cc.isValid(this._owner.node))
  11428. return;
  11429. if (!this._touchEffect)
  11430. return;
  11431. if (fgui.GObject.draggingObject && fgui.GObject.draggingObject.onStage)
  11432. return;
  11433. if (ScrollPane.draggingPane && ScrollPane.draggingPane != this && ScrollPane.draggingPane._owner && ScrollPane.draggingPane._owner.onStage)
  11434. return;
  11435. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  11436. var sensitivity = fgui.UIConfig.touchScrollSensitivity;
  11437. var diff, diff2;
  11438. var sv, sh, st;
  11439. if (this._scrollType == fgui.ScrollType.Vertical) {
  11440. if (!this._isHoldAreaDone) {
  11441. _gestureFlag |= 1;
  11442. diff = Math.abs(this._beginTouchPos.y - pt.y);
  11443. if (diff < sensitivity)
  11444. return;
  11445. if ((_gestureFlag & 2) != 0) {
  11446. diff2 = Math.abs(this._beginTouchPos.x - pt.x);
  11447. if (diff < diff2)
  11448. return;
  11449. }
  11450. }
  11451. sv = true;
  11452. }
  11453. else if (this._scrollType == fgui.ScrollType.Horizontal) {
  11454. if (!this._isHoldAreaDone) {
  11455. _gestureFlag |= 2;
  11456. diff = Math.abs(this._beginTouchPos.x - pt.x);
  11457. if (diff < sensitivity)
  11458. return;
  11459. if ((_gestureFlag & 1) != 0) {
  11460. diff2 = Math.abs(this._beginTouchPos.y - pt.y);
  11461. if (diff < diff2)
  11462. return;
  11463. }
  11464. }
  11465. sh = true;
  11466. }
  11467. else {
  11468. _gestureFlag = 3;
  11469. if (!this._isHoldAreaDone) {
  11470. diff = Math.abs(this._beginTouchPos.y - pt.y);
  11471. if (diff < sensitivity) {
  11472. diff = Math.abs(this._beginTouchPos.x - pt.x);
  11473. if (diff < sensitivity)
  11474. return;
  11475. }
  11476. }
  11477. sv = sh = true;
  11478. }
  11479. var newPosX = Math.floor(this._containerPos.x + pt.x - this._beginTouchPos.x);
  11480. var newPosY = Math.floor(this._containerPos.y + pt.y - this._beginTouchPos.y);
  11481. if (sv) {
  11482. if (newPosY > 0) {
  11483. if (!this._bouncebackEffect)
  11484. this._container.y = 0;
  11485. else if (this._header && this._header.maxHeight != 0)
  11486. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._header.maxHeight));
  11487. else
  11488. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._viewSize.y * PULL_RATIO));
  11489. }
  11490. else if (newPosY < -this._overlapSize.y) {
  11491. if (!this._bouncebackEffect)
  11492. this._container.y = this._overlapSize.y;
  11493. else if (this._footer && this._footer.maxHeight > 0)
  11494. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._footer.maxHeight) - this._overlapSize.y);
  11495. else
  11496. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._viewSize.y * PULL_RATIO) - this._overlapSize.y);
  11497. }
  11498. else
  11499. this._container.y = -newPosY;
  11500. }
  11501. if (sh) {
  11502. if (newPosX > 0) {
  11503. if (!this._bouncebackEffect)
  11504. this._container.x = 0;
  11505. else if (this._header && this._header.maxWidth != 0)
  11506. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._header.maxWidth));
  11507. else
  11508. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._viewSize.x * PULL_RATIO));
  11509. }
  11510. else if (newPosX < 0 - this._overlapSize.x) {
  11511. if (!this._bouncebackEffect)
  11512. this._container.x = -this._overlapSize.x;
  11513. else if (this._footer && this._footer.maxWidth > 0)
  11514. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._footer.maxWidth) - this._overlapSize.x);
  11515. else
  11516. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._viewSize.x * PULL_RATIO) - this._overlapSize.x);
  11517. }
  11518. else
  11519. this._container.x = newPosX;
  11520. }
  11521. var now = fgui.ToolSet.getTime();
  11522. var deltaTime = Math.max(now - this._lastMoveTime, 1 / 60);
  11523. var deltaPositionX = pt.x - this._lastTouchPos.x;
  11524. var deltaPositionY = pt.y - this._lastTouchPos.y;
  11525. if (!sh)
  11526. deltaPositionX = 0;
  11527. if (!sv)
  11528. deltaPositionY = 0;
  11529. if (deltaTime != 0) {
  11530. var frameRate = 60;
  11531. var elapsed = deltaTime * frameRate - 1;
  11532. if (elapsed > 1) {
  11533. var factor = Math.pow(0.833, elapsed);
  11534. this._velocity.x = this._velocity.x * factor;
  11535. this._velocity.y = this._velocity.y * factor;
  11536. }
  11537. this._velocity.x = fgui.ToolSet.lerp(this._velocity.x, (deltaPositionX * 60) / frameRate / deltaTime, deltaTime * 10);
  11538. this._velocity.y = fgui.ToolSet.lerp(this._velocity.y, (deltaPositionY * 60) / frameRate / deltaTime, deltaTime * 10);
  11539. }
  11540. var deltaGlobalPositionX = this._lastTouchGlobalPos.x - evt.pos.x;
  11541. var deltaGlobalPositionY = this._lastTouchGlobalPos.y - evt.pos.y;
  11542. if (deltaPositionX != 0)
  11543. this._velocityScale = Math.abs(deltaGlobalPositionX / deltaPositionX);
  11544. else if (deltaPositionY != 0)
  11545. this._velocityScale = Math.abs(deltaGlobalPositionY / deltaPositionY);
  11546. this._lastTouchPos.set(pt);
  11547. this._lastTouchGlobalPos.x = evt.pos.x;
  11548. this._lastTouchGlobalPos.y = evt.pos.y;
  11549. this._lastMoveTime = now;
  11550. if (this._overlapSize.x > 0)
  11551. this._xPos = fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  11552. if (this._overlapSize.y > 0)
  11553. this._yPos = fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  11554. if (this._loop != 0) {
  11555. newPosX = this._container.x;
  11556. newPosY = -this._container.y;
  11557. if (this.loopCheckingCurrent()) {
  11558. this._containerPos.x += this._container.x - newPosX;
  11559. this._containerPos.y += -this._container.y - newPosY;
  11560. }
  11561. }
  11562. ScrollPane.draggingPane = this;
  11563. this._isHoldAreaDone = true;
  11564. this._dragged = true;
  11565. this.updateScrollBarPos();
  11566. this.updateScrollBarVisible();
  11567. if (this._pageMode)
  11568. this.updatePageController();
  11569. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  11570. }
  11571. onTouchEnd(evt) {
  11572. if (ScrollPane.draggingPane == this)
  11573. ScrollPane.draggingPane = null;
  11574. _gestureFlag = 0;
  11575. if (!this._dragged || !this._touchEffect || !this._owner.node.activeInHierarchy) {
  11576. this._dragged = false;
  11577. return;
  11578. }
  11579. this._dragged = false;
  11580. this._tweenStart.x = this._container.x;
  11581. this._tweenStart.y = -this._container.y;
  11582. sEndPos.set(this._tweenStart);
  11583. var flag = false;
  11584. if (this._container.x > 0) {
  11585. sEndPos.x = 0;
  11586. flag = true;
  11587. }
  11588. else if (this._container.x < -this._overlapSize.x) {
  11589. sEndPos.x = -this._overlapSize.x;
  11590. flag = true;
  11591. }
  11592. if (-this._container.y > 0) {
  11593. sEndPos.y = 0;
  11594. flag = true;
  11595. }
  11596. else if (-this._container.y < -this._overlapSize.y) {
  11597. sEndPos.y = -this._overlapSize.y;
  11598. flag = true;
  11599. }
  11600. if (flag) {
  11601. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  11602. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  11603. if (this._tweenChange.x < -fgui.UIConfig.touchDragSensitivity || this._tweenChange.y < -fgui.UIConfig.touchDragSensitivity) {
  11604. this._refreshEventDispatching = true;
  11605. this._owner.node.emit(fgui.Event.PULL_DOWN_RELEASE), this._owner;
  11606. this._refreshEventDispatching = false;
  11607. }
  11608. else if (this._tweenChange.x > fgui.UIConfig.touchDragSensitivity || this._tweenChange.y > fgui.UIConfig.touchDragSensitivity) {
  11609. this._refreshEventDispatching = true;
  11610. this._owner.node.emit(fgui.Event.PULL_UP_RELEASE, this._owner);
  11611. this._refreshEventDispatching = false;
  11612. }
  11613. if (this._headerLockedSize > 0 && sEndPos[this._refreshBarAxis] == 0) {
  11614. sEndPos[this._refreshBarAxis] = this._headerLockedSize;
  11615. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  11616. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  11617. }
  11618. else if (this._footerLockedSize > 0 && sEndPos[this._refreshBarAxis] == -this._overlapSize[this._refreshBarAxis]) {
  11619. var max = this._overlapSize[this._refreshBarAxis];
  11620. if (max == 0)
  11621. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  11622. else
  11623. max += this._footerLockedSize;
  11624. sEndPos[this._refreshBarAxis] = -max;
  11625. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  11626. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  11627. }
  11628. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  11629. }
  11630. else {
  11631. if (!this._inertiaDisabled) {
  11632. var frameRate = 60;
  11633. var elapsed = (fgui.ToolSet.getTime() - this._lastMoveTime) * frameRate - 1;
  11634. if (elapsed > 1) {
  11635. var factor = Math.pow(0.833, elapsed);
  11636. this._velocity.x = this._velocity.x * factor;
  11637. this._velocity.y = this._velocity.y * factor;
  11638. }
  11639. this.updateTargetAndDuration(this._tweenStart, sEndPos);
  11640. }
  11641. else
  11642. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  11643. sOldChange.x = sEndPos.x - this._tweenStart.x;
  11644. sOldChange.y = sEndPos.y - this._tweenStart.y;
  11645. this.loopCheckingTarget(sEndPos);
  11646. if (this._pageMode || this._snapToItem)
  11647. this.alignPosition(sEndPos, true);
  11648. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  11649. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  11650. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  11651. this.updateScrollBarVisible();
  11652. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  11653. return;
  11654. }
  11655. if (this._pageMode || this._snapToItem) {
  11656. this.fixDuration('x', sOldChange.x);
  11657. this.fixDuration('y', sOldChange.y);
  11658. }
  11659. }
  11660. this.startTween(2);
  11661. }
  11662. onRollOver() {
  11663. this._hover = true;
  11664. this.updateScrollBarVisible();
  11665. }
  11666. onRollOut() {
  11667. this._hover = false;
  11668. this.updateScrollBarVisible();
  11669. }
  11670. onMouseWheel(evt) {
  11671. if (!this._mouseWheelEnabled)
  11672. return;
  11673. let delta = evt.mouseWheelDelta > 0 ? -1 : 1;
  11674. if (this._overlapSize.x > 0 && this._overlapSize.y == 0) {
  11675. if (this._pageMode)
  11676. this.setPosX(this._xPos + this._pageSize.x * delta, false);
  11677. else
  11678. this.setPosX(this._xPos + this._mouseWheelStep * delta, false);
  11679. }
  11680. else {
  11681. if (this._pageMode)
  11682. this.setPosY(this._yPos + this._pageSize.y * delta, false);
  11683. else
  11684. this.setPosY(this._yPos + this._mouseWheelStep * delta, false);
  11685. }
  11686. }
  11687. updateScrollBarPos() {
  11688. if (this._vtScrollBar)
  11689. this._vtScrollBar.setScrollPerc(this._overlapSize.y == 0 ? 0 : fgui.ToolSet.clamp(this._container.y, 0, this._overlapSize.y) / this._overlapSize.y);
  11690. if (this._hzScrollBar)
  11691. this._hzScrollBar.setScrollPerc(this._overlapSize.x == 0 ? 0 : fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x) / this._overlapSize.x);
  11692. this.checkRefreshBar();
  11693. }
  11694. updateScrollBarVisible() {
  11695. if (this._vtScrollBar) {
  11696. if (this._viewSize.y <= this._vtScrollBar.minSize || this._vScrollNone)
  11697. this._vtScrollBar.node.active = false;
  11698. else
  11699. this.updateScrollBarVisible2(this._vtScrollBar);
  11700. }
  11701. if (this._hzScrollBar) {
  11702. if (this._viewSize.x <= this._hzScrollBar.minSize || this._hScrollNone)
  11703. this._hzScrollBar.node.active = false;
  11704. else
  11705. this.updateScrollBarVisible2(this._hzScrollBar);
  11706. }
  11707. }
  11708. updateScrollBarVisible2(bar) {
  11709. if (this._scrollBarDisplayAuto)
  11710. fgui.GTween.kill(bar, false, 'alpha');
  11711. if (this._scrollBarDisplayAuto && !this._hover && this._tweening == 0 && !this._dragged && !bar.gripDragging) {
  11712. if (bar.node.active)
  11713. fgui.GTween.to(1, 0, 0.5).setDelay(0.5).onComplete(this.__barTweenComplete, this).setTarget(bar, 'alpha');
  11714. }
  11715. else {
  11716. bar.alpha = 1;
  11717. bar.node.active = true;
  11718. }
  11719. }
  11720. __barTweenComplete(tweener) {
  11721. var bar = tweener.target;
  11722. bar.alpha = 1;
  11723. bar.node.active = false;
  11724. }
  11725. getLoopPartSize(division, axis) {
  11726. return (this._contentSize[axis] + (axis == 'x' ? this._owner.columnGap : this._owner.lineGap)) / division;
  11727. }
  11728. loopCheckingCurrent() {
  11729. var changed = false;
  11730. if (this._loop == 1 && this._overlapSize.x > 0) {
  11731. if (this._xPos < 0.001) {
  11732. this._xPos += this.getLoopPartSize(2, 'x');
  11733. changed = true;
  11734. }
  11735. else if (this._xPos >= this._overlapSize.x) {
  11736. this._xPos -= this.getLoopPartSize(2, 'x');
  11737. changed = true;
  11738. }
  11739. }
  11740. else if (this._loop == 2 && this._overlapSize.y > 0) {
  11741. if (this._yPos < 0.001) {
  11742. this._yPos += this.getLoopPartSize(2, 'y');
  11743. changed = true;
  11744. }
  11745. else if (this._yPos >= this._overlapSize.y) {
  11746. this._yPos -= this.getLoopPartSize(2, 'y');
  11747. changed = true;
  11748. }
  11749. }
  11750. if (changed) {
  11751. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  11752. }
  11753. return changed;
  11754. }
  11755. loopCheckingTarget(endPos) {
  11756. if (this._loop == 1)
  11757. this.loopCheckingTarget2(endPos, 'x');
  11758. if (this._loop == 2)
  11759. this.loopCheckingTarget2(endPos, 'y');
  11760. }
  11761. loopCheckingTarget2(endPos, axis) {
  11762. var halfSize;
  11763. var tmp;
  11764. if (endPos[axis] > 0) {
  11765. halfSize = this.getLoopPartSize(2, axis);
  11766. tmp = this._tweenStart[axis] - halfSize;
  11767. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  11768. endPos[axis] -= halfSize;
  11769. this._tweenStart[axis] = tmp;
  11770. }
  11771. }
  11772. else if (endPos[axis] < -this._overlapSize[axis]) {
  11773. halfSize = this.getLoopPartSize(2, axis);
  11774. tmp = this._tweenStart[axis] + halfSize;
  11775. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  11776. endPos[axis] += halfSize;
  11777. this._tweenStart[axis] = tmp;
  11778. }
  11779. }
  11780. }
  11781. loopCheckingNewPos(value, axis) {
  11782. if (this._overlapSize[axis] == 0)
  11783. return value;
  11784. var pos = axis == 'x' ? this._xPos : this._yPos;
  11785. var changed = false;
  11786. var v;
  11787. if (value < 0.001) {
  11788. value += this.getLoopPartSize(2, axis);
  11789. if (value > pos) {
  11790. v = this.getLoopPartSize(6, axis);
  11791. v = Math.ceil((value - pos) / v) * v;
  11792. pos = fgui.ToolSet.clamp(pos + v, 0, this._overlapSize[axis]);
  11793. changed = true;
  11794. }
  11795. }
  11796. else if (value >= this._overlapSize[axis]) {
  11797. value -= this.getLoopPartSize(2, axis);
  11798. if (value < pos) {
  11799. v = this.getLoopPartSize(6, axis);
  11800. v = Math.ceil((pos - value) / v) * v;
  11801. pos = fgui.ToolSet.clamp(pos - v, 0, this._overlapSize[axis]);
  11802. changed = true;
  11803. }
  11804. }
  11805. if (changed) {
  11806. if (axis == 'x')
  11807. this._container.x = -Math.floor(pos);
  11808. else
  11809. this._container.y = Math.floor(pos);
  11810. }
  11811. return value;
  11812. }
  11813. alignPosition(pos, inertialScrolling) {
  11814. if (this._pageMode) {
  11815. pos.x = this.alignByPage(pos.x, 'x', inertialScrolling);
  11816. pos.y = this.alignByPage(pos.y, 'y', inertialScrolling);
  11817. }
  11818. else if (this._snapToItem) {
  11819. var pt = this._owner.getSnappingPosition(-pos.x, -pos.y, s_vec2);
  11820. if (pos.x < 0 && pos.x > -this._overlapSize.x)
  11821. pos.x = -pt.x;
  11822. if (pos.y < 0 && pos.y > -this._overlapSize.y)
  11823. pos.y = -pt.y;
  11824. }
  11825. }
  11826. alignByPage(pos, axis, inertialScrolling) {
  11827. var page;
  11828. if (pos > 0)
  11829. page = 0;
  11830. else if (pos < -this._overlapSize[axis])
  11831. page = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  11832. else {
  11833. page = Math.floor(-pos / this._pageSize[axis]);
  11834. var change = inertialScrolling ? pos - this._containerPos[axis] : pos - (axis == 'x' ? this._container.x : -this._container.y);
  11835. var testPageSize = Math.min(this._pageSize[axis], this._contentSize[axis] - (page + 1) * this._pageSize[axis]);
  11836. var delta = -pos - page * this._pageSize[axis];
  11837. if (Math.abs(change) > this._pageSize[axis]) {
  11838. if (delta > testPageSize * 0.5)
  11839. page++;
  11840. }
  11841. else {
  11842. if (delta > testPageSize * (change < 0 ? 0.3 : 0.7))
  11843. page++;
  11844. }
  11845. pos = -page * this._pageSize[axis];
  11846. if (pos < -this._overlapSize[axis])
  11847. pos = -this._overlapSize[axis];
  11848. }
  11849. if (inertialScrolling) {
  11850. var oldPos = this._tweenStart[axis];
  11851. var oldPage;
  11852. if (oldPos > 0)
  11853. oldPage = 0;
  11854. else if (oldPos < -this._overlapSize[axis])
  11855. oldPage = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  11856. else
  11857. oldPage = Math.floor(-oldPos / this._pageSize[axis]);
  11858. var startPage = Math.floor(-this._containerPos[axis] / this._pageSize[axis]);
  11859. if (Math.abs(page - startPage) > 1 && Math.abs(oldPage - startPage) <= 1) {
  11860. if (page > startPage)
  11861. page = startPage + 1;
  11862. else
  11863. page = startPage - 1;
  11864. pos = -page * this._pageSize[axis];
  11865. }
  11866. }
  11867. return pos;
  11868. }
  11869. updateTargetAndDuration(orignPos, resultPos) {
  11870. resultPos.x = this.updateTargetAndDuration2(orignPos.x, 'x');
  11871. resultPos.y = this.updateTargetAndDuration2(orignPos.y, 'y');
  11872. }
  11873. updateTargetAndDuration2(pos, axis) {
  11874. var v = this._velocity[axis];
  11875. var duration = 0;
  11876. if (pos > 0)
  11877. pos = 0;
  11878. else if (pos < -this._overlapSize[axis])
  11879. pos = -this._overlapSize[axis];
  11880. else {
  11881. var isMobile = cc.sys.isMobile;
  11882. var v2 = Math.abs(v) * this._velocityScale;
  11883. if (isMobile)
  11884. v2 *= 1136 / Math.max(cc.winSize.width, cc.winSize.height);
  11885. var ratio = 0;
  11886. if (this._pageMode || !isMobile) {
  11887. if (v2 > 500)
  11888. ratio = Math.pow((v2 - 500) / 500, 2);
  11889. }
  11890. else {
  11891. if (v2 > 1000)
  11892. ratio = Math.pow((v2 - 1000) / 1000, 2);
  11893. }
  11894. if (ratio != 0) {
  11895. if (ratio > 1)
  11896. ratio = 1;
  11897. v2 *= ratio;
  11898. v *= ratio;
  11899. this._velocity[axis] = v;
  11900. duration = Math.log(60 / v2) / Math.log(this._decelerationRate) / 60;
  11901. var change = Math.floor(v * duration * 0.4);
  11902. pos += change;
  11903. }
  11904. }
  11905. if (duration < TWEEN_TIME_DEFAULT)
  11906. duration = TWEEN_TIME_DEFAULT;
  11907. this._tweenDuration[axis] = duration;
  11908. return pos;
  11909. }
  11910. fixDuration(axis, oldChange) {
  11911. if (this._tweenChange[axis] == 0 || Math.abs(this._tweenChange[axis]) >= Math.abs(oldChange))
  11912. return;
  11913. var newDuration = Math.abs(this._tweenChange[axis] / oldChange) * this._tweenDuration[axis];
  11914. if (newDuration < TWEEN_TIME_DEFAULT)
  11915. newDuration = TWEEN_TIME_DEFAULT;
  11916. this._tweenDuration[axis] = newDuration;
  11917. }
  11918. startTween(type) {
  11919. this._tweenTime.set(cc.Vec2.ZERO);
  11920. this._tweening = type;
  11921. this.updateScrollBarVisible();
  11922. }
  11923. killTween() {
  11924. if (this._tweening == 1) {
  11925. this._container.setPosition(this._tweenStart.x + this._tweenChange.x, -(this._tweenStart.y + this._tweenChange.y));
  11926. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  11927. }
  11928. this._tweening = 0;
  11929. this.updateScrollBarVisible();
  11930. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  11931. }
  11932. checkRefreshBar() {
  11933. if (this._header == null && this._footer == null)
  11934. return;
  11935. var pos = this._refreshBarAxis == 'x' ? this._container.x : -this._container.y;
  11936. if (this._header) {
  11937. if (pos > 0) {
  11938. this._header.node.active = true;
  11939. var pt = s_vec2;
  11940. pt.x = this._header.width;
  11941. pt.y = this._header.height;
  11942. pt[this._refreshBarAxis] = pos;
  11943. this._header.setSize(pt.x, pt.y);
  11944. }
  11945. else {
  11946. this._header.node.active = false;
  11947. }
  11948. }
  11949. if (this._footer) {
  11950. var max = this._overlapSize[this._refreshBarAxis];
  11951. if (pos < -max || (max == 0 && this._footerLockedSize > 0)) {
  11952. this._footer.node.active = true;
  11953. pt = s_vec2;
  11954. pt.x = this._footer.x;
  11955. pt.y = this._footer.y;
  11956. if (max > 0)
  11957. pt[this._refreshBarAxis] = pos + this._contentSize[this._refreshBarAxis];
  11958. else
  11959. 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]);
  11960. this._footer.setPosition(pt.x, pt.y);
  11961. pt.x = this._footer.width;
  11962. pt.y = this._footer.height;
  11963. if (max > 0)
  11964. pt[this._refreshBarAxis] = -max - pos;
  11965. else
  11966. pt[this._refreshBarAxis] = this._viewSize[this._refreshBarAxis] - this._footer[this._refreshBarAxis];
  11967. this._footer.setSize(pt.x, pt.y);
  11968. }
  11969. else {
  11970. this._footer.node.active = false;
  11971. }
  11972. }
  11973. }
  11974. update(dt) {
  11975. if (this._tweening == 0)
  11976. return;
  11977. var nx = this.runTween('x', dt);
  11978. var ny = this.runTween('y', dt);
  11979. this._container.setPosition(nx, -ny);
  11980. if (this._tweening == 2) {
  11981. if (this._overlapSize.x > 0)
  11982. this._xPos = fgui.ToolSet.clamp(-nx, 0, this._overlapSize.x);
  11983. if (this._overlapSize.y > 0)
  11984. this._yPos = fgui.ToolSet.clamp(-ny, 0, this._overlapSize.y);
  11985. if (this._pageMode)
  11986. this.updatePageController();
  11987. }
  11988. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  11989. this._tweening = 0;
  11990. this.loopCheckingCurrent();
  11991. this.updateScrollBarPos();
  11992. this.updateScrollBarVisible();
  11993. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  11994. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  11995. }
  11996. else {
  11997. this.updateScrollBarPos();
  11998. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  11999. }
  12000. return true;
  12001. }
  12002. runTween(axis, dt) {
  12003. var newValue;
  12004. if (this._tweenChange[axis] != 0) {
  12005. this._tweenTime[axis] += dt;
  12006. if (this._tweenTime[axis] >= this._tweenDuration[axis]) {
  12007. newValue = this._tweenStart[axis] + this._tweenChange[axis];
  12008. this._tweenChange[axis] = 0;
  12009. }
  12010. else {
  12011. var ratio = easeFunc(this._tweenTime[axis], this._tweenDuration[axis]);
  12012. newValue = this._tweenStart[axis] + Math.floor(this._tweenChange[axis] * ratio);
  12013. }
  12014. var threshold1 = 0;
  12015. var threshold2 = -this._overlapSize[axis];
  12016. if (this._headerLockedSize > 0 && this._refreshBarAxis == axis)
  12017. threshold1 = this._headerLockedSize;
  12018. if (this._footerLockedSize > 0 && this._refreshBarAxis == axis) {
  12019. var max = this._overlapSize[this._refreshBarAxis];
  12020. if (max == 0)
  12021. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12022. else
  12023. max += this._footerLockedSize;
  12024. threshold2 = -max;
  12025. }
  12026. if (this._tweening == 2 && this._bouncebackEffect) {
  12027. if ((newValue > 20 + threshold1 && this._tweenChange[axis] > 0) || (newValue > threshold1 && this._tweenChange[axis] == 0)) {
  12028. this._tweenTime[axis] = 0;
  12029. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  12030. this._tweenChange[axis] = -newValue + threshold1;
  12031. this._tweenStart[axis] = newValue;
  12032. }
  12033. else if ((newValue < threshold2 - 20 && this._tweenChange[axis] < 0) || (newValue < threshold2 && this._tweenChange[axis] == 0)) {
  12034. this._tweenTime[axis] = 0;
  12035. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  12036. this._tweenChange[axis] = threshold2 - newValue;
  12037. this._tweenStart[axis] = newValue;
  12038. }
  12039. }
  12040. else {
  12041. if (newValue > threshold1) {
  12042. newValue = threshold1;
  12043. this._tweenChange[axis] = 0;
  12044. }
  12045. else if (newValue < threshold2) {
  12046. newValue = threshold2;
  12047. this._tweenChange[axis] = 0;
  12048. }
  12049. }
  12050. }
  12051. else
  12052. newValue = axis == 'x' ? this._container.x : -this._container.y;
  12053. return newValue;
  12054. }
  12055. }
  12056. fgui.ScrollPane = ScrollPane;
  12057. var _gestureFlag = 0;
  12058. const TWEEN_TIME_GO = 0.5;
  12059. const TWEEN_TIME_DEFAULT = 0.3;
  12060. const PULL_RATIO = 0.5;
  12061. var s_vec2 = new cc.Vec2();
  12062. var s_rect = new cc.Rect();
  12063. var sEndPos = new cc.Vec2();
  12064. var sOldChange = new cc.Vec2();
  12065. function easeFunc(t, d) {
  12066. return (t = t / d - 1) * t * t + 1;
  12067. }
  12068. })(fgui || (fgui = {}));
  12069. (function (fgui) {
  12070. class Transition {
  12071. constructor(owner) {
  12072. this._ownerBaseX = 0;
  12073. this._ownerBaseY = 0;
  12074. this._totalTimes = 0;
  12075. this._totalTasks = 0;
  12076. this._options = 0;
  12077. this._totalDuration = 0;
  12078. this._autoPlayTimes = 1;
  12079. this._autoPlayDelay = 0;
  12080. this._timeScale = 1;
  12081. this._startTime = 0;
  12082. this._endTime = 0;
  12083. this._owner = owner;
  12084. this._items = new Array();
  12085. }
  12086. play(onComplete, times, delay, startTime, endTime) {
  12087. this._play(onComplete, times, delay, startTime, endTime, false);
  12088. }
  12089. playReverse(onComplete, times, delay) {
  12090. this._play(onComplete, times, delay, 0, -1, true);
  12091. }
  12092. changePlayTimes(value) {
  12093. this._totalTimes = value;
  12094. }
  12095. setAutoPlay(value, times, delay) {
  12096. if (times == undefined)
  12097. times = -1;
  12098. if (delay == undefined)
  12099. delay = 0;
  12100. if (this._autoPlay != value) {
  12101. this._autoPlay = value;
  12102. this._autoPlayTimes = times;
  12103. this._autoPlayDelay = delay;
  12104. if (this._autoPlay) {
  12105. if (this._owner.onStage)
  12106. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  12107. }
  12108. else {
  12109. if (!this._owner.onStage)
  12110. this.stop(false, true);
  12111. }
  12112. }
  12113. }
  12114. _play(onComplete, times, delay, startTime, endTime, reversed) {
  12115. if (times == undefined)
  12116. times = 1;
  12117. if (delay == undefined)
  12118. delay = 0;
  12119. if (startTime == undefined)
  12120. startTime = 0;
  12121. if (endTime == undefined)
  12122. endTime = -1;
  12123. this.stop(true, true);
  12124. this._totalTimes = times;
  12125. this._reversed = reversed;
  12126. this._startTime = startTime;
  12127. this._endTime = endTime;
  12128. this._playing = true;
  12129. this._paused = false;
  12130. this._onComplete = onComplete;
  12131. var cnt = this._items.length;
  12132. for (var i = 0; i < cnt; i++) {
  12133. var item = this._items[i];
  12134. if (item.target == null) {
  12135. if (item.targetId)
  12136. item.target = this._owner.getChildById(item.targetId);
  12137. else
  12138. item.target = this._owner;
  12139. }
  12140. else if (item.target != this._owner && item.target.parent != this._owner)
  12141. item.target = null;
  12142. if (item.target && item.type == ActionType.Transition) {
  12143. var trans = item.target.getTransition(item.value.transName);
  12144. if (trans == this)
  12145. trans = null;
  12146. if (trans) {
  12147. if (item.value.playTimes == 0) {
  12148. var j;
  12149. for (j = i - 1; j >= 0; j--) {
  12150. var item2 = this._items[j];
  12151. if (item2.type == ActionType.Transition) {
  12152. if (item2.value.trans == trans) {
  12153. item2.value.stopTime = item.time - item2.time;
  12154. break;
  12155. }
  12156. }
  12157. }
  12158. if (j < 0)
  12159. item.value.stopTime = 0;
  12160. else
  12161. trans = null;
  12162. }
  12163. else
  12164. item.value.stopTime = -1;
  12165. }
  12166. item.value.trans = trans;
  12167. }
  12168. }
  12169. if (delay == 0)
  12170. this.onDelayedPlay();
  12171. else
  12172. fgui.GTween.delayedCall(delay).setTarget(this).onComplete(this.onDelayedPlay, this);
  12173. }
  12174. stop(setToComplete, processCallback) {
  12175. if (setToComplete == undefined)
  12176. setToComplete = true;
  12177. if (!this._playing)
  12178. return;
  12179. this._playing = false;
  12180. this._totalTasks = 0;
  12181. this._totalTimes = 0;
  12182. var func = this._onComplete;
  12183. this._onComplete = null;
  12184. fgui.GTween.kill(this);
  12185. var cnt = this._items.length;
  12186. if (this._reversed) {
  12187. for (var i = cnt - 1; i >= 0; i--) {
  12188. var item = this._items[i];
  12189. if (item.target == null)
  12190. continue;
  12191. this.stopItem(item, setToComplete);
  12192. }
  12193. }
  12194. else {
  12195. for (i = 0; i < cnt; i++) {
  12196. item = this._items[i];
  12197. if (item.target == null)
  12198. continue;
  12199. this.stopItem(item, setToComplete);
  12200. }
  12201. }
  12202. if (processCallback && func != null) {
  12203. func();
  12204. }
  12205. }
  12206. stopItem(item, setToComplete) {
  12207. if (item.displayLockToken != 0) {
  12208. item.target.releaseDisplayLock(item.displayLockToken);
  12209. item.displayLockToken = 0;
  12210. }
  12211. if (item.tweener) {
  12212. item.tweener.kill(setToComplete);
  12213. item.tweener = null;
  12214. if (item.type == ActionType.Shake && !setToComplete) {
  12215. item.target._gearLocked = true;
  12216. item.target.setPosition(item.target.x - item.value.lastOffsetX, item.target.y - item.value.lastOffsetY);
  12217. item.target._gearLocked = false;
  12218. }
  12219. }
  12220. if (item.type == ActionType.Transition) {
  12221. var trans = item.value.trans;
  12222. if (trans)
  12223. trans.stop(setToComplete, false);
  12224. }
  12225. }
  12226. setPaused(paused) {
  12227. if (!this._playing || this._paused == paused)
  12228. return;
  12229. this._paused = paused;
  12230. var tweener = fgui.GTween.getTween(this);
  12231. if (tweener)
  12232. tweener.setPaused(paused);
  12233. var cnt = this._items.length;
  12234. for (var i = 0; i < cnt; i++) {
  12235. var item = this._items[i];
  12236. if (item.target == null)
  12237. continue;
  12238. if (item.type == ActionType.Transition) {
  12239. if (item.value.trans)
  12240. item.value.trans.setPaused(paused);
  12241. }
  12242. else if (item.type == ActionType.Animation) {
  12243. if (paused) {
  12244. item.value.flag = item.target.getProp(fgui.ObjectPropID.Playing);
  12245. item.target.setProp(fgui.ObjectPropID.Playing, false);
  12246. }
  12247. else
  12248. item.target.setProp(fgui.ObjectPropID.Playing, item.value.flag);
  12249. }
  12250. if (item.tweener)
  12251. item.tweener.setPaused(paused);
  12252. }
  12253. }
  12254. dispose() {
  12255. if (this._playing)
  12256. fgui.GTween.kill(this);
  12257. var cnt = this._items.length;
  12258. for (var i = 0; i < cnt; i++) {
  12259. var item = this._items[i];
  12260. if (item.tweener) {
  12261. item.tweener.kill();
  12262. item.tweener = null;
  12263. }
  12264. item.target = null;
  12265. item.hook = null;
  12266. if (item.tweenConfig)
  12267. item.tweenConfig.endHook = null;
  12268. }
  12269. this._items.length = 0;
  12270. this._playing = false;
  12271. this._onComplete = null;
  12272. }
  12273. get playing() {
  12274. return this._playing;
  12275. }
  12276. setValue(label, ...args) {
  12277. var cnt = this._items.length;
  12278. var value;
  12279. for (var i = 0; i < cnt; i++) {
  12280. var item = this._items[i];
  12281. if (item.label == label) {
  12282. if (item.tweenConfig)
  12283. value = item.tweenConfig.startValue;
  12284. else
  12285. value = item.value;
  12286. }
  12287. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  12288. value = item.tweenConfig.endValue;
  12289. }
  12290. else
  12291. continue;
  12292. switch (item.type) {
  12293. case ActionType.XY:
  12294. case ActionType.Size:
  12295. case ActionType.Pivot:
  12296. case ActionType.Scale:
  12297. case ActionType.Skew:
  12298. value.b1 = true;
  12299. value.b2 = true;
  12300. value.f1 = parseFloat(args[0]);
  12301. value.f2 = parseFloat(args[1]);
  12302. break;
  12303. case ActionType.Alpha:
  12304. value.f1 = parseFloat(args[0]);
  12305. break;
  12306. case ActionType.Rotation:
  12307. value.f1 = parseFloat(args[0]);
  12308. break;
  12309. case ActionType.Color:
  12310. value.f1 = parseFloat(args[0]);
  12311. break;
  12312. case ActionType.Animation:
  12313. value.frame = parseInt(args[0]);
  12314. if (args.length > 1)
  12315. value.playing = args[1];
  12316. break;
  12317. case ActionType.Visible:
  12318. value.visible = args[0];
  12319. break;
  12320. case ActionType.Sound:
  12321. value.sound = args[0];
  12322. if (args.length > 1)
  12323. value.volume = parseFloat(args[1]);
  12324. break;
  12325. case ActionType.Transition:
  12326. value.transName = args[0];
  12327. if (args.length > 1)
  12328. value.playTimes = parseInt(args[1]);
  12329. break;
  12330. case ActionType.Shake:
  12331. value.amplitude = parseFloat(args[0]);
  12332. if (args.length > 1)
  12333. value.duration = parseFloat(args[1]);
  12334. break;
  12335. case ActionType.ColorFilter:
  12336. value.f1 = parseFloat(args[0]);
  12337. value.f2 = parseFloat(args[1]);
  12338. value.f3 = parseFloat(args[2]);
  12339. value.f4 = parseFloat(args[3]);
  12340. break;
  12341. case ActionType.Text:
  12342. case ActionType.Icon:
  12343. value.text = args[0];
  12344. break;
  12345. }
  12346. }
  12347. }
  12348. setHook(label, callback) {
  12349. var cnt = this._items.length;
  12350. for (var i = 0; i < cnt; i++) {
  12351. var item = this._items[i];
  12352. if (item.label == label) {
  12353. item.hook = callback;
  12354. break;
  12355. }
  12356. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  12357. item.tweenConfig.endHook = callback;
  12358. break;
  12359. }
  12360. }
  12361. }
  12362. clearHooks() {
  12363. var cnt = this._items.length;
  12364. for (var i = 0; i < cnt; i++) {
  12365. var item = this._items[i];
  12366. item.hook = null;
  12367. if (item.tweenConfig)
  12368. item.tweenConfig.endHook = null;
  12369. }
  12370. }
  12371. setTarget(label, newTarget) {
  12372. var cnt = this._items.length;
  12373. for (var i = 0; i < cnt; i++) {
  12374. var item = this._items[i];
  12375. if (item.label == label) {
  12376. item.targetId = newTarget.id;
  12377. item.target = null;
  12378. }
  12379. }
  12380. }
  12381. setDuration(label, value) {
  12382. var cnt = this._items.length;
  12383. for (var i = 0; i < cnt; i++) {
  12384. var item = this._items[i];
  12385. if (item.tweenConfig && item.label == label)
  12386. item.tweenConfig.duration = value;
  12387. }
  12388. }
  12389. getLabelTime(label) {
  12390. var cnt = this._items.length;
  12391. for (var i = 0; i < cnt; i++) {
  12392. var item = this._items[i];
  12393. if (item.label == label)
  12394. return item.time;
  12395. else if (item.tweenConfig && item.tweenConfig.endLabel == label)
  12396. return item.time + item.tweenConfig.duration;
  12397. }
  12398. return Number.NaN;
  12399. }
  12400. get timeScale() {
  12401. return this._timeScale;
  12402. }
  12403. set timeScale(value) {
  12404. if (this._timeScale != value) {
  12405. this._timeScale = value;
  12406. if (this._playing) {
  12407. var cnt = this._items.length;
  12408. for (var i = 0; i < cnt; i++) {
  12409. var item = this._items[i];
  12410. if (item.tweener)
  12411. item.tweener.setTimeScale(value);
  12412. else if (item.type == ActionType.Transition) {
  12413. if (item.value.trans)
  12414. item.value.trans.timeScale = value;
  12415. }
  12416. else if (item.type == ActionType.Animation) {
  12417. if (item.target)
  12418. item.target.setProp(fgui.ObjectPropID.TimeScale, value);
  12419. }
  12420. }
  12421. }
  12422. }
  12423. }
  12424. updateFromRelations(targetId, dx, dy) {
  12425. var cnt = this._items.length;
  12426. if (cnt == 0)
  12427. return;
  12428. for (var i = 0; i < cnt; i++) {
  12429. var item = this._items[i];
  12430. if (item.type == ActionType.XY && item.targetId == targetId) {
  12431. if (item.tweenConfig) {
  12432. item.tweenConfig.startValue.f1 += dx;
  12433. item.tweenConfig.startValue.f2 += dy;
  12434. item.tweenConfig.endValue.f1 += dx;
  12435. item.tweenConfig.endValue.f2 += dy;
  12436. }
  12437. else {
  12438. item.value.f1 += dx;
  12439. item.value.f2 += dy;
  12440. }
  12441. }
  12442. }
  12443. }
  12444. onEnable() {
  12445. if (this._autoPlay && !this._playing)
  12446. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  12447. }
  12448. onDisable() {
  12449. if ((this._options & OPTION_AUTO_STOP_DISABLED) == 0)
  12450. this.stop((this._options & OPTION_AUTO_STOP_AT_END) != 0 ? true : false, false);
  12451. }
  12452. onDelayedPlay() {
  12453. this.internalPlay();
  12454. this._playing = this._totalTasks > 0;
  12455. if (this._playing) {
  12456. if ((this._options & OPTION_IGNORE_DISPLAY_CONTROLLER) != 0) {
  12457. var cnt = this._items.length;
  12458. for (var i = 0; i < cnt; i++) {
  12459. var item = this._items[i];
  12460. if (item.target && item.target != this._owner)
  12461. item.displayLockToken = item.target.addDisplayLock();
  12462. }
  12463. }
  12464. }
  12465. else if (this._onComplete != null) {
  12466. var func = this._onComplete;
  12467. this._onComplete = null;
  12468. func();
  12469. }
  12470. }
  12471. internalPlay() {
  12472. this._ownerBaseX = this._owner.x;
  12473. this._ownerBaseY = this._owner.y;
  12474. this._totalTasks = 1;
  12475. var cnt = this._items.length;
  12476. var item;
  12477. var needSkipAnimations = false;
  12478. var i;
  12479. if (!this._reversed) {
  12480. for (i = 0; i < cnt; i++) {
  12481. item = this._items[i];
  12482. if (item.target == null)
  12483. continue;
  12484. if (item.type == ActionType.Animation && this._startTime != 0 && item.time <= this._startTime) {
  12485. needSkipAnimations = true;
  12486. item.value.flag = false;
  12487. }
  12488. else
  12489. this.playItem(item);
  12490. }
  12491. }
  12492. else {
  12493. for (i = cnt - 1; i >= 0; i--) {
  12494. item = this._items[i];
  12495. if (item.target == null)
  12496. continue;
  12497. this.playItem(item);
  12498. }
  12499. }
  12500. if (needSkipAnimations)
  12501. this.skipAnimations();
  12502. this._totalTasks--;
  12503. }
  12504. playItem(item) {
  12505. var time;
  12506. if (item.tweenConfig) {
  12507. if (this._reversed)
  12508. time = (this._totalDuration - item.time - item.tweenConfig.duration);
  12509. else
  12510. time = item.time;
  12511. if (this._endTime == -1 || time <= this._endTime) {
  12512. var startValue;
  12513. var endValue;
  12514. if (this._reversed) {
  12515. startValue = item.tweenConfig.endValue;
  12516. endValue = item.tweenConfig.startValue;
  12517. }
  12518. else {
  12519. startValue = item.tweenConfig.startValue;
  12520. endValue = item.tweenConfig.endValue;
  12521. }
  12522. item.value.b1 = startValue.b1 || endValue.b1;
  12523. item.value.b2 = startValue.b2 || endValue.b2;
  12524. switch (item.type) {
  12525. case ActionType.XY:
  12526. case ActionType.Size:
  12527. case ActionType.Scale:
  12528. case ActionType.Skew:
  12529. item.tweener = fgui.GTween.to2(startValue.f1, startValue.f2, endValue.f1, endValue.f2, item.tweenConfig.duration);
  12530. break;
  12531. case ActionType.Alpha:
  12532. case ActionType.Rotation:
  12533. item.tweener = fgui.GTween.to(startValue.f1, endValue.f1, item.tweenConfig.duration);
  12534. break;
  12535. case ActionType.Color:
  12536. item.tweener = fgui.GTween.toColor(startValue.f1, endValue.f1, item.tweenConfig.duration);
  12537. break;
  12538. case ActionType.ColorFilter:
  12539. item.tweener = fgui.GTween.to4(startValue.f1, startValue.f2, startValue.f3, startValue.f4, endValue.f1, endValue.f2, endValue.f3, endValue.f4, item.tweenConfig.duration);
  12540. break;
  12541. }
  12542. item.tweener.setDelay(time)
  12543. .setEase(item.tweenConfig.easeType)
  12544. .setRepeat(item.tweenConfig.repeat, item.tweenConfig.yoyo)
  12545. .setTimeScale(this._timeScale)
  12546. .setTarget(item)
  12547. .onStart(this.onTweenStart, this)
  12548. .onUpdate(this.onTweenUpdate, this)
  12549. .onComplete(this.onTweenComplete, this);
  12550. if (this._endTime >= 0)
  12551. item.tweener.setBreakpoint(this._endTime - time);
  12552. this._totalTasks++;
  12553. }
  12554. }
  12555. else if (item.type == ActionType.Shake) {
  12556. if (this._reversed)
  12557. time = (this._totalDuration - item.time - item.value.duration);
  12558. else
  12559. time = item.time;
  12560. item.value.offsetX = item.value.offsetY = 0;
  12561. item.value.lastOffsetX = item.value.lastOffsetY = 0;
  12562. item.tweener = fgui.GTween.shake(0, 0, item.value.amplitude, item.value.duration)
  12563. .setDelay(time)
  12564. .setTimeScale(this._timeScale)
  12565. .setTarget(item)
  12566. .onUpdate(this.onTweenUpdate, this)
  12567. .onComplete(this.onTweenComplete, this);
  12568. if (this._endTime >= 0)
  12569. item.tweener.setBreakpoint(this._endTime - item.time);
  12570. this._totalTasks++;
  12571. }
  12572. else {
  12573. if (this._reversed)
  12574. time = (this._totalDuration - item.time);
  12575. else
  12576. time = item.time;
  12577. if (time <= this._startTime) {
  12578. this.applyValue(item);
  12579. this.callHook(item, false);
  12580. }
  12581. else if (this._endTime == -1 || time <= this._endTime) {
  12582. this._totalTasks++;
  12583. item.tweener = fgui.GTween.delayedCall(time)
  12584. .setTimeScale(this._timeScale)
  12585. .setTarget(item)
  12586. .onComplete(this.onDelayedPlayItem, this);
  12587. }
  12588. }
  12589. if (item.tweener)
  12590. item.tweener.seek(this._startTime);
  12591. }
  12592. skipAnimations() {
  12593. var frame;
  12594. var playStartTime;
  12595. var playTotalTime;
  12596. var value;
  12597. var target;
  12598. var item;
  12599. var cnt = this._items.length;
  12600. for (var i = 0; i < cnt; i++) {
  12601. item = this._items[i];
  12602. if (item.type != ActionType.Animation || item.time > this._startTime)
  12603. continue;
  12604. value = item.value;
  12605. if (value.flag)
  12606. continue;
  12607. target = item.target;
  12608. frame = target.getProp(fgui.ObjectPropID.Frame);
  12609. playStartTime = target.getProp(fgui.ObjectPropID.Playing) ? 0 : -1;
  12610. playTotalTime = 0;
  12611. for (var j = i; j < cnt; j++) {
  12612. item = this._items[j];
  12613. if (item.type != ActionType.Animation || item.target != target || item.time > this._startTime)
  12614. continue;
  12615. value = item.value;
  12616. value.flag = true;
  12617. if (value.frame != -1) {
  12618. frame = value.frame;
  12619. if (value.playing)
  12620. playStartTime = item.time;
  12621. else
  12622. playStartTime = -1;
  12623. playTotalTime = 0;
  12624. }
  12625. else {
  12626. if (value.playing) {
  12627. if (playStartTime < 0)
  12628. playStartTime = item.time;
  12629. }
  12630. else {
  12631. if (playStartTime >= 0)
  12632. playTotalTime += (item.time - playStartTime);
  12633. playStartTime = -1;
  12634. }
  12635. }
  12636. this.callHook(item, false);
  12637. }
  12638. if (playStartTime >= 0)
  12639. playTotalTime += (this._startTime - playStartTime);
  12640. target.setProp(fgui.ObjectPropID.Playing, playStartTime >= 0);
  12641. target.setProp(fgui.ObjectPropID.Frame, frame);
  12642. if (playTotalTime > 0)
  12643. target.setProp(fgui.ObjectPropID.DeltaTime, playTotalTime * 1000);
  12644. }
  12645. }
  12646. onDelayedPlayItem(tweener) {
  12647. var item = tweener.target;
  12648. item.tweener = null;
  12649. this._totalTasks--;
  12650. this.applyValue(item);
  12651. this.callHook(item, false);
  12652. this.checkAllComplete();
  12653. }
  12654. onTweenStart(tweener) {
  12655. var item = tweener.target;
  12656. if (item.type == ActionType.XY || item.type == ActionType.Size) {
  12657. var startValue;
  12658. var endValue;
  12659. if (this._reversed) {
  12660. startValue = item.tweenConfig.endValue;
  12661. endValue = item.tweenConfig.startValue;
  12662. }
  12663. else {
  12664. startValue = item.tweenConfig.startValue;
  12665. endValue = item.tweenConfig.endValue;
  12666. }
  12667. if (item.type == ActionType.XY) {
  12668. if (item.target != this._owner) {
  12669. if (!startValue.b1)
  12670. tweener.startValue.x = item.target.x;
  12671. else if (startValue.b3)
  12672. tweener.startValue.x = startValue.f1 * this._owner.width;
  12673. if (!startValue.b2)
  12674. tweener.startValue.y = item.target.y;
  12675. else if (startValue.b3)
  12676. tweener.startValue.y = startValue.f2 * this._owner.height;
  12677. if (!endValue.b1)
  12678. tweener.endValue.x = tweener.startValue.x;
  12679. else if (endValue.b3)
  12680. tweener.endValue.x = endValue.f1 * this._owner.width;
  12681. if (!endValue.b2)
  12682. tweener.endValue.y = tweener.startValue.y;
  12683. else if (endValue.b3)
  12684. tweener.endValue.y = endValue.f2 * this._owner.height;
  12685. }
  12686. else {
  12687. if (!startValue.b1)
  12688. tweener.startValue.x = item.target.x - this._ownerBaseX;
  12689. if (!startValue.b2)
  12690. tweener.startValue.y = item.target.y - this._ownerBaseY;
  12691. if (!endValue.b1)
  12692. tweener.endValue.x = tweener.startValue.x;
  12693. if (!endValue.b2)
  12694. tweener.endValue.y = tweener.startValue.y;
  12695. }
  12696. }
  12697. else {
  12698. if (!startValue.b1)
  12699. tweener.startValue.x = item.target.width;
  12700. if (!startValue.b2)
  12701. tweener.startValue.y = item.target.height;
  12702. if (!endValue.b1)
  12703. tweener.endValue.x = tweener.startValue.x;
  12704. if (!endValue.b2)
  12705. tweener.endValue.y = tweener.startValue.y;
  12706. }
  12707. if (item.tweenConfig.path) {
  12708. item.value.b1 = item.value.b2 = true;
  12709. tweener.setPath(item.tweenConfig.path);
  12710. }
  12711. }
  12712. this.callHook(item, false);
  12713. }
  12714. onTweenUpdate(tweener) {
  12715. var item = tweener.target;
  12716. switch (item.type) {
  12717. case ActionType.XY:
  12718. case ActionType.Size:
  12719. case ActionType.Scale:
  12720. case ActionType.Skew:
  12721. item.value.f1 = tweener.value.x;
  12722. item.value.f2 = tweener.value.y;
  12723. if (item.tweenConfig.path) {
  12724. item.value.f1 += tweener.startValue.x;
  12725. item.value.f2 += tweener.startValue.y;
  12726. }
  12727. break;
  12728. case ActionType.Alpha:
  12729. case ActionType.Rotation:
  12730. item.value.f1 = tweener.value.x;
  12731. break;
  12732. case ActionType.Color:
  12733. item.value.f1 = tweener.value.color;
  12734. break;
  12735. case ActionType.ColorFilter:
  12736. item.value.f1 = tweener.value.x;
  12737. item.value.f2 = tweener.value.y;
  12738. item.value.f3 = tweener.value.z;
  12739. item.value.f4 = tweener.value.w;
  12740. break;
  12741. case ActionType.Shake:
  12742. item.value.offsetX = tweener.deltaValue.x;
  12743. item.value.offsetY = tweener.deltaValue.y;
  12744. break;
  12745. }
  12746. this.applyValue(item);
  12747. }
  12748. onTweenComplete(tweener) {
  12749. var item = tweener.target;
  12750. item.tweener = null;
  12751. this._totalTasks--;
  12752. if (tweener.allCompleted)
  12753. this.callHook(item, true);
  12754. this.checkAllComplete();
  12755. }
  12756. onPlayTransCompleted(item) {
  12757. this._totalTasks--;
  12758. this.checkAllComplete();
  12759. }
  12760. callHook(item, tweenEnd) {
  12761. if (tweenEnd) {
  12762. if (item.tweenConfig && item.tweenConfig.endHook != null)
  12763. item.tweenConfig.endHook(item.label);
  12764. }
  12765. else {
  12766. if (item.time >= this._startTime && item.hook != null)
  12767. item.hook(item.label);
  12768. }
  12769. }
  12770. checkAllComplete() {
  12771. if (this._playing && this._totalTasks == 0) {
  12772. if (this._totalTimes < 0) {
  12773. this.internalPlay();
  12774. if (this._totalTasks == 0)
  12775. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  12776. }
  12777. else {
  12778. this._totalTimes--;
  12779. if (this._totalTimes > 0) {
  12780. this.internalPlay();
  12781. if (this._totalTasks == 0)
  12782. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  12783. }
  12784. else {
  12785. this._playing = false;
  12786. var cnt = this._items.length;
  12787. for (var i = 0; i < cnt; i++) {
  12788. var item = this._items[i];
  12789. if (item.target && item.displayLockToken != 0) {
  12790. item.target.releaseDisplayLock(item.displayLockToken);
  12791. item.displayLockToken = 0;
  12792. }
  12793. }
  12794. if (this._onComplete != null) {
  12795. var func = this._onComplete;
  12796. this._onComplete = null;
  12797. func();
  12798. }
  12799. }
  12800. }
  12801. }
  12802. }
  12803. applyValue(item) {
  12804. item.target._gearLocked = true;
  12805. var value = item.value;
  12806. switch (item.type) {
  12807. case ActionType.XY:
  12808. if (item.target == this._owner) {
  12809. if (value.b1 && value.b2)
  12810. item.target.setPosition(value.f1 + this._ownerBaseX, value.f2 + this._ownerBaseY);
  12811. else if (value.b1)
  12812. item.target.x = value.f1 + this._ownerBaseX;
  12813. else
  12814. item.target.y = value.f2 + this._ownerBaseY;
  12815. }
  12816. else {
  12817. if (value.b3) {
  12818. if (value.b1 && value.b2)
  12819. item.target.setPosition(value.f1 * this._owner.width, value.f2 * this._owner.height);
  12820. else if (value.b1)
  12821. item.target.x = value.f1 * this._owner.width;
  12822. else if (value.b2)
  12823. item.target.y = value.f2 * this._owner.height;
  12824. }
  12825. else {
  12826. if (value.b1 && value.b2)
  12827. item.target.setPosition(value.f1, value.f2);
  12828. else if (value.b1)
  12829. item.target.x = value.f1;
  12830. else if (value.b2)
  12831. item.target.y = value.f2;
  12832. }
  12833. }
  12834. break;
  12835. case ActionType.Size:
  12836. if (!value.b1)
  12837. value.f1 = item.target.width;
  12838. if (!value.b2)
  12839. value.f2 = item.target.height;
  12840. item.target.setSize(value.f1, value.f2);
  12841. break;
  12842. case ActionType.Pivot:
  12843. item.target.setPivot(value.f1, value.f2, item.target.pivotAsAnchor);
  12844. break;
  12845. case ActionType.Alpha:
  12846. item.target.alpha = value.f1;
  12847. break;
  12848. case ActionType.Rotation:
  12849. item.target.rotation = value.f1;
  12850. break;
  12851. case ActionType.Scale:
  12852. item.target.setScale(value.f1, value.f2);
  12853. break;
  12854. case ActionType.Skew:
  12855. item.target.setSkew(value.f1, value.f2);
  12856. break;
  12857. case ActionType.Color:
  12858. let color = item.target.getProp(fgui.ObjectPropID.Color);
  12859. if (color instanceof cc.Color) {
  12860. let i = Math.floor(value.f1);
  12861. color.setR((i >> 16) & 0xFF).setG((i >> 8) & 0xFF).setB(i & 0xFF);
  12862. item.target.setProp(fgui.ObjectPropID.Color, color);
  12863. }
  12864. break;
  12865. case ActionType.Animation:
  12866. if (value.frame >= 0)
  12867. item.target.setProp(fgui.ObjectPropID.Frame, value.frame);
  12868. item.target.setProp(fgui.ObjectPropID.Playing, value.playing);
  12869. item.target.setProp(fgui.ObjectPropID.TimeScale, this._timeScale);
  12870. break;
  12871. case ActionType.Visible:
  12872. item.target.visible = value.visible;
  12873. break;
  12874. case ActionType.Transition:
  12875. if (this._playing) {
  12876. var trans = value.trans;
  12877. if (trans) {
  12878. this._totalTasks++;
  12879. var startTime = this._startTime > item.time ? (this._startTime - item.time) : 0;
  12880. var endTime = this._endTime >= 0 ? (this._endTime - item.time) : -1;
  12881. if (value.stopTime >= 0 && (endTime < 0 || endTime > value.stopTime))
  12882. endTime = value.stopTime;
  12883. trans.timeScale = this._timeScale;
  12884. trans._play(function () { this.onPlayTransCompleted(item); }.bind(this), value.playTimes, 0, startTime, endTime, this._reversed);
  12885. }
  12886. }
  12887. break;
  12888. case ActionType.Sound:
  12889. if (this._playing && item.time >= this._startTime) {
  12890. if (value.audioClip == null) {
  12891. var pi = fgui.UIPackage.getItemByURL(value.sound);
  12892. if (pi)
  12893. value.audioClip = pi.owner.getItemAsset(pi);
  12894. }
  12895. if (value.audioClip)
  12896. fgui.GRoot.inst.playOneShotSound(value.audioClip, value.volume);
  12897. }
  12898. break;
  12899. case ActionType.Shake:
  12900. item.target.setPosition(item.target.x - value.lastOffsetX + value.offsetX, item.target.y - value.lastOffsetY + value.offsetY);
  12901. value.lastOffsetX = value.offsetX;
  12902. value.lastOffsetY = value.offsetY;
  12903. break;
  12904. case ActionType.ColorFilter:
  12905. {
  12906. break;
  12907. }
  12908. case ActionType.Text:
  12909. item.target.text = value.text;
  12910. break;
  12911. case ActionType.Icon:
  12912. item.target.icon = value.text;
  12913. break;
  12914. }
  12915. item.target._gearLocked = false;
  12916. }
  12917. setup(buffer) {
  12918. this.name = buffer.readS();
  12919. this._options = buffer.readInt();
  12920. this._autoPlay = buffer.readBool();
  12921. this._autoPlayTimes = buffer.readInt();
  12922. this._autoPlayDelay = buffer.readFloat();
  12923. var cnt = buffer.readShort();
  12924. for (var i = 0; i < cnt; i++) {
  12925. var dataLen = buffer.readShort();
  12926. var curPos = buffer.position;
  12927. buffer.seek(curPos, 0);
  12928. var item = new Item(buffer.readByte());
  12929. this._items[i] = item;
  12930. item.time = buffer.readFloat();
  12931. var targetId = buffer.readShort();
  12932. if (targetId < 0)
  12933. item.targetId = "";
  12934. else
  12935. item.targetId = this._owner.getChildAt(targetId).id;
  12936. item.label = buffer.readS();
  12937. if (buffer.readBool()) {
  12938. buffer.seek(curPos, 1);
  12939. item.tweenConfig = new TweenConfig();
  12940. item.tweenConfig.duration = buffer.readFloat();
  12941. if (item.time + item.tweenConfig.duration > this._totalDuration)
  12942. this._totalDuration = item.time + item.tweenConfig.duration;
  12943. item.tweenConfig.easeType = buffer.readByte();
  12944. item.tweenConfig.repeat = buffer.readInt();
  12945. item.tweenConfig.yoyo = buffer.readBool();
  12946. item.tweenConfig.endLabel = buffer.readS();
  12947. buffer.seek(curPos, 2);
  12948. this.decodeValue(item, buffer, item.tweenConfig.startValue);
  12949. buffer.seek(curPos, 3);
  12950. this.decodeValue(item, buffer, item.tweenConfig.endValue);
  12951. if (buffer.version >= 2) {
  12952. var pathLen = buffer.readInt();
  12953. if (pathLen > 0) {
  12954. item.tweenConfig.path = new fgui.GPath();
  12955. var pts = new Array();
  12956. for (var j = 0; j < pathLen; j++) {
  12957. var curveType = buffer.readByte();
  12958. switch (curveType) {
  12959. case fgui.CurveType.Bezier:
  12960. pts.push(fgui.GPathPoint.newBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  12961. break;
  12962. case fgui.CurveType.CubicBezier:
  12963. pts.push(fgui.GPathPoint.newCubicBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  12964. break;
  12965. default:
  12966. pts.push(fgui.GPathPoint.newPoint(buffer.readFloat(), buffer.readFloat(), curveType));
  12967. break;
  12968. }
  12969. }
  12970. item.tweenConfig.path.create(pts);
  12971. }
  12972. }
  12973. }
  12974. else {
  12975. if (item.time > this._totalDuration)
  12976. this._totalDuration = item.time;
  12977. buffer.seek(curPos, 2);
  12978. this.decodeValue(item, buffer, item.value);
  12979. }
  12980. buffer.position = curPos + dataLen;
  12981. }
  12982. }
  12983. decodeValue(item, buffer, value) {
  12984. switch (item.type) {
  12985. case ActionType.XY:
  12986. case ActionType.Size:
  12987. case ActionType.Pivot:
  12988. case ActionType.Skew:
  12989. value.b1 = buffer.readBool();
  12990. value.b2 = buffer.readBool();
  12991. value.f1 = buffer.readFloat();
  12992. value.f2 = buffer.readFloat();
  12993. if (buffer.version >= 2 && item.type == ActionType.XY)
  12994. value.b3 = buffer.readBool();
  12995. break;
  12996. case ActionType.Alpha:
  12997. case ActionType.Rotation:
  12998. value.f1 = buffer.readFloat();
  12999. break;
  13000. case ActionType.Scale:
  13001. value.f1 = buffer.readFloat();
  13002. value.f2 = buffer.readFloat();
  13003. break;
  13004. case ActionType.Color:
  13005. let color = buffer.readColor();
  13006. value.f1 = (color.getR() << 16) + (color.getG() << 8) + color.getB();
  13007. break;
  13008. case ActionType.Animation:
  13009. value.playing = buffer.readBool();
  13010. value.frame = buffer.readInt();
  13011. break;
  13012. case ActionType.Visible:
  13013. value.visible = buffer.readBool();
  13014. break;
  13015. case ActionType.Sound:
  13016. value.sound = buffer.readS();
  13017. value.volume = buffer.readFloat();
  13018. break;
  13019. case ActionType.Transition:
  13020. value.transName = buffer.readS();
  13021. value.playTimes = buffer.readInt();
  13022. break;
  13023. case ActionType.Shake:
  13024. value.amplitude = buffer.readFloat();
  13025. value.duration = buffer.readFloat();
  13026. break;
  13027. case ActionType.ColorFilter:
  13028. value.f1 = buffer.readFloat();
  13029. value.f2 = buffer.readFloat();
  13030. value.f3 = buffer.readFloat();
  13031. value.f4 = buffer.readFloat();
  13032. break;
  13033. case ActionType.Text:
  13034. case ActionType.Icon:
  13035. value.text = buffer.readS();
  13036. break;
  13037. }
  13038. }
  13039. }
  13040. fgui.Transition = Transition;
  13041. const OPTION_IGNORE_DISPLAY_CONTROLLER = 1;
  13042. const OPTION_AUTO_STOP_DISABLED = 2;
  13043. const OPTION_AUTO_STOP_AT_END = 4;
  13044. let ActionType;
  13045. (function (ActionType) {
  13046. ActionType[ActionType["XY"] = 0] = "XY";
  13047. ActionType[ActionType["Size"] = 1] = "Size";
  13048. ActionType[ActionType["Scale"] = 2] = "Scale";
  13049. ActionType[ActionType["Pivot"] = 3] = "Pivot";
  13050. ActionType[ActionType["Alpha"] = 4] = "Alpha";
  13051. ActionType[ActionType["Rotation"] = 5] = "Rotation";
  13052. ActionType[ActionType["Color"] = 6] = "Color";
  13053. ActionType[ActionType["Animation"] = 7] = "Animation";
  13054. ActionType[ActionType["Visible"] = 8] = "Visible";
  13055. ActionType[ActionType["Sound"] = 9] = "Sound";
  13056. ActionType[ActionType["Transition"] = 10] = "Transition";
  13057. ActionType[ActionType["Shake"] = 11] = "Shake";
  13058. ActionType[ActionType["ColorFilter"] = 12] = "ColorFilter";
  13059. ActionType[ActionType["Skew"] = 13] = "Skew";
  13060. ActionType[ActionType["Text"] = 14] = "Text";
  13061. ActionType[ActionType["Icon"] = 15] = "Icon";
  13062. ActionType[ActionType["Unknown"] = 16] = "Unknown";
  13063. })(ActionType || (ActionType = {}));
  13064. class Item {
  13065. constructor(type) {
  13066. this.type = type;
  13067. this.value = {};
  13068. this.displayLockToken = 0;
  13069. }
  13070. }
  13071. class TweenConfig {
  13072. constructor() {
  13073. this.easeType = fgui.EaseType.QuadOut;
  13074. this.startValue = { b1: true, b2: true };
  13075. this.endValue = { b1: true, b2: true };
  13076. }
  13077. }
  13078. })(fgui || (fgui = {}));
  13079. (function (fgui) {
  13080. class TranslationHelper {
  13081. static loadFromXML(source) {
  13082. let strings = {};
  13083. TranslationHelper.strings = strings;
  13084. var xml = new cc["SAXParser"]().parse(source).documentElement;
  13085. var nodes = xml.childNodes;
  13086. var length1 = nodes.length;
  13087. for (var i1 = 0; i1 < length1; i1++) {
  13088. var cxml = nodes[i1];
  13089. if (cxml.tagName == "string") {
  13090. var key = cxml.getAttribute("name");
  13091. var text = cxml.childNodes.length > 0 ? cxml.firstChild.nodeValue : "";
  13092. var i = key.indexOf("-");
  13093. if (i == -1)
  13094. continue;
  13095. var key2 = key.substr(0, i);
  13096. var key3 = key.substr(i + 1);
  13097. var col = strings[key2];
  13098. if (!col) {
  13099. col = {};
  13100. strings[key2] = col;
  13101. }
  13102. col[key3] = text;
  13103. }
  13104. }
  13105. }
  13106. static translateComponent(item) {
  13107. if (TranslationHelper.strings == null)
  13108. return;
  13109. var compStrings = TranslationHelper.strings[item.owner.id + item.id];
  13110. if (compStrings == null)
  13111. return;
  13112. var elementId, value;
  13113. var buffer = item.rawData;
  13114. var nextPos;
  13115. var itemCount;
  13116. var i, j, k;
  13117. var dataLen;
  13118. var curPos;
  13119. var valueCnt;
  13120. var page;
  13121. buffer.seek(0, 2);
  13122. var childCount = buffer.readShort();
  13123. for (i = 0; i < childCount; i++) {
  13124. dataLen = buffer.readShort();
  13125. curPos = buffer.position;
  13126. buffer.seek(curPos, 0);
  13127. var baseType = buffer.readByte();
  13128. var type = baseType;
  13129. buffer.skip(4);
  13130. elementId = buffer.readS();
  13131. if (type == fgui.ObjectType.Component) {
  13132. if (buffer.seek(curPos, 6))
  13133. type = buffer.readByte();
  13134. }
  13135. buffer.seek(curPos, 1);
  13136. if ((value = compStrings[elementId + "-tips"]) != null)
  13137. buffer.writeS(value);
  13138. buffer.seek(curPos, 2);
  13139. var gearCnt = buffer.readShort();
  13140. for (j = 0; j < gearCnt; j++) {
  13141. nextPos = buffer.readShort();
  13142. nextPos += buffer.position;
  13143. if (buffer.readByte() == 6) {
  13144. buffer.skip(2);
  13145. valueCnt = buffer.readShort();
  13146. for (k = 0; k < valueCnt; k++) {
  13147. page = buffer.readS();
  13148. if (page != null) {
  13149. if ((value = compStrings[elementId + "-texts_" + k]) != null)
  13150. buffer.writeS(value);
  13151. else
  13152. buffer.skip(2);
  13153. }
  13154. }
  13155. if (buffer.readBool() && (value = compStrings[elementId + "-texts_def"]) != null)
  13156. buffer.writeS(value);
  13157. }
  13158. if (baseType == fgui.ObjectType.Component && buffer.version >= 2) {
  13159. buffer.seek(curPos, 4);
  13160. buffer.skip(2);
  13161. buffer.skip(4 * buffer.readShort());
  13162. var cpCount = buffer.readShort();
  13163. for (var k = 0; k < cpCount; k++) {
  13164. var target = buffer.readS();
  13165. var propertyId = buffer.readShort();
  13166. if (propertyId == 0 && (value = compStrings[elementId + "-cp-" + target]) != null)
  13167. buffer.writeS(value);
  13168. else
  13169. buffer.skip(2);
  13170. }
  13171. }
  13172. buffer.position = nextPos;
  13173. }
  13174. switch (type) {
  13175. case fgui.ObjectType.Text:
  13176. case fgui.ObjectType.RichText:
  13177. case fgui.ObjectType.InputText:
  13178. {
  13179. if ((value = compStrings[elementId]) != null) {
  13180. buffer.seek(curPos, 6);
  13181. buffer.writeS(value);
  13182. }
  13183. if ((value = compStrings[elementId + "-prompt"]) != null) {
  13184. buffer.seek(curPos, 4);
  13185. buffer.writeS(value);
  13186. }
  13187. break;
  13188. }
  13189. case fgui.ObjectType.List:
  13190. case fgui.ObjectType.Tree:
  13191. {
  13192. buffer.seek(curPos, 8);
  13193. buffer.skip(2);
  13194. itemCount = buffer.readShort();
  13195. for (j = 0; j < itemCount; j++) {
  13196. nextPos = buffer.readShort();
  13197. nextPos += buffer.position;
  13198. buffer.skip(2);
  13199. if (type == fgui.ObjectType.Tree)
  13200. buffer.skip(2);
  13201. if ((value = compStrings[elementId + "-" + j]) != null)
  13202. buffer.writeS(value);
  13203. else
  13204. buffer.skip(2);
  13205. if ((value = compStrings[elementId + "-" + j + "-0"]) != null)
  13206. buffer.writeS(value);
  13207. else
  13208. buffer.skip(2);
  13209. if (buffer.version >= 2) {
  13210. buffer.skip(6);
  13211. buffer.skip(buffer.readUshort() * 4);
  13212. var cpCount = buffer.readUshort();
  13213. for (var k = 0; k < cpCount; k++) {
  13214. var target = buffer.readS();
  13215. var propertyId = buffer.readUshort();
  13216. if (propertyId == 0 && (value = compStrings[elementId + "-" + j + "-" + target]) != null)
  13217. buffer.writeS(value);
  13218. else
  13219. buffer.skip(2);
  13220. }
  13221. }
  13222. buffer.position = nextPos;
  13223. }
  13224. break;
  13225. }
  13226. case fgui.ObjectType.Label:
  13227. {
  13228. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  13229. if ((value = compStrings[elementId]) != null)
  13230. buffer.writeS(value);
  13231. else
  13232. buffer.skip(2);
  13233. buffer.skip(2);
  13234. if (buffer.readBool())
  13235. buffer.skip(4);
  13236. buffer.skip(4);
  13237. if (buffer.readBool() && (value = compStrings[elementId + "-prompt"]) != null)
  13238. buffer.writeS(value);
  13239. }
  13240. break;
  13241. }
  13242. case fgui.ObjectType.Button:
  13243. {
  13244. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  13245. if ((value = compStrings[elementId]) != null)
  13246. buffer.writeS(value);
  13247. else
  13248. buffer.skip(2);
  13249. if ((value = compStrings[elementId + "-0"]) != null)
  13250. buffer.writeS(value);
  13251. }
  13252. break;
  13253. }
  13254. case fgui.ObjectType.ComboBox:
  13255. {
  13256. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  13257. itemCount = buffer.readShort();
  13258. for (j = 0; j < itemCount; j++) {
  13259. nextPos = buffer.readShort();
  13260. nextPos += buffer.position;
  13261. if ((value = compStrings[elementId + "-" + j]) != null)
  13262. buffer.writeS(value);
  13263. buffer.position = nextPos;
  13264. }
  13265. if ((value = compStrings[elementId]) != null)
  13266. buffer.writeS(value);
  13267. }
  13268. break;
  13269. }
  13270. }
  13271. buffer.position = curPos + dataLen;
  13272. }
  13273. }
  13274. }
  13275. fgui.TranslationHelper = TranslationHelper;
  13276. })(fgui || (fgui = {}));
  13277. (function (fgui) {
  13278. class UIConfig {
  13279. constructor() {
  13280. }
  13281. }
  13282. UIConfig.defaultFont = "Arial";
  13283. UIConfig.modalLayerColor = new cc.Color(0x33, 0x33, 0x33, 0x33);
  13284. UIConfig.buttonSoundVolumeScale = 1;
  13285. UIConfig.defaultScrollStep = 25;
  13286. UIConfig.defaultScrollDecelerationRate = 0.967;
  13287. UIConfig.defaultScrollBarDisplay = fgui.ScrollBarDisplayType.Visible;
  13288. UIConfig.defaultScrollTouchEffect = true;
  13289. UIConfig.defaultScrollBounceEffect = true;
  13290. UIConfig.defaultComboBoxVisibleItemCount = 10;
  13291. UIConfig.touchScrollSensitivity = 20;
  13292. UIConfig.touchDragSensitivity = 10;
  13293. UIConfig.clickDragSensitivity = 2;
  13294. UIConfig.bringWindowToFrontOnClick = true;
  13295. UIConfig.frameTimeForAsyncUIConstruction = 0.002;
  13296. UIConfig.linkUnderline = true;
  13297. UIConfig.defaultUIGroup = "UI";
  13298. fgui.UIConfig = UIConfig;
  13299. function addLoadHandler(ext) {
  13300. }
  13301. fgui.addLoadHandler = addLoadHandler;
  13302. ;
  13303. let _fontRegistry = {};
  13304. function registerFont(name, font) {
  13305. if (font instanceof cc.Font)
  13306. _fontRegistry[name] = font;
  13307. else
  13308. _fontRegistry[name] = cc.loader.getRes(name, cc.Font);
  13309. }
  13310. fgui.registerFont = registerFont;
  13311. ;
  13312. function getFontByName(name) {
  13313. return _fontRegistry[name];
  13314. }
  13315. fgui.getFontByName = getFontByName;
  13316. })(fgui || (fgui = {}));
  13317. (function (fgui) {
  13318. class UIExternalResManager {
  13319. static refCountRes(asset) {
  13320. }
  13321. static defCountRes(url, asset) {
  13322. if (asset) {
  13323. UIExternalResManager._mapResLastUseTime.set(url, cc.sys.now());
  13324. }
  13325. }
  13326. }
  13327. UIExternalResManager._destroyResTime = 2 * 60 * 1000;
  13328. UIExternalResManager._mapResLastUseTime = new Map();
  13329. fgui.UIExternalResManager = UIExternalResManager;
  13330. })(fgui || (fgui = {}));
  13331. (function (fgui) {
  13332. class UIObjectFactory {
  13333. constructor() {
  13334. }
  13335. static setExtension(url, type) {
  13336. if (url == null)
  13337. throw new Error("Invaild url: " + url);
  13338. var pi = fgui.UIPackage.getItemByURL(url);
  13339. if (pi)
  13340. pi.extensionType = type;
  13341. UIObjectFactory.extensions[url] = type;
  13342. }
  13343. static setLoaderExtension(type) {
  13344. UIObjectFactory.loaderType = type;
  13345. }
  13346. static resolveExtension(pi) {
  13347. var extensionType = UIObjectFactory.extensions["ui://" + pi.owner.id + pi.id];
  13348. if (!extensionType)
  13349. extensionType = UIObjectFactory.extensions["ui://" + pi.owner.name + "/" + pi.name];
  13350. if (extensionType)
  13351. pi.extensionType = extensionType;
  13352. }
  13353. static newObject(type, userClass) {
  13354. var obj;
  13355. UIObjectFactory.counter++;
  13356. if (typeof type === 'number') {
  13357. switch (type) {
  13358. case fgui.ObjectType.Image:
  13359. return new fgui.GImage();
  13360. case fgui.ObjectType.MovieClip:
  13361. return new fgui.GMovieClip();
  13362. case fgui.ObjectType.Component:
  13363. return new fgui.GComponent();
  13364. case fgui.ObjectType.Text:
  13365. return new fgui.GTextField();
  13366. case fgui.ObjectType.RichText:
  13367. return new fgui.GRichTextField();
  13368. case fgui.ObjectType.InputText:
  13369. return new fgui.GTextInput();
  13370. case fgui.ObjectType.Group:
  13371. return new fgui.GGroup();
  13372. case fgui.ObjectType.List:
  13373. return new fgui.GList();
  13374. case fgui.ObjectType.Graph:
  13375. return new fgui.GGraph();
  13376. case fgui.ObjectType.Loader:
  13377. if (UIObjectFactory.loaderType)
  13378. return new UIObjectFactory.loaderType();
  13379. else
  13380. return new fgui.GLoader();
  13381. case fgui.ObjectType.Button:
  13382. return new fgui.GButton();
  13383. case fgui.ObjectType.Label:
  13384. return new fgui.GLabel();
  13385. case fgui.ObjectType.ProgressBar:
  13386. return new fgui.GProgressBar();
  13387. case fgui.ObjectType.Slider:
  13388. return new fgui.GSlider();
  13389. case fgui.ObjectType.ScrollBar:
  13390. return new fgui.GScrollBar();
  13391. case fgui.ObjectType.ComboBox:
  13392. return new fgui.GComboBox();
  13393. case fgui.ObjectType.Tree:
  13394. return new fgui.GTree();
  13395. case fgui.ObjectType.Loader3D:
  13396. return new fgui.GLoader3D();
  13397. default:
  13398. return null;
  13399. }
  13400. }
  13401. else {
  13402. if (type.type == fgui.PackageItemType.Component) {
  13403. if (userClass)
  13404. obj = new userClass();
  13405. else if (type.extensionType)
  13406. obj = new type.extensionType();
  13407. else
  13408. obj = UIObjectFactory.newObject(type.objectType);
  13409. }
  13410. else
  13411. obj = UIObjectFactory.newObject(type.objectType);
  13412. if (obj)
  13413. obj.packageItem = type;
  13414. }
  13415. return obj;
  13416. }
  13417. }
  13418. UIObjectFactory.counter = 0;
  13419. UIObjectFactory.extensions = {};
  13420. fgui.UIObjectFactory = UIObjectFactory;
  13421. })(fgui || (fgui = {}));
  13422. (function (fgui) {
  13423. class UIPackage {
  13424. constructor() {
  13425. this._items = [];
  13426. this._itemsById = {};
  13427. this._itemsByName = {};
  13428. this._sprites = {};
  13429. this._dependencies = [];
  13430. this._branches = [];
  13431. this._branchIndex = -1;
  13432. this._asyncOperation = new fgui.AsyncOperation();
  13433. }
  13434. static get branch() {
  13435. return UIPackage._branch;
  13436. }
  13437. static set branch(value) {
  13438. UIPackage._branch = value;
  13439. for (var pkgId in UIPackage._instById) {
  13440. var pkg = UIPackage._instById[pkgId];
  13441. if (pkg._branches) {
  13442. pkg._branchIndex = pkg._branches.indexOf(value);
  13443. }
  13444. }
  13445. }
  13446. static getVar(key) {
  13447. return UIPackage._vars[key];
  13448. }
  13449. static setVar(key, value) {
  13450. UIPackage._vars[key] = value;
  13451. }
  13452. static getById(id) {
  13453. return UIPackage._instById[id];
  13454. }
  13455. static getByName(name) {
  13456. return UIPackage._instByName[name];
  13457. }
  13458. static addPackage(path) {
  13459. let pkg = UIPackage._instById[path];
  13460. if (pkg)
  13461. return pkg;
  13462. let asset = cc.resources.get(path, cc.BufferAsset);
  13463. if (!asset)
  13464. throw "Resource '" + path + "' not ready";
  13465. if (!asset._buffer)
  13466. throw 'Missing asset data.';
  13467. pkg = new UIPackage();
  13468. pkg._bundle = cc.resources;
  13469. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  13470. UIPackage._instById[pkg.id] = pkg;
  13471. UIPackage._instByName[pkg.name] = pkg;
  13472. UIPackage._instById[pkg._path] = pkg;
  13473. return pkg;
  13474. }
  13475. static loadPackage(...args) {
  13476. let path;
  13477. let onProgress;
  13478. let onComplete;
  13479. let bundle;
  13480. if (args[0] instanceof cc.AssetManager.Bundle) {
  13481. bundle = args[0];
  13482. path = args[1];
  13483. if (args.length > 3) {
  13484. onProgress = args[2];
  13485. onComplete = args[3];
  13486. }
  13487. else
  13488. onComplete = args[2];
  13489. }
  13490. else {
  13491. path = args[0];
  13492. if (args.length > 2) {
  13493. onProgress = args[1];
  13494. onComplete = args[2];
  13495. }
  13496. else
  13497. onComplete = args[1];
  13498. }
  13499. bundle = bundle || cc.resources;
  13500. bundle.load(path, cc.BufferAsset, onProgress, function (err, asset) {
  13501. if (err) {
  13502. if (onComplete != null)
  13503. onComplete(err, null);
  13504. return;
  13505. }
  13506. let pkg = new UIPackage();
  13507. pkg._bundle = bundle;
  13508. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  13509. let cnt = pkg._items.length;
  13510. let urls = [];
  13511. let types = [];
  13512. for (var i = 0; i < cnt; i++) {
  13513. var pi = pkg._items[i];
  13514. if (pi.type == fgui.PackageItemType.Sound) {
  13515. let assetType = ItemTypeToAssetType[pi.type];
  13516. urls.push(pi.file);
  13517. types.push(assetType);
  13518. }
  13519. if (pi.type == fgui.PackageItemType.Atlas) {
  13520. pkg.getItemAssetAsync(pi, (err, item) => { });
  13521. }
  13522. }
  13523. let total = urls.length;
  13524. let lastErr;
  13525. let taskComplete = (err) => {
  13526. total--;
  13527. if (err)
  13528. lastErr = err;
  13529. if (total <= 0) {
  13530. UIPackage._instById[pkg.id] = pkg;
  13531. UIPackage._instByName[pkg.name] = pkg;
  13532. if (pkg._path)
  13533. UIPackage._instByName[pkg._path] = pkg;
  13534. if (onComplete != null)
  13535. onComplete(lastErr, pkg);
  13536. }
  13537. };
  13538. if (total > 0) {
  13539. urls.forEach((url, index) => {
  13540. bundle.load(url, types[index], onProgress, taskComplete);
  13541. });
  13542. }
  13543. else
  13544. taskComplete();
  13545. });
  13546. }
  13547. static removePackage(packageIdOrName) {
  13548. var pkg = UIPackage._instById[packageIdOrName];
  13549. if (!pkg)
  13550. pkg = UIPackage._instByName[packageIdOrName];
  13551. if (!pkg)
  13552. throw 'No package found: ' + packageIdOrName;
  13553. pkg.dispose();
  13554. delete UIPackage._instById[pkg.id];
  13555. delete UIPackage._instByName[pkg.name];
  13556. if (pkg._path)
  13557. delete UIPackage._instById[pkg._path];
  13558. }
  13559. static createObject(pkgName, resName, userClass) {
  13560. var pkg = UIPackage.getByName(pkgName);
  13561. if (pkg)
  13562. return pkg.createObject(resName, userClass);
  13563. else
  13564. return null;
  13565. }
  13566. static createObjectFromURL(url, userClass) {
  13567. var pi = UIPackage.getItemByURL(url);
  13568. if (pi)
  13569. return pi.owner.internalCreateObject(pi, userClass);
  13570. else
  13571. return null;
  13572. }
  13573. static getItemURL(pkgName, resName) {
  13574. var pkg = UIPackage.getByName(pkgName);
  13575. if (!pkg)
  13576. return null;
  13577. var pi = pkg._itemsByName[resName];
  13578. if (!pi)
  13579. return null;
  13580. return 'ui://' + pkg.id + pi.id;
  13581. }
  13582. static getItemByURL(url) {
  13583. var pos1 = url.indexOf('//');
  13584. if (pos1 == -1)
  13585. return null;
  13586. var pos2 = url.indexOf('/', pos1 + 2);
  13587. if (pos2 == -1) {
  13588. if (url.length > 13) {
  13589. var pkgId = url.substr(5, 8);
  13590. var pkg = UIPackage.getById(pkgId);
  13591. if (pkg != null) {
  13592. var srcId = url.substr(13);
  13593. return pkg.getItemById(srcId);
  13594. }
  13595. }
  13596. }
  13597. else {
  13598. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  13599. pkg = UIPackage.getByName(pkgName);
  13600. if (pkg != null) {
  13601. var srcName = url.substr(pos2 + 1);
  13602. return pkg.getItemByName(srcName);
  13603. }
  13604. }
  13605. return null;
  13606. }
  13607. static normalizeURL(url) {
  13608. if (url == null)
  13609. return null;
  13610. var pos1 = url.indexOf('//');
  13611. if (pos1 == -1)
  13612. return null;
  13613. var pos2 = url.indexOf('/', pos1 + 2);
  13614. if (pos2 == -1)
  13615. return url;
  13616. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  13617. var srcName = url.substr(pos2 + 1);
  13618. return UIPackage.getItemURL(pkgName, srcName);
  13619. }
  13620. static setStringsSource(source) {
  13621. fgui.TranslationHelper.loadFromXML(source);
  13622. }
  13623. loadPackage(buffer, path) {
  13624. if (buffer.readUint() != 0x46475549)
  13625. throw "FairyGUI: old package format found in '" + path + "'";
  13626. this._path = path;
  13627. buffer.version = buffer.readInt();
  13628. var ver2 = buffer.version >= 2;
  13629. var compressed = buffer.readBool();
  13630. this._id = buffer.readString();
  13631. this._name = buffer.readString();
  13632. buffer.skip(20);
  13633. var indexTablePos = buffer.position;
  13634. var cnt;
  13635. var i;
  13636. var nextPos;
  13637. var str;
  13638. var branchIncluded;
  13639. buffer.seek(indexTablePos, 4);
  13640. cnt = buffer.readInt();
  13641. var stringTable = new Array(cnt);
  13642. buffer.stringTable = stringTable;
  13643. for (i = 0; i < cnt; i++)
  13644. stringTable[i] = buffer.readString();
  13645. if (buffer.seek(indexTablePos, 5)) {
  13646. cnt = buffer.readInt();
  13647. for (i = 0; i < cnt; i++) {
  13648. let index = buffer.readUshort();
  13649. let len = buffer.readInt();
  13650. stringTable[index] = buffer.readString(len);
  13651. }
  13652. }
  13653. buffer.seek(indexTablePos, 0);
  13654. cnt = buffer.readShort();
  13655. for (i = 0; i < cnt; i++)
  13656. this._dependencies.push({ id: buffer.readS(), name: buffer.readS() });
  13657. if (ver2) {
  13658. cnt = buffer.readShort();
  13659. if (cnt > 0) {
  13660. this._branches = buffer.readSArray(cnt);
  13661. if (UIPackage._branch)
  13662. this._branchIndex = this._branches.indexOf(UIPackage._branch);
  13663. }
  13664. branchIncluded = cnt > 0;
  13665. }
  13666. buffer.seek(indexTablePos, 1);
  13667. var pi;
  13668. let pos = path.lastIndexOf('/');
  13669. let shortPath = pos == -1 ? '' : path.substr(0, pos + 1);
  13670. path = path + '_';
  13671. cnt = buffer.readShort();
  13672. for (i = 0; i < cnt; i++) {
  13673. nextPos = buffer.readInt();
  13674. nextPos += buffer.position;
  13675. pi = new fgui.PackageItem();
  13676. pi.owner = this;
  13677. pi.type = buffer.readByte();
  13678. pi.id = buffer.readS();
  13679. pi.name = buffer.readS();
  13680. buffer.readS();
  13681. pi.file = buffer.readS();
  13682. buffer.readBool();
  13683. pi.width = buffer.readInt();
  13684. pi.height = buffer.readInt();
  13685. switch (pi.type) {
  13686. case fgui.PackageItemType.Image: {
  13687. pi.objectType = fgui.ObjectType.Image;
  13688. var scaleOption = buffer.readByte();
  13689. if (scaleOption == 1) {
  13690. pi.scale9Grid = new cc.Rect();
  13691. pi.scale9Grid.x = buffer.readInt();
  13692. pi.scale9Grid.y = buffer.readInt();
  13693. pi.scale9Grid.width = buffer.readInt();
  13694. pi.scale9Grid.height = buffer.readInt();
  13695. pi.tileGridIndice = buffer.readInt();
  13696. }
  13697. else if (scaleOption == 2)
  13698. pi.scaleByTile = true;
  13699. pi.smoothing = buffer.readBool();
  13700. break;
  13701. }
  13702. case fgui.PackageItemType.MovieClip: {
  13703. pi.smoothing = buffer.readBool();
  13704. pi.objectType = fgui.ObjectType.MovieClip;
  13705. pi.rawData = buffer.readBuffer();
  13706. break;
  13707. }
  13708. case fgui.PackageItemType.Font: {
  13709. pi.rawData = buffer.readBuffer();
  13710. break;
  13711. }
  13712. case fgui.PackageItemType.Component: {
  13713. var extension = buffer.readByte();
  13714. if (extension > 0)
  13715. pi.objectType = extension;
  13716. else
  13717. pi.objectType = fgui.ObjectType.Component;
  13718. pi.rawData = buffer.readBuffer();
  13719. fgui.UIObjectFactory.resolveExtension(pi);
  13720. break;
  13721. }
  13722. case fgui.PackageItemType.Atlas:
  13723. case fgui.PackageItemType.Sound:
  13724. case fgui.PackageItemType.Misc: {
  13725. pi.file = path + cc.path.mainFileName(pi.file);
  13726. break;
  13727. }
  13728. case fgui.PackageItemType.Spine:
  13729. case fgui.PackageItemType.DragonBones: {
  13730. pi.file = shortPath + cc.path.mainFileName(pi.file);
  13731. pi.skeletonAnchor = new cc.Vec2();
  13732. pi.skeletonAnchor.x = buffer.readFloat();
  13733. pi.skeletonAnchor.y = buffer.readFloat();
  13734. break;
  13735. }
  13736. }
  13737. if (ver2) {
  13738. str = buffer.readS();
  13739. if (str)
  13740. pi.name = str + '/' + pi.name;
  13741. var branchCnt = buffer.readUbyte();
  13742. if (branchCnt > 0) {
  13743. if (branchIncluded)
  13744. pi.branches = buffer.readSArray(branchCnt);
  13745. else
  13746. this._itemsById[buffer.readS()] = pi;
  13747. }
  13748. var highResCnt = buffer.readUbyte();
  13749. if (highResCnt > 0)
  13750. pi.highResolution = buffer.readSArray(highResCnt);
  13751. }
  13752. this._items.push(pi);
  13753. this._itemsById[pi.id] = pi;
  13754. if (pi.name != null)
  13755. this._itemsByName[pi.name] = pi;
  13756. buffer.position = nextPos;
  13757. }
  13758. buffer.seek(indexTablePos, 2);
  13759. cnt = buffer.readShort();
  13760. for (i = 0; i < cnt; i++) {
  13761. nextPos = buffer.readShort();
  13762. nextPos += buffer.position;
  13763. var itemId = buffer.readS();
  13764. pi = this._itemsById[buffer.readS()];
  13765. let rect = new cc.Rect();
  13766. rect.x = buffer.readInt();
  13767. rect.y = buffer.readInt();
  13768. rect.width = buffer.readInt();
  13769. rect.height = buffer.readInt();
  13770. var sprite = { atlas: pi, rect: rect, offset: new cc.Vec2(), originalSize: new cc.Size(0, 0) };
  13771. sprite.rotated = buffer.readBool();
  13772. if (ver2 && buffer.readBool()) {
  13773. sprite.offset.x = buffer.readInt();
  13774. sprite.offset.y = buffer.readInt();
  13775. sprite.originalSize.width = buffer.readInt();
  13776. sprite.originalSize.height = buffer.readInt();
  13777. }
  13778. else {
  13779. sprite.originalSize.width = sprite.rect.width;
  13780. sprite.originalSize.height = sprite.rect.height;
  13781. }
  13782. this._sprites[itemId] = sprite;
  13783. buffer.position = nextPos;
  13784. }
  13785. if (buffer.seek(indexTablePos, 3)) {
  13786. cnt = buffer.readShort();
  13787. for (i = 0; i < cnt; i++) {
  13788. nextPos = buffer.readInt();
  13789. nextPos += buffer.position;
  13790. pi = this._itemsById[buffer.readS()];
  13791. if (pi && pi.type == fgui.PackageItemType.Image)
  13792. pi.hitTestData = new fgui.PixelHitTestData(buffer);
  13793. buffer.position = nextPos;
  13794. }
  13795. }
  13796. }
  13797. dispose() {
  13798. var cnt = this._items.length;
  13799. for (var i = 0; i < cnt; i++) {
  13800. var pi = this._items[i];
  13801. if (pi.asset)
  13802. cc.assetManager.releaseAsset(pi.asset);
  13803. }
  13804. }
  13805. get id() {
  13806. return this._id;
  13807. }
  13808. get name() {
  13809. return this._name;
  13810. }
  13811. get path() {
  13812. return this._path;
  13813. }
  13814. get dependencies() {
  13815. return this._dependencies;
  13816. }
  13817. createObject(resName, userClass) {
  13818. var pi = this._itemsByName[resName];
  13819. if (pi)
  13820. return this.internalCreateObject(pi, userClass);
  13821. else
  13822. return null;
  13823. }
  13824. internalCreateObject(item, userClass) {
  13825. var g = fgui.UIObjectFactory.newObject(item, userClass);
  13826. if (g == null)
  13827. return null;
  13828. UIPackage._constructing++;
  13829. g.constructFromResource();
  13830. UIPackage._constructing--;
  13831. return g;
  13832. }
  13833. getItemById(itemId) {
  13834. return this._itemsById[itemId];
  13835. }
  13836. getItemByName(resName) {
  13837. return this._itemsByName[resName];
  13838. }
  13839. getItemAssetByName(resName) {
  13840. var pi = this._itemsByName[resName];
  13841. if (pi == null) {
  13842. throw 'Resource not found -' + resName;
  13843. }
  13844. return this.getItemAsset(pi);
  13845. }
  13846. getItemAssetSync(item) {
  13847. switch (item.type) {
  13848. case fgui.PackageItemType.Image:
  13849. if (!item.decoded) {
  13850. item.decoded = true;
  13851. var sprite = this._sprites[item.id];
  13852. if (sprite) {
  13853. let atlasTexture = this.getItemAsset(sprite.atlas);
  13854. if (atlasTexture) {
  13855. let 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);
  13856. if (item.scale9Grid) {
  13857. sf.insetLeft = item.scale9Grid.x;
  13858. sf.insetTop = item.scale9Grid.y;
  13859. sf.insetRight = item.width - item.scale9Grid.xMax;
  13860. sf.insetBottom = item.height - item.scale9Grid.yMax;
  13861. }
  13862. item.asset = sf;
  13863. }
  13864. }
  13865. }
  13866. break;
  13867. case fgui.PackageItemType.Atlas:
  13868. case fgui.PackageItemType.Sound:
  13869. if (!item.decoded) {
  13870. item.decoded = true;
  13871. item.asset = this._bundle.get(item.file, ItemTypeToAssetType[item.type]);
  13872. if (!item.asset)
  13873. console.log("Resource '" + item.file + "' not found");
  13874. }
  13875. break;
  13876. case fgui.PackageItemType.Font:
  13877. if (!item.decoded) {
  13878. item.decoded = true;
  13879. this.loadFont(item);
  13880. }
  13881. break;
  13882. case fgui.PackageItemType.MovieClip:
  13883. if (!item.decoded) {
  13884. item.decoded = true;
  13885. this.loadMovieClip(item);
  13886. }
  13887. break;
  13888. default:
  13889. break;
  13890. }
  13891. return item.asset;
  13892. }
  13893. getItemAsset(item) {
  13894. switch (item.type) {
  13895. case fgui.PackageItemType.Sound:
  13896. if (!item.decoded) {
  13897. item.decoded = true;
  13898. item.asset = this._bundle.get(item.file, ItemTypeToAssetType[item.type]);
  13899. if (!item.asset)
  13900. console.log("Resource '" + item.file + "' not found");
  13901. }
  13902. break;
  13903. case fgui.PackageItemType.Font:
  13904. if (!item.decoded) {
  13905. item.decoded = true;
  13906. this.loadFont(item);
  13907. }
  13908. break;
  13909. case fgui.PackageItemType.MovieClip:
  13910. if (!item.decoded) {
  13911. item.decoded = true;
  13912. this.loadMovieClip(item);
  13913. }
  13914. break;
  13915. default:
  13916. break;
  13917. }
  13918. return item.asset;
  13919. }
  13920. getItemAssetAsync(item, onComplete) {
  13921. if (item.decoded) {
  13922. onComplete(null, item);
  13923. return;
  13924. }
  13925. if (item.loading) {
  13926. item.loading.push(onComplete);
  13927. return;
  13928. }
  13929. switch (item.type) {
  13930. case fgui.PackageItemType.Spine:
  13931. item.loading = [onComplete];
  13932. this.loadSpine(item);
  13933. break;
  13934. case fgui.PackageItemType.DragonBones:
  13935. item.loading = [onComplete];
  13936. this.loadDragonBones(item);
  13937. break;
  13938. case fgui.PackageItemType.Atlas:
  13939. item.loading = [onComplete];
  13940. this.loadAtlas(item);
  13941. break;
  13942. case fgui.PackageItemType.Image:
  13943. item.loading = [onComplete];
  13944. this.loadImage(item);
  13945. break;
  13946. default:
  13947. this.getItemAsset(item);
  13948. onComplete(null, item);
  13949. break;
  13950. }
  13951. }
  13952. loadAllAssets() {
  13953. var cnt = this._items.length;
  13954. for (var i = 0; i < cnt; i++) {
  13955. var pi = this._items[i];
  13956. this.getItemAsset(pi);
  13957. }
  13958. }
  13959. loadMovieClip(item) {
  13960. var buffer = item.rawData;
  13961. buffer.seek(0, 0);
  13962. item.interval = buffer.readInt() / 1000;
  13963. item.swing = buffer.readBool();
  13964. item.repeatDelay = buffer.readInt() / 1000;
  13965. buffer.seek(0, 1);
  13966. var frameCount = buffer.readShort();
  13967. item.frames = Array(frameCount);
  13968. var spriteId;
  13969. var sprite;
  13970. for (var i = 0; i < frameCount; i++) {
  13971. var nextPos = buffer.readShort();
  13972. nextPos += buffer.position;
  13973. let rect = new cc.Rect();
  13974. rect.x = buffer.readInt();
  13975. rect.y = buffer.readInt();
  13976. rect.width = buffer.readInt();
  13977. rect.height = buffer.readInt();
  13978. let addDelay = buffer.readInt() / 1000;
  13979. let frame = { rect: rect, addDelay: addDelay };
  13980. spriteId = buffer.readS();
  13981. if (spriteId != null && (sprite = this._sprites[spriteId]) != null) {
  13982. let atlasTexture = this.getItemAsset(sprite.atlas);
  13983. if (atlasTexture) {
  13984. let sx = item.width / frame.rect.width;
  13985. 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));
  13986. }
  13987. }
  13988. item.frames[i] = frame;
  13989. buffer.position = nextPos;
  13990. }
  13991. }
  13992. loadFont(item) {
  13993. var font = new cc.LabelAtlas();
  13994. item.asset = font;
  13995. font._fntConfig = {
  13996. commonHeight: 0,
  13997. fontSize: 0,
  13998. kerningDict: {},
  13999. fontDefDictionary: {},
  14000. };
  14001. let dict = font._fntConfig.fontDefDictionary;
  14002. var buffer = item.rawData;
  14003. buffer.seek(0, 0);
  14004. let ttf = buffer.readBool();
  14005. let canTint = buffer.readBool();
  14006. let resizable = buffer.readBool();
  14007. buffer.readBool();
  14008. let fontSize = buffer.readInt();
  14009. var xadvance = buffer.readInt();
  14010. var lineHeight = buffer.readInt();
  14011. let mainTexture;
  14012. var mainSprite = this._sprites[item.id];
  14013. if (mainSprite)
  14014. mainTexture = this.getItemAsset(mainSprite.atlas);
  14015. buffer.seek(0, 1);
  14016. var bg;
  14017. var cnt = buffer.readInt();
  14018. for (var i = 0; i < cnt; i++) {
  14019. var nextPos = buffer.readShort();
  14020. nextPos += buffer.position;
  14021. bg = {};
  14022. var ch = buffer.readUshort();
  14023. dict[ch] = bg;
  14024. let rect = new cc.Rect();
  14025. bg.rect = rect;
  14026. var img = buffer.readS();
  14027. rect.x = buffer.readInt();
  14028. rect.y = buffer.readInt();
  14029. bg.xOffset = buffer.readInt();
  14030. bg.yOffset = buffer.readInt();
  14031. rect.width = buffer.readInt();
  14032. rect.height = buffer.readInt();
  14033. bg.xAdvance = buffer.readInt();
  14034. bg.channel = buffer.readByte();
  14035. if (bg.channel == 1)
  14036. bg.channel = 3;
  14037. else if (bg.channel == 2)
  14038. bg.channel = 2;
  14039. else if (bg.channel == 3)
  14040. bg.channel = 1;
  14041. if (ttf) {
  14042. rect.x += mainSprite.rect.x;
  14043. rect.y += mainSprite.rect.y;
  14044. }
  14045. else {
  14046. let sprite = this._sprites[img];
  14047. if (sprite) {
  14048. rect.set(sprite.rect);
  14049. bg.xOffset += sprite.offset.x;
  14050. bg.yOffset += sprite.offset.y;
  14051. if (fontSize == 0)
  14052. fontSize = sprite.originalSize.height;
  14053. if (!mainTexture) {
  14054. sprite.atlas.load();
  14055. mainTexture = sprite.atlas.asset;
  14056. }
  14057. }
  14058. if (bg.xAdvance == 0) {
  14059. if (xadvance == 0)
  14060. bg.xAdvance = bg.xOffset + bg.rect.width;
  14061. else
  14062. bg.xAdvance = xadvance;
  14063. }
  14064. }
  14065. buffer.position = nextPos;
  14066. }
  14067. font.fontSize = fontSize;
  14068. font._fntConfig.fontSize = fontSize;
  14069. font._fntConfig.commonHeight = lineHeight == 0 ? fontSize : lineHeight;
  14070. font._fntConfig.resizable = resizable;
  14071. font._fntConfig.canTint = canTint;
  14072. let spriteFrame = new cc.SpriteFrame();
  14073. spriteFrame.setTexture(mainTexture);
  14074. font.spriteFrame = spriteFrame;
  14075. font.onLoad();
  14076. }
  14077. loadSpine(item) {
  14078. this._bundle.load(item.file, sp.SkeletonData, (err, asset) => {
  14079. item.decoded = true;
  14080. item.asset = asset;
  14081. let arr = item.loading;
  14082. delete item.loading;
  14083. arr.forEach((e) => e(err, item));
  14084. });
  14085. }
  14086. loadDragonBones(item) {
  14087. this._bundle.load(item.file, dragonBones.DragonBonesAsset, (err, asset) => {
  14088. if (err) {
  14089. item.decoded = true;
  14090. let arr = item.loading;
  14091. delete item.loading;
  14092. arr.forEach((e) => e(err, item));
  14093. return;
  14094. }
  14095. item.asset = asset;
  14096. let atlasFile = item.file.replace('_ske', '_tex');
  14097. let pos = atlasFile.lastIndexOf('.');
  14098. if (pos != -1)
  14099. atlasFile = atlasFile.substr(0, pos + 1) + 'json';
  14100. this._bundle.load(atlasFile, dragonBones.DragonBonesAtlasAsset, (err, asset) => {
  14101. item.decoded = true;
  14102. item.atlasAsset = asset;
  14103. let arr = item.loading;
  14104. delete item.loading;
  14105. arr.forEach((e) => e(err, item));
  14106. });
  14107. });
  14108. }
  14109. loadAtlas(item) {
  14110. this._bundle.load(item.file, cc.Texture2D, (err, asset) => {
  14111. if (err) {
  14112. item.decoded = true;
  14113. let arr = item.loading;
  14114. delete item.loading;
  14115. arr.forEach((e) => e(err, item));
  14116. return;
  14117. }
  14118. item.decoded = true;
  14119. item.asset = asset;
  14120. let arr = item.loading;
  14121. delete item.loading;
  14122. arr.forEach((e) => e(err, item));
  14123. });
  14124. }
  14125. loadImage(item) {
  14126. var sprite = this._sprites[item.id];
  14127. if (sprite) {
  14128. this.getItemAssetAsync(sprite.atlas, (err, altaItem) => {
  14129. if (err) {
  14130. item.decoded = true;
  14131. let arr = item.loading;
  14132. delete item.loading;
  14133. arr.forEach((e) => e(err, item));
  14134. return;
  14135. }
  14136. let atlasTexture = altaItem.asset;
  14137. let 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);
  14138. if (item.scale9Grid) {
  14139. sf.insetLeft = item.scale9Grid.x;
  14140. sf.insetTop = item.scale9Grid.y;
  14141. sf.insetRight = item.width - item.scale9Grid.xMax;
  14142. sf.insetBottom = item.height - item.scale9Grid.yMax;
  14143. }
  14144. item.asset = sf;
  14145. item.decoded = true;
  14146. let arr = item.loading;
  14147. delete item.loading;
  14148. arr.forEach((e) => e(err, item));
  14149. });
  14150. }
  14151. }
  14152. }
  14153. UIPackage._constructing = 0;
  14154. UIPackage._instById = {};
  14155. UIPackage._instByName = {};
  14156. UIPackage._branch = '';
  14157. UIPackage._vars = {};
  14158. fgui.UIPackage = UIPackage;
  14159. const ItemTypeToAssetType = {
  14160. [fgui.PackageItemType.Atlas]: cc.Texture2D,
  14161. [fgui.PackageItemType.Sound]: cc.AudioClip,
  14162. };
  14163. })(fgui || (fgui = {}));
  14164. (function (fgui) {
  14165. class Window extends fgui.GComponent {
  14166. constructor() {
  14167. super();
  14168. this._requestingCmd = 0;
  14169. this._uiSources = new Array();
  14170. this.bringToFontOnClick = fgui.UIConfig.bringWindowToFrontOnClick;
  14171. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this, true);
  14172. }
  14173. addUISource(source) {
  14174. this._uiSources.push(source);
  14175. }
  14176. set contentPane(val) {
  14177. if (this._contentPane != val) {
  14178. if (this._contentPane)
  14179. this.removeChild(this._contentPane);
  14180. this._contentPane = val;
  14181. if (this._contentPane) {
  14182. this.addChild(this._contentPane);
  14183. this.setSize(this._contentPane.width, this._contentPane.height);
  14184. this._contentPane.addRelation(this, fgui.RelationType.Size);
  14185. this._frame = (this._contentPane.getChild("frame"));
  14186. if (this._frame) {
  14187. this.closeButton = this._frame.getChild("closeButton");
  14188. this.dragArea = this._frame.getChild("dragArea");
  14189. this.contentArea = this._frame.getChild("contentArea");
  14190. }
  14191. }
  14192. }
  14193. }
  14194. get contentPane() {
  14195. return this._contentPane;
  14196. }
  14197. get frame() {
  14198. return this._frame;
  14199. }
  14200. get closeButton() {
  14201. return this._closeButton;
  14202. }
  14203. set closeButton(value) {
  14204. if (this._closeButton)
  14205. this._closeButton.offClick(this.closeEventHandler, this);
  14206. this._closeButton = value;
  14207. if (this._closeButton)
  14208. this._closeButton.onClick(this.closeEventHandler, this);
  14209. }
  14210. get dragArea() {
  14211. return this._dragArea;
  14212. }
  14213. set dragArea(value) {
  14214. if (this._dragArea != value) {
  14215. if (this._dragArea) {
  14216. this._dragArea.draggable = false;
  14217. this._dragArea.off(fgui.Event.DRAG_START, this.onDragStart_1, this);
  14218. }
  14219. this._dragArea = value;
  14220. if (this._dragArea) {
  14221. this._dragArea.draggable = true;
  14222. this._dragArea.on(fgui.Event.DRAG_START, this.onDragStart_1, this);
  14223. }
  14224. }
  14225. }
  14226. get contentArea() {
  14227. return this._contentArea;
  14228. }
  14229. set contentArea(value) {
  14230. this._contentArea = value;
  14231. }
  14232. show() {
  14233. fgui.GRoot.inst.showWindow(this);
  14234. }
  14235. showOn(root) {
  14236. root.showWindow(this);
  14237. }
  14238. hide() {
  14239. if (this.isShowing)
  14240. this.doHideAnimation();
  14241. }
  14242. hideImmediately() {
  14243. var r = (this.parent instanceof fgui.GRoot) ? this.parent : null;
  14244. if (!r)
  14245. r = fgui.GRoot.inst;
  14246. r.hideWindowImmediately(this);
  14247. }
  14248. centerOn(r, restraint) {
  14249. this.setPosition(Math.round((r.width - this.width) / 2), Math.round((r.height - this.height) / 2));
  14250. if (restraint) {
  14251. this.addRelation(r, fgui.RelationType.Center_Center);
  14252. this.addRelation(r, fgui.RelationType.Middle_Middle);
  14253. }
  14254. }
  14255. toggleStatus() {
  14256. if (this.isTop)
  14257. this.hide();
  14258. else
  14259. this.show();
  14260. }
  14261. get isShowing() {
  14262. return this.parent != null;
  14263. }
  14264. get isTop() {
  14265. return this.parent && this.parent.getChildIndex(this) == this.parent.numChildren - 1;
  14266. }
  14267. get modal() {
  14268. return this._modal;
  14269. }
  14270. set modal(val) {
  14271. this._modal = val;
  14272. }
  14273. bringToFront() {
  14274. this.root.bringToFront(this);
  14275. }
  14276. showModalWait(requestingCmd) {
  14277. if (requestingCmd != null)
  14278. this._requestingCmd = requestingCmd;
  14279. if (fgui.UIConfig.windowModalWaiting) {
  14280. if (!this._modalWaitPane)
  14281. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.windowModalWaiting);
  14282. this.layoutModalWaitPane();
  14283. this.addChild(this._modalWaitPane);
  14284. }
  14285. }
  14286. layoutModalWaitPane() {
  14287. if (this._contentArea) {
  14288. var pt = this._frame.localToGlobal();
  14289. pt = this.globalToLocal(pt.x, pt.y, pt);
  14290. this._modalWaitPane.setPosition(pt.x + this._contentArea.x, pt.y + this._contentArea.y);
  14291. this._modalWaitPane.setSize(this._contentArea.width, this._contentArea.height);
  14292. }
  14293. else
  14294. this._modalWaitPane.setSize(this.width, this.height);
  14295. }
  14296. closeModalWait(requestingCmd) {
  14297. if (requestingCmd != null) {
  14298. if (this._requestingCmd != requestingCmd)
  14299. return false;
  14300. }
  14301. this._requestingCmd = 0;
  14302. if (this._modalWaitPane && this._modalWaitPane.parent)
  14303. this.removeChild(this._modalWaitPane);
  14304. return true;
  14305. }
  14306. get modalWaiting() {
  14307. return this._modalWaitPane && this._modalWaitPane.parent != null;
  14308. }
  14309. init() {
  14310. if (this._inited || this._loading)
  14311. return;
  14312. if (this._uiSources.length > 0) {
  14313. this._loading = false;
  14314. var cnt = this._uiSources.length;
  14315. for (var i = 0; i < cnt; i++) {
  14316. var lib = this._uiSources[i];
  14317. if (!lib.loaded) {
  14318. lib.load(this.__uiLoadComplete, this);
  14319. this._loading = true;
  14320. }
  14321. }
  14322. if (!this._loading)
  14323. this._init();
  14324. }
  14325. else
  14326. this._init();
  14327. }
  14328. onInit() {
  14329. }
  14330. onShown() {
  14331. }
  14332. onHide() {
  14333. }
  14334. doShowAnimation() {
  14335. this.onShown();
  14336. }
  14337. doHideAnimation() {
  14338. this.hideImmediately();
  14339. }
  14340. __uiLoadComplete() {
  14341. var cnt = this._uiSources.length;
  14342. for (var i = 0; i < cnt; i++) {
  14343. var lib = this._uiSources[i];
  14344. if (!lib.loaded)
  14345. return;
  14346. }
  14347. this._loading = false;
  14348. this._init();
  14349. }
  14350. _init() {
  14351. this._inited = true;
  14352. this.onInit();
  14353. if (this.isShowing)
  14354. this.doShowAnimation();
  14355. }
  14356. dispose() {
  14357. if (this.parent)
  14358. this.hideImmediately();
  14359. super.dispose();
  14360. }
  14361. closeEventHandler(evt) {
  14362. this.hide();
  14363. }
  14364. onEnable() {
  14365. super.onEnable();
  14366. if (!this._inited)
  14367. this.init();
  14368. else
  14369. this.doShowAnimation();
  14370. }
  14371. onDisable() {
  14372. super.onDisable();
  14373. this.closeModalWait();
  14374. this.onHide();
  14375. }
  14376. onTouchBegin_1(evt) {
  14377. if (this.isShowing && this.bringToFontOnClick)
  14378. this.bringToFront();
  14379. }
  14380. onDragStart_1(evt) {
  14381. var original = fgui.GObject.cast(evt.currentTarget);
  14382. original.stopDrag();
  14383. this.startDrag(evt.touchId);
  14384. }
  14385. }
  14386. fgui.Window = Window;
  14387. })(fgui || (fgui = {}));
  14388. (function (fgui) {
  14389. class ControllerAction {
  14390. constructor() {
  14391. }
  14392. static createAction(type) {
  14393. switch (type) {
  14394. case 0:
  14395. return new fgui.PlayTransitionAction();
  14396. case 1:
  14397. return new fgui.ChangePageAction();
  14398. }
  14399. return null;
  14400. }
  14401. run(controller, prevPage, curPage) {
  14402. if ((this.fromPage == null || this.fromPage.length == 0 || this.fromPage.indexOf(prevPage) != -1)
  14403. && (this.toPage == null || this.toPage.length == 0 || this.toPage.indexOf(curPage) != -1))
  14404. this.enter(controller);
  14405. else
  14406. this.leave(controller);
  14407. }
  14408. enter(controller) {
  14409. }
  14410. leave(controller) {
  14411. }
  14412. setup(buffer) {
  14413. var cnt;
  14414. var i;
  14415. cnt = buffer.readShort();
  14416. this.fromPage = [];
  14417. for (i = 0; i < cnt; i++)
  14418. this.fromPage[i] = buffer.readS();
  14419. cnt = buffer.readShort();
  14420. this.toPage = [];
  14421. for (i = 0; i < cnt; i++)
  14422. this.toPage[i] = buffer.readS();
  14423. }
  14424. }
  14425. fgui.ControllerAction = ControllerAction;
  14426. })(fgui || (fgui = {}));
  14427. (function (fgui) {
  14428. class ChangePageAction extends fgui.ControllerAction {
  14429. constructor() {
  14430. super();
  14431. }
  14432. enter(controller) {
  14433. if (!this.controllerName)
  14434. return;
  14435. var gcom;
  14436. if (this.objectId) {
  14437. var obj = controller.parent.getChildById(this.objectId);
  14438. if (obj instanceof fgui.GComponent)
  14439. gcom = obj;
  14440. else
  14441. return;
  14442. }
  14443. else
  14444. gcom = controller.parent;
  14445. if (gcom) {
  14446. var cc = gcom.getController(this.controllerName);
  14447. if (cc && cc != controller && !cc.changing) {
  14448. if (this.targetPage == "~1") {
  14449. if (controller.selectedIndex < cc.pageCount)
  14450. cc.selectedIndex = controller.selectedIndex;
  14451. }
  14452. else if (this.targetPage == "~2")
  14453. cc.selectedPage = controller.selectedPage;
  14454. else
  14455. cc.selectedPageId = this.targetPage;
  14456. }
  14457. }
  14458. }
  14459. setup(buffer) {
  14460. super.setup(buffer);
  14461. this.objectId = buffer.readS();
  14462. this.controllerName = buffer.readS();
  14463. this.targetPage = buffer.readS();
  14464. }
  14465. }
  14466. fgui.ChangePageAction = ChangePageAction;
  14467. })(fgui || (fgui = {}));
  14468. (function (fgui) {
  14469. class PlayTransitionAction extends fgui.ControllerAction {
  14470. constructor() {
  14471. super();
  14472. this.playTimes = 1;
  14473. this.delay = 0;
  14474. this.stopOnExit = false;
  14475. }
  14476. enter(controller) {
  14477. var trans = controller.parent.getTransition(this.transitionName);
  14478. if (trans) {
  14479. if (this._currentTransition && this._currentTransition.playing)
  14480. trans.changePlayTimes(this.playTimes);
  14481. else
  14482. trans.play(null, this.playTimes, this.delay);
  14483. this._currentTransition = trans;
  14484. }
  14485. }
  14486. leave(controller) {
  14487. if (this.stopOnExit && this._currentTransition) {
  14488. this._currentTransition.stop();
  14489. this._currentTransition = null;
  14490. }
  14491. }
  14492. setup(buffer) {
  14493. super.setup(buffer);
  14494. this.transitionName = buffer.readS();
  14495. this.playTimes = buffer.readInt();
  14496. this.delay = buffer.readFloat();
  14497. this.stopOnExit = buffer.readBool();
  14498. }
  14499. }
  14500. fgui.PlayTransitionAction = PlayTransitionAction;
  14501. })(fgui || (fgui = {}));
  14502. (function (fgui) {
  14503. let BlendMode;
  14504. (function (BlendMode) {
  14505. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  14506. BlendMode[BlendMode["None"] = 1] = "None";
  14507. BlendMode[BlendMode["Add"] = 2] = "Add";
  14508. BlendMode[BlendMode["Multiply"] = 3] = "Multiply";
  14509. BlendMode[BlendMode["Screen"] = 4] = "Screen";
  14510. BlendMode[BlendMode["Erase"] = 5] = "Erase";
  14511. BlendMode[BlendMode["Mask"] = 6] = "Mask";
  14512. BlendMode[BlendMode["Below"] = 7] = "Below";
  14513. BlendMode[BlendMode["Off"] = 8] = "Off";
  14514. BlendMode[BlendMode["Custom1"] = 9] = "Custom1";
  14515. BlendMode[BlendMode["Custom2"] = 10] = "Custom2";
  14516. BlendMode[BlendMode["Custom3"] = 11] = "Custom3";
  14517. })(BlendMode = fgui.BlendMode || (fgui.BlendMode = {}));
  14518. class BlendModeUtils {
  14519. static apply(node, blendMode) {
  14520. let f = factors[blendMode];
  14521. let renderers = node.getComponentsInChildren(cc.RenderComponent);
  14522. renderers.forEach(element => {
  14523. element.srcBlendFactor = f[0];
  14524. element.dstBlendFactor = f[1];
  14525. });
  14526. }
  14527. static override(blendMode, srcFactor, dstFactor) {
  14528. factors[blendMode][0] = srcFactor;
  14529. factors[blendMode][1] = dstFactor;
  14530. }
  14531. }
  14532. fgui.BlendModeUtils = BlendModeUtils;
  14533. const factors = [
  14534. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  14535. [cc.macro.ONE, cc.macro.ONE],
  14536. [cc.macro.SRC_ALPHA, cc.macro.ONE],
  14537. [cc.macro.DST_COLOR, cc.macro.ONE_MINUS_SRC_ALPHA],
  14538. [cc.macro.ONE, cc.macro.ONE_MINUS_SRC_COLOR],
  14539. [cc.macro.ZERO, cc.macro.ONE_MINUS_SRC_ALPHA],
  14540. [cc.macro.ZERO, cc.macro.SRC_ALPHA],
  14541. [cc.macro.ONE_MINUS_DST_ALPHA, cc.macro.DST_ALPHA],
  14542. [cc.macro.ONE, cc.macro.ZERO],
  14543. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  14544. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  14545. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  14546. ];
  14547. })(fgui || (fgui = {}));
  14548. (function (fgui) {
  14549. const { ccclass, property, requireComponent } = cc._decorator;
  14550. let Image = class Image extends cc.Sprite {
  14551. constructor() {
  14552. super();
  14553. this._flip = fgui.FlipType.None;
  14554. this._fillMethod = fgui.FillMethod.None;
  14555. this._fillOrigin = fgui.FillOrigin.Left;
  14556. this._fillAmount = 0;
  14557. }
  14558. get flip() {
  14559. return this._flip;
  14560. }
  14561. set flip(value) {
  14562. if (this._flip != value) {
  14563. this._flip = value;
  14564. let sx = 1, sy = 1;
  14565. if (this._flip == fgui.FlipType.Horizontal || this._flip == fgui.FlipType.Both)
  14566. sx = -1;
  14567. if (this._flip == fgui.FlipType.Vertical || this._flip == fgui.FlipType.Both)
  14568. sy = -1;
  14569. if (sx != 1 || sy != 1)
  14570. this.node.setAnchorPoint(0.5, 0.5);
  14571. this.node.setScale(sx, sy);
  14572. }
  14573. }
  14574. get fillMethod() {
  14575. return this._fillMethod;
  14576. }
  14577. set fillMethod(value) {
  14578. if (this._fillMethod != value) {
  14579. this._fillMethod = value;
  14580. if (this._fillMethod != 0) {
  14581. this.type = cc.Sprite.Type.FILLED;
  14582. if (this._fillMethod <= 3)
  14583. this.fillType = this._fillMethod - 1;
  14584. else
  14585. this.fillType = cc.Sprite.FillType.RADIAL;
  14586. this.fillCenter = new cc.Vec2(0.5, 0.5);
  14587. this.setupFill();
  14588. }
  14589. else {
  14590. this.type = cc.Sprite.Type.SIMPLE;
  14591. }
  14592. }
  14593. }
  14594. get fillOrigin() {
  14595. return this._fillOrigin;
  14596. }
  14597. set fillOrigin(value) {
  14598. if (this._fillOrigin != value) {
  14599. this._fillOrigin = value;
  14600. if (this._fillMethod != 0)
  14601. this.setupFill();
  14602. }
  14603. }
  14604. get fillClockwise() {
  14605. return this._fillClockwise;
  14606. }
  14607. set fillClockwise(value) {
  14608. if (this._fillClockwise != value) {
  14609. this._fillClockwise = value;
  14610. if (this._fillMethod != 0)
  14611. this.setupFill();
  14612. }
  14613. }
  14614. get fillAmount() {
  14615. return this._fillAmount;
  14616. }
  14617. set fillAmount(value) {
  14618. if (this._fillAmount != value) {
  14619. this._fillAmount = value;
  14620. if (this._fillMethod != 0) {
  14621. if (this._fillClockwise)
  14622. this.fillRange = -this._fillAmount;
  14623. else
  14624. this.fillRange = this._fillAmount;
  14625. }
  14626. }
  14627. }
  14628. setupFill() {
  14629. if (this._fillMethod == fgui.FillMethod.Horizontal) {
  14630. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Right || this._fillOrigin == fgui.FillOrigin.Bottom;
  14631. this.fillStart = this._fillClockwise ? 1 : 0;
  14632. }
  14633. else if (this._fillMethod == fgui.FillMethod.Vertical) {
  14634. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Left || this._fillOrigin == fgui.FillOrigin.Top;
  14635. this.fillStart = this._fillClockwise ? 1 : 0;
  14636. }
  14637. else {
  14638. switch (this._fillOrigin) {
  14639. case fgui.FillOrigin.Right:
  14640. this.fillOrigin = 0;
  14641. break;
  14642. case fgui.FillOrigin.Top:
  14643. this.fillStart = 0.25;
  14644. break;
  14645. case fgui.FillOrigin.Left:
  14646. this.fillStart = 0.5;
  14647. break;
  14648. case fgui.FillOrigin.Bottom:
  14649. this.fillStart = 0.75;
  14650. break;
  14651. }
  14652. }
  14653. }
  14654. get grayed() {
  14655. return this._grayed;
  14656. }
  14657. set grayed(value) {
  14658. if (this._grayed == value)
  14659. return;
  14660. this._grayed = value;
  14661. let material;
  14662. if (value) {
  14663. material = this._graySpriteMaterial;
  14664. if (!material)
  14665. material = cc.Material.getBuiltinMaterial('2d-gray-sprite');
  14666. material = this._graySpriteMaterial = cc.MaterialVariant.create(material, this);
  14667. }
  14668. else {
  14669. material = this._spriteMaterial;
  14670. if (!material)
  14671. material = cc.Material.getBuiltinMaterial('2d-sprite', this);
  14672. material = this._spriteMaterial = cc.MaterialVariant.create(material, this);
  14673. }
  14674. this.setMaterial(0, material);
  14675. }
  14676. };
  14677. Image = __decorate([
  14678. ccclass
  14679. ], Image);
  14680. fgui.Image = Image;
  14681. })(fgui || (fgui = {}));
  14682. (function (fgui) {
  14683. class MovieClip extends fgui.Image {
  14684. constructor() {
  14685. super();
  14686. this.interval = 0;
  14687. this.repeatDelay = 0;
  14688. this.timeScale = 1;
  14689. this._playing = true;
  14690. this._frameCount = 0;
  14691. this._frame = 0;
  14692. this._start = 0;
  14693. this._end = 0;
  14694. this._times = 0;
  14695. this._endAt = 0;
  14696. this._status = 0;
  14697. this._smoothing = true;
  14698. this._frameElapsed = 0;
  14699. this._reversed = false;
  14700. this._repeatedCount = 0;
  14701. }
  14702. get frames() {
  14703. return this._frames;
  14704. }
  14705. set frames(value) {
  14706. this._frames = value;
  14707. if (this._frames) {
  14708. this._frameCount = this._frames.length;
  14709. if (this._end == -1 || this._end > this._frameCount - 1)
  14710. this._end = this._frameCount - 1;
  14711. if (this._endAt == -1 || this._endAt > this._frameCount - 1)
  14712. this._endAt = this._frameCount - 1;
  14713. if (this._frame < 0 || this._frame > this._frameCount - 1)
  14714. this._frame = this._frameCount - 1;
  14715. this.type = cc.Sprite.Type.SIMPLE;
  14716. this.drawFrame();
  14717. this._frameElapsed = 0;
  14718. this._repeatedCount = 0;
  14719. this._reversed = false;
  14720. }
  14721. else {
  14722. this._frameCount = 0;
  14723. }
  14724. }
  14725. get frameCount() {
  14726. return this._frameCount;
  14727. }
  14728. get frame() {
  14729. return this._frame;
  14730. }
  14731. set frame(value) {
  14732. if (this._frame != value) {
  14733. if (this._frames && value >= this._frameCount)
  14734. value = this._frameCount - 1;
  14735. this._frame = value;
  14736. this._frameElapsed = 0;
  14737. this.drawFrame();
  14738. }
  14739. }
  14740. get playing() {
  14741. return this._playing;
  14742. }
  14743. set playing(value) {
  14744. if (this._playing != value) {
  14745. this._playing = value;
  14746. }
  14747. }
  14748. get smoothing() {
  14749. return this._smoothing;
  14750. }
  14751. set smoothing(value) {
  14752. this._smoothing = value;
  14753. }
  14754. rewind() {
  14755. this._frame = 0;
  14756. this._frameElapsed = 0;
  14757. this._reversed = false;
  14758. this._repeatedCount = 0;
  14759. this.drawFrame();
  14760. }
  14761. syncStatus(anotherMc) {
  14762. this._frame = anotherMc._frame;
  14763. this._frameElapsed = anotherMc._frameElapsed;
  14764. this._reversed = anotherMc._reversed;
  14765. this._repeatedCount = anotherMc._repeatedCount;
  14766. this.drawFrame();
  14767. }
  14768. advance(timeInMiniseconds) {
  14769. var beginFrame = this._frame;
  14770. var beginReversed = this._reversed;
  14771. var backupTime = timeInMiniseconds;
  14772. while (true) {
  14773. var tt = this.interval + this._frames[this._frame].addDelay;
  14774. if (this._frame == 0 && this._repeatedCount > 0)
  14775. tt += this.repeatDelay;
  14776. if (timeInMiniseconds < tt) {
  14777. this._frameElapsed = 0;
  14778. break;
  14779. }
  14780. timeInMiniseconds -= tt;
  14781. if (this.swing) {
  14782. if (this._reversed) {
  14783. this._frame--;
  14784. if (this._frame <= 0) {
  14785. this._frame = 0;
  14786. this._repeatedCount++;
  14787. this._reversed = !this._reversed;
  14788. }
  14789. }
  14790. else {
  14791. this._frame++;
  14792. if (this._frame > this._frameCount - 1) {
  14793. this._frame = Math.max(0, this._frameCount - 2);
  14794. this._repeatedCount++;
  14795. this._reversed = !this._reversed;
  14796. }
  14797. }
  14798. }
  14799. else {
  14800. this._frame++;
  14801. if (this._frame > this._frameCount - 1) {
  14802. this._frame = 0;
  14803. this._repeatedCount++;
  14804. }
  14805. }
  14806. if (this._frame == beginFrame && this._reversed == beginReversed) {
  14807. var roundTime = backupTime - timeInMiniseconds;
  14808. timeInMiniseconds -= Math.floor(timeInMiniseconds / roundTime) * roundTime;
  14809. }
  14810. }
  14811. this.drawFrame();
  14812. }
  14813. setPlaySettings(start, end, times, endAt, endCallback, callbackObj) {
  14814. if (start == undefined)
  14815. start = 0;
  14816. if (end == undefined)
  14817. end = -1;
  14818. if (times == undefined)
  14819. times = 0;
  14820. if (endAt == undefined)
  14821. endAt = -1;
  14822. this._start = start;
  14823. this._end = end;
  14824. if (this._end == -1 || this._end > this._frameCount - 1)
  14825. this._end = this._frameCount - 1;
  14826. this._times = times;
  14827. this._endAt = endAt;
  14828. if (this._endAt == -1)
  14829. this._endAt = this._end;
  14830. this._status = 0;
  14831. this._callback = endCallback;
  14832. this._callbackObj = callbackObj;
  14833. this.frame = start;
  14834. }
  14835. update(dt) {
  14836. if (!this._playing || this._frameCount == 0 || this._status == 3)
  14837. return;
  14838. if (this.timeScale != 1)
  14839. dt *= this.timeScale;
  14840. this._frameElapsed += dt;
  14841. var tt = this.interval + this._frames[this._frame].addDelay;
  14842. if (this._frame == 0 && this._repeatedCount > 0)
  14843. tt += this.repeatDelay;
  14844. if (this._frameElapsed < tt)
  14845. return;
  14846. this._frameElapsed -= tt;
  14847. if (this._frameElapsed > this.interval)
  14848. this._frameElapsed = this.interval;
  14849. if (this.swing) {
  14850. if (this._reversed) {
  14851. this._frame--;
  14852. if (this._frame <= 0) {
  14853. this._frame = 0;
  14854. this._repeatedCount++;
  14855. this._reversed = !this._reversed;
  14856. }
  14857. }
  14858. else {
  14859. this._frame++;
  14860. if (this._frame > this._frameCount - 1) {
  14861. this._frame = Math.max(0, this._frameCount - 2);
  14862. this._repeatedCount++;
  14863. this._reversed = !this._reversed;
  14864. }
  14865. }
  14866. }
  14867. else {
  14868. this._frame++;
  14869. if (this._frame > this._frameCount - 1) {
  14870. this._frame = 0;
  14871. this._repeatedCount++;
  14872. }
  14873. }
  14874. if (this._status == 1) {
  14875. this._frame = this._start;
  14876. this._frameElapsed = 0;
  14877. this._status = 0;
  14878. }
  14879. else if (this._status == 2) {
  14880. this._frame = this._endAt;
  14881. this._frameElapsed = 0;
  14882. this._status = 3;
  14883. if (this._callback != null) {
  14884. var callback = this._callback;
  14885. var caller = this._callbackObj;
  14886. this._callback = null;
  14887. this._callbackObj = null;
  14888. callback.call(caller);
  14889. }
  14890. }
  14891. else {
  14892. if (this._frame == this._end) {
  14893. if (this._times > 0) {
  14894. this._times--;
  14895. if (this._times == 0)
  14896. this._status = 2;
  14897. else
  14898. this._status = 1;
  14899. }
  14900. else if (this._start != 0)
  14901. this._status = 1;
  14902. }
  14903. }
  14904. this.drawFrame();
  14905. }
  14906. drawFrame() {
  14907. if (this._frameCount > 0 && this._frame < this._frames.length) {
  14908. var frame = this._frames[this._frame];
  14909. this.spriteFrame = frame.texture;
  14910. }
  14911. }
  14912. }
  14913. fgui.MovieClip = MovieClip;
  14914. })(fgui || (fgui = {}));
  14915. (function (fgui) {
  14916. class Event extends cc.Event {
  14917. constructor(type, bubbles) {
  14918. super(type, bubbles);
  14919. this.pos = new cc.Vec2();
  14920. this.touchId = 0;
  14921. this.clickCount = 0;
  14922. this.button = 0;
  14923. this.keyModifiers = 0;
  14924. this.mouseWheelDelta = 0;
  14925. }
  14926. get isShiftDown() {
  14927. return false;
  14928. }
  14929. get isCtrlDown() {
  14930. return false;
  14931. }
  14932. captureTouch() {
  14933. let obj = fgui.GObject.cast(this.currentTarget);
  14934. if (obj)
  14935. this._processor.addTouchMonitor(this.touchId, obj);
  14936. }
  14937. static _borrow(type, bubbles) {
  14938. let evt;
  14939. if (eventPool.length) {
  14940. evt = eventPool.pop();
  14941. evt.type = type;
  14942. evt.bubbles = bubbles;
  14943. }
  14944. else {
  14945. evt = new Event(type, bubbles);
  14946. }
  14947. return evt;
  14948. }
  14949. static _return(evt) {
  14950. evt.initiator = null;
  14951. evt.touch = null;
  14952. evt.unuse();
  14953. eventPool.push(evt);
  14954. }
  14955. }
  14956. Event.TOUCH_BEGIN = 'fui_touch_begin';
  14957. Event.TOUCH_MOVE = 'fui_touch_move';
  14958. Event.TOUCH_END = 'fui_touch_end';
  14959. Event.CLICK = 'fui_click';
  14960. Event.ROLL_OVER = 'fui_roll_over';
  14961. Event.ROLL_OUT = 'fui_roll_out';
  14962. Event.MOUSE_WHEEL = 'fui_mouse_wheel';
  14963. Event.DISPLAY = 'fui_display';
  14964. Event.UNDISPLAY = 'fui_undisplay';
  14965. Event.GEAR_STOP = 'fui_gear_stop';
  14966. Event.LINK = 'fui_text_link';
  14967. Event.Submit = 'editing-return';
  14968. Event.TEXT_CHANGE = 'text-changed';
  14969. Event.STATUS_CHANGED = 'fui_status_changed';
  14970. Event.XY_CHANGED = 'fui_xy_changed';
  14971. Event.SIZE_CHANGED = 'fui_size_changed';
  14972. Event.SIZE_DELAY_CHANGE = 'fui_size_delay_change';
  14973. Event.DRAG_START = 'fui_drag_start';
  14974. Event.DRAG_MOVE = 'fui_drag_move';
  14975. Event.DRAG_END = 'fui_drag_end';
  14976. Event.DROP = 'fui_drop';
  14977. Event.SCROLL = 'fui_scroll';
  14978. Event.SCROLL_END = 'fui_scroll_end';
  14979. Event.PULL_DOWN_RELEASE = 'fui_pull_down_release';
  14980. Event.PULL_UP_RELEASE = 'fui_pull_up_release';
  14981. Event.CLICK_ITEM = 'fui_click_item';
  14982. Event.LIST_ITEM_CREATED = 'fgui_list_item_created';
  14983. Event.LIST_ITEM_CREATED_REFRESH = 'fgui_list_item_created_refresh';
  14984. fgui.Event = Event;
  14985. var eventPool = new Array();
  14986. })(fgui || (fgui = {}));
  14987. (function (fgui) {
  14988. class PixelHitTest {
  14989. constructor(data, offsetX, offsetY) {
  14990. this._data = data;
  14991. this.offsetX = offsetX == undefined ? 0 : offsetX;
  14992. this.offsetY = offsetY == undefined ? 0 : offsetY;
  14993. this.scaleX = 1;
  14994. this.scaleY = 1;
  14995. }
  14996. hitTest(pt) {
  14997. let x = Math.floor((pt.x / this.scaleX - this.offsetX) * this._data.scale);
  14998. let y = Math.floor((pt.y / this.scaleY - this.offsetY) * this._data.scale);
  14999. if (x < 0 || y < 0 || x >= this._data.pixelWidth)
  15000. return false;
  15001. var pos = y * this._data.pixelWidth + x;
  15002. var pos2 = Math.floor(pos / 8);
  15003. var pos3 = pos % 8;
  15004. if (pos2 >= 0 && pos2 < this._data.pixels.length)
  15005. return ((this._data.pixels[pos2] >> pos3) & 0x1) == 1;
  15006. else
  15007. return false;
  15008. }
  15009. }
  15010. fgui.PixelHitTest = PixelHitTest;
  15011. class PixelHitTestData {
  15012. constructor(ba) {
  15013. ba.readInt();
  15014. this.pixelWidth = ba.readInt();
  15015. this.scale = 1 / ba.readByte();
  15016. this.pixels = ba.readBuffer().data;
  15017. }
  15018. }
  15019. fgui.PixelHitTestData = PixelHitTestData;
  15020. class ChildHitArea {
  15021. constructor(child) {
  15022. this._child = child;
  15023. }
  15024. hitTest(pt, globalPt) {
  15025. return this._child.hitTest(globalPt, false) != null;
  15026. }
  15027. }
  15028. fgui.ChildHitArea = ChildHitArea;
  15029. })(fgui || (fgui = {}));
  15030. (function (fgui) {
  15031. class InputProcessor extends cc.Component {
  15032. constructor() {
  15033. super();
  15034. this._touches = new Array();
  15035. this._rollOutChain = new Array();
  15036. this._rollOverChain = new Array();
  15037. this._touchPos = new cc.Vec2();
  15038. }
  15039. onLoad() {
  15040. this._owner = this.node['$gobj'];
  15041. }
  15042. onEnable() {
  15043. let node = this.node;
  15044. node.on(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  15045. node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  15046. node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  15047. node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  15048. node.on(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  15049. node.on(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  15050. node.on(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  15051. node.on(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  15052. this._touchListener = this.node['_touchListener'];
  15053. }
  15054. onDisable() {
  15055. let node = this.node;
  15056. node.off(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  15057. node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  15058. node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  15059. node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  15060. node.off(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  15061. node.off(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  15062. node.off(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  15063. node.off(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  15064. this._touchListener = null;
  15065. }
  15066. getAllTouches(touchIds) {
  15067. touchIds = touchIds || new Array();
  15068. let cnt = this._touches.length;
  15069. for (let i = 0; i < cnt; i++) {
  15070. let ti = this._touches[i];
  15071. if (ti.touchId != -1)
  15072. touchIds.push(ti.touchId);
  15073. }
  15074. return touchIds;
  15075. }
  15076. getTouchPosition(touchId) {
  15077. if (touchId === undefined)
  15078. touchId = -1;
  15079. let cnt = this._touches.length;
  15080. for (let i = 0; i < cnt; i++) {
  15081. let ti = this._touches[i];
  15082. if (ti.touchId != -1 && (touchId == -1 || ti.touchId == touchId))
  15083. return ti.pos;
  15084. }
  15085. return cc.Vec2.ZERO;
  15086. }
  15087. getTouchTarget() {
  15088. let cnt = this._touches.length;
  15089. for (let i = 0; i < cnt; i++) {
  15090. let ti = this._touches[i];
  15091. if (ti.touchId != -1)
  15092. return ti.target;
  15093. }
  15094. return null;
  15095. }
  15096. addTouchMonitor(touchId, target) {
  15097. let ti = this.getInfo(touchId, false);
  15098. if (!ti)
  15099. return;
  15100. let index = ti.touchMonitors.indexOf(target);
  15101. if (index == -1)
  15102. ti.touchMonitors.push(target);
  15103. }
  15104. removeTouchMonitor(target) {
  15105. let cnt = this._touches.length;
  15106. for (let i = 0; i < cnt; i++) {
  15107. let ti = this._touches[i];
  15108. let index = ti.touchMonitors.indexOf(target);
  15109. if (index != -1)
  15110. ti.touchMonitors.splice(index, 1);
  15111. }
  15112. }
  15113. cancelClick(touchId) {
  15114. let ti = this.getInfo(touchId, false);
  15115. if (ti)
  15116. ti.clickCancelled = true;
  15117. }
  15118. simulateClick(target) {
  15119. let evt;
  15120. evt = fgui.Event._borrow(fgui.Event.TOUCH_BEGIN, true);
  15121. evt.initiator = target;
  15122. evt.pos.set(target.localToGlobal());
  15123. evt.touchId = 0;
  15124. evt.clickCount = 1;
  15125. evt.button = 0;
  15126. evt._processor = this;
  15127. if (this._captureCallback)
  15128. this._captureCallback.call(this._owner, evt);
  15129. target.node.dispatchEvent(evt);
  15130. evt.unuse();
  15131. evt.type = fgui.Event.TOUCH_END;
  15132. evt.bubbles = true;
  15133. target.node.dispatchEvent(evt);
  15134. evt.unuse();
  15135. evt.type = fgui.Event.CLICK;
  15136. evt.bubbles = true;
  15137. target.node.dispatchEvent(evt);
  15138. fgui.Event._return(evt);
  15139. }
  15140. touchBeginHandler(touch, evt) {
  15141. let ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  15142. this._touchListener.setSwallowTouches(ti.target != this._owner);
  15143. this.setBegin(ti);
  15144. let evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_BEGIN, true);
  15145. if (this._captureCallback)
  15146. this._captureCallback.call(this._owner, evt2);
  15147. ti.target.node.dispatchEvent(evt2);
  15148. this.handleRollOver(ti, ti.target);
  15149. return true;
  15150. }
  15151. touchMoveHandler(touch, evt) {
  15152. let ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  15153. this.handleRollOver(ti, ti.target);
  15154. if (ti.began) {
  15155. let evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  15156. let done = false;
  15157. let cnt = ti.touchMonitors.length;
  15158. for (let i = 0; i < cnt; i++) {
  15159. let mm = ti.touchMonitors[i];
  15160. if (mm.node == null || !mm.node.activeInHierarchy)
  15161. continue;
  15162. evt2.unuse();
  15163. evt2.type = fgui.Event.TOUCH_MOVE;
  15164. mm.node.dispatchEvent(evt2);
  15165. if (mm == this._owner)
  15166. done = true;
  15167. }
  15168. if (!done && this.node) {
  15169. evt2.unuse();
  15170. evt2.type = fgui.Event.TOUCH_MOVE;
  15171. this.node.dispatchEvent(evt2);
  15172. }
  15173. fgui.Event._return(evt2);
  15174. }
  15175. }
  15176. touchEndHandler(touch, evt) {
  15177. let ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  15178. this.setEnd(ti);
  15179. let evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  15180. let cnt = ti.touchMonitors.length;
  15181. for (let i = 0; i < cnt; i++) {
  15182. let mm = ti.touchMonitors[i];
  15183. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy || (mm instanceof fgui.GComponent && mm.isAncestorOf(ti.target)))
  15184. continue;
  15185. evt2.unuse();
  15186. evt2.type = fgui.Event.TOUCH_END;
  15187. mm.node.dispatchEvent(evt2);
  15188. }
  15189. ti.touchMonitors.length = 0;
  15190. if (ti.target && ti.target.node) {
  15191. if (ti.target instanceof fgui.GRichTextField)
  15192. ti.target.node.getComponent(cc.RichText)['_onTouchEnded'](evt2);
  15193. evt2.unuse();
  15194. evt2.type = fgui.Event.TOUCH_END;
  15195. evt2.bubbles = true;
  15196. ti.target.node.dispatchEvent(evt2);
  15197. }
  15198. fgui.Event._return(evt2);
  15199. ti.target = this.clickTest(ti);
  15200. if (ti.target) {
  15201. evt2 = this.getEvent(ti, ti.target, fgui.Event.CLICK, true);
  15202. ti.target.node.dispatchEvent(evt2);
  15203. fgui.Event._return(evt2);
  15204. }
  15205. if (cc.sys.isMobile)
  15206. this.handleRollOver(ti, null);
  15207. else
  15208. this.handleRollOver(ti, ti.target);
  15209. ti.target = null;
  15210. ti.touchId = -1;
  15211. ti.button = -1;
  15212. }
  15213. touchCancelHandler(touch, evt) {
  15214. let ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  15215. let evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  15216. let cnt = ti.touchMonitors.length;
  15217. for (let i = 0; i < cnt; i++) {
  15218. let mm = ti.touchMonitors[i];
  15219. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy || (mm instanceof fgui.GComponent && mm.isAncestorOf(ti.target)))
  15220. continue;
  15221. evt2.initiator = mm;
  15222. mm.node.dispatchEvent(evt2);
  15223. }
  15224. ti.touchMonitors.length = 0;
  15225. if (ti.target && ti.target.node) {
  15226. evt2.bubbles = true;
  15227. ti.target.node.dispatchEvent(evt2);
  15228. }
  15229. fgui.Event._return(evt2);
  15230. this.handleRollOver(ti, null);
  15231. ti.target = null;
  15232. ti.touchId = -1;
  15233. ti.button = -1;
  15234. }
  15235. mouseDownHandler(evt) {
  15236. let ti = this.getInfo(0, true);
  15237. ti.button = evt.getButton();
  15238. }
  15239. mouseUpHandler(evt) {
  15240. let ti = this.getInfo(0, true);
  15241. ti.button = evt.getButton();
  15242. }
  15243. mouseMoveHandler(evt) {
  15244. let ti = this.getInfo(0, false);
  15245. if (ti && Math.abs(ti.pos.x - evt.getLocationX()) < 1 && Math.abs(ti.pos.y - (fgui.GRoot.inst.height - evt.getLocationY())) < 1)
  15246. return;
  15247. ti = this.updateInfo(0, evt.getLocation());
  15248. this.handleRollOver(ti, ti.target);
  15249. if (ti.began) {
  15250. let evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  15251. let done = false;
  15252. let cnt = ti.touchMonitors.length;
  15253. for (let i = 0; i < cnt; i++) {
  15254. let mm = ti.touchMonitors[i];
  15255. if (mm.node == null || !mm.node.activeInHierarchy)
  15256. continue;
  15257. evt2.initiator = mm;
  15258. mm.node.dispatchEvent(evt2);
  15259. if (mm == this._owner)
  15260. done = true;
  15261. }
  15262. if (!done && this.node) {
  15263. evt2.initiator = this._owner;
  15264. this.node.dispatchEvent(evt2);
  15265. fgui.Event._return(evt2);
  15266. }
  15267. fgui.Event._return(evt2);
  15268. }
  15269. }
  15270. mouseWheelHandler(evt) {
  15271. let ti = this.updateInfo(0, evt.getLocation());
  15272. ti.mouseWheelDelta = Math.max(evt.getScrollX(), evt.getScrollY());
  15273. let evt2 = this.getEvent(ti, ti.target, fgui.Event.MOUSE_WHEEL, true);
  15274. ti.target.node.dispatchEvent(evt2);
  15275. fgui.Event._return(evt2);
  15276. }
  15277. updateInfo(touchId, pos, touch) {
  15278. let camera = cc.Camera.findCamera(this.node);
  15279. if (camera)
  15280. camera.getScreenToWorldPoint(pos, this._touchPos);
  15281. else
  15282. this._touchPos.set(pos);
  15283. this._touchPos.y = fgui.GRoot.inst.height - this._touchPos.y;
  15284. let target = this._owner.hitTest(this._touchPos);
  15285. if (!target)
  15286. target = this._owner;
  15287. let ti = this.getInfo(touchId);
  15288. ti.target = target;
  15289. ti.pos.set(this._touchPos);
  15290. ti.button = cc.Event.EventMouse.BUTTON_LEFT;
  15291. ti.touch = touch;
  15292. return ti;
  15293. }
  15294. getInfo(touchId, createIfNotExisits) {
  15295. if (createIfNotExisits === undefined)
  15296. createIfNotExisits = true;
  15297. let ret = null;
  15298. let cnt = this._touches.length;
  15299. for (let i = 0; i < cnt; i++) {
  15300. let ti = this._touches[i];
  15301. if (ti.touchId == touchId)
  15302. return ti;
  15303. else if (ti.touchId == -1)
  15304. ret = ti;
  15305. }
  15306. if (!ret) {
  15307. if (!createIfNotExisits)
  15308. return null;
  15309. ret = new TouchInfo();
  15310. this._touches.push(ret);
  15311. }
  15312. ret.touchId = touchId;
  15313. return ret;
  15314. }
  15315. setBegin(ti) {
  15316. ti.began = true;
  15317. ti.clickCancelled = false;
  15318. ti.downPos.set(ti.pos);
  15319. ti.downTargets.length = 0;
  15320. let obj = ti.target;
  15321. while (obj) {
  15322. ti.downTargets.push(obj);
  15323. obj = obj.findParent();
  15324. }
  15325. }
  15326. setEnd(ti) {
  15327. ti.began = false;
  15328. let now = fgui.ToolSet.getTime();
  15329. let elapsed = now - ti.lastClickTime;
  15330. if (elapsed < 0.45) {
  15331. if (ti.clickCount == 2)
  15332. ti.clickCount = 1;
  15333. else
  15334. ti.clickCount++;
  15335. }
  15336. else
  15337. ti.clickCount = 1;
  15338. ti.lastClickTime = now;
  15339. }
  15340. clickTest(ti) {
  15341. if (ti.downTargets.length == 0 || ti.clickCancelled || Math.abs(ti.pos.x - ti.downPos.x) > 50 || Math.abs(ti.pos.y - ti.downPos.y) > 50)
  15342. return null;
  15343. let obj = ti.downTargets[0];
  15344. if (obj && obj.node && obj.node.activeInHierarchy)
  15345. return obj;
  15346. obj = ti.target;
  15347. while (obj) {
  15348. let index = ti.downTargets.indexOf(obj);
  15349. if (index != -1 && obj.node && obj.node.activeInHierarchy)
  15350. break;
  15351. obj = obj.findParent();
  15352. }
  15353. return obj;
  15354. }
  15355. handleRollOver(ti, target) {
  15356. if (ti.lastRollOver == target)
  15357. return;
  15358. let element = ti.lastRollOver;
  15359. while (element && element.node) {
  15360. this._rollOutChain.push(element);
  15361. element = element.findParent();
  15362. }
  15363. element = target;
  15364. while (element && element.node) {
  15365. let i = this._rollOutChain.indexOf(element);
  15366. if (i != -1) {
  15367. this._rollOutChain.length = i;
  15368. break;
  15369. }
  15370. this._rollOverChain.push(element);
  15371. element = element.findParent();
  15372. }
  15373. ti.lastRollOver = target;
  15374. let cnt = this._rollOutChain.length;
  15375. for (let i = 0; i < cnt; i++) {
  15376. element = this._rollOutChain[i];
  15377. if (element.node && element.node.activeInHierarchy) {
  15378. let evt = this.getEvent(ti, element, fgui.Event.ROLL_OUT, false);
  15379. element.node.dispatchEvent(evt);
  15380. fgui.Event._return(evt);
  15381. }
  15382. }
  15383. cnt = this._rollOverChain.length;
  15384. for (let i = 0; i < cnt; i++) {
  15385. element = this._rollOverChain[i];
  15386. if (element.node && element.node.activeInHierarchy) {
  15387. let evt = this.getEvent(ti, element, fgui.Event.ROLL_OVER, false);
  15388. element.node.dispatchEvent(evt);
  15389. fgui.Event._return(evt);
  15390. }
  15391. }
  15392. this._rollOutChain.length = 0;
  15393. this._rollOverChain.length = 0;
  15394. }
  15395. getEvent(ti, target, type, bubbles) {
  15396. let evt = fgui.Event._borrow(type, bubbles);
  15397. evt.initiator = target;
  15398. evt.touch = ti.touch;
  15399. evt.pos.set(ti.pos);
  15400. evt.touchId = ti.touch ? ti.touch.getID() : 0;
  15401. evt.clickCount = ti.clickCount;
  15402. evt.button = ti.button;
  15403. evt.mouseWheelDelta = ti.mouseWheelDelta;
  15404. evt._processor = this;
  15405. return evt;
  15406. }
  15407. }
  15408. fgui.InputProcessor = InputProcessor;
  15409. class TouchInfo {
  15410. constructor() {
  15411. this.pos = new cc.Vec2();
  15412. this.touchId = 0;
  15413. this.clickCount = 0;
  15414. this.mouseWheelDelta = 0;
  15415. this.button = -1;
  15416. this.downPos = new cc.Vec2();
  15417. this.began = false;
  15418. this.clickCancelled = false;
  15419. this.lastClickTime = 0;
  15420. this.downTargets = new Array();
  15421. this.touchMonitors = new Array();
  15422. }
  15423. }
  15424. })(fgui || (fgui = {}));
  15425. (function (fgui) {
  15426. class GearBase {
  15427. constructor(owner) {
  15428. this._owner = owner;
  15429. }
  15430. static create(owner, index) {
  15431. if (!Classes)
  15432. Classes = [
  15433. fgui.GearDisplay, fgui.GearXY, fgui.GearSize, fgui.GearLook, fgui.GearColor,
  15434. fgui.GearAnimation, fgui.GearText, fgui.GearIcon, fgui.GearDisplay2, fgui.GearFontSize
  15435. ];
  15436. return new (Classes[index])(owner);
  15437. }
  15438. dispose() {
  15439. if (this._tweenConfig && this._tweenConfig._tweener) {
  15440. this._tweenConfig._tweener.kill();
  15441. this._tweenConfig._tweener = null;
  15442. }
  15443. }
  15444. get controller() {
  15445. return this._controller;
  15446. }
  15447. set controller(val) {
  15448. if (val != this._controller) {
  15449. this._controller = val;
  15450. if (this._controller)
  15451. this.init();
  15452. }
  15453. }
  15454. get tweenConfig() {
  15455. if (!this._tweenConfig)
  15456. this._tweenConfig = new GearTweenConfig();
  15457. return this._tweenConfig;
  15458. }
  15459. setup(buffer) {
  15460. this._controller = this._owner.parent.getControllerAt(buffer.readShort());
  15461. this.init();
  15462. var i;
  15463. var page;
  15464. var cnt = buffer.readShort();
  15465. if (this instanceof fgui.GearDisplay) {
  15466. this.pages = buffer.readSArray(cnt);
  15467. }
  15468. else if (this instanceof fgui.GearDisplay2) {
  15469. this.pages = buffer.readSArray(cnt);
  15470. }
  15471. else {
  15472. for (i = 0; i < cnt; i++) {
  15473. page = buffer.readS();
  15474. if (page == null)
  15475. continue;
  15476. this.addStatus(page, buffer);
  15477. }
  15478. if (buffer.readBool())
  15479. this.addStatus(null, buffer);
  15480. }
  15481. if (buffer.readBool()) {
  15482. this._tweenConfig = new GearTweenConfig();
  15483. this._tweenConfig.easeType = buffer.readByte();
  15484. this._tweenConfig.duration = buffer.readFloat();
  15485. this._tweenConfig.delay = buffer.readFloat();
  15486. }
  15487. if (buffer.version >= 2) {
  15488. if (this instanceof fgui.GearXY) {
  15489. if (buffer.readBool()) {
  15490. this.positionsInPercent = true;
  15491. for (i = 0; i < cnt; i++) {
  15492. page = buffer.readS();
  15493. if (page == null)
  15494. continue;
  15495. this.addExtStatus(page, buffer);
  15496. }
  15497. if (buffer.readBool())
  15498. this.addExtStatus(null, buffer);
  15499. }
  15500. }
  15501. else if (this instanceof fgui.GearDisplay2)
  15502. this.condition = buffer.readByte();
  15503. }
  15504. }
  15505. updateFromRelations(dx, dy) {
  15506. }
  15507. addStatus(pageId, buffer) {
  15508. }
  15509. init() {
  15510. }
  15511. apply() {
  15512. }
  15513. updateState() {
  15514. }
  15515. }
  15516. fgui.GearBase = GearBase;
  15517. var Classes;
  15518. class GearTweenConfig {
  15519. constructor() {
  15520. this.tween = true;
  15521. this.easeType = fgui.EaseType.QuadOut;
  15522. this.duration = 0.3;
  15523. this.delay = 0;
  15524. }
  15525. }
  15526. fgui.GearTweenConfig = GearTweenConfig;
  15527. })(fgui || (fgui = {}));
  15528. (function (fgui) {
  15529. class GearAnimation extends fgui.GearBase {
  15530. constructor(owner) {
  15531. super(owner);
  15532. }
  15533. init() {
  15534. this._default = {
  15535. playing: this._owner.getProp(fgui.ObjectPropID.Playing),
  15536. frame: this._owner.getProp(fgui.ObjectPropID.Frame)
  15537. };
  15538. this._storage = {};
  15539. }
  15540. addStatus(pageId, buffer) {
  15541. var gv;
  15542. if (pageId == null)
  15543. gv = this._default;
  15544. else
  15545. this._storage[pageId] = gv = {};
  15546. gv.playing = buffer.readBool();
  15547. gv.frame = buffer.readInt();
  15548. }
  15549. apply() {
  15550. this._owner._gearLocked = true;
  15551. var gv = this._storage[this._controller.selectedPageId];
  15552. if (!gv)
  15553. gv = this._default;
  15554. this._owner.setProp(fgui.ObjectPropID.Playing, gv.playing);
  15555. this._owner.setProp(fgui.ObjectPropID.Frame, gv.frame);
  15556. this._owner._gearLocked = false;
  15557. }
  15558. updateState() {
  15559. var gv = this._storage[this._controller.selectedPageId];
  15560. if (!gv)
  15561. this._storage[this._controller.selectedPageId] = gv = {};
  15562. gv.playing = this._owner.getProp(fgui.ObjectPropID.Playing);
  15563. gv.frame = this._owner.getProp(fgui.ObjectPropID.Frame);
  15564. }
  15565. }
  15566. fgui.GearAnimation = GearAnimation;
  15567. })(fgui || (fgui = {}));
  15568. (function (fgui) {
  15569. class GearColor extends fgui.GearBase {
  15570. constructor(owner) {
  15571. super(owner);
  15572. }
  15573. init() {
  15574. this._default = {
  15575. color: this._owner.getProp(fgui.ObjectPropID.Color),
  15576. strokeColor: this._owner.getProp(fgui.ObjectPropID.OutlineColor)
  15577. };
  15578. this._storage = {};
  15579. }
  15580. addStatus(pageId, buffer) {
  15581. var gv;
  15582. if (pageId == null)
  15583. gv = this._default;
  15584. else
  15585. this._storage[pageId] = gv = {};
  15586. gv.color = buffer.readColor();
  15587. gv.strokeColor = buffer.readColor();
  15588. }
  15589. apply() {
  15590. this._owner._gearLocked = true;
  15591. var gv = this._storage[this._controller.selectedPageId];
  15592. if (!gv)
  15593. gv = this._default;
  15594. this._owner.setProp(fgui.ObjectPropID.Color, gv.color);
  15595. this._owner.setProp(fgui.ObjectPropID.OutlineColor, gv.strokeColor);
  15596. this._owner._gearLocked = false;
  15597. }
  15598. updateState() {
  15599. var gv = this._storage[this._controller.selectedPageId];
  15600. if (!gv)
  15601. this._storage[this._controller.selectedPageId] = gv = {};
  15602. gv.color = this._owner.getProp(fgui.ObjectPropID.Color);
  15603. gv.strokeColor = this._owner.getProp(fgui.ObjectPropID.OutlineColor);
  15604. }
  15605. }
  15606. fgui.GearColor = GearColor;
  15607. })(fgui || (fgui = {}));
  15608. (function (fgui) {
  15609. class GearDisplay extends fgui.GearBase {
  15610. constructor(owner) {
  15611. super(owner);
  15612. this._displayLockToken = 1;
  15613. this._visible = 0;
  15614. }
  15615. init() {
  15616. this.pages = null;
  15617. }
  15618. apply() {
  15619. this._displayLockToken++;
  15620. if (this._displayLockToken == 0)
  15621. this._displayLockToken = 1;
  15622. if (this.pages == null || this.pages.length == 0
  15623. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  15624. this._visible = 1;
  15625. else
  15626. this._visible = 0;
  15627. }
  15628. addLock() {
  15629. this._visible++;
  15630. return this._displayLockToken;
  15631. }
  15632. releaseLock(token) {
  15633. if (token == this._displayLockToken)
  15634. this._visible--;
  15635. }
  15636. get connected() {
  15637. return this._controller == null || this._visible > 0;
  15638. }
  15639. }
  15640. fgui.GearDisplay = GearDisplay;
  15641. })(fgui || (fgui = {}));
  15642. (function (fgui) {
  15643. class GearDisplay2 extends fgui.GearBase {
  15644. constructor(owner) {
  15645. super(owner);
  15646. this._visible = 0;
  15647. }
  15648. init() {
  15649. this.pages = null;
  15650. }
  15651. apply() {
  15652. if (this.pages == null || this.pages.length == 0
  15653. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  15654. this._visible = 1;
  15655. else
  15656. this._visible = 0;
  15657. }
  15658. evaluate(connected) {
  15659. var v = this._controller == null || this._visible > 0;
  15660. if (this.condition == 0)
  15661. v = v && connected;
  15662. else
  15663. v = v || connected;
  15664. return v;
  15665. }
  15666. }
  15667. fgui.GearDisplay2 = GearDisplay2;
  15668. })(fgui || (fgui = {}));
  15669. (function (fgui) {
  15670. class GearFontSize extends fgui.GearBase {
  15671. constructor(owner) {
  15672. super(owner);
  15673. this._default = 0;
  15674. }
  15675. init() {
  15676. this._default = this._owner.getProp(fgui.ObjectPropID.FontSize);
  15677. this._storage = {};
  15678. }
  15679. addStatus(pageId, buffer) {
  15680. if (pageId == null)
  15681. this._default = buffer.readInt();
  15682. else
  15683. this._storage[pageId] = buffer.readInt();
  15684. }
  15685. apply() {
  15686. this._owner._gearLocked = true;
  15687. var data = this._storage[this._controller.selectedPageId];
  15688. if (data != undefined)
  15689. this._owner.setProp(fgui.ObjectPropID.FontSize, data);
  15690. else
  15691. this._owner.setProp(fgui.ObjectPropID.FontSize, this._default);
  15692. this._owner._gearLocked = false;
  15693. }
  15694. updateState() {
  15695. this._storage[this._controller.selectedPageId] = this._owner.getProp(fgui.ObjectPropID.FontSize);
  15696. }
  15697. }
  15698. fgui.GearFontSize = GearFontSize;
  15699. })(fgui || (fgui = {}));
  15700. (function (fgui) {
  15701. class GearIcon extends fgui.GearBase {
  15702. constructor(owner) {
  15703. super(owner);
  15704. }
  15705. init() {
  15706. this._default = this._owner.icon;
  15707. this._storage = {};
  15708. }
  15709. addStatus(pageId, buffer) {
  15710. if (pageId == null)
  15711. this._default = buffer.readS();
  15712. else
  15713. this._storage[pageId] = buffer.readS();
  15714. }
  15715. apply() {
  15716. this._owner._gearLocked = true;
  15717. var data = this._storage[this._controller.selectedPageId];
  15718. if (data !== undefined)
  15719. this._owner.icon = data;
  15720. else
  15721. this._owner.icon = this._default;
  15722. this._owner._gearLocked = false;
  15723. }
  15724. updateState() {
  15725. this._storage[this._controller.selectedPageId] = this._owner.icon;
  15726. }
  15727. }
  15728. fgui.GearIcon = GearIcon;
  15729. })(fgui || (fgui = {}));
  15730. (function (fgui) {
  15731. class GearLook extends fgui.GearBase {
  15732. constructor(owner) {
  15733. super(owner);
  15734. }
  15735. init() {
  15736. this._default = {
  15737. alpha: this._owner.alpha,
  15738. rotation: this._owner.rotation,
  15739. grayed: this._owner.grayed,
  15740. touchable: this._owner.touchable
  15741. };
  15742. this._storage = {};
  15743. }
  15744. addStatus(pageId, buffer) {
  15745. var gv;
  15746. if (pageId == null)
  15747. gv = this._default;
  15748. else
  15749. this._storage[pageId] = gv = {};
  15750. gv.alpha = buffer.readFloat();
  15751. gv.rotation = buffer.readFloat();
  15752. gv.grayed = buffer.readBool();
  15753. gv.touchable = buffer.readBool();
  15754. }
  15755. apply() {
  15756. var gv = this._storage[this._controller.selectedPageId];
  15757. if (!gv)
  15758. gv = this._default;
  15759. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  15760. this._owner._gearLocked = true;
  15761. this._owner.grayed = gv.grayed;
  15762. this._owner.touchable = gv.touchable;
  15763. this._owner._gearLocked = false;
  15764. if (this._tweenConfig._tweener) {
  15765. if (this._tweenConfig._tweener.endValue.x != gv.alpha || this._tweenConfig._tweener.endValue.y != gv.rotation) {
  15766. this._tweenConfig._tweener.kill(true);
  15767. this._tweenConfig._tweener = null;
  15768. }
  15769. else
  15770. return;
  15771. }
  15772. var a = gv.alpha != this._owner.alpha;
  15773. var b = gv.rotation != this._owner.rotation;
  15774. if (a || b) {
  15775. if (this._owner.checkGearController(0, this._controller))
  15776. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  15777. this._tweenConfig._tweener = fgui.GTween.to2(this._owner.alpha, this._owner.rotation, gv.alpha, gv.rotation, this._tweenConfig.duration)
  15778. .setDelay(this._tweenConfig.delay)
  15779. .setEase(this._tweenConfig.easeType)
  15780. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  15781. .setTarget(this)
  15782. .onUpdate(this.__tweenUpdate, this)
  15783. .onComplete(this.__tweenComplete, this);
  15784. }
  15785. }
  15786. else {
  15787. this._owner._gearLocked = true;
  15788. this._owner.grayed = gv.grayed;
  15789. this._owner.touchable = gv.touchable;
  15790. this._owner.alpha = gv.alpha;
  15791. this._owner.rotation = gv.rotation;
  15792. this._owner._gearLocked = false;
  15793. }
  15794. }
  15795. __tweenUpdate(tweener) {
  15796. var flag = tweener.userData;
  15797. this._owner._gearLocked = true;
  15798. if ((flag & 1) != 0)
  15799. this._owner.alpha = tweener.value.x;
  15800. if ((flag & 2) != 0)
  15801. this._owner.rotation = tweener.value.y;
  15802. this._owner._gearLocked = false;
  15803. }
  15804. __tweenComplete() {
  15805. if (this._tweenConfig._displayLockToken != 0) {
  15806. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  15807. this._tweenConfig._displayLockToken = 0;
  15808. }
  15809. this._tweenConfig._tweener = null;
  15810. }
  15811. updateState() {
  15812. var gv = this._storage[this._controller.selectedPageId];
  15813. if (!gv)
  15814. this._storage[this._controller.selectedPageId] = gv = {};
  15815. gv.alpha = this._owner.alpha;
  15816. gv.rotation = this._owner.rotation;
  15817. gv.grayed = this._owner.grayed;
  15818. gv.touchable = this._owner.touchable;
  15819. }
  15820. }
  15821. fgui.GearLook = GearLook;
  15822. })(fgui || (fgui = {}));
  15823. (function (fgui) {
  15824. class GearSize extends fgui.GearBase {
  15825. constructor(owner) {
  15826. super(owner);
  15827. }
  15828. init() {
  15829. this._default = {
  15830. width: this._owner.width,
  15831. height: this._owner.height,
  15832. scaleX: this._owner.scaleX,
  15833. scaleY: this._owner.scaleY
  15834. };
  15835. this._storage = {};
  15836. }
  15837. addStatus(pageId, buffer) {
  15838. var gv;
  15839. if (pageId == null)
  15840. gv = this._default;
  15841. else
  15842. this._storage[pageId] = gv = {};
  15843. gv.width = buffer.readInt();
  15844. gv.height = buffer.readInt();
  15845. gv.scaleX = buffer.readFloat();
  15846. gv.scaleY = buffer.readFloat();
  15847. }
  15848. apply() {
  15849. var gv = this._storage[this._controller.selectedPageId];
  15850. if (!gv)
  15851. gv = this._default;
  15852. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  15853. if (this._tweenConfig._tweener) {
  15854. if (this._tweenConfig._tweener.endValue.x != gv.width || this._tweenConfig._tweener.endValue.y != gv.height
  15855. || this._tweenConfig._tweener.endValue.z != gv.scaleX || this._tweenConfig._tweener.endValue.w != gv.scaleY) {
  15856. this._tweenConfig._tweener.kill(true);
  15857. this._tweenConfig._tweener = null;
  15858. }
  15859. else
  15860. return;
  15861. }
  15862. var a = gv.width != this._owner.width || gv.height != this._owner.height;
  15863. var b = gv.scaleX != this._owner.scaleX || gv.scaleY != this._owner.scaleY;
  15864. if (a || b) {
  15865. if (this._owner.checkGearController(0, this._controller))
  15866. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  15867. 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)
  15868. .setDelay(this._tweenConfig.delay)
  15869. .setEase(this._tweenConfig.easeType)
  15870. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  15871. .setTarget(this)
  15872. .onUpdate(this.__tweenUpdate, this)
  15873. .onComplete(this.__tweenComplete, this);
  15874. }
  15875. }
  15876. else {
  15877. this._owner._gearLocked = true;
  15878. this._owner.setSize(gv.width, gv.height, this._owner.gearXY.controller == this._controller);
  15879. this._owner.setScale(gv.scaleX, gv.scaleY);
  15880. this._owner._gearLocked = false;
  15881. }
  15882. }
  15883. __tweenUpdate(tweener) {
  15884. var flag = tweener.userData;
  15885. this._owner._gearLocked = true;
  15886. if ((flag & 1) != 0)
  15887. this._owner.setSize(tweener.value.x, tweener.value.y, this._owner.checkGearController(1, this._controller));
  15888. if ((flag & 2) != 0)
  15889. this._owner.setScale(tweener.value.z, tweener.value.w);
  15890. this._owner._gearLocked = false;
  15891. }
  15892. __tweenComplete() {
  15893. if (this._tweenConfig._displayLockToken != 0) {
  15894. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  15895. this._tweenConfig._displayLockToken = 0;
  15896. }
  15897. this._tweenConfig._tweener = null;
  15898. }
  15899. updateState() {
  15900. var gv = this._storage[this._controller.selectedPageId];
  15901. if (!gv)
  15902. this._storage[this._controller.selectedPageId] = gv = {};
  15903. gv.width = this._owner.width;
  15904. gv.height = this._owner.height;
  15905. gv.scaleX = this._owner.scaleX;
  15906. gv.scaleY = this._owner.scaleY;
  15907. }
  15908. updateFromRelations(dx, dy) {
  15909. if (this._controller == null || this._storage == null)
  15910. return;
  15911. for (var key in this._storage) {
  15912. var gv = this._storage[key];
  15913. gv.width += dx;
  15914. gv.height += dy;
  15915. }
  15916. this._default.width += dx;
  15917. this._default.height += dy;
  15918. this.updateState();
  15919. }
  15920. }
  15921. fgui.GearSize = GearSize;
  15922. })(fgui || (fgui = {}));
  15923. (function (fgui) {
  15924. class GearText extends fgui.GearBase {
  15925. constructor(owner) {
  15926. super(owner);
  15927. }
  15928. init() {
  15929. this._default = this._owner.text;
  15930. this._storage = {};
  15931. }
  15932. addStatus(pageId, buffer) {
  15933. if (pageId == null)
  15934. this._default = buffer.readS();
  15935. else
  15936. this._storage[pageId] = buffer.readS();
  15937. }
  15938. apply() {
  15939. this._owner._gearLocked = true;
  15940. var data = this._storage[this._controller.selectedPageId];
  15941. if (data !== undefined)
  15942. this._owner.text = data;
  15943. else
  15944. this._owner.text = this._default;
  15945. this._owner._gearLocked = false;
  15946. }
  15947. updateState() {
  15948. this._storage[this._controller.selectedPageId] = this._owner.text;
  15949. }
  15950. }
  15951. fgui.GearText = GearText;
  15952. })(fgui || (fgui = {}));
  15953. (function (fgui) {
  15954. class GearXY extends fgui.GearBase {
  15955. constructor(owner) {
  15956. super(owner);
  15957. }
  15958. init() {
  15959. this._default = {
  15960. x: this._owner.x,
  15961. y: this._owner.y,
  15962. px: this._owner.x / this._owner.parent.width,
  15963. py: this._owner.y / this._owner.parent.height
  15964. };
  15965. this._storage = {};
  15966. }
  15967. addStatus(pageId, buffer) {
  15968. var gv;
  15969. if (pageId == null)
  15970. gv = this._default;
  15971. else
  15972. this._storage[pageId] = gv = {};
  15973. gv.x = buffer.readInt();
  15974. gv.y = buffer.readInt();
  15975. }
  15976. addExtStatus(pageId, buffer) {
  15977. var gv;
  15978. if (pageId == null)
  15979. gv = this._default;
  15980. else
  15981. gv = this._storage[pageId];
  15982. gv.px = buffer.readFloat();
  15983. gv.py = buffer.readFloat();
  15984. }
  15985. apply() {
  15986. var gv = this._storage[this._controller.selectedPageId];
  15987. if (!gv)
  15988. gv = this._default;
  15989. var ex;
  15990. var ey;
  15991. if (this.positionsInPercent && this._owner.parent) {
  15992. ex = gv.px * this._owner.parent.width;
  15993. ey = gv.py * this._owner.parent.height;
  15994. }
  15995. else {
  15996. ex = gv.x;
  15997. ey = gv.y;
  15998. }
  15999. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  16000. if (this._tweenConfig._tweener) {
  16001. if (this._tweenConfig._tweener.endValue.x != ex || this._tweenConfig._tweener.endValue.y != ey) {
  16002. this._tweenConfig._tweener.kill(true);
  16003. this._tweenConfig._tweener = null;
  16004. }
  16005. else
  16006. return;
  16007. }
  16008. var ox = this._owner.x;
  16009. var oy = this._owner.y;
  16010. if (ox != ex || oy != ey) {
  16011. if (this._owner.checkGearController(0, this._controller))
  16012. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  16013. this._tweenConfig._tweener = fgui.GTween.to2(ox, oy, ex, ey, this._tweenConfig.duration)
  16014. .setDelay(this._tweenConfig.delay)
  16015. .setEase(this._tweenConfig.easeType)
  16016. .setTarget(this)
  16017. .onUpdate(this.__tweenUpdate, this)
  16018. .onComplete(this.__tweenComplete, this);
  16019. }
  16020. }
  16021. else {
  16022. this._owner._gearLocked = true;
  16023. this._owner.setPosition(ex, ey);
  16024. this._owner._gearLocked = false;
  16025. }
  16026. }
  16027. __tweenUpdate(tweener) {
  16028. this._owner._gearLocked = true;
  16029. this._owner.setPosition(tweener.value.x, tweener.value.y);
  16030. this._owner._gearLocked = false;
  16031. }
  16032. __tweenComplete() {
  16033. if (this._tweenConfig._displayLockToken != 0) {
  16034. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  16035. this._tweenConfig._displayLockToken = 0;
  16036. }
  16037. this._tweenConfig._tweener = null;
  16038. }
  16039. updateState() {
  16040. var gv = this._storage[this._controller.selectedPageId];
  16041. if (!gv)
  16042. this._storage[this._controller.selectedPageId] = gv = {};
  16043. gv.x = this._owner.x;
  16044. gv.y = this._owner.y;
  16045. gv.px = this._owner.x / this._owner.parent.width;
  16046. gv.py = this._owner.y / this._owner.parent.height;
  16047. }
  16048. updateFromRelations(dx, dy) {
  16049. if (this._controller == null || this._storage == null || this.positionsInPercent)
  16050. return;
  16051. for (var key in this._storage) {
  16052. var pt = this._storage[key];
  16053. pt.x += dx;
  16054. pt.y += dy;
  16055. }
  16056. this._default.x += dx;
  16057. this._default.y += dy;
  16058. this.updateState();
  16059. }
  16060. }
  16061. fgui.GearXY = GearXY;
  16062. })(fgui || (fgui = {}));
  16063. (function (fgui) {
  16064. const _PiOver2 = Math.PI * 0.5;
  16065. const _TwoPi = Math.PI * 2;
  16066. function evaluateEase(easeType, time, duration, overshootOrAmplitude, period) {
  16067. switch (easeType) {
  16068. case fgui.EaseType.Linear:
  16069. return time / duration;
  16070. case fgui.EaseType.SineIn:
  16071. return -Math.cos(time / duration * _PiOver2) + 1;
  16072. case fgui.EaseType.SineOut:
  16073. return Math.sin(time / duration * _PiOver2);
  16074. case fgui.EaseType.SineInOut:
  16075. return -0.5 * (Math.cos(Math.PI * time / duration) - 1);
  16076. case fgui.EaseType.QuadIn:
  16077. return (time /= duration) * time;
  16078. case fgui.EaseType.QuadOut:
  16079. return -(time /= duration) * (time - 2);
  16080. case fgui.EaseType.QuadInOut:
  16081. if ((time /= duration * 0.5) < 1)
  16082. return 0.5 * time * time;
  16083. return -0.5 * ((--time) * (time - 2) - 1);
  16084. case fgui.EaseType.CubicIn:
  16085. return (time /= duration) * time * time;
  16086. case fgui.EaseType.CubicOut:
  16087. return ((time = time / duration - 1) * time * time + 1);
  16088. case fgui.EaseType.CubicInOut:
  16089. if ((time /= duration * 0.5) < 1)
  16090. return 0.5 * time * time * time;
  16091. return 0.5 * ((time -= 2) * time * time + 2);
  16092. case fgui.EaseType.QuartIn:
  16093. return (time /= duration) * time * time * time;
  16094. case fgui.EaseType.QuartOut:
  16095. return -((time = time / duration - 1) * time * time * time - 1);
  16096. case fgui.EaseType.QuartInOut:
  16097. if ((time /= duration * 0.5) < 1)
  16098. return 0.5 * time * time * time * time;
  16099. return -0.5 * ((time -= 2) * time * time * time - 2);
  16100. case fgui.EaseType.QuintIn:
  16101. return (time /= duration) * time * time * time * time;
  16102. case fgui.EaseType.QuintOut:
  16103. return ((time = time / duration - 1) * time * time * time * time + 1);
  16104. case fgui.EaseType.QuintInOut:
  16105. if ((time /= duration * 0.5) < 1)
  16106. return 0.5 * time * time * time * time * time;
  16107. return 0.5 * ((time -= 2) * time * time * time * time + 2);
  16108. case fgui.EaseType.ExpoIn:
  16109. return (time == 0) ? 0 : Math.pow(2, 10 * (time / duration - 1));
  16110. case fgui.EaseType.ExpoOut:
  16111. if (time == duration)
  16112. return 1;
  16113. return (-Math.pow(2, -10 * time / duration) + 1);
  16114. case fgui.EaseType.ExpoInOut:
  16115. if (time == 0)
  16116. return 0;
  16117. if (time == duration)
  16118. return 1;
  16119. if ((time /= duration * 0.5) < 1)
  16120. return 0.5 * Math.pow(2, 10 * (time - 1));
  16121. return 0.5 * (-Math.pow(2, -10 * --time) + 2);
  16122. case fgui.EaseType.CircIn:
  16123. return -(Math.sqrt(1 - (time /= duration) * time) - 1);
  16124. case fgui.EaseType.CircOut:
  16125. return Math.sqrt(1 - (time = time / duration - 1) * time);
  16126. case fgui.EaseType.CircInOut:
  16127. if ((time /= duration * 0.5) < 1)
  16128. return -0.5 * (Math.sqrt(1 - time * time) - 1);
  16129. return 0.5 * (Math.sqrt(1 - (time -= 2) * time) + 1);
  16130. case fgui.EaseType.ElasticIn:
  16131. var s0;
  16132. if (time == 0)
  16133. return 0;
  16134. if ((time /= duration) == 1)
  16135. return 1;
  16136. if (period == 0)
  16137. period = duration * 0.3;
  16138. if (overshootOrAmplitude < 1) {
  16139. overshootOrAmplitude = 1;
  16140. s0 = period / 4;
  16141. }
  16142. else
  16143. s0 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  16144. return -(overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s0) * _TwoPi / period));
  16145. case fgui.EaseType.ElasticOut:
  16146. var s1;
  16147. if (time == 0)
  16148. return 0;
  16149. if ((time /= duration) == 1)
  16150. return 1;
  16151. if (period == 0)
  16152. period = duration * 0.3;
  16153. if (overshootOrAmplitude < 1) {
  16154. overshootOrAmplitude = 1;
  16155. s1 = period / 4;
  16156. }
  16157. else
  16158. s1 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  16159. return (overshootOrAmplitude * Math.pow(2, -10 * time) * Math.sin((time * duration - s1) * _TwoPi / period) + 1);
  16160. case fgui.EaseType.ElasticInOut:
  16161. var s;
  16162. if (time == 0)
  16163. return 0;
  16164. if ((time /= duration * 0.5) == 2)
  16165. return 1;
  16166. if (period == 0)
  16167. period = duration * (0.3 * 1.5);
  16168. if (overshootOrAmplitude < 1) {
  16169. overshootOrAmplitude = 1;
  16170. s = period / 4;
  16171. }
  16172. else
  16173. s = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  16174. if (time < 1)
  16175. return -0.5 * (overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period));
  16176. return overshootOrAmplitude * Math.pow(2, -10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period) * 0.5 + 1;
  16177. case fgui.EaseType.BackIn:
  16178. return (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude);
  16179. case fgui.EaseType.BackOut:
  16180. return ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);
  16181. case fgui.EaseType.BackInOut:
  16182. if ((time /= duration * 0.5) < 1)
  16183. return 0.5 * (time * time * (((overshootOrAmplitude *= (1.525)) + 1) * time - overshootOrAmplitude));
  16184. return 0.5 * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525)) + 1) * time + overshootOrAmplitude) + 2);
  16185. case fgui.EaseType.BounceIn:
  16186. return bounce_easeIn(time, duration);
  16187. case fgui.EaseType.BounceOut:
  16188. return bounce_easeOut(time, duration);
  16189. case fgui.EaseType.BounceInOut:
  16190. return bounce_easeInOut(time, duration);
  16191. default:
  16192. return -(time /= duration) * (time - 2);
  16193. }
  16194. }
  16195. fgui.evaluateEase = evaluateEase;
  16196. function bounce_easeIn(time, duration) {
  16197. return 1 - bounce_easeOut(duration - time, duration);
  16198. }
  16199. function bounce_easeOut(time, duration) {
  16200. if ((time /= duration) < (1 / 2.75)) {
  16201. return (7.5625 * time * time);
  16202. }
  16203. if (time < (2 / 2.75)) {
  16204. return (7.5625 * (time -= (1.5 / 2.75)) * time + 0.75);
  16205. }
  16206. if (time < (2.5 / 2.75)) {
  16207. return (7.5625 * (time -= (2.25 / 2.75)) * time + 0.9375);
  16208. }
  16209. return (7.5625 * (time -= (2.625 / 2.75)) * time + 0.984375);
  16210. }
  16211. function bounce_easeInOut(time, duration) {
  16212. if (time < duration * 0.5) {
  16213. return bounce_easeIn(time * 2, duration) * 0.5;
  16214. }
  16215. return bounce_easeOut(time * 2 - duration, duration) * 0.5 + 0.5;
  16216. }
  16217. })(fgui || (fgui = {}));
  16218. (function (fgui) {
  16219. class EaseType {
  16220. }
  16221. EaseType.Linear = 0;
  16222. EaseType.SineIn = 1;
  16223. EaseType.SineOut = 2;
  16224. EaseType.SineInOut = 3;
  16225. EaseType.QuadIn = 4;
  16226. EaseType.QuadOut = 5;
  16227. EaseType.QuadInOut = 6;
  16228. EaseType.CubicIn = 7;
  16229. EaseType.CubicOut = 8;
  16230. EaseType.CubicInOut = 9;
  16231. EaseType.QuartIn = 10;
  16232. EaseType.QuartOut = 11;
  16233. EaseType.QuartInOut = 12;
  16234. EaseType.QuintIn = 13;
  16235. EaseType.QuintOut = 14;
  16236. EaseType.QuintInOut = 15;
  16237. EaseType.ExpoIn = 16;
  16238. EaseType.ExpoOut = 17;
  16239. EaseType.ExpoInOut = 18;
  16240. EaseType.CircIn = 19;
  16241. EaseType.CircOut = 20;
  16242. EaseType.CircInOut = 21;
  16243. EaseType.ElasticIn = 22;
  16244. EaseType.ElasticOut = 23;
  16245. EaseType.ElasticInOut = 24;
  16246. EaseType.BackIn = 25;
  16247. EaseType.BackOut = 26;
  16248. EaseType.BackInOut = 27;
  16249. EaseType.BounceIn = 28;
  16250. EaseType.BounceOut = 29;
  16251. EaseType.BounceInOut = 30;
  16252. EaseType.Custom = 31;
  16253. fgui.EaseType = EaseType;
  16254. })(fgui || (fgui = {}));
  16255. (function (fgui) {
  16256. class GPath {
  16257. constructor() {
  16258. this._segments = new Array();
  16259. this._points = new Array();
  16260. }
  16261. get length() {
  16262. return this._fullLength;
  16263. }
  16264. create(pt1, pt2, pt3, pt4) {
  16265. var points;
  16266. if (Array.isArray(pt1))
  16267. points = pt1;
  16268. else {
  16269. points = new Array();
  16270. points.push(pt1);
  16271. points.push(pt2);
  16272. if (pt3)
  16273. points.push(pt3);
  16274. if (pt4)
  16275. points.push(pt4);
  16276. }
  16277. this._segments.length = 0;
  16278. this._points.length = 0;
  16279. this._fullLength = 0;
  16280. var cnt = points.length;
  16281. if (cnt == 0)
  16282. return;
  16283. var splinePoints = s_points;
  16284. splinePoints.length = 0;
  16285. var prev = points[0];
  16286. if (prev.curveType == fgui.CurveType.CRSpline)
  16287. splinePoints.push(new cc.Vec2(prev.x, prev.y));
  16288. for (var i = 1; i < cnt; i++) {
  16289. var current = points[i];
  16290. if (prev.curveType != fgui.CurveType.CRSpline) {
  16291. var seg = {};
  16292. seg.type = prev.curveType;
  16293. seg.ptStart = this._points.length;
  16294. if (prev.curveType == fgui.CurveType.Straight) {
  16295. seg.ptCount = 2;
  16296. this._points.push(new cc.Vec2(prev.x, prev.y));
  16297. this._points.push(new cc.Vec2(current.x, current.y));
  16298. }
  16299. else if (prev.curveType == fgui.CurveType.Bezier) {
  16300. seg.ptCount = 3;
  16301. this._points.push(new cc.Vec2(prev.x, prev.y));
  16302. this._points.push(new cc.Vec2(current.x, current.y));
  16303. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  16304. }
  16305. else if (prev.curveType == fgui.CurveType.CubicBezier) {
  16306. seg.ptCount = 4;
  16307. this._points.push(new cc.Vec2(prev.x, prev.y));
  16308. this._points.push(new cc.Vec2(current.x, current.y));
  16309. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  16310. this._points.push(new cc.Vec2(prev.control2_x, prev.control2_y));
  16311. }
  16312. seg.length = fgui.ToolSet.distance(prev.x, prev.y, current.x, current.y);
  16313. this._fullLength += seg.length;
  16314. this._segments.push(seg);
  16315. }
  16316. if (current.curveType != fgui.CurveType.CRSpline) {
  16317. if (splinePoints.length > 0) {
  16318. splinePoints.push(new cc.Vec2(current.x, current.y));
  16319. this.createSplineSegment();
  16320. }
  16321. }
  16322. else
  16323. splinePoints.push(new cc.Vec2(current.x, current.y));
  16324. prev = current;
  16325. }
  16326. if (splinePoints.length > 1)
  16327. this.createSplineSegment();
  16328. }
  16329. createSplineSegment() {
  16330. var splinePoints = s_points;
  16331. var cnt = splinePoints.length;
  16332. splinePoints.splice(0, 0, splinePoints[0]);
  16333. splinePoints.push(splinePoints[cnt]);
  16334. splinePoints.push(splinePoints[cnt]);
  16335. cnt += 3;
  16336. var seg = {};
  16337. seg.type = fgui.CurveType.CRSpline;
  16338. seg.ptStart = this._points.length;
  16339. seg.ptCount = cnt;
  16340. this._points = this._points.concat(splinePoints);
  16341. seg.length = 0;
  16342. for (var i = 1; i < cnt; i++) {
  16343. seg.length += fgui.ToolSet.distance(splinePoints[i - 1].x, splinePoints[i - 1].y, splinePoints[i].x, splinePoints[i].y);
  16344. }
  16345. this._fullLength += seg.length;
  16346. this._segments.push(seg);
  16347. splinePoints.length = 0;
  16348. }
  16349. clear() {
  16350. this._segments.length = 0;
  16351. this._points.length = 0;
  16352. }
  16353. getPointAt(t, result) {
  16354. if (!result)
  16355. result = new cc.Vec2();
  16356. else
  16357. result.x = result.y = 0;
  16358. t = fgui.ToolSet.clamp01(t);
  16359. var cnt = this._segments.length;
  16360. if (cnt == 0) {
  16361. return result;
  16362. }
  16363. var seg;
  16364. if (t == 1) {
  16365. seg = this._segments[cnt - 1];
  16366. if (seg.type == fgui.CurveType.Straight) {
  16367. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  16368. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  16369. return result;
  16370. }
  16371. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  16372. return this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  16373. else
  16374. return this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  16375. }
  16376. var len = t * this._fullLength;
  16377. for (var i = 0; i < cnt; i++) {
  16378. seg = this._segments[i];
  16379. len -= seg.length;
  16380. if (len < 0) {
  16381. t = 1 + len / seg.length;
  16382. if (seg.type == fgui.CurveType.Straight) {
  16383. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  16384. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  16385. }
  16386. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  16387. result = this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  16388. else
  16389. result = this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  16390. break;
  16391. }
  16392. }
  16393. return result;
  16394. }
  16395. get segmentCount() {
  16396. return this._segments.length;
  16397. }
  16398. getAnchorsInSegment(segmentIndex, points) {
  16399. if (points == null)
  16400. points = new Array();
  16401. var seg = this._segments[segmentIndex];
  16402. for (var i = 0; i < seg.ptCount; i++)
  16403. points.push(new cc.Vec2(this._points[seg.ptStart + i].x, this._points[seg.ptStart + i].y));
  16404. return points;
  16405. }
  16406. getPointsInSegment(segmentIndex, t0, t1, points, ts, pointDensity) {
  16407. if (points == null)
  16408. points = new Array();
  16409. if (!pointDensity || isNaN(pointDensity))
  16410. pointDensity = 0.1;
  16411. if (ts)
  16412. ts.push(t0);
  16413. var seg = this._segments[segmentIndex];
  16414. if (seg.type == fgui.CurveType.Straight) {
  16415. 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)));
  16416. 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)));
  16417. }
  16418. else {
  16419. var func;
  16420. if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  16421. func = this.onBezierCurve;
  16422. else
  16423. func = this.onCRSplineCurve;
  16424. points.push(func.call(this, seg.ptStart, seg.ptCount, t0, new cc.Vec2()));
  16425. var SmoothAmount = Math.min(seg.length * pointDensity, 50);
  16426. for (var j = 0; j <= SmoothAmount; j++) {
  16427. var t = j / SmoothAmount;
  16428. if (t > t0 && t < t1) {
  16429. points.push(func.call(this, seg.ptStart, seg.ptCount, t, new cc.Vec2()));
  16430. if (ts != null)
  16431. ts.push(t);
  16432. }
  16433. }
  16434. points.push(func.call(this, seg.ptStart, seg.ptCount, t1, new cc.Vec2()));
  16435. }
  16436. if (ts != null)
  16437. ts.push(t1);
  16438. return points;
  16439. }
  16440. getAllPoints(points, ts, pointDensity) {
  16441. if (points == null)
  16442. points = new Array();
  16443. if (!pointDensity || isNaN(pointDensity))
  16444. pointDensity = 0.1;
  16445. var cnt = this._segments.length;
  16446. for (var i = 0; i < cnt; i++)
  16447. this.getPointsInSegment(i, 0, 1, points, ts, pointDensity);
  16448. return points;
  16449. }
  16450. onCRSplineCurve(ptStart, ptCount, t, result) {
  16451. var adjustedIndex = Math.floor(t * (ptCount - 4)) + ptStart;
  16452. var p0x = this._points[adjustedIndex].x;
  16453. var p0y = this._points[adjustedIndex].y;
  16454. var p1x = this._points[adjustedIndex + 1].x;
  16455. var p1y = this._points[adjustedIndex + 1].y;
  16456. var p2x = this._points[adjustedIndex + 2].x;
  16457. var p2y = this._points[adjustedIndex + 2].y;
  16458. var p3x = this._points[adjustedIndex + 3].x;
  16459. var p3y = this._points[adjustedIndex + 3].y;
  16460. var adjustedT = (t == 1) ? 1 : fgui.ToolSet.repeat(t * (ptCount - 4), 1);
  16461. var t0 = ((-adjustedT + 2) * adjustedT - 1) * adjustedT * 0.5;
  16462. var t1 = (((3 * adjustedT - 5) * adjustedT) * adjustedT + 2) * 0.5;
  16463. var t2 = ((-3 * adjustedT + 4) * adjustedT + 1) * adjustedT * 0.5;
  16464. var t3 = ((adjustedT - 1) * adjustedT * adjustedT) * 0.5;
  16465. result.x = p0x * t0 + p1x * t1 + p2x * t2 + p3x * t3;
  16466. result.y = p0y * t0 + p1y * t1 + p2y * t2 + p3y * t3;
  16467. return result;
  16468. }
  16469. onBezierCurve(ptStart, ptCount, t, result) {
  16470. var t2 = 1 - t;
  16471. var p0x = this._points[ptStart].x;
  16472. var p0y = this._points[ptStart].y;
  16473. var p1x = this._points[ptStart + 1].x;
  16474. var p1y = this._points[ptStart + 1].y;
  16475. var cp0x = this._points[ptStart + 2].x;
  16476. var cp0y = this._points[ptStart + 2].y;
  16477. if (ptCount == 4) {
  16478. var cp1x = this._points[ptStart + 3].x;
  16479. var cp1y = this._points[ptStart + 3].y;
  16480. result.x = t2 * t2 * t2 * p0x + 3 * t2 * t2 * t * cp0x + 3 * t2 * t * t * cp1x + t * t * t * p1x;
  16481. result.y = t2 * t2 * t2 * p0y + 3 * t2 * t2 * t * cp0y + 3 * t2 * t * t * cp1y + t * t * t * p1y;
  16482. }
  16483. else {
  16484. result.x = t2 * t2 * p0x + 2 * t2 * t * cp0x + t * t * p1x;
  16485. result.y = t2 * t2 * p0y + 2 * t2 * t * cp0y + t * t * p1y;
  16486. }
  16487. return result;
  16488. }
  16489. }
  16490. fgui.GPath = GPath;
  16491. var s_points = new Array();
  16492. })(fgui || (fgui = {}));
  16493. (function (fgui) {
  16494. let CurveType;
  16495. (function (CurveType) {
  16496. CurveType[CurveType["CRSpline"] = 0] = "CRSpline";
  16497. CurveType[CurveType["Bezier"] = 1] = "Bezier";
  16498. CurveType[CurveType["CubicBezier"] = 2] = "CubicBezier";
  16499. CurveType[CurveType["Straight"] = 3] = "Straight";
  16500. })(CurveType = fgui.CurveType || (fgui.CurveType = {}));
  16501. class GPathPoint {
  16502. constructor() {
  16503. this.x = 0;
  16504. this.y = 0;
  16505. this.control1_x = 0;
  16506. this.control1_y = 0;
  16507. this.control2_x = 0;
  16508. this.control2_y = 0;
  16509. this.curveType = 0;
  16510. }
  16511. static newPoint(x = 0, y = 0, curveType = 0) {
  16512. var pt = new GPathPoint();
  16513. pt.x = x;
  16514. pt.y = y;
  16515. pt.control1_x = 0;
  16516. pt.control1_y = 0;
  16517. pt.control2_x = 0;
  16518. pt.control2_y = 0;
  16519. pt.curveType = curveType;
  16520. return pt;
  16521. }
  16522. static newBezierPoint(x = 0, y = 0, control1_x = 0, control1_y = 0) {
  16523. var pt = new GPathPoint();
  16524. pt.x = x;
  16525. pt.y = y;
  16526. pt.control1_x = control1_x;
  16527. pt.control1_y = control1_y;
  16528. pt.control2_x = 0;
  16529. pt.control2_y = 0;
  16530. pt.curveType = CurveType.Bezier;
  16531. return pt;
  16532. }
  16533. static newCubicBezierPoint(x = 0, y = 0, control1_x = 0, control1_y = 0, control2_x = 0, control2_y = 0) {
  16534. var pt = new GPathPoint();
  16535. pt.x = x;
  16536. pt.y = y;
  16537. pt.control1_x = control1_x;
  16538. pt.control1_y = control1_y;
  16539. pt.control2_x = control2_x;
  16540. pt.control2_y = control2_y;
  16541. pt.curveType = CurveType.CubicBezier;
  16542. return pt;
  16543. }
  16544. clone() {
  16545. var ret = new GPathPoint();
  16546. ret.x = this.x;
  16547. ret.y = this.y;
  16548. ret.control1_x = this.control1_x;
  16549. ret.control1_y = this.control1_y;
  16550. ret.control2_x = this.control2_x;
  16551. ret.control2_y = this.control2_y;
  16552. ret.curveType = this.curveType;
  16553. return ret;
  16554. }
  16555. }
  16556. fgui.GPathPoint = GPathPoint;
  16557. })(fgui || (fgui = {}));
  16558. (function (fgui) {
  16559. class GTween {
  16560. static to(start, end, duration) {
  16561. return fgui.TweenManager.createTween()._to(start, end, duration);
  16562. }
  16563. static to2(start, start2, end, end2, duration) {
  16564. return fgui.TweenManager.createTween()._to2(start, start2, end, end2, duration);
  16565. }
  16566. static to3(start, start2, start3, end, end2, end3, duration) {
  16567. return fgui.TweenManager.createTween()._to3(start, start2, start3, end, end2, end3, duration);
  16568. }
  16569. static to4(start, start2, start3, start4, end, end2, end3, end4, duration) {
  16570. return fgui.TweenManager.createTween()._to4(start, start2, start3, start4, end, end2, end3, end4, duration);
  16571. }
  16572. static toColor(start, end, duration) {
  16573. return fgui.TweenManager.createTween()._toColor(start, end, duration);
  16574. }
  16575. static delayedCall(delay) {
  16576. return fgui.TweenManager.createTween().setDelay(delay);
  16577. }
  16578. static shake(startX, startY, amplitude, duration) {
  16579. return fgui.TweenManager.createTween()._shake(startX, startY, amplitude, duration);
  16580. }
  16581. static isTweening(target, propType) {
  16582. return fgui.TweenManager.isTweening(target, propType);
  16583. }
  16584. static kill(target, complete, propType) {
  16585. fgui.TweenManager.killTweens(target, complete, propType);
  16586. }
  16587. static getTween(target, propType) {
  16588. return fgui.TweenManager.getTween(target, propType);
  16589. }
  16590. }
  16591. GTween.catchCallbackExceptions = true;
  16592. fgui.GTween = GTween;
  16593. })(fgui || (fgui = {}));
  16594. (function (fgui) {
  16595. class GTweener {
  16596. constructor() {
  16597. this._startValue = new fgui.TweenValue();
  16598. this._endValue = new fgui.TweenValue();
  16599. this._value = new fgui.TweenValue();
  16600. this._deltaValue = new fgui.TweenValue();
  16601. this._reset();
  16602. }
  16603. setDelay(value) {
  16604. this._delay = value;
  16605. return this;
  16606. }
  16607. get delay() {
  16608. return this._delay;
  16609. }
  16610. setDuration(value) {
  16611. this._duration = value;
  16612. return this;
  16613. }
  16614. get duration() {
  16615. return this._duration;
  16616. }
  16617. setBreakpoint(value) {
  16618. this._breakpoint = value;
  16619. return this;
  16620. }
  16621. setEase(value) {
  16622. this._easeType = value;
  16623. return this;
  16624. }
  16625. setEasePeriod(value) {
  16626. this._easePeriod = value;
  16627. return this;
  16628. }
  16629. setEaseOvershootOrAmplitude(value) {
  16630. this._easeOvershootOrAmplitude = value;
  16631. return this;
  16632. }
  16633. setRepeat(repeat, yoyo) {
  16634. this._repeat = repeat;
  16635. this._yoyo = yoyo;
  16636. return this;
  16637. }
  16638. get repeat() {
  16639. return this._repeat;
  16640. }
  16641. setTimeScale(value) {
  16642. this._timeScale = value;
  16643. return this;
  16644. }
  16645. setSnapping(value) {
  16646. this._snapping = value;
  16647. return this;
  16648. }
  16649. setTarget(value, propType) {
  16650. this._target = value;
  16651. this._propType = propType;
  16652. if (value instanceof fgui.GObject)
  16653. this._node = value.node;
  16654. else if (value instanceof cc.Node)
  16655. this._node = value;
  16656. return this;
  16657. }
  16658. get target() {
  16659. return this._target;
  16660. }
  16661. setPath(value) {
  16662. this._path = value;
  16663. return this;
  16664. }
  16665. setUserData(value) {
  16666. this._userData = value;
  16667. return this;
  16668. }
  16669. get userData() {
  16670. return this._userData;
  16671. }
  16672. onUpdate(callback, target) {
  16673. this._onUpdate = callback;
  16674. this._onUpdateCaller = target;
  16675. return this;
  16676. }
  16677. onStart(callback, target) {
  16678. this._onStart = callback;
  16679. this._onStartCaller = target;
  16680. return this;
  16681. }
  16682. onComplete(callback, target) {
  16683. this._onComplete = callback;
  16684. this._onCompleteCaller = target;
  16685. return this;
  16686. }
  16687. get startValue() {
  16688. return this._startValue;
  16689. }
  16690. get endValue() {
  16691. return this._endValue;
  16692. }
  16693. get value() {
  16694. return this._value;
  16695. }
  16696. get deltaValue() {
  16697. return this._deltaValue;
  16698. }
  16699. get normalizedTime() {
  16700. return this._normalizedTime;
  16701. }
  16702. get completed() {
  16703. return this._ended != 0;
  16704. }
  16705. get allCompleted() {
  16706. return this._ended == 1;
  16707. }
  16708. setPaused(paused) {
  16709. this._paused = paused;
  16710. return this;
  16711. }
  16712. seek(time) {
  16713. if (this._killed)
  16714. return;
  16715. this._elapsedTime = time;
  16716. if (this._elapsedTime < this._delay) {
  16717. if (this._started)
  16718. this._elapsedTime = this._delay;
  16719. else
  16720. return;
  16721. }
  16722. this.update();
  16723. }
  16724. kill(complete) {
  16725. if (this._killed)
  16726. return;
  16727. if (complete) {
  16728. if (this._ended == 0) {
  16729. if (this._breakpoint >= 0)
  16730. this._elapsedTime = this._delay + this._breakpoint;
  16731. else if (this._repeat >= 0)
  16732. this._elapsedTime = this._delay + this._duration * (this._repeat + 1);
  16733. else
  16734. this._elapsedTime = this._delay + this._duration * 2;
  16735. this.update();
  16736. }
  16737. this.callCompleteCallback();
  16738. }
  16739. this._killed = true;
  16740. }
  16741. _to(start, end, duration) {
  16742. this._valueSize = 1;
  16743. this._startValue.x = start;
  16744. this._endValue.x = end;
  16745. this._duration = duration;
  16746. return this;
  16747. }
  16748. _to2(start, start2, end, end2, duration) {
  16749. this._valueSize = 2;
  16750. this._startValue.x = start;
  16751. this._endValue.x = end;
  16752. this._startValue.y = start2;
  16753. this._endValue.y = end2;
  16754. this._duration = duration;
  16755. return this;
  16756. }
  16757. _to3(start, start2, start3, end, end2, end3, duration) {
  16758. this._valueSize = 3;
  16759. this._startValue.x = start;
  16760. this._endValue.x = end;
  16761. this._startValue.y = start2;
  16762. this._endValue.y = end2;
  16763. this._startValue.z = start3;
  16764. this._endValue.z = end3;
  16765. this._duration = duration;
  16766. return this;
  16767. }
  16768. _to4(start, start2, start3, start4, end, end2, end3, end4, duration) {
  16769. this._valueSize = 4;
  16770. this._startValue.x = start;
  16771. this._endValue.x = end;
  16772. this._startValue.y = start2;
  16773. this._endValue.y = end2;
  16774. this._startValue.z = start3;
  16775. this._endValue.z = end3;
  16776. this._startValue.w = start4;
  16777. this._endValue.w = end4;
  16778. this._duration = duration;
  16779. return this;
  16780. }
  16781. _toColor(start, end, duration) {
  16782. this._valueSize = 4;
  16783. this._startValue.color = start;
  16784. this._endValue.color = end;
  16785. this._duration = duration;
  16786. return this;
  16787. }
  16788. _shake(startX, startY, amplitude, duration) {
  16789. this._valueSize = 5;
  16790. this._startValue.x = startX;
  16791. this._startValue.y = startY;
  16792. this._startValue.w = amplitude;
  16793. this._duration = duration;
  16794. return this;
  16795. }
  16796. _init() {
  16797. this._delay = 0;
  16798. this._duration = 0;
  16799. this._breakpoint = -1;
  16800. this._easeType = fgui.EaseType.QuadOut;
  16801. this._timeScale = 1;
  16802. this._easePeriod = 0;
  16803. this._easeOvershootOrAmplitude = 1.70158;
  16804. this._snapping = false;
  16805. this._repeat = 0;
  16806. this._yoyo = false;
  16807. this._valueSize = 0;
  16808. this._started = false;
  16809. this._paused = false;
  16810. this._killed = false;
  16811. this._elapsedTime = 0;
  16812. this._normalizedTime = 0;
  16813. this._ended = 0;
  16814. }
  16815. _reset() {
  16816. this._target = null;
  16817. this._propType = null;
  16818. this._userData = null;
  16819. this._node = null;
  16820. this._path = null;
  16821. this._onStart = this._onUpdate = this._onComplete = null;
  16822. this._onStartCaller = this._onUpdateCaller = this._onCompleteCaller = null;
  16823. }
  16824. _update(dt) {
  16825. if (this._node && !cc.isValid(this._node)) {
  16826. this._killed = true;
  16827. return;
  16828. }
  16829. if (this._timeScale != 1)
  16830. dt *= this._timeScale;
  16831. if (dt == 0)
  16832. return;
  16833. if (this._ended != 0) {
  16834. this.callCompleteCallback();
  16835. this._killed = true;
  16836. return;
  16837. }
  16838. this._elapsedTime += dt;
  16839. this.update();
  16840. if (this._ended != 0) {
  16841. if (!this._killed) {
  16842. this.callCompleteCallback();
  16843. this._killed = true;
  16844. }
  16845. }
  16846. }
  16847. update() {
  16848. this._ended = 0;
  16849. if (this._valueSize == 0) {
  16850. if (this._elapsedTime >= this._delay + this._duration)
  16851. this._ended = 1;
  16852. return;
  16853. }
  16854. if (!this._started) {
  16855. if (this._elapsedTime < this._delay)
  16856. return;
  16857. this._started = true;
  16858. this.callStartCallback();
  16859. if (this._killed)
  16860. return;
  16861. }
  16862. var reversed = false;
  16863. var tt = this._elapsedTime - this._delay;
  16864. if (this._breakpoint >= 0 && tt >= this._breakpoint) {
  16865. tt = this._breakpoint;
  16866. this._ended = 2;
  16867. }
  16868. if (this._repeat != 0) {
  16869. var round = Math.floor(tt / this._duration);
  16870. tt -= this._duration * round;
  16871. if (this._yoyo)
  16872. reversed = round % 2 == 1;
  16873. if (this._repeat > 0 && this._repeat - round < 0) {
  16874. if (this._yoyo)
  16875. reversed = this._repeat % 2 == 1;
  16876. tt = this._duration;
  16877. this._ended = 1;
  16878. }
  16879. }
  16880. else if (tt >= this._duration) {
  16881. tt = this._duration;
  16882. this._ended = 1;
  16883. }
  16884. this._normalizedTime = fgui.evaluateEase(this._easeType, reversed ? (this._duration - tt) : tt, this._duration, this._easeOvershootOrAmplitude, this._easePeriod);
  16885. this._value.setZero();
  16886. this._deltaValue.setZero();
  16887. if (this._valueSize == 5) {
  16888. if (this._ended == 0) {
  16889. var r = this._startValue.w * (1 - this._normalizedTime);
  16890. var rx = r * (Math.random() > 0.5 ? 1 : -1);
  16891. var ry = r * (Math.random() > 0.5 ? 1 : -1);
  16892. this._deltaValue.x = rx;
  16893. this._deltaValue.y = ry;
  16894. this._value.x = this._startValue.x + rx;
  16895. this._value.y = this._startValue.y + ry;
  16896. }
  16897. else {
  16898. this._value.x = this._startValue.x;
  16899. this._value.y = this._startValue.y;
  16900. }
  16901. }
  16902. else if (this._path) {
  16903. var pt = s_vec2;
  16904. this._path.getPointAt(this._normalizedTime, pt);
  16905. if (this._snapping) {
  16906. pt.x = Math.round(pt.x);
  16907. pt.y = Math.round(pt.y);
  16908. }
  16909. this._deltaValue.x = pt.x - this._value.x;
  16910. this._deltaValue.y = pt.y - this._value.y;
  16911. this._value.x = pt.x;
  16912. this._value.y = pt.y;
  16913. }
  16914. else {
  16915. for (var i = 0; i < this._valueSize; i++) {
  16916. var n1 = this._startValue.getField(i);
  16917. var n2 = this._endValue.getField(i);
  16918. var f = n1 + (n2 - n1) * this._normalizedTime;
  16919. if (this._snapping)
  16920. f = Math.round(f);
  16921. this._deltaValue.setField(i, f - this._value.getField(i));
  16922. this._value.setField(i, f);
  16923. }
  16924. }
  16925. if (this._target != null && this._propType != null) {
  16926. if (this._propType instanceof Function) {
  16927. switch (this._valueSize) {
  16928. case 1:
  16929. this._propType.call(this._target, this._value.x);
  16930. break;
  16931. case 2:
  16932. this._propType.call(this._target, this._value.x, this._value.y);
  16933. break;
  16934. case 3:
  16935. this._propType.call(this._target, this._value.x, this._value.y, this._value.z);
  16936. break;
  16937. case 4:
  16938. this._propType.call(this._target, this._value.x, this._value.y, this._value.z, this._value.w);
  16939. break;
  16940. case 5:
  16941. this._propType.call(this._target, this._value.color);
  16942. break;
  16943. case 6:
  16944. this._propType.call(this._target, this._value.x, this._value.y);
  16945. break;
  16946. }
  16947. }
  16948. else {
  16949. if (this._valueSize == 5)
  16950. this._target[this._propType] = this._value.color;
  16951. else
  16952. this._target[this._propType] = this._value.x;
  16953. }
  16954. }
  16955. this.callUpdateCallback();
  16956. }
  16957. callStartCallback() {
  16958. if (this._onStart != null) {
  16959. try {
  16960. this._onStart.call(this._onStartCaller, this);
  16961. }
  16962. catch (err) {
  16963. console.log("FairyGUI: error in start callback > " + err);
  16964. }
  16965. }
  16966. }
  16967. callUpdateCallback() {
  16968. if (this._onUpdate != null) {
  16969. try {
  16970. this._onUpdate.call(this._onUpdateCaller, this);
  16971. }
  16972. catch (err) {
  16973. console.log("FairyGUI: error in update callback > " + err);
  16974. }
  16975. }
  16976. }
  16977. callCompleteCallback() {
  16978. if (this._onComplete != null) {
  16979. try {
  16980. this._onComplete.call(this._onCompleteCaller, this);
  16981. }
  16982. catch (err) {
  16983. console.log("FairyGUI: error in complete callback > " + err);
  16984. }
  16985. }
  16986. }
  16987. }
  16988. fgui.GTweener = GTweener;
  16989. var s_vec2 = new cc.Vec2();
  16990. })(fgui || (fgui = {}));
  16991. (function (fgui) {
  16992. var _activeTweens = new Array(30);
  16993. var _tweenerPool = new Array();
  16994. var _totalActiveTweens = 0;
  16995. var _root;
  16996. class TweenManager {
  16997. static createTween() {
  16998. if (!_root) {
  16999. _root = new cc.Node("[TweenManager]");
  17000. cc.game["addPersistRootNode"](_root);
  17001. cc.director.getScheduler().schedule(TweenManager.update, _root, 0, false);
  17002. }
  17003. var tweener;
  17004. var cnt = _tweenerPool.length;
  17005. if (cnt > 0) {
  17006. tweener = _tweenerPool.pop();
  17007. }
  17008. else
  17009. tweener = new fgui.GTweener();
  17010. tweener._init();
  17011. _activeTweens[_totalActiveTweens++] = tweener;
  17012. if (_totalActiveTweens == _activeTweens.length)
  17013. _activeTweens.length = _activeTweens.length + Math.ceil(_activeTweens.length * 0.5);
  17014. return tweener;
  17015. }
  17016. static isTweening(target, propType) {
  17017. if (target == null)
  17018. return false;
  17019. var anyType = propType == null || propType == undefined;
  17020. for (var i = 0; i < _totalActiveTweens; i++) {
  17021. var tweener = _activeTweens[i];
  17022. if (tweener && tweener.target == target && !tweener._killed
  17023. && (anyType || tweener._propType == propType))
  17024. return true;
  17025. }
  17026. return false;
  17027. }
  17028. static killTweens(target, completed, propType) {
  17029. if (target == null)
  17030. return false;
  17031. var flag = false;
  17032. var cnt = _totalActiveTweens;
  17033. var anyType = propType == null || propType == undefined;
  17034. for (var i = 0; i < cnt; i++) {
  17035. var tweener = _activeTweens[i];
  17036. if (tweener && tweener.target == target && !tweener._killed
  17037. && (anyType || tweener._propType == propType)) {
  17038. tweener.kill(completed);
  17039. flag = true;
  17040. }
  17041. }
  17042. return flag;
  17043. }
  17044. static getTween(target, propType) {
  17045. if (target == null)
  17046. return null;
  17047. var cnt = _totalActiveTweens;
  17048. var anyType = propType == null || propType == undefined;
  17049. for (var i = 0; i < cnt; i++) {
  17050. var tweener = _activeTweens[i];
  17051. if (tweener && tweener.target == target && !tweener._killed
  17052. && (anyType || tweener._propType == propType)) {
  17053. return tweener;
  17054. }
  17055. }
  17056. return null;
  17057. }
  17058. static update(dt) {
  17059. let tweens = _activeTweens;
  17060. var cnt = _totalActiveTweens;
  17061. var freePosStart = -1;
  17062. for (var i = 0; i < cnt; i++) {
  17063. var tweener = tweens[i];
  17064. if (tweener == null) {
  17065. if (freePosStart == -1)
  17066. freePosStart = i;
  17067. }
  17068. else if (tweener._killed) {
  17069. tweener._reset();
  17070. _tweenerPool.push(tweener);
  17071. tweens[i] = null;
  17072. if (freePosStart == -1)
  17073. freePosStart = i;
  17074. }
  17075. else {
  17076. if ((tweener._target instanceof fgui.GObject) && tweener._target.node == null)
  17077. tweener._killed = true;
  17078. else if (!tweener._paused)
  17079. tweener._update(dt);
  17080. if (freePosStart != -1) {
  17081. tweens[freePosStart] = tweener;
  17082. tweens[i] = null;
  17083. freePosStart++;
  17084. }
  17085. }
  17086. }
  17087. if (freePosStart >= 0) {
  17088. if (_totalActiveTweens != cnt) {
  17089. var j = cnt;
  17090. cnt = _totalActiveTweens - cnt;
  17091. for (i = 0; i < cnt; i++)
  17092. tweens[freePosStart++] = tweens[j++];
  17093. }
  17094. _totalActiveTweens = freePosStart;
  17095. }
  17096. return false;
  17097. }
  17098. }
  17099. fgui.TweenManager = TweenManager;
  17100. })(fgui || (fgui = {}));
  17101. (function (fgui) {
  17102. class TweenValue {
  17103. constructor() {
  17104. this.x = this.y = this.z = this.w = 0;
  17105. }
  17106. get color() {
  17107. return (this.w << 24) + (this.x << 16) + (this.y << 8) + this.z;
  17108. }
  17109. set color(value) {
  17110. this.x = (value & 0xFF0000) >> 16;
  17111. this.y = (value & 0x00FF00) >> 8;
  17112. this.z = (value & 0x0000FF);
  17113. this.w = (value & 0xFF000000) >> 24;
  17114. }
  17115. getField(index) {
  17116. switch (index) {
  17117. case 0:
  17118. return this.x;
  17119. case 1:
  17120. return this.y;
  17121. case 2:
  17122. return this.z;
  17123. case 3:
  17124. return this.w;
  17125. default:
  17126. throw new Error("Index out of bounds: " + index);
  17127. }
  17128. }
  17129. setField(index, value) {
  17130. switch (index) {
  17131. case 0:
  17132. this.x = value;
  17133. break;
  17134. case 1:
  17135. this.y = value;
  17136. break;
  17137. case 2:
  17138. this.z = value;
  17139. break;
  17140. case 3:
  17141. this.w = value;
  17142. break;
  17143. default:
  17144. throw new Error("Index out of bounds: " + index);
  17145. }
  17146. }
  17147. setZero() {
  17148. this.x = this.y = this.z = this.w = 0;
  17149. }
  17150. }
  17151. fgui.TweenValue = TweenValue;
  17152. })(fgui || (fgui = {}));
  17153. (function (fgui) {
  17154. class ByteBuffer {
  17155. constructor(buffer, offset = 0, length = -1) {
  17156. this.version = 0;
  17157. if (length == -1)
  17158. length = buffer.byteLength - offset;
  17159. this._bytes = new Uint8Array(buffer, offset, length);
  17160. this._view = new DataView(this._bytes.buffer, offset, length);
  17161. this._pos = 0;
  17162. this._length = length;
  17163. }
  17164. get data() {
  17165. return this._bytes;
  17166. }
  17167. get position() {
  17168. return this._pos;
  17169. }
  17170. set position(value) {
  17171. if (value > this._length)
  17172. throw "Out of bounds";
  17173. this._pos = value;
  17174. }
  17175. skip(count) {
  17176. this._pos += count;
  17177. }
  17178. validate(forward) {
  17179. if (this._pos + forward > this._length)
  17180. throw "Out of bounds";
  17181. }
  17182. readByte() {
  17183. this.validate(1);
  17184. return this._view.getInt8(this._pos++);
  17185. }
  17186. readUbyte() {
  17187. return this._bytes[this._pos++];
  17188. }
  17189. readBool() {
  17190. return this.readByte() == 1;
  17191. }
  17192. readShort() {
  17193. this.validate(2);
  17194. let ret = this._view.getInt16(this._pos, this.littleEndian);
  17195. this._pos += 2;
  17196. return ret;
  17197. }
  17198. readUshort() {
  17199. this.validate(2);
  17200. let ret = this._view.getUint16(this._pos, this.littleEndian);
  17201. this._pos += 2;
  17202. return ret;
  17203. }
  17204. readInt() {
  17205. this.validate(4);
  17206. let ret = this._view.getInt32(this._pos, this.littleEndian);
  17207. this._pos += 4;
  17208. return ret;
  17209. }
  17210. readUint() {
  17211. this.validate(4);
  17212. let ret = this._view.getUint32(this._pos, this.littleEndian);
  17213. this._pos += 4;
  17214. return ret;
  17215. }
  17216. readFloat() {
  17217. this.validate(4);
  17218. let ret = this._view.getFloat32(this._pos, this.littleEndian);
  17219. this._pos += 4;
  17220. return ret;
  17221. }
  17222. readString(len) {
  17223. if (len == undefined)
  17224. len = this.readUshort();
  17225. this.validate(len);
  17226. let v = "", max = this._pos + len, c = 0, c2 = 0, c3 = 0, f = String.fromCharCode;
  17227. let u = this._bytes, i = 0;
  17228. let pos = this._pos;
  17229. while (pos < max) {
  17230. c = u[pos++];
  17231. if (c < 0x80) {
  17232. if (c != 0) {
  17233. v += f(c);
  17234. }
  17235. }
  17236. else if (c < 0xE0) {
  17237. v += f(((c & 0x3F) << 6) | (u[pos++] & 0x7F));
  17238. }
  17239. else if (c < 0xF0) {
  17240. c2 = u[pos++];
  17241. v += f(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (u[pos++] & 0x7F));
  17242. }
  17243. else {
  17244. c2 = u[pos++];
  17245. c3 = u[pos++];
  17246. v += f(((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 << 6) & 0x7F) | (u[pos++] & 0x7F));
  17247. }
  17248. i++;
  17249. }
  17250. this._pos += len;
  17251. return v;
  17252. }
  17253. readS() {
  17254. var index = this.readUshort();
  17255. if (index == 65534)
  17256. return null;
  17257. else if (index == 65533)
  17258. return "";
  17259. else
  17260. return this.stringTable[index];
  17261. }
  17262. readSArray(cnt) {
  17263. var ret = new Array(cnt);
  17264. for (var i = 0; i < cnt; i++)
  17265. ret[i] = this.readS();
  17266. return ret;
  17267. }
  17268. writeS(value) {
  17269. var index = this.readUshort();
  17270. if (index != 65534 && index != 65533)
  17271. this.stringTable[index] = value;
  17272. }
  17273. readColor(hasAlpha) {
  17274. var r = this.readUbyte();
  17275. var g = this.readUbyte();
  17276. var b = this.readUbyte();
  17277. var a = this.readUbyte();
  17278. return new cc.Color(r, g, b, (hasAlpha ? a : 255));
  17279. }
  17280. readChar() {
  17281. var i = this.readUshort();
  17282. return String.fromCharCode(i);
  17283. }
  17284. readBuffer() {
  17285. var count = this.readUint();
  17286. this.validate(count);
  17287. var ba = new ByteBuffer(this._bytes.buffer, this._bytes.byteOffset + this._pos, count);
  17288. ba.stringTable = this.stringTable;
  17289. ba.version = this.version;
  17290. this._pos += count;
  17291. return ba;
  17292. }
  17293. seek(indexTablePos, blockIndex) {
  17294. var tmp = this._pos;
  17295. this._pos = indexTablePos;
  17296. var segCount = this.readByte();
  17297. if (blockIndex < segCount) {
  17298. var useShort = this.readByte() == 1;
  17299. var newPos;
  17300. if (useShort) {
  17301. this._pos += 2 * blockIndex;
  17302. newPos = this.readUshort();
  17303. }
  17304. else {
  17305. this._pos += 4 * blockIndex;
  17306. newPos = this.readUint();
  17307. }
  17308. if (newPos > 0) {
  17309. this._pos = indexTablePos + newPos;
  17310. return true;
  17311. }
  17312. else {
  17313. this._pos = tmp;
  17314. return false;
  17315. }
  17316. }
  17317. else {
  17318. this._pos = tmp;
  17319. return false;
  17320. }
  17321. }
  17322. }
  17323. fgui.ByteBuffer = ByteBuffer;
  17324. })(fgui || (fgui = {}));
  17325. (function (fgui) {
  17326. class ColorMatrix {
  17327. constructor(p_brightness, p_contrast, p_saturation, p_hue) {
  17328. this.matrix = new Array(LENGTH);
  17329. this.reset();
  17330. if (p_brightness !== undefined || p_contrast !== undefined || p_saturation !== undefined || p_hue !== undefined)
  17331. this.adjustColor(p_brightness, p_contrast, p_saturation, p_hue);
  17332. }
  17333. reset() {
  17334. for (var i = 0; i < LENGTH; i++) {
  17335. this.matrix[i] = IDENTITY_MATRIX[i];
  17336. }
  17337. }
  17338. invert() {
  17339. this.multiplyMatrix([-1, 0, 0, 0, 255,
  17340. 0, -1, 0, 0, 255,
  17341. 0, 0, -1, 0, 255,
  17342. 0, 0, 0, 1, 0]);
  17343. }
  17344. adjustColor(p_brightness, p_contrast, p_saturation, p_hue) {
  17345. this.adjustHue(p_hue || 0);
  17346. this.adjustContrast(p_contrast || 0);
  17347. this.adjustBrightness(p_brightness || 0);
  17348. this.adjustSaturation(p_saturation || 0);
  17349. }
  17350. adjustBrightness(p_val) {
  17351. p_val = this.cleanValue(p_val, 1) * 255;
  17352. this.multiplyMatrix([
  17353. 1, 0, 0, 0, p_val,
  17354. 0, 1, 0, 0, p_val,
  17355. 0, 0, 1, 0, p_val,
  17356. 0, 0, 0, 1, 0
  17357. ]);
  17358. }
  17359. adjustContrast(p_val) {
  17360. p_val = this.cleanValue(p_val, 1);
  17361. var s = p_val + 1;
  17362. var o = 128 * (1 - s);
  17363. this.multiplyMatrix([
  17364. s, 0, 0, 0, o,
  17365. 0, s, 0, 0, o,
  17366. 0, 0, s, 0, o,
  17367. 0, 0, 0, 1, 0
  17368. ]);
  17369. }
  17370. adjustSaturation(p_val) {
  17371. p_val = this.cleanValue(p_val, 1);
  17372. p_val += 1;
  17373. var invSat = 1 - p_val;
  17374. var invLumR = invSat * LUMA_R;
  17375. var invLumG = invSat * LUMA_G;
  17376. var invLumB = invSat * LUMA_B;
  17377. this.multiplyMatrix([
  17378. (invLumR + p_val), invLumG, invLumB, 0, 0,
  17379. invLumR, (invLumG + p_val), invLumB, 0, 0,
  17380. invLumR, invLumG, (invLumB + p_val), 0, 0,
  17381. 0, 0, 0, 1, 0
  17382. ]);
  17383. }
  17384. adjustHue(p_val) {
  17385. p_val = this.cleanValue(p_val, 1);
  17386. p_val *= Math.PI;
  17387. var cos = Math.cos(p_val);
  17388. var sin = Math.sin(p_val);
  17389. this.multiplyMatrix([
  17390. ((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,
  17391. ((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,
  17392. ((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,
  17393. 0, 0, 0, 1, 0
  17394. ]);
  17395. }
  17396. concat(p_matrix) {
  17397. if (p_matrix.length != LENGTH) {
  17398. return;
  17399. }
  17400. this.multiplyMatrix(p_matrix);
  17401. }
  17402. clone() {
  17403. var result = new ColorMatrix();
  17404. result.copyMatrix(this.matrix);
  17405. return result;
  17406. }
  17407. copyMatrix(p_matrix) {
  17408. var l = LENGTH;
  17409. for (var i = 0; i < l; i++) {
  17410. this.matrix[i] = p_matrix[i];
  17411. }
  17412. }
  17413. multiplyMatrix(p_matrix) {
  17414. var col = [];
  17415. var i = 0;
  17416. for (var y = 0; y < 4; ++y) {
  17417. for (var x = 0; x < 5; ++x) {
  17418. col[i + x] = p_matrix[i] * this.matrix[x] +
  17419. p_matrix[i + 1] * this.matrix[x + 5] +
  17420. p_matrix[i + 2] * this.matrix[x + 10] +
  17421. p_matrix[i + 3] * this.matrix[x + 15] +
  17422. (x == 4 ? p_matrix[i + 4] : 0);
  17423. }
  17424. i += 5;
  17425. }
  17426. this.copyMatrix(col);
  17427. }
  17428. cleanValue(p_val, p_limit) {
  17429. return Math.min(p_limit, Math.max(-p_limit, p_val));
  17430. }
  17431. }
  17432. fgui.ColorMatrix = ColorMatrix;
  17433. const IDENTITY_MATRIX = [
  17434. 1, 0, 0, 0, 0,
  17435. 0, 1, 0, 0, 0,
  17436. 0, 0, 1, 0, 0,
  17437. 0, 0, 0, 1, 0
  17438. ];
  17439. const LENGTH = IDENTITY_MATRIX.length;
  17440. const LUMA_R = 0.299;
  17441. const LUMA_G = 0.587;
  17442. const LUMA_B = 0.114;
  17443. })(fgui || (fgui = {}));
  17444. (function (fgui) {
  17445. class UBBParser {
  17446. constructor() {
  17447. this._readPos = 0;
  17448. this._handlers = {};
  17449. this._handlers['url'] = this.onTag_URL;
  17450. this._handlers['img'] = this.onTag_IMG;
  17451. this._handlers['b'] = this.onTag_Simple;
  17452. this._handlers['i'] = this.onTag_Simple;
  17453. this._handlers['u'] = this.onTag_Simple;
  17454. this._handlers['color'] = this.onTag_COLOR;
  17455. this._handlers['size'] = this.onTag_SIZE;
  17456. }
  17457. registerHandler(name, handler) {
  17458. this._handlers[name] = handler;
  17459. }
  17460. onTag_URL(tagName, end, attr) {
  17461. if (!end) {
  17462. let ret;
  17463. if (attr != null)
  17464. ret = '<on click="onClickLink" param="' + attr + '">';
  17465. else {
  17466. var href = this.getTagText();
  17467. ret = '<on click="onClickLink" param="' + href + '">';
  17468. }
  17469. if (this.linkUnderline)
  17470. ret += '<u>';
  17471. if (this.linkColor)
  17472. ret += '<color=' + this.linkColor + '>';
  17473. return ret;
  17474. }
  17475. else {
  17476. let ret = '';
  17477. if (this.linkColor)
  17478. ret += '</color>';
  17479. if (this.linkUnderline)
  17480. ret += '</u>';
  17481. ret += '</on>';
  17482. return ret;
  17483. }
  17484. }
  17485. onTag_IMG(tagName, end, attr) {
  17486. if (!end) {
  17487. var src = this.getTagText(true);
  17488. if (!src)
  17489. return null;
  17490. return '<img src="' + src + '"/>';
  17491. }
  17492. else
  17493. return null;
  17494. }
  17495. onTag_Simple(tagName, end, attr) {
  17496. return end ? '</' + tagName + '>' : '<' + tagName + '>';
  17497. }
  17498. onTag_COLOR(tagName, end, attr) {
  17499. if (!end) {
  17500. this.lastColor = attr;
  17501. return '<color=' + attr + '>';
  17502. }
  17503. else
  17504. return '</color>';
  17505. }
  17506. onTag_FONT(tagName, end, attr) {
  17507. if (!end)
  17508. return '<font face="' + attr + '">';
  17509. else
  17510. return '</font>';
  17511. }
  17512. onTag_SIZE(tagName, end, attr) {
  17513. if (!end) {
  17514. this.lastSize = attr;
  17515. return '<size=' + attr + '>';
  17516. }
  17517. else
  17518. return '</size>';
  17519. }
  17520. getTagText(remove) {
  17521. var pos1 = this._readPos;
  17522. var pos2;
  17523. var result = '';
  17524. while ((pos2 = this._text.indexOf('[', pos1)) != -1) {
  17525. if (this._text.charCodeAt(pos2 - 1) == 92) {
  17526. result += this._text.substring(pos1, pos2 - 1);
  17527. result += '[';
  17528. pos1 = pos2 + 1;
  17529. }
  17530. else {
  17531. result += this._text.substring(pos1, pos2);
  17532. break;
  17533. }
  17534. }
  17535. if (pos2 == -1)
  17536. return null;
  17537. if (remove)
  17538. this._readPos = pos2;
  17539. return result;
  17540. }
  17541. parse(text, remove) {
  17542. this._text = text;
  17543. this.lastColor = null;
  17544. this.lastSize = null;
  17545. var pos1 = 0, pos2, pos3;
  17546. var end;
  17547. var tag, attr;
  17548. var repl;
  17549. var func;
  17550. var result = '';
  17551. while ((pos2 = this._text.indexOf('[', pos1)) != -1) {
  17552. if (pos2 > 0 && this._text.charCodeAt(pos2 - 1) == 92) {
  17553. result += this._text.substring(pos1, pos2 - 1);
  17554. result += '[';
  17555. pos1 = pos2 + 1;
  17556. continue;
  17557. }
  17558. result += this._text.substring(pos1, pos2);
  17559. pos1 = pos2;
  17560. pos2 = this._text.indexOf(']', pos1);
  17561. if (pos2 == -1)
  17562. break;
  17563. end = this._text.charAt(pos1 + 1) == '/';
  17564. tag = this._text.substring(end ? pos1 + 2 : pos1 + 1, pos2);
  17565. this._readPos = pos2 + 1;
  17566. attr = null;
  17567. repl = null;
  17568. pos3 = tag.indexOf('=');
  17569. if (pos3 != -1) {
  17570. attr = tag.substring(pos3 + 1);
  17571. tag = tag.substring(0, pos3);
  17572. }
  17573. tag = tag.toLowerCase();
  17574. func = this._handlers[tag];
  17575. if (func != null) {
  17576. repl = func.call(this, tag, end, attr);
  17577. if (repl != null && !remove)
  17578. result += repl;
  17579. }
  17580. else
  17581. result += this._text.substring(pos1, this._readPos);
  17582. pos1 = this._readPos;
  17583. }
  17584. if (pos1 < this._text.length)
  17585. result += this._text.substr(pos1);
  17586. this._text = null;
  17587. return result;
  17588. }
  17589. }
  17590. UBBParser.inst = new UBBParser();
  17591. fgui.UBBParser = UBBParser;
  17592. })(fgui || (fgui = {}));
  17593. (function (fgui) {
  17594. class ToolSet {
  17595. static startsWith(source, str, ignoreCase) {
  17596. if (!source)
  17597. return false;
  17598. else if (source.length < str.length)
  17599. return false;
  17600. else {
  17601. source = source.substring(0, str.length);
  17602. if (!ignoreCase)
  17603. return source == str;
  17604. else
  17605. return source.toLowerCase() == str.toLowerCase();
  17606. }
  17607. }
  17608. static encodeHTML(str) {
  17609. if (!str)
  17610. return '';
  17611. else
  17612. return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;');
  17613. }
  17614. static clamp(value, min, max) {
  17615. if (value < min)
  17616. value = min;
  17617. else if (value > max)
  17618. value = max;
  17619. return value;
  17620. }
  17621. static clamp01(value) {
  17622. if (value > 1)
  17623. value = 1;
  17624. else if (value < 0)
  17625. value = 0;
  17626. return value;
  17627. }
  17628. static lerp(start, end, percent) {
  17629. return start + percent * (end - start);
  17630. }
  17631. static getTime() {
  17632. let currentTime = cc.sys.now();
  17633. return currentTime / 1000;
  17634. }
  17635. static toGrayed(c) {
  17636. let v = c.getR() * 0.299 + c.getG() * 0.587 + c.getB() * 0.114;
  17637. return new cc.Color(v, v, v, c.getA());
  17638. }
  17639. static repeat(t, length) {
  17640. return t - Math.floor(t / length) * length;
  17641. }
  17642. static distance(x1, y1, x2, y2) {
  17643. return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  17644. }
  17645. }
  17646. fgui.ToolSet = ToolSet;
  17647. })(fgui || (fgui = {}));