fairygui.js 689 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860
  1. ;window.fairygui = window.fgui = {};
  2. (function (fgui) {
  3. class AssetProxy {
  4. constructor() {
  5. this._asset = Laya.loader;
  6. }
  7. static get inst() {
  8. if (!AssetProxy._inst)
  9. AssetProxy._inst = new AssetProxy();
  10. return AssetProxy._inst;
  11. }
  12. getRes(url) {
  13. return this._asset.getRes(url);
  14. }
  15. load(url, complete, progress, type, priority, cache) {
  16. this._asset.load(url, complete, progress, type, priority, cache);
  17. }
  18. setAsset(asset) {
  19. this._asset = asset;
  20. }
  21. }
  22. fgui.AssetProxy = AssetProxy;
  23. })(fgui);
  24. (function (fgui) {
  25. class AsyncOperation {
  26. constructor() {
  27. this._itemList = new Array();
  28. this._objectPool = [];
  29. }
  30. createObject(pkgName, resName) {
  31. var pkg = fgui.UIPackage.getByName(pkgName);
  32. if (pkg) {
  33. var pi = pkg.getItemByName(resName);
  34. if (!pi)
  35. throw new Error("resource not found: " + resName);
  36. this.internalCreateObject(pi);
  37. }
  38. else
  39. throw new Error("package not found: " + pkgName);
  40. }
  41. createObjectFromURL(url) {
  42. var pi = fgui.UIPackage.getItemByURL(url);
  43. if (pi)
  44. this.internalCreateObject(pi);
  45. else
  46. throw new Error("resource not found: " + url);
  47. }
  48. cancel() {
  49. Laya.timer.clear(this, this.run);
  50. this._itemList.length = 0;
  51. if (this._objectPool.length > 0) {
  52. var cnt = this._objectPool.length;
  53. for (var i = 0; i < cnt; i++) {
  54. this._objectPool[i].dispose();
  55. }
  56. this._objectPool.length = 0;
  57. }
  58. }
  59. internalCreateObject(item) {
  60. this._itemList.length = 0;
  61. this._objectPool.length = 0;
  62. var di = { pi: item, type: item.objectType };
  63. di.childCount = this.collectComponentChildren(item);
  64. this._itemList.push(di);
  65. this._index = 0;
  66. Laya.timer.frameLoop(1, this, this.run);
  67. }
  68. collectComponentChildren(item) {
  69. var buffer = item.rawData;
  70. buffer.seek(0, 2);
  71. var di;
  72. var pi;
  73. var i;
  74. var dataLen;
  75. var curPos;
  76. var pkg;
  77. var dcnt = buffer.getInt16();
  78. for (i = 0; i < dcnt; i++) {
  79. dataLen = buffer.getInt16();
  80. curPos = buffer.pos;
  81. buffer.seek(curPos, 0);
  82. var type = buffer.readByte();
  83. var src = buffer.readS();
  84. var pkgId = buffer.readS();
  85. buffer.pos = curPos;
  86. if (src != null) {
  87. if (pkgId != null)
  88. pkg = fgui.UIPackage.getById(pkgId);
  89. else
  90. pkg = item.owner;
  91. pi = pkg ? pkg.getItemById(src) : null;
  92. di = { pi: pi, type: type };
  93. if (pi && pi.type == fgui.PackageItemType.Component)
  94. di.childCount = this.collectComponentChildren(pi);
  95. }
  96. else {
  97. di = { type: type };
  98. if (type == fgui.ObjectType.List) //list
  99. di.listItemCount = this.collectListChildren(buffer);
  100. }
  101. this._itemList.push(di);
  102. buffer.pos = curPos + dataLen;
  103. }
  104. return dcnt;
  105. }
  106. collectListChildren(buffer) {
  107. buffer.seek(buffer.pos, 8);
  108. var listItemCount = 0;
  109. var i;
  110. var nextPos;
  111. var url;
  112. var pi;
  113. var di;
  114. var defaultItem = buffer.readS();
  115. var itemCount = buffer.getInt16();
  116. for (i = 0; i < itemCount; i++) {
  117. nextPos = buffer.getInt16();
  118. nextPos += buffer.pos;
  119. url = buffer.readS();
  120. if (url == null)
  121. url = defaultItem;
  122. if (url) {
  123. pi = fgui.UIPackage.getItemByURL(url);
  124. if (pi) {
  125. di = { pi: pi, type: pi.objectType };
  126. if (pi.type == fgui.PackageItemType.Component)
  127. di.childCount = this.collectComponentChildren(pi);
  128. this._itemList.push(di);
  129. listItemCount++;
  130. }
  131. }
  132. buffer.pos = nextPos;
  133. }
  134. return listItemCount;
  135. }
  136. run() {
  137. var obj;
  138. var di;
  139. var poolStart;
  140. var k;
  141. var t = Laya.Browser.now();
  142. var frameTime = fgui.UIConfig.frameTimeForAsyncUIConstruction;
  143. var totalItems = this._itemList.length;
  144. while (this._index < totalItems) {
  145. di = this._itemList[this._index];
  146. if (di.pi) {
  147. obj = fgui.UIObjectFactory.newObject(di.pi);
  148. this._objectPool.push(obj);
  149. fgui.UIPackage._constructing++;
  150. if (di.pi.type == fgui.PackageItemType.Component) {
  151. poolStart = this._objectPool.length - di.childCount - 1;
  152. obj.constructFromResource2(this._objectPool, poolStart);
  153. this._objectPool.splice(poolStart, di.childCount);
  154. }
  155. else {
  156. obj.constructFromResource();
  157. }
  158. fgui.UIPackage._constructing--;
  159. }
  160. else {
  161. obj = fgui.UIObjectFactory.newObject(di.type);
  162. this._objectPool.push(obj);
  163. if (di.type == fgui.ObjectType.List && di.listItemCount > 0) {
  164. poolStart = this._objectPool.length - di.listItemCount - 1;
  165. for (k = 0; k < di.listItemCount; k++) //把他们都放到pool里,这样GList在创建时就不需要创建对象了
  166. obj.itemPool.returnObject(this._objectPool[k + poolStart]);
  167. this._objectPool.splice(poolStart, di.listItemCount);
  168. }
  169. }
  170. this._index++;
  171. if ((this._index % 5 == 0) && Laya.Browser.now() - t >= frameTime)
  172. return;
  173. }
  174. Laya.timer.clear(this, this.run);
  175. var result = this._objectPool[0];
  176. this._itemList.length = 0;
  177. this._objectPool.length = 0;
  178. if (this.callback != null)
  179. this.callback.runWith(result);
  180. }
  181. }
  182. fgui.AsyncOperation = AsyncOperation;
  183. })(fgui);
  184. (function (fgui) {
  185. var _nextPageId = 0;
  186. class Controller extends Laya.EventDispatcher {
  187. constructor() {
  188. super();
  189. this._pageIds = [];
  190. this._pageNames = [];
  191. this._selectedIndex = -1;
  192. this._previousIndex = -1;
  193. }
  194. dispose() {
  195. this.offAll();
  196. }
  197. get selectedIndex() {
  198. return this._selectedIndex;
  199. }
  200. set selectedIndex(value) {
  201. if (this._selectedIndex != value) {
  202. if (value > this._pageIds.length - 1)
  203. throw "index out of bounds: " + value;
  204. this.changing = true;
  205. this._previousIndex = this._selectedIndex;
  206. this._selectedIndex = value;
  207. this.parent.applyController(this);
  208. this.event(fgui.Events.STATE_CHANGED, this);
  209. this.changing = false;
  210. }
  211. }
  212. /**
  213. * 功能和设置selectedIndex一样,但不会触发事件
  214. */
  215. setSelectedIndex(value) {
  216. if (this._selectedIndex != value) {
  217. if (value > this._pageIds.length - 1)
  218. throw "index out of bounds: " + value;
  219. this.changing = true;
  220. this._previousIndex = this._selectedIndex;
  221. this._selectedIndex = value;
  222. this.parent.applyController(this);
  223. this.changing = false;
  224. }
  225. }
  226. get previsousIndex() {
  227. return this._previousIndex;
  228. }
  229. get selectedPage() {
  230. if (this._selectedIndex == -1)
  231. return null;
  232. else
  233. return this._pageNames[this._selectedIndex];
  234. }
  235. set selectedPage(val) {
  236. var i = this._pageNames.indexOf(val);
  237. if (i == -1)
  238. i = 0;
  239. this.selectedIndex = i;
  240. }
  241. /**
  242. * 功能和设置selectedPage一样,但不会触发事件
  243. */
  244. setSelectedPage(value) {
  245. var i = this._pageNames.indexOf(value);
  246. if (i == -1)
  247. i = 0;
  248. this.setSelectedIndex(i);
  249. }
  250. get previousPage() {
  251. if (this._previousIndex == -1)
  252. return null;
  253. else
  254. return this._pageNames[this._previousIndex];
  255. }
  256. get pageCount() {
  257. return this._pageIds.length;
  258. }
  259. getPageName(index) {
  260. return this._pageNames[index];
  261. }
  262. addPage(name) {
  263. this.addPageAt(name, this._pageIds.length);
  264. }
  265. addPageAt(name, index) {
  266. var nid = "" + (_nextPageId++);
  267. if (index == this._pageIds.length) {
  268. this._pageIds.push(nid);
  269. this._pageNames.push(name);
  270. }
  271. else {
  272. this._pageIds.splice(index, 0, nid);
  273. this._pageNames.splice(index, 0, name);
  274. }
  275. }
  276. removePage(name) {
  277. var i = this._pageNames.indexOf(name);
  278. if (i != -1) {
  279. this._pageIds.splice(i, 1);
  280. this._pageNames.splice(i, 1);
  281. if (this._selectedIndex >= this._pageIds.length)
  282. this.selectedIndex = this._selectedIndex - 1;
  283. else
  284. this.parent.applyController(this);
  285. }
  286. }
  287. removePageAt(index) {
  288. this._pageIds.splice(index, 1);
  289. this._pageNames.splice(index, 1);
  290. if (this._selectedIndex >= this._pageIds.length)
  291. this.selectedIndex = this._selectedIndex - 1;
  292. else
  293. this.parent.applyController(this);
  294. }
  295. clearPages() {
  296. this._pageIds.length = 0;
  297. this._pageNames.length = 0;
  298. if (this._selectedIndex != -1)
  299. this.selectedIndex = -1;
  300. else
  301. this.parent.applyController(this);
  302. }
  303. hasPage(aName) {
  304. return this._pageNames.indexOf(aName) != -1;
  305. }
  306. getPageIndexById(aId) {
  307. return this._pageIds.indexOf(aId);
  308. }
  309. getPageIdByName(aName) {
  310. var i = this._pageNames.indexOf(aName);
  311. if (i != -1)
  312. return this._pageIds[i];
  313. else
  314. return null;
  315. }
  316. getPageNameById(aId) {
  317. var i = this._pageIds.indexOf(aId);
  318. if (i != -1)
  319. return this._pageNames[i];
  320. else
  321. return null;
  322. }
  323. getPageId(index) {
  324. return this._pageIds[index];
  325. }
  326. get selectedPageId() {
  327. if (this._selectedIndex == -1)
  328. return null;
  329. else
  330. return this._pageIds[this._selectedIndex];
  331. }
  332. set selectedPageId(val) {
  333. var i = this._pageIds.indexOf(val);
  334. this.selectedIndex = i;
  335. }
  336. set oppositePageId(val) {
  337. var i = this._pageIds.indexOf(val);
  338. if (i > 0)
  339. this.selectedIndex = 0;
  340. else if (this._pageIds.length > 1)
  341. this.selectedIndex = 1;
  342. }
  343. get previousPageId() {
  344. if (this._previousIndex == -1)
  345. return null;
  346. else
  347. return this._pageIds[this._previousIndex];
  348. }
  349. runActions() {
  350. if (this._actions) {
  351. var cnt = this._actions.length;
  352. for (var i = 0; i < cnt; i++) {
  353. this._actions[i].run(this, this.previousPageId, this.selectedPageId);
  354. }
  355. }
  356. }
  357. setup(buffer) {
  358. var beginPos = buffer.pos;
  359. buffer.seek(beginPos, 0);
  360. this.name = buffer.readS();
  361. if (buffer.readBool())
  362. this.autoRadioGroupDepth = true;
  363. buffer.seek(beginPos, 1);
  364. var i;
  365. var nextPos;
  366. var cnt = buffer.getInt16();
  367. for (i = 0; i < cnt; i++) {
  368. this._pageIds.push(buffer.readS());
  369. this._pageNames.push(buffer.readS());
  370. }
  371. var homePageIndex = 0;
  372. if (buffer.version >= 2) {
  373. var homePageType = buffer.getByte();
  374. switch (homePageType) {
  375. case 1:
  376. homePageIndex = buffer.getInt16();
  377. break;
  378. case 2:
  379. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.branch);
  380. if (homePageIndex == -1)
  381. homePageIndex = 0;
  382. break;
  383. case 3:
  384. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.getVar(buffer.readS()));
  385. if (homePageIndex == -1)
  386. homePageIndex = 0;
  387. break;
  388. }
  389. }
  390. buffer.seek(beginPos, 2);
  391. cnt = buffer.getInt16();
  392. if (cnt > 0) {
  393. if (!this._actions)
  394. this._actions = [];
  395. for (i = 0; i < cnt; i++) {
  396. nextPos = buffer.getInt16();
  397. nextPos += buffer.pos;
  398. var action = fgui.ControllerAction.createAction(buffer.readByte());
  399. action.setup(buffer);
  400. this._actions.push(action);
  401. buffer.pos = nextPos;
  402. }
  403. }
  404. if (this.parent && this._pageIds.length > 0)
  405. this._selectedIndex = homePageIndex;
  406. else
  407. this._selectedIndex = -1;
  408. }
  409. }
  410. fgui.Controller = Controller;
  411. })(fgui);
  412. (function (fgui) {
  413. class DragDropManager {
  414. constructor() {
  415. this._agent = new fgui.GLoader();
  416. this._agent.draggable = true;
  417. this._agent.touchable = false; ////important
  418. this._agent.setSize(100, 100);
  419. this._agent.setPivot(0.5, 0.5, true);
  420. this._agent.align = "center";
  421. this._agent.verticalAlign = "middle";
  422. this._agent.sortingOrder = 1000000;
  423. this._agent.on(fgui.Events.DRAG_END, this, this.__dragEnd);
  424. }
  425. static get inst() {
  426. if (!DragDropManager._inst)
  427. DragDropManager._inst = new DragDropManager();
  428. return DragDropManager._inst;
  429. }
  430. get dragAgent() {
  431. return this._agent;
  432. }
  433. get dragging() {
  434. return this._agent.parent != null;
  435. }
  436. startDrag(source, icon, sourceData, touchID) {
  437. if (this._agent.parent)
  438. return;
  439. this._sourceData = sourceData;
  440. this._agent.url = icon;
  441. fgui.GRoot.inst.addChild(this._agent);
  442. var pt = fgui.GRoot.inst.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY);
  443. this._agent.setXY(pt.x, pt.y);
  444. this._agent.startDrag(touchID);
  445. }
  446. cancel() {
  447. if (this._agent.parent) {
  448. this._agent.stopDrag();
  449. fgui.GRoot.inst.removeChild(this._agent);
  450. this._sourceData = null;
  451. }
  452. }
  453. __dragEnd(evt) {
  454. if (!this._agent.parent) //cancelled
  455. return;
  456. fgui.GRoot.inst.removeChild(this._agent);
  457. var sourceData = this._sourceData;
  458. this._sourceData = null;
  459. var obj = fgui.GObject.cast(evt.target);
  460. while (obj) {
  461. if (obj.displayObject.hasListener(fgui.Events.DROP)) {
  462. obj.requestFocus();
  463. obj.displayObject.event(fgui.Events.DROP, [sourceData, fgui.Events.createEvent(fgui.Events.DROP, obj.displayObject, evt)]);
  464. return;
  465. }
  466. obj = obj.parent;
  467. }
  468. }
  469. }
  470. fgui.DragDropManager = DragDropManager;
  471. })(fgui);
  472. (function (fgui) {
  473. class Events {
  474. static createEvent(type, target, source) {
  475. this.$event.setTo(type, target, source ? (source.target || target) : target);
  476. this.$event.touchId = source ? (source.touchId || 0) : 0;
  477. this.$event.nativeEvent = source;
  478. this.$event["_stoped"] = false;
  479. return this.$event;
  480. }
  481. static dispatch(type, target, source) {
  482. target.event(type, this.createEvent(type, target, source));
  483. }
  484. }
  485. Events.STATE_CHANGED = "fui_state_changed";
  486. Events.XY_CHANGED = "fui_xy_changed";
  487. Events.SIZE_CHANGED = "fui_size_changed";
  488. Events.SIZE_DELAY_CHANGE = "fui_size_delay_change";
  489. Events.CLICK_ITEM = "fui_click_item";
  490. Events.SCROLL = "fui_scroll";
  491. Events.SCROLL_END = "fui_scroll_end";
  492. Events.DROP = "fui_drop";
  493. Events.DRAG_START = "fui_drag_start";
  494. Events.DRAG_MOVE = "fui_drag_move";
  495. Events.DRAG_END = "fui_drag_end";
  496. Events.PULL_DOWN_RELEASE = "fui_pull_down_release";
  497. Events.PULL_UP_RELEASE = "fui_pull_up_release";
  498. Events.GEAR_STOP = "fui_gear_stop";
  499. Events.$event = new Laya.Event();
  500. fgui.Events = Events;
  501. })(fgui);
  502. (function (fgui) {
  503. let ButtonMode;
  504. (function (ButtonMode) {
  505. ButtonMode[ButtonMode["Common"] = 0] = "Common";
  506. ButtonMode[ButtonMode["Check"] = 1] = "Check";
  507. ButtonMode[ButtonMode["Radio"] = 2] = "Radio";
  508. })(ButtonMode = fgui.ButtonMode || (fgui.ButtonMode = {}));
  509. let AutoSizeType;
  510. (function (AutoSizeType) {
  511. AutoSizeType[AutoSizeType["None"] = 0] = "None";
  512. AutoSizeType[AutoSizeType["Both"] = 1] = "Both";
  513. AutoSizeType[AutoSizeType["Height"] = 2] = "Height";
  514. })(AutoSizeType = fgui.AutoSizeType || (fgui.AutoSizeType = {}));
  515. let AlignType;
  516. (function (AlignType) {
  517. AlignType[AlignType["Left"] = 0] = "Left";
  518. AlignType[AlignType["Center"] = 1] = "Center";
  519. AlignType[AlignType["Right"] = 2] = "Right";
  520. })(AlignType = fgui.AlignType || (fgui.AlignType = {}));
  521. let VertAlignType;
  522. (function (VertAlignType) {
  523. VertAlignType[VertAlignType["Top"] = 0] = "Top";
  524. VertAlignType[VertAlignType["Middle"] = 1] = "Middle";
  525. VertAlignType[VertAlignType["Bottom"] = 2] = "Bottom";
  526. })(VertAlignType = fgui.VertAlignType || (fgui.VertAlignType = {}));
  527. let LoaderFillType;
  528. (function (LoaderFillType) {
  529. LoaderFillType[LoaderFillType["None"] = 0] = "None";
  530. LoaderFillType[LoaderFillType["Scale"] = 1] = "Scale";
  531. LoaderFillType[LoaderFillType["ScaleMatchHeight"] = 2] = "ScaleMatchHeight";
  532. LoaderFillType[LoaderFillType["ScaleMatchWidth"] = 3] = "ScaleMatchWidth";
  533. LoaderFillType[LoaderFillType["ScaleFree"] = 4] = "ScaleFree";
  534. LoaderFillType[LoaderFillType["ScaleNoBorder"] = 5] = "ScaleNoBorder";
  535. })(LoaderFillType = fgui.LoaderFillType || (fgui.LoaderFillType = {}));
  536. let ListLayoutType;
  537. (function (ListLayoutType) {
  538. ListLayoutType[ListLayoutType["SingleColumn"] = 0] = "SingleColumn";
  539. ListLayoutType[ListLayoutType["SingleRow"] = 1] = "SingleRow";
  540. ListLayoutType[ListLayoutType["FlowHorizontal"] = 2] = "FlowHorizontal";
  541. ListLayoutType[ListLayoutType["FlowVertical"] = 3] = "FlowVertical";
  542. ListLayoutType[ListLayoutType["Pagination"] = 4] = "Pagination";
  543. })(ListLayoutType = fgui.ListLayoutType || (fgui.ListLayoutType = {}));
  544. let ListSelectionMode;
  545. (function (ListSelectionMode) {
  546. ListSelectionMode[ListSelectionMode["Single"] = 0] = "Single";
  547. ListSelectionMode[ListSelectionMode["Multiple"] = 1] = "Multiple";
  548. ListSelectionMode[ListSelectionMode["Multiple_SingleClick"] = 2] = "Multiple_SingleClick";
  549. ListSelectionMode[ListSelectionMode["None"] = 3] = "None";
  550. })(ListSelectionMode = fgui.ListSelectionMode || (fgui.ListSelectionMode = {}));
  551. let OverflowType;
  552. (function (OverflowType) {
  553. OverflowType[OverflowType["Visible"] = 0] = "Visible";
  554. OverflowType[OverflowType["Hidden"] = 1] = "Hidden";
  555. OverflowType[OverflowType["Scroll"] = 2] = "Scroll";
  556. })(OverflowType = fgui.OverflowType || (fgui.OverflowType = {}));
  557. let PackageItemType;
  558. (function (PackageItemType) {
  559. PackageItemType[PackageItemType["Image"] = 0] = "Image";
  560. PackageItemType[PackageItemType["MovieClip"] = 1] = "MovieClip";
  561. PackageItemType[PackageItemType["Sound"] = 2] = "Sound";
  562. PackageItemType[PackageItemType["Component"] = 3] = "Component";
  563. PackageItemType[PackageItemType["Atlas"] = 4] = "Atlas";
  564. PackageItemType[PackageItemType["Font"] = 5] = "Font";
  565. PackageItemType[PackageItemType["Swf"] = 6] = "Swf";
  566. PackageItemType[PackageItemType["Misc"] = 7] = "Misc";
  567. PackageItemType[PackageItemType["Unknown"] = 8] = "Unknown";
  568. PackageItemType[PackageItemType["Spine"] = 9] = "Spine";
  569. PackageItemType[PackageItemType["DragonBones"] = 10] = "DragonBones";
  570. })(PackageItemType = fgui.PackageItemType || (fgui.PackageItemType = {}));
  571. let ObjectType;
  572. (function (ObjectType) {
  573. ObjectType[ObjectType["Image"] = 0] = "Image";
  574. ObjectType[ObjectType["MovieClip"] = 1] = "MovieClip";
  575. ObjectType[ObjectType["Swf"] = 2] = "Swf";
  576. ObjectType[ObjectType["Graph"] = 3] = "Graph";
  577. ObjectType[ObjectType["Loader"] = 4] = "Loader";
  578. ObjectType[ObjectType["Group"] = 5] = "Group";
  579. ObjectType[ObjectType["Text"] = 6] = "Text";
  580. ObjectType[ObjectType["RichText"] = 7] = "RichText";
  581. ObjectType[ObjectType["InputText"] = 8] = "InputText";
  582. ObjectType[ObjectType["Component"] = 9] = "Component";
  583. ObjectType[ObjectType["List"] = 10] = "List";
  584. ObjectType[ObjectType["Label"] = 11] = "Label";
  585. ObjectType[ObjectType["Button"] = 12] = "Button";
  586. ObjectType[ObjectType["ComboBox"] = 13] = "ComboBox";
  587. ObjectType[ObjectType["ProgressBar"] = 14] = "ProgressBar";
  588. ObjectType[ObjectType["Slider"] = 15] = "Slider";
  589. ObjectType[ObjectType["ScrollBar"] = 16] = "ScrollBar";
  590. ObjectType[ObjectType["Tree"] = 17] = "Tree";
  591. ObjectType[ObjectType["Loader3D"] = 18] = "Loader3D";
  592. })(ObjectType = fgui.ObjectType || (fgui.ObjectType = {}));
  593. let ProgressTitleType;
  594. (function (ProgressTitleType) {
  595. ProgressTitleType[ProgressTitleType["Percent"] = 0] = "Percent";
  596. ProgressTitleType[ProgressTitleType["ValueAndMax"] = 1] = "ValueAndMax";
  597. ProgressTitleType[ProgressTitleType["Value"] = 2] = "Value";
  598. ProgressTitleType[ProgressTitleType["Max"] = 3] = "Max";
  599. })(ProgressTitleType = fgui.ProgressTitleType || (fgui.ProgressTitleType = {}));
  600. let ScrollBarDisplayType;
  601. (function (ScrollBarDisplayType) {
  602. ScrollBarDisplayType[ScrollBarDisplayType["Default"] = 0] = "Default";
  603. ScrollBarDisplayType[ScrollBarDisplayType["Visible"] = 1] = "Visible";
  604. ScrollBarDisplayType[ScrollBarDisplayType["Auto"] = 2] = "Auto";
  605. ScrollBarDisplayType[ScrollBarDisplayType["Hidden"] = 3] = "Hidden";
  606. })(ScrollBarDisplayType = fgui.ScrollBarDisplayType || (fgui.ScrollBarDisplayType = {}));
  607. let ScrollType;
  608. (function (ScrollType) {
  609. ScrollType[ScrollType["Horizontal"] = 0] = "Horizontal";
  610. ScrollType[ScrollType["Vertical"] = 1] = "Vertical";
  611. ScrollType[ScrollType["Both"] = 2] = "Both";
  612. })(ScrollType = fgui.ScrollType || (fgui.ScrollType = {}));
  613. let FlipType;
  614. (function (FlipType) {
  615. FlipType[FlipType["None"] = 0] = "None";
  616. FlipType[FlipType["Horizontal"] = 1] = "Horizontal";
  617. FlipType[FlipType["Vertical"] = 2] = "Vertical";
  618. FlipType[FlipType["Both"] = 3] = "Both";
  619. })(FlipType = fgui.FlipType || (fgui.FlipType = {}));
  620. let ChildrenRenderOrder;
  621. (function (ChildrenRenderOrder) {
  622. ChildrenRenderOrder[ChildrenRenderOrder["Ascent"] = 0] = "Ascent";
  623. ChildrenRenderOrder[ChildrenRenderOrder["Descent"] = 1] = "Descent";
  624. ChildrenRenderOrder[ChildrenRenderOrder["Arch"] = 2] = "Arch";
  625. })(ChildrenRenderOrder = fgui.ChildrenRenderOrder || (fgui.ChildrenRenderOrder = {}));
  626. let GroupLayoutType;
  627. (function (GroupLayoutType) {
  628. GroupLayoutType[GroupLayoutType["None"] = 0] = "None";
  629. GroupLayoutType[GroupLayoutType["Horizontal"] = 1] = "Horizontal";
  630. GroupLayoutType[GroupLayoutType["Vertical"] = 2] = "Vertical";
  631. })(GroupLayoutType = fgui.GroupLayoutType || (fgui.GroupLayoutType = {}));
  632. let PopupDirection;
  633. (function (PopupDirection) {
  634. PopupDirection[PopupDirection["Auto"] = 0] = "Auto";
  635. PopupDirection[PopupDirection["Up"] = 1] = "Up";
  636. PopupDirection[PopupDirection["Down"] = 2] = "Down";
  637. })(PopupDirection = fgui.PopupDirection || (fgui.PopupDirection = {}));
  638. let RelationType;
  639. (function (RelationType) {
  640. RelationType[RelationType["Left_Left"] = 0] = "Left_Left";
  641. RelationType[RelationType["Left_Center"] = 1] = "Left_Center";
  642. RelationType[RelationType["Left_Right"] = 2] = "Left_Right";
  643. RelationType[RelationType["Center_Center"] = 3] = "Center_Center";
  644. RelationType[RelationType["Right_Left"] = 4] = "Right_Left";
  645. RelationType[RelationType["Right_Center"] = 5] = "Right_Center";
  646. RelationType[RelationType["Right_Right"] = 6] = "Right_Right";
  647. RelationType[RelationType["Top_Top"] = 7] = "Top_Top";
  648. RelationType[RelationType["Top_Middle"] = 8] = "Top_Middle";
  649. RelationType[RelationType["Top_Bottom"] = 9] = "Top_Bottom";
  650. RelationType[RelationType["Middle_Middle"] = 10] = "Middle_Middle";
  651. RelationType[RelationType["Bottom_Top"] = 11] = "Bottom_Top";
  652. RelationType[RelationType["Bottom_Middle"] = 12] = "Bottom_Middle";
  653. RelationType[RelationType["Bottom_Bottom"] = 13] = "Bottom_Bottom";
  654. RelationType[RelationType["Width"] = 14] = "Width";
  655. RelationType[RelationType["Height"] = 15] = "Height";
  656. RelationType[RelationType["LeftExt_Left"] = 16] = "LeftExt_Left";
  657. RelationType[RelationType["LeftExt_Right"] = 17] = "LeftExt_Right";
  658. RelationType[RelationType["RightExt_Left"] = 18] = "RightExt_Left";
  659. RelationType[RelationType["RightExt_Right"] = 19] = "RightExt_Right";
  660. RelationType[RelationType["TopExt_Top"] = 20] = "TopExt_Top";
  661. RelationType[RelationType["TopExt_Bottom"] = 21] = "TopExt_Bottom";
  662. RelationType[RelationType["BottomExt_Top"] = 22] = "BottomExt_Top";
  663. RelationType[RelationType["BottomExt_Bottom"] = 23] = "BottomExt_Bottom";
  664. RelationType[RelationType["Size"] = 24] = "Size";
  665. })(RelationType = fgui.RelationType || (fgui.RelationType = {}));
  666. let FillMethod;
  667. (function (FillMethod) {
  668. FillMethod[FillMethod["None"] = 0] = "None";
  669. FillMethod[FillMethod["Horizontal"] = 1] = "Horizontal";
  670. FillMethod[FillMethod["Vertical"] = 2] = "Vertical";
  671. FillMethod[FillMethod["Radial90"] = 3] = "Radial90";
  672. FillMethod[FillMethod["Radial180"] = 4] = "Radial180";
  673. FillMethod[FillMethod["Radial360"] = 5] = "Radial360";
  674. })(FillMethod = fgui.FillMethod || (fgui.FillMethod = {}));
  675. let FillOrigin;
  676. (function (FillOrigin) {
  677. FillOrigin[FillOrigin["Top"] = 0] = "Top";
  678. FillOrigin[FillOrigin["Bottom"] = 1] = "Bottom";
  679. FillOrigin[FillOrigin["Left"] = 2] = "Left";
  680. FillOrigin[FillOrigin["Right"] = 3] = "Right";
  681. FillOrigin[FillOrigin["TopLeft"] = 0] = "TopLeft";
  682. FillOrigin[FillOrigin["TopRight"] = 1] = "TopRight";
  683. FillOrigin[FillOrigin["BottomLeft"] = 2] = "BottomLeft";
  684. FillOrigin[FillOrigin["BottomRight"] = 3] = "BottomRight";
  685. })(FillOrigin = fgui.FillOrigin || (fgui.FillOrigin = {}));
  686. let FillOrigin90;
  687. (function (FillOrigin90) {
  688. FillOrigin90[FillOrigin90["TopLeft"] = 0] = "TopLeft";
  689. FillOrigin90[FillOrigin90["TopRight"] = 1] = "TopRight";
  690. FillOrigin90[FillOrigin90["BottomLeft"] = 2] = "BottomLeft";
  691. FillOrigin90[FillOrigin90["BottomRight"] = 3] = "BottomRight";
  692. })(FillOrigin90 = fgui.FillOrigin90 || (fgui.FillOrigin90 = {}));
  693. let ObjectPropID;
  694. (function (ObjectPropID) {
  695. ObjectPropID[ObjectPropID["Text"] = 0] = "Text";
  696. ObjectPropID[ObjectPropID["Icon"] = 1] = "Icon";
  697. ObjectPropID[ObjectPropID["Color"] = 2] = "Color";
  698. ObjectPropID[ObjectPropID["OutlineColor"] = 3] = "OutlineColor";
  699. ObjectPropID[ObjectPropID["Playing"] = 4] = "Playing";
  700. ObjectPropID[ObjectPropID["Frame"] = 5] = "Frame";
  701. ObjectPropID[ObjectPropID["DeltaTime"] = 6] = "DeltaTime";
  702. ObjectPropID[ObjectPropID["TimeScale"] = 7] = "TimeScale";
  703. ObjectPropID[ObjectPropID["FontSize"] = 8] = "FontSize";
  704. ObjectPropID[ObjectPropID["Selected"] = 9] = "Selected";
  705. })(ObjectPropID = fgui.ObjectPropID || (fgui.ObjectPropID = {}));
  706. })(fgui);
  707. (function (fgui) {
  708. class GObject {
  709. constructor() {
  710. this._x = 0;
  711. this._y = 0;
  712. this._alpha = 1;
  713. this._rotation = 0;
  714. this._visible = true;
  715. this._touchable = true;
  716. this._scaleX = 1;
  717. this._scaleY = 1;
  718. this._skewX = 0;
  719. this._skewY = 0;
  720. this._pivotX = 0;
  721. this._pivotY = 0;
  722. this._pivotOffsetX = 0;
  723. this._pivotOffsetY = 0;
  724. this._sortingOrder = 0;
  725. this._internalVisible = true;
  726. this._yOffset = 0;
  727. this.minWidth = 0;
  728. this.minHeight = 0;
  729. this.maxWidth = 0;
  730. this.maxHeight = 0;
  731. this.sourceWidth = 0;
  732. this.sourceHeight = 0;
  733. this.initWidth = 0;
  734. this.initHeight = 0;
  735. this._width = 0;
  736. this._height = 0;
  737. this._rawWidth = 0;
  738. this._rawHeight = 0;
  739. this._sizePercentInGroup = 0;
  740. this._id = "" + _gInstanceCounter++;
  741. this._name = "";
  742. this.createDisplayObject();
  743. this._relations = new fgui.Relations(this);
  744. this._gears = new Array(10);
  745. }
  746. get id() {
  747. return this._id;
  748. }
  749. get name() {
  750. return this._name;
  751. }
  752. set name(value) {
  753. this._name = value;
  754. }
  755. get x() {
  756. return this._x;
  757. }
  758. set x(value) {
  759. this.setXY(value, this._y);
  760. }
  761. get y() {
  762. return this._y;
  763. }
  764. set y(value) {
  765. this.setXY(this._x, value);
  766. }
  767. setXY(xv, yv) {
  768. if (this._x != xv || this._y != yv) {
  769. var dx = xv - this._x;
  770. var dy = yv - this._y;
  771. this._x = xv;
  772. this._y = yv;
  773. this.handleXYChanged();
  774. if (this instanceof fgui.GGroup)
  775. this.moveChildren(dx, dy);
  776. this.updateGear(1);
  777. if (this._parent && !(this._parent instanceof fgui.GList)) {
  778. this._parent.setBoundsChangedFlag();
  779. if (this._group)
  780. this._group.setBoundsChangedFlag(true);
  781. this.displayObject.event(fgui.Events.XY_CHANGED);
  782. }
  783. if (GObject.draggingObject == this && !sUpdateInDragging)
  784. this.localToGlobalRect(0, 0, this.width, this.height, sGlobalRect);
  785. }
  786. }
  787. get xMin() {
  788. return this._pivotAsAnchor ? (this._x - this._width * this._pivotX) : this._x;
  789. }
  790. set xMin(value) {
  791. if (this._pivotAsAnchor)
  792. this.setXY(value + this._width * this._pivotX, this._y);
  793. else
  794. this.setXY(value, this._y);
  795. }
  796. get yMin() {
  797. return this._pivotAsAnchor ? (this._y - this._height * this._pivotY) : this._y;
  798. }
  799. set yMin(value) {
  800. if (this._pivotAsAnchor)
  801. this.setXY(this._x, value + this._height * this._pivotY);
  802. else
  803. this.setXY(this._x, value);
  804. }
  805. get pixelSnapping() {
  806. return this._pixelSnapping;
  807. }
  808. set pixelSnapping(value) {
  809. if (this._pixelSnapping != value) {
  810. this._pixelSnapping = value;
  811. this.handleXYChanged();
  812. }
  813. }
  814. center(restraint) {
  815. var r;
  816. if (this._parent)
  817. r = this.parent;
  818. else
  819. r = this.root;
  820. this.setXY((r.width - this.width) / 2, (r.height - this.height) / 2);
  821. if (restraint) {
  822. this.addRelation(r, fgui.RelationType.Center_Center);
  823. this.addRelation(r, fgui.RelationType.Middle_Middle);
  824. }
  825. }
  826. get width() {
  827. this.ensureSizeCorrect();
  828. if (this._relations.sizeDirty)
  829. this._relations.ensureRelationsSizeCorrect();
  830. return this._width;
  831. }
  832. set width(value) {
  833. this.setSize(value, this._rawHeight);
  834. }
  835. get height() {
  836. this.ensureSizeCorrect();
  837. if (this._relations.sizeDirty)
  838. this._relations.ensureRelationsSizeCorrect();
  839. return this._height;
  840. }
  841. set height(value) {
  842. this.setSize(this._rawWidth, value);
  843. }
  844. setSize(wv, hv, ignorePivot) {
  845. if (this._rawWidth != wv || this._rawHeight != hv) {
  846. this._rawWidth = wv;
  847. this._rawHeight = hv;
  848. if (wv < this.minWidth)
  849. wv = this.minWidth;
  850. if (hv < this.minHeight)
  851. hv = this.minHeight;
  852. if (this.maxWidth > 0 && wv > this.maxWidth)
  853. wv = this.maxWidth;
  854. if (this.maxHeight > 0 && hv > this.maxHeight)
  855. hv = this.maxHeight;
  856. var dWidth = wv - this._width;
  857. var dHeight = hv - this._height;
  858. this._width = wv;
  859. this._height = hv;
  860. this.handleSizeChanged();
  861. if (this._pivotX != 0 || this._pivotY != 0) {
  862. if (!this._pivotAsAnchor) {
  863. if (!ignorePivot)
  864. this.setXY(this.x - this._pivotX * dWidth, this.y - this._pivotY * dHeight);
  865. this.updatePivotOffset();
  866. }
  867. else
  868. this.applyPivot();
  869. }
  870. if (this instanceof fgui.GGroup)
  871. this.resizeChildren(dWidth, dHeight);
  872. this.updateGear(2);
  873. if (this._parent) {
  874. this._relations.onOwnerSizeChanged(dWidth, dHeight, this._pivotAsAnchor || !ignorePivot);
  875. this._parent.setBoundsChangedFlag();
  876. if (this._group)
  877. this._group.setBoundsChangedFlag();
  878. }
  879. this.displayObject.event(fgui.Events.SIZE_CHANGED);
  880. }
  881. }
  882. ensureSizeCorrect() {
  883. }
  884. makeFullScreen() {
  885. this.setSize(fgui.GRoot.inst.width, fgui.GRoot.inst.height);
  886. }
  887. get actualWidth() {
  888. return this.width * Math.abs(this._scaleX);
  889. }
  890. get actualHeight() {
  891. return this.height * Math.abs(this._scaleY);
  892. }
  893. get scaleX() {
  894. return this._scaleX;
  895. }
  896. set scaleX(value) {
  897. this.setScale(value, this._scaleY);
  898. }
  899. get scaleY() {
  900. return this._scaleY;
  901. }
  902. set scaleY(value) {
  903. this.setScale(this._scaleX, value);
  904. }
  905. setScale(sx, sy) {
  906. if (this._scaleX != sx || this._scaleY != sy) {
  907. this._scaleX = sx;
  908. this._scaleY = sy;
  909. this.handleScaleChanged();
  910. this.applyPivot();
  911. this.updateGear(2);
  912. }
  913. }
  914. get skewX() {
  915. return this._skewX;
  916. }
  917. set skewX(value) {
  918. this.setSkew(value, this._skewY);
  919. }
  920. get skewY() {
  921. return this._skewY;
  922. }
  923. set skewY(value) {
  924. this.setSkew(this._skewX, value);
  925. }
  926. setSkew(sx, sy) {
  927. if (this._skewX != sx || this._skewY != sy) {
  928. this._skewX = sx;
  929. this._skewY = sy;
  930. if (this._displayObject) {
  931. this._displayObject.skew(-sx, sy);
  932. this.applyPivot();
  933. }
  934. }
  935. }
  936. get pivotX() {
  937. return this._pivotX;
  938. }
  939. set pivotX(value) {
  940. this.setPivot(value, this._pivotY);
  941. }
  942. get pivotY() {
  943. return this._pivotY;
  944. }
  945. set pivotY(value) {
  946. this.setPivot(this._pivotX, value);
  947. }
  948. setPivot(xv, yv = 0, asAnchor) {
  949. if (this._pivotX != xv || this._pivotY != yv || this._pivotAsAnchor != asAnchor) {
  950. this._pivotX = xv;
  951. this._pivotY = yv;
  952. this._pivotAsAnchor = asAnchor;
  953. this.updatePivotOffset();
  954. this.handleXYChanged();
  955. }
  956. }
  957. get pivotAsAnchor() {
  958. return this._pivotAsAnchor;
  959. }
  960. internalSetPivot(xv, yv, asAnchor) {
  961. this._pivotX = xv;
  962. this._pivotY = yv;
  963. this._pivotAsAnchor = asAnchor;
  964. if (this._pivotAsAnchor)
  965. this.handleXYChanged();
  966. }
  967. updatePivotOffset() {
  968. if (this._displayObject) {
  969. if (this._displayObject.transform && (this._pivotX != 0 || this._pivotY != 0)) {
  970. sHelperPoint.x = this._pivotX * this._width;
  971. sHelperPoint.y = this._pivotY * this._height;
  972. var pt = this._displayObject.transform.transformPoint(sHelperPoint);
  973. this._pivotOffsetX = this._pivotX * this._width - pt.x;
  974. this._pivotOffsetY = this._pivotY * this._height - pt.y;
  975. }
  976. else {
  977. this._pivotOffsetX = 0;
  978. this._pivotOffsetY = 0;
  979. }
  980. }
  981. }
  982. applyPivot() {
  983. if (this._pivotX != 0 || this._pivotY != 0) {
  984. this.updatePivotOffset();
  985. this.handleXYChanged();
  986. }
  987. }
  988. get touchable() {
  989. return this._touchable;
  990. }
  991. set touchable(value) {
  992. if (this._touchable != value) {
  993. this._touchable = value;
  994. this.updateGear(3);
  995. if ((this instanceof fgui.GImage) || (this instanceof fgui.GMovieClip)
  996. || (this instanceof fgui.GTextField) && !(this instanceof fgui.GTextInput) && !(this instanceof fgui.GRichTextField))
  997. //Touch is not supported by GImage/GMovieClip/GTextField
  998. return;
  999. if (this._displayObject)
  1000. this._displayObject.mouseEnabled = this._touchable;
  1001. }
  1002. }
  1003. get grayed() {
  1004. return this._grayed;
  1005. }
  1006. set grayed(value) {
  1007. if (this._grayed != value) {
  1008. this._grayed = value;
  1009. this.handleGrayedChanged();
  1010. this.updateGear(3);
  1011. }
  1012. }
  1013. get enabled() {
  1014. return !this._grayed && this._touchable;
  1015. }
  1016. set enabled(value) {
  1017. this.grayed = !value;
  1018. this.touchable = value;
  1019. }
  1020. get rotation() {
  1021. return this._rotation;
  1022. }
  1023. set rotation(value) {
  1024. if (this._rotation != value) {
  1025. this._rotation = value;
  1026. if (this._displayObject) {
  1027. this._displayObject.rotation = this.normalizeRotation;
  1028. this.applyPivot();
  1029. }
  1030. this.updateGear(3);
  1031. }
  1032. }
  1033. get normalizeRotation() {
  1034. var rot = this._rotation % 360;
  1035. if (rot > 180)
  1036. rot = rot - 360;
  1037. else if (rot < -180)
  1038. rot = 360 + rot;
  1039. return rot;
  1040. }
  1041. get alpha() {
  1042. return this._alpha;
  1043. }
  1044. set alpha(value) {
  1045. if (this._alpha != value) {
  1046. this._alpha = value;
  1047. this.handleAlphaChanged();
  1048. this.updateGear(3);
  1049. }
  1050. }
  1051. get visible() {
  1052. return this._visible;
  1053. }
  1054. set visible(value) {
  1055. if (this._visible != value) {
  1056. this._visible = value;
  1057. this.handleVisibleChanged();
  1058. if (this._parent)
  1059. this._parent.setBoundsChangedFlag();
  1060. if (this._group && this._group.excludeInvisibles)
  1061. this._group.setBoundsChangedFlag();
  1062. }
  1063. }
  1064. get internalVisible() {
  1065. return this._internalVisible && (!this._group || this._group.internalVisible)
  1066. && !this._displayObject._cacheStyle.maskParent;
  1067. }
  1068. get internalVisible2() {
  1069. return this._visible && (!this._group || this._group.internalVisible2);
  1070. }
  1071. get internalVisible3() {
  1072. return this._internalVisible && this._visible;
  1073. }
  1074. get sortingOrder() {
  1075. return this._sortingOrder;
  1076. }
  1077. set sortingOrder(value) {
  1078. if (value < 0)
  1079. value = 0;
  1080. if (this._sortingOrder != value) {
  1081. var old = this._sortingOrder;
  1082. this._sortingOrder = value;
  1083. if (this._parent)
  1084. this._parent.childSortingOrderChanged(this, old, this._sortingOrder);
  1085. }
  1086. }
  1087. get focused() {
  1088. return this.root.focus == this;
  1089. }
  1090. requestFocus() {
  1091. this.root.focus = this;
  1092. }
  1093. get tooltips() {
  1094. return this._tooltips;
  1095. }
  1096. set tooltips(value) {
  1097. if (this._tooltips) {
  1098. this.off(Laya.Event.ROLL_OVER, this, this.__rollOver);
  1099. this.off(Laya.Event.ROLL_OUT, this, this.__rollOut);
  1100. }
  1101. this._tooltips = value;
  1102. if (this._tooltips) {
  1103. this.on(Laya.Event.ROLL_OVER, this, this.__rollOver);
  1104. this.on(Laya.Event.ROLL_OUT, this, this.__rollOut);
  1105. }
  1106. }
  1107. __rollOver(evt) {
  1108. Laya.timer.once(100, this, this.__doShowTooltips);
  1109. }
  1110. __doShowTooltips() {
  1111. var r = this.root;
  1112. if (r)
  1113. this.root.showTooltips(this._tooltips);
  1114. }
  1115. __rollOut(evt) {
  1116. Laya.timer.clear(this, this.__doShowTooltips);
  1117. this.root.hideTooltips();
  1118. }
  1119. get blendMode() {
  1120. return this._displayObject.blendMode;
  1121. }
  1122. set blendMode(value) {
  1123. this._displayObject.blendMode = value;
  1124. }
  1125. get filters() {
  1126. return this._displayObject.filters;
  1127. }
  1128. set filters(value) {
  1129. this._displayObject.filters = value;
  1130. }
  1131. get inContainer() {
  1132. return this._displayObject != null && this._displayObject.parent != null;
  1133. }
  1134. get onStage() {
  1135. return this._displayObject != null && this._displayObject.stage != null;
  1136. }
  1137. get resourceURL() {
  1138. if (this.packageItem)
  1139. return "ui://" + this.packageItem.owner.id + this.packageItem.id;
  1140. else
  1141. return null;
  1142. }
  1143. set group(value) {
  1144. if (this._group != value) {
  1145. if (this._group)
  1146. this._group.setBoundsChangedFlag();
  1147. this._group = value;
  1148. if (this._group)
  1149. this._group.setBoundsChangedFlag();
  1150. }
  1151. }
  1152. get group() {
  1153. return this._group;
  1154. }
  1155. getGear(index) {
  1156. var gear = this._gears[index];
  1157. if (!gear)
  1158. this._gears[index] = gear = fgui.GearBase.create(this, index);
  1159. return gear;
  1160. }
  1161. updateGear(index) {
  1162. if (this._underConstruct || this._gearLocked)
  1163. return;
  1164. var gear = this._gears[index];
  1165. if (gear && gear.controller)
  1166. gear.updateState();
  1167. }
  1168. checkGearController(index, c) {
  1169. return this._gears[index] && this._gears[index].controller == c;
  1170. }
  1171. updateGearFromRelations(index, dx, dy) {
  1172. if (this._gears[index])
  1173. this._gears[index].updateFromRelations(dx, dy);
  1174. }
  1175. addDisplayLock() {
  1176. var gearDisplay = (this._gears[0]);
  1177. if (gearDisplay && gearDisplay.controller) {
  1178. var ret = gearDisplay.addLock();
  1179. this.checkGearDisplay();
  1180. return ret;
  1181. }
  1182. else
  1183. return 0;
  1184. }
  1185. releaseDisplayLock(token) {
  1186. var gearDisplay = (this._gears[0]);
  1187. if (gearDisplay && gearDisplay.controller) {
  1188. gearDisplay.releaseLock(token);
  1189. this.checkGearDisplay();
  1190. }
  1191. }
  1192. checkGearDisplay() {
  1193. if (this._handlingController)
  1194. return;
  1195. var connected = !this._gears[0] || (this._gears[0]).connected;
  1196. if (this._gears[8])
  1197. connected = this._gears[8].evaluate(connected);
  1198. if (connected != this._internalVisible) {
  1199. this._internalVisible = connected;
  1200. if (this._parent) {
  1201. this._parent.childStateChanged(this);
  1202. if (this._group && this._group.excludeInvisibles)
  1203. this._group.setBoundsChangedFlag();
  1204. }
  1205. }
  1206. }
  1207. get relations() {
  1208. return this._relations;
  1209. }
  1210. addRelation(target, relationType, usePercent) {
  1211. this._relations.add(target, relationType, usePercent);
  1212. }
  1213. removeRelation(target, relationType) {
  1214. this._relations.remove(target, relationType);
  1215. }
  1216. get displayObject() {
  1217. return this._displayObject;
  1218. }
  1219. get parent() {
  1220. return this._parent;
  1221. }
  1222. set parent(val) {
  1223. this._parent = val;
  1224. }
  1225. removeFromParent() {
  1226. if (this._parent)
  1227. this._parent.removeChild(this);
  1228. }
  1229. get root() {
  1230. if (this instanceof fgui.GRoot)
  1231. return this;
  1232. var p = this._parent;
  1233. while (p) {
  1234. if (p instanceof fgui.GRoot)
  1235. return p;
  1236. p = p.parent;
  1237. }
  1238. return fgui.GRoot.inst;
  1239. }
  1240. get asCom() {
  1241. return this;
  1242. }
  1243. get asButton() {
  1244. return this;
  1245. }
  1246. get asLabel() {
  1247. return this;
  1248. }
  1249. get asProgress() {
  1250. return this;
  1251. }
  1252. get asTextField() {
  1253. return this;
  1254. }
  1255. get asRichTextField() {
  1256. return this;
  1257. }
  1258. get asTextInput() {
  1259. return this;
  1260. }
  1261. get asLoader() {
  1262. return this;
  1263. }
  1264. get asList() {
  1265. return this;
  1266. }
  1267. get asTree() {
  1268. return this;
  1269. }
  1270. get asGraph() {
  1271. return this;
  1272. }
  1273. get asGroup() {
  1274. return this;
  1275. }
  1276. get asSlider() {
  1277. return this;
  1278. }
  1279. get asComboBox() {
  1280. return this;
  1281. }
  1282. get asImage() {
  1283. return this;
  1284. }
  1285. get asMovieClip() {
  1286. return this;
  1287. }
  1288. get text() {
  1289. return null;
  1290. }
  1291. set text(value) {
  1292. }
  1293. get icon() {
  1294. return null;
  1295. }
  1296. set icon(value) {
  1297. }
  1298. get treeNode() {
  1299. return this._treeNode;
  1300. }
  1301. get isDisposed() {
  1302. return this._displayObject == null;
  1303. }
  1304. dispose() {
  1305. this.removeFromParent();
  1306. this._relations.dispose();
  1307. this._displayObject.destroy();
  1308. this._displayObject = null;
  1309. for (var i = 0; i < 10; i++) {
  1310. var gear = this._gears[i];
  1311. if (gear)
  1312. gear.dispose();
  1313. }
  1314. }
  1315. onClick(thisObj, listener, args) {
  1316. this.on(Laya.Event.CLICK, thisObj, listener, args);
  1317. }
  1318. offClick(thisObj, listener) {
  1319. this.off(Laya.Event.CLICK, thisObj, listener);
  1320. }
  1321. hasClickListener() {
  1322. return this._displayObject.hasListener(Laya.Event.CLICK);
  1323. }
  1324. on(type, thisObject, listener, args) {
  1325. this._displayObject.on(type, thisObject, listener, args);
  1326. }
  1327. off(type, thisObject, listener) {
  1328. this._displayObject.off(type, thisObject, listener);
  1329. }
  1330. get draggable() {
  1331. return this._draggable;
  1332. }
  1333. set draggable(value) {
  1334. if (this._draggable != value) {
  1335. this._draggable = value;
  1336. this.initDrag();
  1337. }
  1338. }
  1339. get dragBounds() {
  1340. return this._dragBounds;
  1341. }
  1342. set dragBounds(value) {
  1343. this._dragBounds = value;
  1344. }
  1345. startDrag(touchID) {
  1346. if (this._displayObject.stage == null)
  1347. return;
  1348. this.dragBegin(touchID);
  1349. }
  1350. stopDrag() {
  1351. this.dragEnd();
  1352. }
  1353. get dragging() {
  1354. return GObject.draggingObject == this;
  1355. }
  1356. localToGlobal(ax, ay, result) {
  1357. ax = ax || 0;
  1358. ay = ay || 0;
  1359. if (this._pivotAsAnchor) {
  1360. ax += this._pivotX * this._width;
  1361. ay += this._pivotY * this._height;
  1362. }
  1363. result = result || new Laya.Point();
  1364. result.x = ax;
  1365. result.y = ay;
  1366. return this._displayObject.localToGlobal(result, false);
  1367. }
  1368. globalToLocal(ax, ay, result) {
  1369. ax = ax || 0;
  1370. ay = ay || 0;
  1371. result = result || new Laya.Point();
  1372. result.x = ax;
  1373. result.y = ay;
  1374. result = this._displayObject.globalToLocal(result, false);
  1375. if (this._pivotAsAnchor) {
  1376. result.x -= this._pivotX * this._width;
  1377. result.y -= this._pivotY * this._height;
  1378. }
  1379. return result;
  1380. }
  1381. localToGlobalRect(ax, ay, aw, ah, result) {
  1382. ax = ax || 0;
  1383. ay = ay || 0;
  1384. aw = aw || 0;
  1385. ah = ah || 0;
  1386. result = result || new Laya.Rectangle();
  1387. var pt = this.localToGlobal(ax, ay);
  1388. result.x = pt.x;
  1389. result.y = pt.y;
  1390. pt = this.localToGlobal(ax + aw, ay + ah);
  1391. result.width = pt.x - result.x;
  1392. result.height = pt.y - result.y;
  1393. return result;
  1394. }
  1395. globalToLocalRect(ax, ay, aw, ah, result) {
  1396. ax = ax || 0;
  1397. ay = ay || 0;
  1398. aw = aw || 0;
  1399. ah = ah || 0;
  1400. result = result || new Laya.Rectangle();
  1401. var pt = this.globalToLocal(ax, ay);
  1402. result.x = pt.x;
  1403. result.y = pt.y;
  1404. pt = this.globalToLocal(ax + aw, ay + ah);
  1405. result.width = pt.x - result.x;
  1406. result.height = pt.y - result.y;
  1407. return result;
  1408. }
  1409. handleControllerChanged(c) {
  1410. this._handlingController = true;
  1411. for (var i = 0; i < 10; i++) {
  1412. var gear = this._gears[i];
  1413. if (gear && gear.controller == c)
  1414. gear.apply();
  1415. }
  1416. this._handlingController = false;
  1417. this.checkGearDisplay();
  1418. }
  1419. createDisplayObject() {
  1420. this._displayObject = new Laya.Sprite();
  1421. this._displayObject["$owner"] = this;
  1422. }
  1423. handleXYChanged() {
  1424. var xv = this._x;
  1425. var yv = this._y + this._yOffset;
  1426. if (this._pivotAsAnchor) {
  1427. xv -= this._pivotX * this._width;
  1428. yv -= this._pivotY * this._height;
  1429. }
  1430. if (this._pixelSnapping) {
  1431. xv = Math.round(xv);
  1432. yv = Math.round(yv);
  1433. }
  1434. this._displayObject.pos(xv + this._pivotOffsetX, yv + this._pivotOffsetY);
  1435. }
  1436. handleSizeChanged() {
  1437. this._displayObject.size(this._width, this._height);
  1438. }
  1439. handleScaleChanged() {
  1440. this._displayObject.scale(this._scaleX, this._scaleY, true);
  1441. }
  1442. handleGrayedChanged() {
  1443. fgui.ToolSet.setColorFilter(this._displayObject, this._grayed);
  1444. }
  1445. handleAlphaChanged() {
  1446. this._displayObject.alpha = this._alpha;
  1447. }
  1448. handleVisibleChanged() {
  1449. this._displayObject.visible = this.internalVisible2;
  1450. }
  1451. getProp(index) {
  1452. switch (index) {
  1453. case fgui.ObjectPropID.Text:
  1454. return this.text;
  1455. case fgui.ObjectPropID.Icon:
  1456. return this.icon;
  1457. case fgui.ObjectPropID.Color:
  1458. return null;
  1459. case fgui.ObjectPropID.OutlineColor:
  1460. return null;
  1461. case fgui.ObjectPropID.Playing:
  1462. return false;
  1463. case fgui.ObjectPropID.Frame:
  1464. return 0;
  1465. case fgui.ObjectPropID.DeltaTime:
  1466. return 0;
  1467. case fgui.ObjectPropID.TimeScale:
  1468. return 1;
  1469. case fgui.ObjectPropID.FontSize:
  1470. return 0;
  1471. case fgui.ObjectPropID.Selected:
  1472. return false;
  1473. default:
  1474. return undefined;
  1475. }
  1476. }
  1477. setProp(index, value) {
  1478. switch (index) {
  1479. case fgui.ObjectPropID.Text:
  1480. this.text = value;
  1481. break;
  1482. case fgui.ObjectPropID.Icon:
  1483. this.icon = value;
  1484. break;
  1485. }
  1486. }
  1487. constructFromResource() {
  1488. }
  1489. setup_beforeAdd(buffer, beginPos) {
  1490. buffer.seek(beginPos, 0);
  1491. buffer.skip(5);
  1492. var f1;
  1493. var f2;
  1494. this._id = buffer.readS();
  1495. this._name = buffer.readS();
  1496. f1 = buffer.getInt32();
  1497. f2 = buffer.getInt32();
  1498. this.setXY(f1, f2);
  1499. if (buffer.readBool()) {
  1500. this.initWidth = buffer.getInt32();
  1501. this.initHeight = buffer.getInt32();
  1502. this.setSize(this.initWidth, this.initHeight, true);
  1503. }
  1504. if (buffer.readBool()) {
  1505. this.minWidth = buffer.getInt32();
  1506. this.maxWidth = buffer.getInt32();
  1507. this.minHeight = buffer.getInt32();
  1508. this.maxHeight = buffer.getInt32();
  1509. }
  1510. if (buffer.readBool()) {
  1511. f1 = buffer.getFloat32();
  1512. f2 = buffer.getFloat32();
  1513. this.setScale(f1, f2);
  1514. }
  1515. if (buffer.readBool()) {
  1516. f1 = buffer.getFloat32();
  1517. f2 = buffer.getFloat32();
  1518. this.setSkew(f1, f2);
  1519. }
  1520. if (buffer.readBool()) {
  1521. f1 = buffer.getFloat32();
  1522. f2 = buffer.getFloat32();
  1523. this.setPivot(f1, f2, buffer.readBool());
  1524. }
  1525. f1 = buffer.getFloat32();
  1526. if (f1 != 1)
  1527. this.alpha = f1;
  1528. f1 = buffer.getFloat32();
  1529. if (f1 != 0)
  1530. this.rotation = f1;
  1531. if (!buffer.readBool())
  1532. this.visible = false;
  1533. if (!buffer.readBool())
  1534. this.touchable = false;
  1535. if (buffer.readBool())
  1536. this.grayed = true;
  1537. var bm = buffer.readByte();
  1538. if (fgui.BlendMode[bm])
  1539. this.blendMode = fgui.BlendMode[bm];
  1540. var filter = buffer.readByte();
  1541. if (filter == 1) {
  1542. fgui.ToolSet.setColorFilter(this._displayObject, [buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32()]);
  1543. }
  1544. var str = buffer.readS();
  1545. if (str != null)
  1546. this.data = str;
  1547. }
  1548. setup_afterAdd(buffer, beginPos) {
  1549. buffer.seek(beginPos, 1);
  1550. var str = buffer.readS();
  1551. if (str != null)
  1552. this.tooltips = str;
  1553. var groupId = buffer.getInt16();
  1554. if (groupId >= 0)
  1555. this.group = this.parent.getChildAt(groupId);
  1556. buffer.seek(beginPos, 2);
  1557. var cnt = buffer.getInt16();
  1558. for (var i = 0; i < cnt; i++) {
  1559. var nextPos = buffer.getInt16();
  1560. nextPos += buffer.pos;
  1561. var gear = this.getGear(buffer.readByte());
  1562. gear.setup(buffer);
  1563. buffer.pos = nextPos;
  1564. }
  1565. }
  1566. //drag support
  1567. //-------------------------------------------------------------------
  1568. initDrag() {
  1569. if (this._draggable)
  1570. this.on(Laya.Event.MOUSE_DOWN, this, this.__begin);
  1571. else
  1572. this.off(Laya.Event.MOUSE_DOWN, this, this.__begin);
  1573. }
  1574. dragBegin(touchID) {
  1575. if (GObject.draggingObject) {
  1576. let tmp = GObject.draggingObject;
  1577. tmp.stopDrag();
  1578. GObject.draggingObject = null;
  1579. fgui.Events.dispatch(fgui.Events.DRAG_END, tmp._displayObject, { touchId: touchID });
  1580. }
  1581. sGlobalDragStart.x = Laya.stage.mouseX;
  1582. sGlobalDragStart.y = Laya.stage.mouseY;
  1583. this.localToGlobalRect(0, 0, this.width, this.height, sGlobalRect);
  1584. this._dragTesting = true;
  1585. GObject.draggingObject = this;
  1586. Laya.stage.on(Laya.Event.MOUSE_MOVE, this, this.__moving);
  1587. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.__end);
  1588. }
  1589. dragEnd() {
  1590. if (GObject.draggingObject == this) {
  1591. this.reset();
  1592. this._dragTesting = false;
  1593. GObject.draggingObject = null;
  1594. }
  1595. sDraggingQuery = false;
  1596. }
  1597. reset() {
  1598. Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.__moving);
  1599. Laya.stage.off(Laya.Event.MOUSE_UP, this, this.__end);
  1600. }
  1601. __begin() {
  1602. if (!this._dragStartPos)
  1603. this._dragStartPos = new Laya.Point();
  1604. this._dragStartPos.x = Laya.stage.mouseX;
  1605. this._dragStartPos.y = Laya.stage.mouseY;
  1606. this._dragTesting = true;
  1607. Laya.stage.on(Laya.Event.MOUSE_MOVE, this, this.__moving);
  1608. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.__end);
  1609. }
  1610. __moving(evt) {
  1611. if (GObject.draggingObject != this && this._draggable && this._dragTesting) {
  1612. var sensitivity = fgui.UIConfig.touchDragSensitivity;
  1613. if (this._dragStartPos
  1614. && Math.abs(this._dragStartPos.x - Laya.stage.mouseX) < sensitivity
  1615. && Math.abs(this._dragStartPos.y - Laya.stage.mouseY) < sensitivity)
  1616. return;
  1617. this._dragTesting = false;
  1618. sDraggingQuery = true;
  1619. fgui.Events.dispatch(fgui.Events.DRAG_START, this._displayObject, evt);
  1620. if (sDraggingQuery)
  1621. this.dragBegin();
  1622. }
  1623. if (GObject.draggingObject == this) {
  1624. var xx = Laya.stage.mouseX - sGlobalDragStart.x + sGlobalRect.x;
  1625. var yy = Laya.stage.mouseY - sGlobalDragStart.y + sGlobalRect.y;
  1626. if (this._dragBounds) {
  1627. var rect = fgui.GRoot.inst.localToGlobalRect(this._dragBounds.x, this._dragBounds.y, this._dragBounds.width, this._dragBounds.height, sDragHelperRect);
  1628. if (xx < rect.x)
  1629. xx = rect.x;
  1630. else if (xx + sGlobalRect.width > rect.right) {
  1631. xx = rect.right - sGlobalRect.width;
  1632. if (xx < rect.x)
  1633. xx = rect.x;
  1634. }
  1635. if (yy < rect.y)
  1636. yy = rect.y;
  1637. else if (yy + sGlobalRect.height > rect.bottom) {
  1638. yy = rect.bottom - sGlobalRect.height;
  1639. if (yy < rect.y)
  1640. yy = rect.y;
  1641. }
  1642. }
  1643. sUpdateInDragging = true;
  1644. var pt = this.parent.globalToLocal(xx, yy, sHelperPoint);
  1645. this.setXY(Math.round(pt.x), Math.round(pt.y));
  1646. sUpdateInDragging = false;
  1647. fgui.Events.dispatch(fgui.Events.DRAG_MOVE, this._displayObject, evt);
  1648. }
  1649. }
  1650. __end(evt) {
  1651. if (GObject.draggingObject == this) {
  1652. GObject.draggingObject = null;
  1653. this.reset();
  1654. fgui.Events.dispatch(fgui.Events.DRAG_END, this._displayObject, evt);
  1655. }
  1656. else if (this._dragTesting) {
  1657. this._dragTesting = false;
  1658. this.reset();
  1659. }
  1660. }
  1661. //-------------------------------------------------------------------
  1662. static cast(sprite) {
  1663. return (sprite["$owner"]);
  1664. }
  1665. }
  1666. fgui.GObject = GObject;
  1667. fgui.BlendMode = {
  1668. 2: Laya.BlendMode.LIGHTER,
  1669. 3: Laya.BlendMode.MULTIPLY,
  1670. 4: Laya.BlendMode.SCREEN
  1671. };
  1672. var _gInstanceCounter = 0;
  1673. var sGlobalDragStart = new Laya.Point();
  1674. var sGlobalRect = new Laya.Rectangle();
  1675. var sHelperPoint = new Laya.Point();
  1676. var sDragHelperRect = new Laya.Rectangle();
  1677. var sUpdateInDragging;
  1678. var sDraggingQuery;
  1679. })(fgui);
  1680. ///<reference path="GObject.ts"/>
  1681. ///<reference path="GObject.ts"/>
  1682. (function (fgui) {
  1683. class GTextField extends fgui.GObject {
  1684. constructor() {
  1685. super();
  1686. }
  1687. get font() {
  1688. return null;
  1689. }
  1690. set font(value) {
  1691. }
  1692. get fontSize() {
  1693. return 0;
  1694. }
  1695. set fontSize(value) {
  1696. }
  1697. get color() {
  1698. return null;
  1699. }
  1700. set color(value) {
  1701. }
  1702. get align() {
  1703. return null;
  1704. }
  1705. set align(value) {
  1706. }
  1707. get valign() {
  1708. return null;
  1709. }
  1710. set valign(value) {
  1711. }
  1712. get leading() {
  1713. return 0;
  1714. }
  1715. set leading(value) {
  1716. }
  1717. get letterSpacing() {
  1718. return 0;
  1719. }
  1720. set letterSpacing(value) {
  1721. }
  1722. get bold() {
  1723. return false;
  1724. }
  1725. set bold(value) {
  1726. }
  1727. get italic() {
  1728. return false;
  1729. }
  1730. set italic(value) {
  1731. }
  1732. get underline() {
  1733. return false;
  1734. }
  1735. set underline(value) {
  1736. }
  1737. get singleLine() {
  1738. return false;
  1739. }
  1740. set singleLine(value) {
  1741. }
  1742. get stroke() {
  1743. return 0;
  1744. }
  1745. set stroke(value) {
  1746. }
  1747. get strokeColor() {
  1748. return null;
  1749. }
  1750. set strokeColor(value) {
  1751. }
  1752. set ubbEnabled(value) {
  1753. this._ubbEnabled = value;
  1754. }
  1755. get ubbEnabled() {
  1756. return this._ubbEnabled;
  1757. }
  1758. get autoSize() {
  1759. return this._autoSize;
  1760. }
  1761. set autoSize(value) {
  1762. if (this._autoSize != value) {
  1763. this._autoSize = value;
  1764. this._widthAutoSize = this._autoSize == fgui.AutoSizeType.Both;
  1765. this._heightAutoSize = this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height;
  1766. this.updateAutoSize();
  1767. }
  1768. }
  1769. updateAutoSize() {
  1770. }
  1771. get textWidth() {
  1772. return 0;
  1773. }
  1774. parseTemplate(template) {
  1775. var pos1 = 0, pos2, pos3;
  1776. var tag;
  1777. var value;
  1778. var result = "";
  1779. while ((pos2 = template.indexOf("{", pos1)) != -1) {
  1780. if (pos2 > 0 && template.charCodeAt(pos2 - 1) == 92) //\
  1781. {
  1782. result += template.substring(pos1, pos2 - 1);
  1783. result += "{";
  1784. pos1 = pos2 + 1;
  1785. continue;
  1786. }
  1787. result += template.substring(pos1, pos2);
  1788. pos1 = pos2;
  1789. pos2 = template.indexOf("}", pos1);
  1790. if (pos2 == -1)
  1791. break;
  1792. if (pos2 == pos1 + 1) {
  1793. result += template.substr(pos1, 2);
  1794. pos1 = pos2 + 1;
  1795. continue;
  1796. }
  1797. tag = template.substring(pos1 + 1, pos2);
  1798. pos3 = tag.indexOf("=");
  1799. if (pos3 != -1) {
  1800. value = this._templateVars[tag.substring(0, pos3)];
  1801. if (value == null)
  1802. result += tag.substring(pos3 + 1);
  1803. else
  1804. result += value;
  1805. }
  1806. else {
  1807. value = this._templateVars[tag];
  1808. if (value != null)
  1809. result += value;
  1810. }
  1811. pos1 = pos2 + 1;
  1812. }
  1813. if (pos1 < template.length)
  1814. result += template.substr(pos1);
  1815. return result;
  1816. }
  1817. get templateVars() {
  1818. return this._templateVars;
  1819. }
  1820. set templateVars(value) {
  1821. if (!this._templateVars && !value)
  1822. return;
  1823. this._templateVars = value;
  1824. this.flushVars();
  1825. }
  1826. setVar(name, value) {
  1827. if (!this._templateVars)
  1828. this._templateVars = {};
  1829. this._templateVars[name] = value;
  1830. return this;
  1831. }
  1832. flushVars() {
  1833. this.text = this._text;
  1834. }
  1835. getProp(index) {
  1836. switch (index) {
  1837. case fgui.ObjectPropID.Color:
  1838. return this.color;
  1839. case fgui.ObjectPropID.OutlineColor:
  1840. return this.strokeColor;
  1841. case fgui.ObjectPropID.FontSize:
  1842. return this.fontSize;
  1843. default:
  1844. return super.getProp(index);
  1845. }
  1846. }
  1847. setProp(index, value) {
  1848. switch (index) {
  1849. case fgui.ObjectPropID.Color:
  1850. this.color = value;
  1851. break;
  1852. case fgui.ObjectPropID.OutlineColor:
  1853. this.strokeColor = value;
  1854. break;
  1855. case fgui.ObjectPropID.FontSize:
  1856. this.fontSize = value;
  1857. break;
  1858. default:
  1859. super.setProp(index, value);
  1860. break;
  1861. }
  1862. }
  1863. setup_beforeAdd(buffer, beginPos) {
  1864. super.setup_beforeAdd(buffer, beginPos);
  1865. buffer.seek(beginPos, 5);
  1866. var iv;
  1867. this.font = buffer.readS();
  1868. this.fontSize = buffer.getInt16();
  1869. this.color = buffer.readColorS();
  1870. iv = buffer.readByte();
  1871. this.align = iv == 0 ? "left" : (iv == 1 ? "center" : "right");
  1872. iv = buffer.readByte();
  1873. this.valign = iv == 0 ? "top" : (iv == 1 ? "middle" : "bottom");
  1874. this.leading = buffer.getInt16();
  1875. this.letterSpacing = buffer.getInt16();
  1876. this.ubbEnabled = buffer.readBool();
  1877. this.autoSize = buffer.readByte();
  1878. this.underline = buffer.readBool();
  1879. this.italic = buffer.readBool();
  1880. this.bold = buffer.readBool();
  1881. this.singleLine = buffer.readBool();
  1882. if (buffer.readBool()) {
  1883. this.strokeColor = buffer.readColorS();
  1884. this.stroke = buffer.getFloat32() + 1;
  1885. }
  1886. if (buffer.readBool()) //shadow
  1887. buffer.skip(12);
  1888. if (buffer.readBool())
  1889. this._templateVars = {};
  1890. }
  1891. setup_afterAdd(buffer, beginPos) {
  1892. super.setup_afterAdd(buffer, beginPos);
  1893. buffer.seek(beginPos, 6);
  1894. var str = buffer.readS();
  1895. if (str != null)
  1896. this.text = str;
  1897. }
  1898. }
  1899. fgui.GTextField = GTextField;
  1900. })(fgui);
  1901. ///<reference path="GTextField.ts"/>
  1902. ///<reference path="GTextField.ts"/>
  1903. (function (fgui) {
  1904. class GBasicTextField extends fgui.GTextField {
  1905. constructor() {
  1906. super();
  1907. this._letterSpacing = 0;
  1908. this._textWidth = 0;
  1909. this._textHeight = 0;
  1910. this._text = "";
  1911. this._color = "#000000";
  1912. this._textField.align = "left";
  1913. this._textField.font = fgui.UIConfig.defaultFont;
  1914. this._autoSize = fgui.AutoSizeType.Both;
  1915. this._widthAutoSize = this._heightAutoSize = true;
  1916. this._textField["_sizeDirty"] = false;
  1917. }
  1918. createDisplayObject() {
  1919. this._displayObject = this._textField = new TextExt(this);
  1920. this._displayObject["$owner"] = this;
  1921. this._displayObject.mouseEnabled = false;
  1922. }
  1923. get nativeText() {
  1924. return this._textField;
  1925. }
  1926. set text(value) {
  1927. this._text = value;
  1928. if (this._text == null)
  1929. this._text = "";
  1930. if (this._bitmapFont == null) {
  1931. if (this._widthAutoSize)
  1932. this._textField.width = 10000;
  1933. var text2 = this._text;
  1934. if (this._templateVars)
  1935. text2 = this.parseTemplate(text2);
  1936. if (this._ubbEnabled) //laya还不支持同一个文本不同样式
  1937. this._textField.text = fgui.UBBParser.inst.parse(text2, true);
  1938. else
  1939. this._textField.text = text2;
  1940. }
  1941. else {
  1942. this._textField.text = "";
  1943. this._textField["setChanged"]();
  1944. }
  1945. if (this.parent && this.parent._underConstruct)
  1946. this._textField.typeset();
  1947. }
  1948. get text() {
  1949. return this._text;
  1950. }
  1951. get font() {
  1952. return this._textField.font;
  1953. }
  1954. set font(value) {
  1955. this._font = value;
  1956. if (fgui.ToolSet.startsWith(this._font, "ui://"))
  1957. this._bitmapFont = fgui.UIPackage.getItemAssetByURL(this._font);
  1958. else
  1959. delete this._bitmapFont;
  1960. if (this._bitmapFont) {
  1961. this._textField["setChanged"]();
  1962. }
  1963. else {
  1964. if (this._font)
  1965. this._textField.font = this._font;
  1966. else
  1967. this._textField.font = fgui.UIConfig.defaultFont;
  1968. }
  1969. }
  1970. get fontSize() {
  1971. return this._textField.fontSize;
  1972. }
  1973. set fontSize(value) {
  1974. this._textField.fontSize = value;
  1975. }
  1976. get color() {
  1977. return this._color;
  1978. }
  1979. set color(value) {
  1980. if (this._color != value) {
  1981. this._color = value;
  1982. this.updateGear(4);
  1983. if (this.grayed)
  1984. this._textField.color = "#AAAAAA";
  1985. else
  1986. this._textField.color = this._color;
  1987. }
  1988. }
  1989. get align() {
  1990. return this._textField.align;
  1991. }
  1992. set align(value) {
  1993. this._textField.align = value;
  1994. }
  1995. get valign() {
  1996. return this._textField.valign;
  1997. }
  1998. set valign(value) {
  1999. this._textField.valign = value;
  2000. }
  2001. get leading() {
  2002. return this._textField.leading;
  2003. }
  2004. set leading(value) {
  2005. this._textField.leading = value;
  2006. }
  2007. get letterSpacing() {
  2008. return this._letterSpacing;
  2009. }
  2010. set letterSpacing(value) {
  2011. this._letterSpacing = value;
  2012. }
  2013. get bold() {
  2014. return this._textField.bold;
  2015. }
  2016. set bold(value) {
  2017. this._textField.bold = value;
  2018. }
  2019. get italic() {
  2020. return this._textField.italic;
  2021. }
  2022. set italic(value) {
  2023. this._textField.italic = value;
  2024. }
  2025. get underline() {
  2026. return this._textField.underline;
  2027. }
  2028. set underline(value) {
  2029. this._textField.underline = value;
  2030. }
  2031. get singleLine() {
  2032. return this._singleLine;
  2033. }
  2034. set singleLine(value) {
  2035. this._singleLine = value;
  2036. this._textField.wordWrap = !this._widthAutoSize && !this._singleLine;
  2037. }
  2038. get stroke() {
  2039. return this._textField.stroke;
  2040. }
  2041. set stroke(value) {
  2042. this._textField.stroke = value;
  2043. }
  2044. get strokeColor() {
  2045. return this._textField.strokeColor;
  2046. }
  2047. set strokeColor(value) {
  2048. if (this._textField.strokeColor != value) {
  2049. this._textField.strokeColor = value;
  2050. this.updateGear(4);
  2051. }
  2052. }
  2053. updateAutoSize() {
  2054. /*一般没有剪裁文字的需要,感觉HIDDEN有消耗,所以不用了
  2055. if(this._heightAutoSize)
  2056. this._textField.overflow = Text.VISIBLE;
  2057. else
  2058. this._textField.overflow = Text.HIDDEN;*/
  2059. this._textField.wordWrap = !this._widthAutoSize && !this._singleLine;
  2060. if (!this._underConstruct) {
  2061. if (!this._heightAutoSize)
  2062. this._textField.size(this.width, this.height);
  2063. else if (!this._widthAutoSize)
  2064. this._textField.width = this.width;
  2065. }
  2066. }
  2067. get textWidth() {
  2068. if (this._textField["_isChanged"])
  2069. this._textField.typeset();
  2070. return this._textWidth;
  2071. }
  2072. ensureSizeCorrect() {
  2073. if (!this._underConstruct && this._textField["_isChanged"])
  2074. this._textField.typeset();
  2075. }
  2076. typeset() {
  2077. if (this._bitmapFont)
  2078. this.renderWithBitmapFont();
  2079. else if (this._widthAutoSize || this._heightAutoSize)
  2080. this.updateSize();
  2081. }
  2082. updateSize() {
  2083. this._textWidth = Math.ceil(this._textField.textWidth);
  2084. this._textHeight = Math.ceil(this._textField.textHeight);
  2085. var w, h = 0;
  2086. if (this._widthAutoSize) {
  2087. w = this._textWidth;
  2088. if (this._textField.width != w) {
  2089. this._textField.width = w;
  2090. if (this._textField.align != "left")
  2091. this._textField["baseTypeset"]();
  2092. }
  2093. }
  2094. else
  2095. w = this.width;
  2096. if (this._heightAutoSize) {
  2097. h = this._textHeight;
  2098. if (!this._widthAutoSize) {
  2099. if (this._textField.height != this._textHeight)
  2100. this._textField.height = this._textHeight;
  2101. }
  2102. }
  2103. else {
  2104. h = this.height;
  2105. if (this._textHeight > h)
  2106. this._textHeight = h;
  2107. if (this._textField.height != this._textHeight)
  2108. this._textField.height = this._textHeight;
  2109. }
  2110. this._updatingSize = true;
  2111. this.setSize(w, h);
  2112. this._updatingSize = false;
  2113. }
  2114. renderWithBitmapFont() {
  2115. var gr = this._displayObject.graphics;
  2116. gr.clear();
  2117. if (!this._lines)
  2118. this._lines = new Array();
  2119. else
  2120. returnList(this._lines);
  2121. var lineSpacing = this.leading - 1;
  2122. var rectWidth = this.width - GUTTER_X * 2;
  2123. var lineWidth = 0, lineHeight = 0, lineTextHeight = 0;
  2124. var glyphWidth = 0, glyphHeight = 0;
  2125. var wordChars = 0, wordStart = 0, wordEnd = 0;
  2126. var lastLineHeight = 0;
  2127. var lineBuffer = "";
  2128. var lineY = GUTTER_Y;
  2129. var line;
  2130. var wordWrap = !this._widthAutoSize && !this._singleLine;
  2131. var fontSize = this.fontSize;
  2132. var fontScale = this._bitmapFont.resizable ? fontSize / this._bitmapFont.size : 1;
  2133. this._textWidth = 0;
  2134. this._textHeight = 0;
  2135. var text2 = this._text;
  2136. if (this._templateVars)
  2137. text2 = this.parseTemplate(text2);
  2138. var textLength = text2.length;
  2139. for (var offset = 0; offset < textLength; ++offset) {
  2140. var ch = text2.charAt(offset);
  2141. var cc = ch.charCodeAt(0);
  2142. if (cc == 10) {
  2143. lineBuffer += ch;
  2144. line = borrow();
  2145. line.width = lineWidth;
  2146. if (lineTextHeight == 0) {
  2147. if (lastLineHeight == 0)
  2148. lastLineHeight = fontSize;
  2149. if (lineHeight == 0)
  2150. lineHeight = lastLineHeight;
  2151. lineTextHeight = lineHeight;
  2152. }
  2153. line.height = lineHeight;
  2154. lastLineHeight = lineHeight;
  2155. line.textHeight = lineTextHeight;
  2156. line.text = lineBuffer;
  2157. line.y = lineY;
  2158. lineY += (line.height + lineSpacing);
  2159. if (line.width > this._textWidth)
  2160. this._textWidth = line.width;
  2161. this._lines.push(line);
  2162. lineBuffer = "";
  2163. lineWidth = 0;
  2164. lineHeight = 0;
  2165. lineTextHeight = 0;
  2166. wordChars = 0;
  2167. wordStart = 0;
  2168. wordEnd = 0;
  2169. continue;
  2170. }
  2171. if (cc >= 65 && cc <= 90 || cc >= 97 && cc <= 122) //a-z,A-Z
  2172. {
  2173. if (wordChars == 0)
  2174. wordStart = lineWidth;
  2175. wordChars++;
  2176. }
  2177. else {
  2178. if (wordChars > 0)
  2179. wordEnd = lineWidth;
  2180. wordChars = 0;
  2181. }
  2182. if (cc == 32) {
  2183. glyphWidth = Math.ceil(fontSize / 2);
  2184. glyphHeight = fontSize;
  2185. }
  2186. else {
  2187. var glyph = this._bitmapFont.glyphs[ch];
  2188. if (glyph) {
  2189. glyphWidth = Math.ceil(glyph.advance * fontScale);
  2190. glyphHeight = Math.ceil(glyph.lineHeight * fontScale);
  2191. }
  2192. else {
  2193. glyphWidth = 0;
  2194. glyphHeight = 0;
  2195. }
  2196. }
  2197. if (glyphHeight > lineTextHeight)
  2198. lineTextHeight = glyphHeight;
  2199. if (glyphHeight > lineHeight)
  2200. lineHeight = glyphHeight;
  2201. if (lineWidth != 0)
  2202. lineWidth += this._letterSpacing;
  2203. lineWidth += glyphWidth;
  2204. if (!wordWrap || lineWidth <= rectWidth) {
  2205. lineBuffer += ch;
  2206. }
  2207. else {
  2208. line = borrow();
  2209. line.height = lineHeight;
  2210. line.textHeight = lineTextHeight;
  2211. if (lineBuffer.length == 0) { //the line cannt fit even a char
  2212. line.text = ch;
  2213. }
  2214. else if (wordChars > 0 && wordEnd > 0) { //if word had broken, move it to new line
  2215. lineBuffer += ch;
  2216. var len = lineBuffer.length - wordChars;
  2217. line.text = fgui.ToolSet.trimRight(lineBuffer.substr(0, len));
  2218. line.width = wordEnd;
  2219. lineBuffer = lineBuffer.substr(len);
  2220. lineWidth -= wordStart;
  2221. }
  2222. else {
  2223. line.text = lineBuffer;
  2224. line.width = lineWidth - (glyphWidth + this._letterSpacing);
  2225. lineBuffer = ch;
  2226. lineWidth = glyphWidth;
  2227. lineHeight = glyphHeight;
  2228. lineTextHeight = glyphHeight;
  2229. }
  2230. line.y = lineY;
  2231. lineY += (line.height + lineSpacing);
  2232. if (line.width > this._textWidth)
  2233. this._textWidth = line.width;
  2234. wordChars = 0;
  2235. wordStart = 0;
  2236. wordEnd = 0;
  2237. this._lines.push(line);
  2238. }
  2239. }
  2240. if (lineBuffer.length > 0) {
  2241. line = borrow();
  2242. line.width = lineWidth;
  2243. if (lineHeight == 0)
  2244. lineHeight = lastLineHeight;
  2245. if (lineTextHeight == 0)
  2246. lineTextHeight = lineHeight;
  2247. line.height = lineHeight;
  2248. line.textHeight = lineTextHeight;
  2249. line.text = lineBuffer;
  2250. line.y = lineY;
  2251. if (line.width > this._textWidth)
  2252. this._textWidth = line.width;
  2253. this._lines.push(line);
  2254. }
  2255. if (this._textWidth > 0)
  2256. this._textWidth += GUTTER_X * 2;
  2257. var count = this._lines.length;
  2258. if (count == 0) {
  2259. this._textHeight = 0;
  2260. }
  2261. else {
  2262. line = this._lines[this._lines.length - 1];
  2263. this._textHeight = line.y + line.height + GUTTER_Y;
  2264. }
  2265. var w, h = 0;
  2266. if (this._widthAutoSize) {
  2267. if (this._textWidth == 0)
  2268. w = 0;
  2269. else
  2270. w = this._textWidth;
  2271. }
  2272. else
  2273. w = this.width;
  2274. if (this._heightAutoSize) {
  2275. if (this._textHeight == 0)
  2276. h = 0;
  2277. else
  2278. h = this._textHeight;
  2279. }
  2280. else
  2281. h = this.height;
  2282. this._updatingSize = true;
  2283. this.setSize(w, h);
  2284. this._updatingSize = false;
  2285. this.doAlign();
  2286. if (w == 0 || h == 0)
  2287. return;
  2288. var charX = GUTTER_X;
  2289. var lineIndent = 0;
  2290. var charIndent = 0;
  2291. rectWidth = this.width - GUTTER_X * 2;
  2292. var lineCount = this._lines.length;
  2293. var color = this._bitmapFont.tint ? this._color : null;
  2294. for (var i = 0; i < lineCount; i++) {
  2295. line = this._lines[i];
  2296. charX = GUTTER_X;
  2297. if (this.align == "center")
  2298. lineIndent = (rectWidth - line.width) / 2;
  2299. else if (this.align == "right")
  2300. lineIndent = rectWidth - line.width;
  2301. else
  2302. lineIndent = 0;
  2303. textLength = line.text.length;
  2304. for (var j = 0; j < textLength; j++) {
  2305. ch = line.text.charAt(j);
  2306. cc = ch.charCodeAt(0);
  2307. if (cc == 10)
  2308. continue;
  2309. if (cc == 32) {
  2310. charX += this._letterSpacing + Math.ceil(fontSize / 2);
  2311. continue;
  2312. }
  2313. glyph = this._bitmapFont.glyphs[ch];
  2314. if (glyph) {
  2315. charIndent = (line.height + line.textHeight) / 2 - Math.ceil(glyph.lineHeight * fontScale);
  2316. if (glyph.texture) {
  2317. gr.drawTexture(glyph.texture, charX + lineIndent + Math.ceil(glyph.x * fontScale), line.y + charIndent + Math.ceil(glyph.y * fontScale), glyph.width * fontScale, glyph.height * fontScale, null, 1, color);
  2318. }
  2319. charX += this._letterSpacing + Math.ceil(glyph.advance * fontScale);
  2320. }
  2321. else {
  2322. charX += this._letterSpacing;
  2323. }
  2324. } //this.text loop
  2325. } //line loop
  2326. }
  2327. handleSizeChanged() {
  2328. if (this._updatingSize)
  2329. return;
  2330. if (this._underConstruct)
  2331. this._textField.size(this._width, this._height);
  2332. else {
  2333. if (this._bitmapFont) {
  2334. if (!this._widthAutoSize)
  2335. this._textField["setChanged"]();
  2336. else
  2337. this.doAlign();
  2338. }
  2339. else {
  2340. if (!this._widthAutoSize) {
  2341. if (!this._heightAutoSize)
  2342. this._textField.size(this._width, this._height);
  2343. else
  2344. this._textField.width = this._width;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. handleGrayedChanged() {
  2350. super.handleGrayedChanged();
  2351. if (this.grayed)
  2352. this._textField.color = "#AAAAAA";
  2353. else
  2354. this._textField.color = this._color;
  2355. }
  2356. doAlign() {
  2357. if (this.valign == "top" || this._textHeight == 0)
  2358. this._yOffset = GUTTER_Y;
  2359. else {
  2360. var dh = this.height - this._textHeight;
  2361. if (dh < 0)
  2362. dh = 0;
  2363. if (this.valign == "middle")
  2364. this._yOffset = Math.floor(dh / 2);
  2365. else
  2366. this._yOffset = Math.floor(dh);
  2367. }
  2368. this.handleXYChanged();
  2369. }
  2370. flushVars() {
  2371. this.text = this._text;
  2372. }
  2373. }
  2374. fgui.GBasicTextField = GBasicTextField;
  2375. class TextExt extends Laya.Text {
  2376. constructor(owner) {
  2377. super();
  2378. this._owner = owner;
  2379. }
  2380. baseTypeset() {
  2381. this._lock = true;
  2382. this.typeset();
  2383. this._lock = false;
  2384. }
  2385. typeset() {
  2386. this._sizeDirty = true; //阻止SIZE_DELAY_CHANGE的触发
  2387. super.typeset();
  2388. if (!this._lock)
  2389. this._owner.typeset();
  2390. if (this._isChanged) {
  2391. Laya.timer.clear(this, this.typeset);
  2392. this._isChanged = false;
  2393. }
  2394. this._sizeDirty = false;
  2395. }
  2396. setChanged() {
  2397. this.isChanged = true;
  2398. }
  2399. set isChanged(value) {
  2400. if (value && !this._sizeDirty) {
  2401. if (this._owner.autoSize != fgui.AutoSizeType.None && this._owner.parent) {
  2402. this._sizeDirty = true;
  2403. this.event(fgui.Events.SIZE_DELAY_CHANGE);
  2404. }
  2405. }
  2406. super["isChanged"] = value;
  2407. }
  2408. }
  2409. var pool = [];
  2410. function borrow() {
  2411. if (pool.length) {
  2412. var ret = pool.pop();
  2413. ret.width = 0;
  2414. ret.height = 0;
  2415. ret.textHeight = 0;
  2416. ret.text = null;
  2417. ret.y = 0;
  2418. return ret;
  2419. }
  2420. else
  2421. return {
  2422. width: 0,
  2423. height: 0,
  2424. textHeight: 0,
  2425. text: null,
  2426. y: 0
  2427. };
  2428. }
  2429. function returnList(value) {
  2430. var length = value.length;
  2431. for (var i = 0; i < length; i++) {
  2432. var li = value[i];
  2433. pool.push(li);
  2434. }
  2435. value.length = 0;
  2436. }
  2437. const GUTTER_X = 2;
  2438. const GUTTER_Y = 2;
  2439. })(fgui);
  2440. (function (fgui) {
  2441. class Margin {
  2442. constructor() {
  2443. this.left = 0;
  2444. this.right = 0;
  2445. this.top = 0;
  2446. this.bottom = 0;
  2447. }
  2448. copy(source) {
  2449. this.top = source.top;
  2450. this.bottom = source.bottom;
  2451. this.left = source.left;
  2452. this.right = source.right;
  2453. }
  2454. }
  2455. fgui.Margin = Margin;
  2456. })(fgui);
  2457. ///<reference path="GObject.ts"/>
  2458. ///<reference path="Margin.ts"/>
  2459. ///<reference path="GObject.ts"/>
  2460. ///<reference path="Margin.ts"/>
  2461. (function (fgui) {
  2462. class GComponent extends fgui.GObject {
  2463. constructor() {
  2464. super();
  2465. this._sortingChildCount = 0;
  2466. this._children = [];
  2467. this._controllers = [];
  2468. this._transitions = [];
  2469. this._margin = new fgui.Margin();
  2470. this._alignOffset = new Laya.Point();
  2471. this._opaque = false;
  2472. this._childrenRenderOrder = 0;
  2473. this._apexIndex = 0;
  2474. }
  2475. createDisplayObject() {
  2476. super.createDisplayObject();
  2477. this._displayObject.mouseEnabled = true;
  2478. this._displayObject.mouseThrough = true;
  2479. this._container = this._displayObject;
  2480. }
  2481. dispose() {
  2482. var i;
  2483. var cnt;
  2484. cnt = this._transitions.length;
  2485. for (i = 0; i < cnt; ++i) {
  2486. var trans = this._transitions[i];
  2487. trans.dispose();
  2488. }
  2489. cnt = this._controllers.length;
  2490. for (i = 0; i < cnt; ++i) {
  2491. var cc = this._controllers[i];
  2492. cc.dispose();
  2493. }
  2494. if (this.scrollPane)
  2495. this.scrollPane.dispose();
  2496. cnt = this._children.length;
  2497. for (i = cnt - 1; i >= 0; --i) {
  2498. var obj = this._children[i];
  2499. obj.parent = null; //avoid removeFromParent call
  2500. obj.dispose();
  2501. }
  2502. this._boundsChanged = false;
  2503. super.dispose();
  2504. }
  2505. get displayListContainer() {
  2506. return this._container;
  2507. }
  2508. addChild(child) {
  2509. this.addChildAt(child, this._children.length);
  2510. return child;
  2511. }
  2512. addChildAt(child, index) {
  2513. if (!child)
  2514. throw "child is null";
  2515. if (index >= 0 && index <= this._children.length) {
  2516. if (child.parent == this) {
  2517. this.setChildIndex(child, index);
  2518. }
  2519. else {
  2520. child.removeFromParent();
  2521. child.parent = this;
  2522. var cnt = this._children.length;
  2523. if (child.sortingOrder != 0) {
  2524. this._sortingChildCount++;
  2525. index = this.getInsertPosForSortingChild(child);
  2526. }
  2527. else if (this._sortingChildCount > 0) {
  2528. if (index > (cnt - this._sortingChildCount))
  2529. index = cnt - this._sortingChildCount;
  2530. }
  2531. if (index == cnt)
  2532. this._children.push(child);
  2533. else
  2534. this._children.splice(index, 0, child);
  2535. this.childStateChanged(child);
  2536. this.setBoundsChangedFlag();
  2537. }
  2538. return child;
  2539. }
  2540. else {
  2541. throw "Invalid child index";
  2542. }
  2543. }
  2544. getInsertPosForSortingChild(target) {
  2545. var cnt = this._children.length;
  2546. var i = 0;
  2547. for (i = 0; i < cnt; i++) {
  2548. var child = this._children[i];
  2549. if (child == target)
  2550. continue;
  2551. if (target.sortingOrder < child.sortingOrder)
  2552. break;
  2553. }
  2554. return i;
  2555. }
  2556. removeChild(child, dispose) {
  2557. var childIndex = this._children.indexOf(child);
  2558. if (childIndex != -1) {
  2559. this.removeChildAt(childIndex, dispose);
  2560. }
  2561. return child;
  2562. }
  2563. removeChildAt(index, dispose) {
  2564. if (index >= 0 && index < this._children.length) {
  2565. var child = this._children[index];
  2566. child.parent = null;
  2567. if (child.sortingOrder != 0)
  2568. this._sortingChildCount--;
  2569. this._children.splice(index, 1);
  2570. child.group = null;
  2571. if (child.inContainer) {
  2572. this._container.removeChild(child.displayObject);
  2573. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2574. Laya.timer.callLater(this, this.buildNativeDisplayList);
  2575. }
  2576. if (dispose)
  2577. child.dispose();
  2578. this.setBoundsChangedFlag();
  2579. return child;
  2580. }
  2581. else {
  2582. throw "Invalid child index";
  2583. }
  2584. }
  2585. removeChildren(beginIndex, endIndex, dispose) {
  2586. if (beginIndex == undefined)
  2587. beginIndex = 0;
  2588. if (endIndex == undefined)
  2589. endIndex = -1;
  2590. if (endIndex < 0 || endIndex >= this._children.length)
  2591. endIndex = this._children.length - 1;
  2592. for (var i = beginIndex; i <= endIndex; ++i)
  2593. this.removeChildAt(beginIndex, dispose);
  2594. }
  2595. getChildAt(index) {
  2596. if (index >= 0 && index < this._children.length)
  2597. return this._children[index];
  2598. else
  2599. throw "Invalid child index";
  2600. }
  2601. getChild(name) {
  2602. var cnt = this._children.length;
  2603. for (var i = 0; i < cnt; ++i) {
  2604. if (this._children[i].name == name)
  2605. return this._children[i];
  2606. }
  2607. return null;
  2608. }
  2609. getChildByPath(path) {
  2610. var arr = path.split(".");
  2611. var cnt = arr.length;
  2612. var gcom = this;
  2613. var obj;
  2614. for (var i = 0; i < cnt; ++i) {
  2615. obj = gcom.getChild(arr[i]);
  2616. if (!obj)
  2617. break;
  2618. if (i != cnt - 1) {
  2619. if (!(obj instanceof GComponent)) {
  2620. obj = null;
  2621. break;
  2622. }
  2623. else
  2624. gcom = obj;
  2625. }
  2626. }
  2627. return obj;
  2628. }
  2629. getVisibleChild(name) {
  2630. var cnt = this._children.length;
  2631. for (var i = 0; i < cnt; ++i) {
  2632. var child = this._children[i];
  2633. if (child.internalVisible && child.internalVisible2 && child.name == name)
  2634. return child;
  2635. }
  2636. return null;
  2637. }
  2638. getChildInGroup(name, group) {
  2639. var cnt = this._children.length;
  2640. for (var i = 0; i < cnt; ++i) {
  2641. var child = this._children[i];
  2642. if (child.group == group && child.name == name)
  2643. return child;
  2644. }
  2645. return null;
  2646. }
  2647. getChildById(id) {
  2648. var cnt = this._children.length;
  2649. for (var i = 0; i < cnt; ++i) {
  2650. if (this._children[i]._id == id)
  2651. return this._children[i];
  2652. }
  2653. return null;
  2654. }
  2655. getChildIndex(child) {
  2656. return this._children.indexOf(child);
  2657. }
  2658. setChildIndex(child, index) {
  2659. var oldIndex = this._children.indexOf(child);
  2660. if (oldIndex == -1)
  2661. throw "Not a child of this container";
  2662. if (child.sortingOrder != 0) //no effect
  2663. return;
  2664. var cnt = this._children.length;
  2665. if (this._sortingChildCount > 0) {
  2666. if (index > (cnt - this._sortingChildCount - 1))
  2667. index = cnt - this._sortingChildCount - 1;
  2668. }
  2669. this._setChildIndex(child, oldIndex, index);
  2670. }
  2671. setChildIndexBefore(child, index) {
  2672. var oldIndex = this._children.indexOf(child);
  2673. if (oldIndex == -1)
  2674. throw "Not a child of this container";
  2675. if (child.sortingOrder != 0) //no effect
  2676. return oldIndex;
  2677. var cnt = this._children.length;
  2678. if (this._sortingChildCount > 0) {
  2679. if (index > (cnt - this._sortingChildCount - 1))
  2680. index = cnt - this._sortingChildCount - 1;
  2681. }
  2682. if (oldIndex < index)
  2683. return this._setChildIndex(child, oldIndex, index - 1);
  2684. else
  2685. return this._setChildIndex(child, oldIndex, index);
  2686. }
  2687. _setChildIndex(child, oldIndex, index) {
  2688. var cnt = this._children.length;
  2689. if (index > cnt)
  2690. index = cnt;
  2691. if (oldIndex == index)
  2692. return oldIndex;
  2693. this._children.splice(oldIndex, 1);
  2694. this._children.splice(index, 0, child);
  2695. if (child.inContainer) {
  2696. var displayIndex = 0;
  2697. var g;
  2698. var i;
  2699. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent) {
  2700. for (i = 0; i < index; i++) {
  2701. g = this._children[i];
  2702. if (g.inContainer)
  2703. displayIndex++;
  2704. }
  2705. if (displayIndex == this._container.numChildren)
  2706. displayIndex--;
  2707. this._container.setChildIndex(child.displayObject, displayIndex);
  2708. }
  2709. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent) {
  2710. for (i = cnt - 1; i > index; i--) {
  2711. g = this._children[i];
  2712. if (g.inContainer)
  2713. displayIndex++;
  2714. }
  2715. if (displayIndex == this._container.numChildren)
  2716. displayIndex--;
  2717. this._container.setChildIndex(child.displayObject, displayIndex);
  2718. }
  2719. else {
  2720. Laya.timer.callLater(this, this.buildNativeDisplayList);
  2721. }
  2722. this.setBoundsChangedFlag();
  2723. }
  2724. return index;
  2725. }
  2726. swapChildren(child1, child2) {
  2727. var index1 = this._children.indexOf(child1);
  2728. var index2 = this._children.indexOf(child2);
  2729. if (index1 == -1 || index2 == -1)
  2730. throw "Not a child of this container";
  2731. this.swapChildrenAt(index1, index2);
  2732. }
  2733. swapChildrenAt(index1, index2) {
  2734. var child1 = this._children[index1];
  2735. var child2 = this._children[index2];
  2736. this.setChildIndex(child1, index2);
  2737. this.setChildIndex(child2, index1);
  2738. }
  2739. get numChildren() {
  2740. return this._children.length;
  2741. }
  2742. isAncestorOf(child) {
  2743. if (!child)
  2744. return false;
  2745. var p = child.parent;
  2746. while (p) {
  2747. if (p == this)
  2748. return true;
  2749. p = p.parent;
  2750. }
  2751. return false;
  2752. }
  2753. addController(controller) {
  2754. this._controllers.push(controller);
  2755. controller.parent = this;
  2756. this.applyController(controller);
  2757. }
  2758. getControllerAt(index) {
  2759. return this._controllers[index];
  2760. }
  2761. getController(name) {
  2762. var cnt = this._controllers.length;
  2763. for (var i = 0; i < cnt; ++i) {
  2764. var c = this._controllers[i];
  2765. if (c.name == name)
  2766. return c;
  2767. }
  2768. return null;
  2769. }
  2770. removeController(c) {
  2771. var index = this._controllers.indexOf(c);
  2772. if (index == -1)
  2773. throw new Error("controller not exists");
  2774. c.parent = null;
  2775. this._controllers.splice(index, 1);
  2776. var length = this._children.length;
  2777. for (var i = 0; i < length; i++) {
  2778. var child = this._children[i];
  2779. child.handleControllerChanged(c);
  2780. }
  2781. }
  2782. get controllers() {
  2783. return this._controllers;
  2784. }
  2785. childStateChanged(child) {
  2786. if (this._buildingDisplayList)
  2787. return;
  2788. var cnt = this._children.length;
  2789. if (child instanceof fgui.GGroup) {
  2790. for (var i = 0; i < cnt; i++) {
  2791. var g = this._children[i];
  2792. if (g.group == child)
  2793. this.childStateChanged(g);
  2794. }
  2795. return;
  2796. }
  2797. if (!child.displayObject)
  2798. return;
  2799. if (child.internalVisible && child.displayObject != this._displayObject.mask) {
  2800. if (!child.displayObject.parent) {
  2801. var index = 0;
  2802. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent) {
  2803. for (i = 0; i < cnt; i++) {
  2804. g = this._children[i];
  2805. if (g == child)
  2806. break;
  2807. if (g.displayObject && g.displayObject.parent)
  2808. index++;
  2809. }
  2810. this._container.addChildAt(child.displayObject, index);
  2811. }
  2812. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent) {
  2813. for (i = cnt - 1; i >= 0; i--) {
  2814. g = this._children[i];
  2815. if (g == child)
  2816. break;
  2817. if (g.displayObject && g.displayObject.parent)
  2818. index++;
  2819. }
  2820. this._container.addChildAt(child.displayObject, index);
  2821. }
  2822. else {
  2823. this._container.addChild(child.displayObject);
  2824. Laya.timer.callLater(this, this.buildNativeDisplayList);
  2825. }
  2826. }
  2827. }
  2828. else {
  2829. if (child.displayObject.parent) {
  2830. this._container.removeChild(child.displayObject);
  2831. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2832. Laya.timer.callLater(this, this.buildNativeDisplayList);
  2833. }
  2834. }
  2835. }
  2836. buildNativeDisplayList() {
  2837. if (!this._displayObject)
  2838. return;
  2839. var cnt = this._children.length;
  2840. if (cnt == 0)
  2841. return;
  2842. var i;
  2843. var child;
  2844. switch (this._childrenRenderOrder) {
  2845. case fgui.ChildrenRenderOrder.Ascent:
  2846. {
  2847. for (i = 0; i < cnt; i++) {
  2848. child = this._children[i];
  2849. if (child.displayObject && child.internalVisible)
  2850. this._container.addChild(child.displayObject);
  2851. }
  2852. }
  2853. break;
  2854. case fgui.ChildrenRenderOrder.Descent:
  2855. {
  2856. for (i = cnt - 1; i >= 0; i--) {
  2857. child = this._children[i];
  2858. if (child.displayObject && child.internalVisible)
  2859. this._container.addChild(child.displayObject);
  2860. }
  2861. }
  2862. break;
  2863. case fgui.ChildrenRenderOrder.Arch:
  2864. {
  2865. var apex = fgui.ToolSet.clamp(this._apexIndex, 0, cnt);
  2866. for (i = 0; i < apex; i++) {
  2867. child = this._children[i];
  2868. if (child.displayObject && child.internalVisible)
  2869. this._container.addChild(child.displayObject);
  2870. }
  2871. for (i = cnt - 1; i >= apex; i--) {
  2872. child = this._children[i];
  2873. if (child.displayObject && child.internalVisible)
  2874. this._container.addChild(child.displayObject);
  2875. }
  2876. }
  2877. break;
  2878. }
  2879. }
  2880. applyController(c) {
  2881. this._applyingController = c;
  2882. var child;
  2883. var length = this._children.length;
  2884. for (var i = 0; i < length; i++) {
  2885. child = this._children[i];
  2886. child.handleControllerChanged(c);
  2887. }
  2888. this._applyingController = null;
  2889. c.runActions();
  2890. }
  2891. applyAllControllers() {
  2892. var cnt = this._controllers.length;
  2893. for (var i = 0; i < cnt; ++i) {
  2894. this.applyController(this._controllers[i]);
  2895. }
  2896. }
  2897. adjustRadioGroupDepth(obj, c) {
  2898. var cnt = this._children.length;
  2899. var i;
  2900. var child;
  2901. var myIndex = -1, maxIndex = -1;
  2902. for (i = 0; i < cnt; i++) {
  2903. child = this._children[i];
  2904. if (child == obj) {
  2905. myIndex = i;
  2906. }
  2907. else if ((child instanceof fgui.GButton)
  2908. && (child).relatedController == c) {
  2909. if (i > maxIndex)
  2910. maxIndex = i;
  2911. }
  2912. }
  2913. if (myIndex < maxIndex) {
  2914. //如果正在applyingController,此时修改显示列表是危险的,但真正排除危险只能用显示列表的副本去做,这样性能可能损耗较大,
  2915. //这里取个巧,让可能漏过的child补一下handleControllerChanged,反正重复执行是无害的。
  2916. if (this._applyingController)
  2917. this._children[maxIndex].handleControllerChanged(this._applyingController);
  2918. this.swapChildrenAt(myIndex, maxIndex);
  2919. }
  2920. }
  2921. getTransitionAt(index) {
  2922. return this._transitions[index];
  2923. }
  2924. getTransition(transName) {
  2925. var cnt = this._transitions.length;
  2926. for (var i = 0; i < cnt; ++i) {
  2927. var trans = this._transitions[i];
  2928. if (trans.name == transName)
  2929. return trans;
  2930. }
  2931. return null;
  2932. }
  2933. isChildInView(child) {
  2934. if (this._displayObject.scrollRect) {
  2935. return child.x + child.width >= 0 && child.x <= this.width
  2936. && child.y + child.height >= 0 && child.y <= this.height;
  2937. }
  2938. else if (this._scrollPane) {
  2939. return this._scrollPane.isChildInView(child);
  2940. }
  2941. else
  2942. return true;
  2943. }
  2944. getFirstChildInView() {
  2945. var cnt = this._children.length;
  2946. for (var i = 0; i < cnt; ++i) {
  2947. var child = this._children[i];
  2948. if (this.isChildInView(child))
  2949. return i;
  2950. }
  2951. return -1;
  2952. }
  2953. get scrollPane() {
  2954. return this._scrollPane;
  2955. }
  2956. get opaque() {
  2957. return this._opaque;
  2958. }
  2959. set opaque(value) {
  2960. if (this._opaque != value) {
  2961. this._opaque = value;
  2962. if (this._opaque) {
  2963. if (!this._displayObject.hitArea)
  2964. this._displayObject.hitArea = new Laya.Rectangle();
  2965. if (this._displayObject.hitArea instanceof Laya.Rectangle)
  2966. this._displayObject.hitArea.setTo(0, 0, this._width, this._height);
  2967. this._displayObject.mouseThrough = false;
  2968. }
  2969. else {
  2970. if (this._displayObject.hitArea instanceof Laya.Rectangle)
  2971. this._displayObject.hitArea = null;
  2972. this._displayObject.mouseThrough = true;
  2973. }
  2974. }
  2975. }
  2976. get margin() {
  2977. return this._margin;
  2978. }
  2979. set margin(value) {
  2980. this._margin.copy(value);
  2981. if (this._displayObject.scrollRect) {
  2982. this._container.pos(this._margin.left + this._alignOffset.x, this._margin.top + this._alignOffset.y);
  2983. }
  2984. this.handleSizeChanged();
  2985. }
  2986. get childrenRenderOrder() {
  2987. return this._childrenRenderOrder;
  2988. }
  2989. set childrenRenderOrder(value) {
  2990. if (this._childrenRenderOrder != value) {
  2991. this._childrenRenderOrder = value;
  2992. this.buildNativeDisplayList();
  2993. }
  2994. }
  2995. get apexIndex() {
  2996. return this._apexIndex;
  2997. }
  2998. set apexIndex(value) {
  2999. if (this._apexIndex != value) {
  3000. this._apexIndex = value;
  3001. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  3002. this.buildNativeDisplayList();
  3003. }
  3004. }
  3005. get mask() {
  3006. return this._mask;
  3007. }
  3008. set mask(value) {
  3009. this.setMask(value, false);
  3010. }
  3011. setMask(value, reversed) {
  3012. if (this._mask && this._mask != value) {
  3013. if (this._mask.blendMode == "destination-out")
  3014. this._mask.blendMode = null;
  3015. }
  3016. this._mask = value;
  3017. if (!this._mask) {
  3018. this._displayObject.mask = null;
  3019. if (this._displayObject.hitArea instanceof fgui.ChildHitArea)
  3020. this._displayObject.hitArea = null;
  3021. return;
  3022. }
  3023. if (this._mask.hitArea) {
  3024. this._displayObject.hitArea = new fgui.ChildHitArea(this._mask, reversed);
  3025. this._displayObject.mouseThrough = false;
  3026. this._displayObject.hitTestPrior = true;
  3027. }
  3028. if (reversed) {
  3029. this._displayObject.mask = null;
  3030. this._displayObject.cacheAs = "bitmap";
  3031. this._mask.blendMode = "destination-out";
  3032. }
  3033. else
  3034. this._displayObject.mask = this._mask;
  3035. }
  3036. get baseUserData() {
  3037. var buffer = this.packageItem.rawData;
  3038. buffer.seek(0, 4);
  3039. return buffer.readS();
  3040. }
  3041. updateHitArea() {
  3042. if (this._displayObject.hitArea instanceof fgui.PixelHitTest) {
  3043. var hitTest = (this._displayObject.hitArea);
  3044. if (this.sourceWidth != 0)
  3045. hitTest.scaleX = this._width / this.sourceWidth;
  3046. if (this.sourceHeight != 0)
  3047. hitTest.scaleY = this._height / this.sourceHeight;
  3048. }
  3049. else if (this._displayObject.hitArea instanceof Laya.Rectangle) {
  3050. this._displayObject.hitArea.setTo(0, 0, this._width, this._height);
  3051. }
  3052. }
  3053. updateMask() {
  3054. var rect = this._displayObject.scrollRect;
  3055. if (!rect)
  3056. rect = new Laya.Rectangle();
  3057. rect.x = this._margin.left;
  3058. rect.y = this._margin.top;
  3059. rect.width = this._width - this._margin.right;
  3060. rect.height = this._height - this._margin.bottom;
  3061. this._displayObject.scrollRect = rect;
  3062. }
  3063. setupScroll(buffer) {
  3064. if (this._displayObject == this._container) {
  3065. this._container = new Laya.Sprite();
  3066. this._displayObject.addChild(this._container);
  3067. }
  3068. this._scrollPane = new fgui.ScrollPane(this);
  3069. this._scrollPane.setup(buffer);
  3070. }
  3071. setupOverflow(overflow) {
  3072. if (overflow == fgui.OverflowType.Hidden) {
  3073. if (this._displayObject == this._container) {
  3074. this._container = new Laya.Sprite();
  3075. this._displayObject.addChild(this._container);
  3076. }
  3077. this.updateMask();
  3078. this._container.pos(this._margin.left, this._margin.top);
  3079. }
  3080. else if (this._margin.left != 0 || this._margin.top != 0) {
  3081. if (this._displayObject == this._container) {
  3082. this._container = new Laya.Sprite();
  3083. this._displayObject.addChild(this._container);
  3084. }
  3085. this._container.pos(this._margin.left, this._margin.top);
  3086. }
  3087. }
  3088. handleSizeChanged() {
  3089. super.handleSizeChanged();
  3090. if (this._scrollPane)
  3091. this._scrollPane.onOwnerSizeChanged();
  3092. else if (this._displayObject.scrollRect)
  3093. this.updateMask();
  3094. if (this._displayObject.hitArea)
  3095. this.updateHitArea();
  3096. }
  3097. handleGrayedChanged() {
  3098. var c = this.getController("grayed");
  3099. if (c) {
  3100. c.selectedIndex = this.grayed ? 1 : 0;
  3101. return;
  3102. }
  3103. var v = this.grayed;
  3104. var cnt = this._children.length;
  3105. for (var i = 0; i < cnt; ++i) {
  3106. this._children[i].grayed = v;
  3107. }
  3108. }
  3109. handleControllerChanged(c) {
  3110. super.handleControllerChanged(c);
  3111. if (this._scrollPane)
  3112. this._scrollPane.handleControllerChanged(c);
  3113. }
  3114. setBoundsChangedFlag() {
  3115. if (!this._scrollPane && !this._trackBounds)
  3116. return;
  3117. if (!this._boundsChanged) {
  3118. this._boundsChanged = true;
  3119. Laya.timer.callLater(this, this.__render);
  3120. }
  3121. }
  3122. __render() {
  3123. if (this._boundsChanged) {
  3124. var i1 = 0;
  3125. var len = this._children.length;
  3126. var child;
  3127. for (i1 = 0; i1 < len; i1++) {
  3128. child = this._children[i1];
  3129. child.ensureSizeCorrect();
  3130. }
  3131. this.updateBounds();
  3132. }
  3133. }
  3134. ensureBoundsCorrect() {
  3135. var i1 = 0;
  3136. var len = this._children.length;
  3137. var child;
  3138. for (i1 = 0; i1 < len; i1++) {
  3139. child = this._children[i1];
  3140. child.ensureSizeCorrect();
  3141. }
  3142. if (this._boundsChanged)
  3143. this.updateBounds();
  3144. }
  3145. updateBounds() {
  3146. var ax = 0, ay = 0, aw = 0, ah = 0;
  3147. var len = this._children.length;
  3148. if (len > 0) {
  3149. ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  3150. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  3151. var tmp = 0;
  3152. var i1 = 0;
  3153. for (i1 = 0; i1 < len; i1++) {
  3154. var child = this._children[i1];
  3155. tmp = child.x;
  3156. if (tmp < ax)
  3157. ax = tmp;
  3158. tmp = child.y;
  3159. if (tmp < ay)
  3160. ay = tmp;
  3161. tmp = child.x + child.actualWidth;
  3162. if (tmp > ar)
  3163. ar = tmp;
  3164. tmp = child.y + child.actualHeight;
  3165. if (tmp > ab)
  3166. ab = tmp;
  3167. }
  3168. aw = ar - ax;
  3169. ah = ab - ay;
  3170. }
  3171. this.setBounds(ax, ay, aw, ah);
  3172. }
  3173. setBounds(ax, ay, aw, ah) {
  3174. this._boundsChanged = false;
  3175. if (this._scrollPane)
  3176. this._scrollPane.setContentSize(Math.round(ax + aw), Math.round(ay + ah));
  3177. }
  3178. get viewWidth() {
  3179. if (this._scrollPane)
  3180. return this._scrollPane.viewWidth;
  3181. else
  3182. return this.width - this._margin.left - this._margin.right;
  3183. }
  3184. set viewWidth(value) {
  3185. if (this._scrollPane)
  3186. this._scrollPane.viewWidth = value;
  3187. else
  3188. this.width = value + this._margin.left + this._margin.right;
  3189. }
  3190. get viewHeight() {
  3191. if (this._scrollPane)
  3192. return this._scrollPane.viewHeight;
  3193. else
  3194. return this.height - this._margin.top - this._margin.bottom;
  3195. }
  3196. set viewHeight(value) {
  3197. if (this._scrollPane)
  3198. this._scrollPane.viewHeight = value;
  3199. else
  3200. this.height = value + this._margin.top + this._margin.bottom;
  3201. }
  3202. getSnappingPosition(xValue, yValue, result) {
  3203. return this.getSnappingPositionWithDir(xValue, yValue, 0, 0, result);
  3204. }
  3205. /**
  3206. * dir正数表示右移或者下移,负数表示左移或者上移
  3207. */
  3208. getSnappingPositionWithDir(xValue, yValue, xDir, yDir, result) {
  3209. if (!result)
  3210. result = new Laya.Point();
  3211. var cnt = this._children.length;
  3212. if (cnt == 0) {
  3213. result.x = 0;
  3214. result.y = 0;
  3215. return result;
  3216. }
  3217. this.ensureBoundsCorrect();
  3218. var obj = null;
  3219. var prev = null;
  3220. var i = 0;
  3221. if (yValue != 0) {
  3222. for (; i < cnt; i++) {
  3223. obj = this._children[i];
  3224. if (yValue < obj.y) {
  3225. if (i == 0) {
  3226. yValue = 0;
  3227. break;
  3228. }
  3229. else {
  3230. prev = this._children[i - 1];
  3231. if (yValue < prev.y + prev.actualHeight / 2) //top half part
  3232. yValue = prev.y;
  3233. else //bottom half part
  3234. yValue = obj.y;
  3235. break;
  3236. }
  3237. }
  3238. }
  3239. if (i == cnt)
  3240. yValue = obj.y;
  3241. }
  3242. if (xValue != 0) {
  3243. if (i > 0)
  3244. i--;
  3245. for (; i < cnt; i++) {
  3246. obj = this._children[i];
  3247. if (xValue < obj.x) {
  3248. if (i == 0) {
  3249. xValue = 0;
  3250. break;
  3251. }
  3252. else {
  3253. prev = this._children[i - 1];
  3254. if (xValue < prev.x + prev.actualWidth / 2) //top half part
  3255. xValue = prev.x;
  3256. else //bottom half part
  3257. xValue = obj.x;
  3258. break;
  3259. }
  3260. }
  3261. }
  3262. if (i == cnt)
  3263. xValue = obj.x;
  3264. }
  3265. result.x = xValue;
  3266. result.y = yValue;
  3267. return result;
  3268. }
  3269. childSortingOrderChanged(child, oldValue, newValue) {
  3270. if (newValue == 0) {
  3271. this._sortingChildCount--;
  3272. this.setChildIndex(child, this._children.length);
  3273. }
  3274. else {
  3275. if (oldValue == 0)
  3276. this._sortingChildCount++;
  3277. var oldIndex = this._children.indexOf(child);
  3278. var index = this.getInsertPosForSortingChild(child);
  3279. if (oldIndex < index)
  3280. this._setChildIndex(child, oldIndex, index - 1);
  3281. else
  3282. this._setChildIndex(child, oldIndex, index);
  3283. }
  3284. }
  3285. constructFromResource() {
  3286. this.constructFromResource2(null, 0);
  3287. }
  3288. constructFromResource2(objectPool, poolIndex) {
  3289. var contentItem = this.packageItem.getBranch();
  3290. if (!contentItem.decoded) {
  3291. contentItem.decoded = true;
  3292. fgui.TranslationHelper.translateComponent(contentItem);
  3293. }
  3294. var i;
  3295. var dataLen;
  3296. var curPos;
  3297. var nextPos;
  3298. var f1;
  3299. var f2;
  3300. var i1;
  3301. var i2;
  3302. var buffer = contentItem.rawData;
  3303. buffer.seek(0, 0);
  3304. this._underConstruct = true;
  3305. this.sourceWidth = buffer.getInt32();
  3306. this.sourceHeight = buffer.getInt32();
  3307. this.initWidth = this.sourceWidth;
  3308. this.initHeight = this.sourceHeight;
  3309. this.setSize(this.sourceWidth, this.sourceHeight);
  3310. if (buffer.readBool()) {
  3311. this.minWidth = buffer.getInt32();
  3312. this.maxWidth = buffer.getInt32();
  3313. this.minHeight = buffer.getInt32();
  3314. this.maxHeight = buffer.getInt32();
  3315. }
  3316. if (buffer.readBool()) {
  3317. f1 = buffer.getFloat32();
  3318. f2 = buffer.getFloat32();
  3319. this.internalSetPivot(f1, f2, buffer.readBool());
  3320. }
  3321. if (buffer.readBool()) {
  3322. this._margin.top = buffer.getInt32();
  3323. this._margin.bottom = buffer.getInt32();
  3324. this._margin.left = buffer.getInt32();
  3325. this._margin.right = buffer.getInt32();
  3326. }
  3327. var overflow = buffer.readByte();
  3328. if (overflow == fgui.OverflowType.Scroll) {
  3329. var savedPos = buffer.pos;
  3330. buffer.seek(0, 7);
  3331. this.setupScroll(buffer);
  3332. buffer.pos = savedPos;
  3333. }
  3334. else
  3335. this.setupOverflow(overflow);
  3336. if (buffer.readBool())
  3337. buffer.skip(8);
  3338. this._buildingDisplayList = true;
  3339. buffer.seek(0, 1);
  3340. var controllerCount = buffer.getInt16();
  3341. for (i = 0; i < controllerCount; i++) {
  3342. nextPos = buffer.getInt16();
  3343. nextPos += buffer.pos;
  3344. var controller = new fgui.Controller();
  3345. this._controllers.push(controller);
  3346. controller.parent = this;
  3347. controller.setup(buffer);
  3348. buffer.pos = nextPos;
  3349. }
  3350. buffer.seek(0, 2);
  3351. var child;
  3352. var childCount = buffer.getInt16();
  3353. for (i = 0; i < childCount; i++) {
  3354. dataLen = buffer.getInt16();
  3355. curPos = buffer.pos;
  3356. if (objectPool)
  3357. child = objectPool[poolIndex + i];
  3358. else {
  3359. buffer.seek(curPos, 0);
  3360. var type = buffer.readByte();
  3361. var src = buffer.readS();
  3362. var pkgId = buffer.readS();
  3363. var pi = null;
  3364. if (src != null) {
  3365. var pkg;
  3366. if (pkgId != null)
  3367. pkg = fgui.UIPackage.getById(pkgId);
  3368. else
  3369. pkg = contentItem.owner;
  3370. pi = pkg ? pkg.getItemById(src) : null;
  3371. }
  3372. if (pi) {
  3373. child = fgui.UIObjectFactory.newObject(pi);
  3374. child.constructFromResource();
  3375. }
  3376. else
  3377. child = fgui.UIObjectFactory.newObject(type);
  3378. }
  3379. child._underConstruct = true;
  3380. child.setup_beforeAdd(buffer, curPos);
  3381. child.parent = this;
  3382. this._children.push(child);
  3383. buffer.pos = curPos + dataLen;
  3384. }
  3385. buffer.seek(0, 3);
  3386. this.relations.setup(buffer, true);
  3387. buffer.seek(0, 2);
  3388. buffer.skip(2);
  3389. for (i = 0; i < childCount; i++) {
  3390. nextPos = buffer.getInt16();
  3391. nextPos += buffer.pos;
  3392. buffer.seek(buffer.pos, 3);
  3393. this._children[i].relations.setup(buffer, false);
  3394. buffer.pos = nextPos;
  3395. }
  3396. buffer.seek(0, 2);
  3397. buffer.skip(2);
  3398. for (i = 0; i < childCount; i++) {
  3399. nextPos = buffer.getInt16();
  3400. nextPos += buffer.pos;
  3401. child = this._children[i];
  3402. child.setup_afterAdd(buffer, buffer.pos);
  3403. child._underConstruct = false;
  3404. buffer.pos = nextPos;
  3405. }
  3406. buffer.seek(0, 4);
  3407. buffer.skip(2); //customData
  3408. this.opaque = buffer.readBool();
  3409. var maskId = buffer.getInt16();
  3410. if (maskId != -1) {
  3411. this.setMask(this.getChildAt(maskId).displayObject, buffer.readBool());
  3412. }
  3413. var hitTestId = buffer.readS();
  3414. i1 = buffer.getInt32();
  3415. i2 = buffer.getInt32();
  3416. var hitArea;
  3417. if (hitTestId) {
  3418. pi = contentItem.owner.getItemById(hitTestId);
  3419. if (pi && pi.pixelHitTestData)
  3420. hitArea = new fgui.PixelHitTest(pi.pixelHitTestData, i1, i2);
  3421. }
  3422. else if (i1 != 0 && i2 != -1) {
  3423. hitArea = new fgui.ChildHitArea(this.getChildAt(i2).displayObject);
  3424. }
  3425. if (hitArea) {
  3426. this._displayObject.hitArea = hitArea;
  3427. this._displayObject.mouseThrough = false;
  3428. this._displayObject.hitTestPrior = true;
  3429. }
  3430. buffer.seek(0, 5);
  3431. var transitionCount = buffer.getInt16();
  3432. for (i = 0; i < transitionCount; i++) {
  3433. nextPos = buffer.getInt16();
  3434. nextPos += buffer.pos;
  3435. var trans = new fgui.Transition(this);
  3436. trans.setup(buffer);
  3437. this._transitions.push(trans);
  3438. buffer.pos = nextPos;
  3439. }
  3440. if (this._transitions.length > 0) {
  3441. this.displayObject.on(Laya.Event.DISPLAY, this, this.___added);
  3442. this.displayObject.on(Laya.Event.UNDISPLAY, this, this.___removed);
  3443. }
  3444. this.applyAllControllers();
  3445. this._buildingDisplayList = false;
  3446. this._underConstruct = false;
  3447. this.buildNativeDisplayList();
  3448. this.setBoundsChangedFlag();
  3449. if (contentItem.objectType != fgui.ObjectType.Component)
  3450. this.constructExtension(buffer);
  3451. this.onConstruct();
  3452. }
  3453. constructExtension(buffer) {
  3454. }
  3455. onConstruct() {
  3456. this.constructFromXML(null); //old version
  3457. }
  3458. constructFromXML(xml) {
  3459. }
  3460. setup_afterAdd(buffer, beginPos) {
  3461. super.setup_afterAdd(buffer, beginPos);
  3462. buffer.seek(beginPos, 4);
  3463. var pageController = buffer.getInt16();
  3464. if (pageController != -1 && this._scrollPane)
  3465. this._scrollPane.pageController = this._parent.getControllerAt(pageController);
  3466. var cnt;
  3467. var i;
  3468. cnt = buffer.getInt16();
  3469. for (i = 0; i < cnt; i++) {
  3470. var cc = this.getController(buffer.readS());
  3471. var pageId = buffer.readS();
  3472. if (cc)
  3473. cc.selectedPageId = pageId;
  3474. }
  3475. if (buffer.version >= 2) {
  3476. cnt = buffer.getInt16();
  3477. for (i = 0; i < cnt; i++) {
  3478. var target = buffer.readS();
  3479. var propertyId = buffer.getInt16();
  3480. var value = buffer.readS();
  3481. var obj = this.getChildByPath(target);
  3482. if (obj)
  3483. obj.setProp(propertyId, value);
  3484. }
  3485. }
  3486. }
  3487. ___added() {
  3488. var cnt = this._transitions.length;
  3489. for (var i = 0; i < cnt; ++i) {
  3490. this._transitions[i].onOwnerAddedToStage();
  3491. }
  3492. }
  3493. ___removed() {
  3494. var cnt = this._transitions.length;
  3495. for (var i = 0; i < cnt; ++i) {
  3496. this._transitions[i].onOwnerRemovedFromStage();
  3497. }
  3498. }
  3499. }
  3500. fgui.GComponent = GComponent;
  3501. })(fgui);
  3502. ///<reference path="GComponent.ts"/>
  3503. ///<reference path="GComponent.ts"/>
  3504. (function (fgui) {
  3505. class GButton extends fgui.GComponent {
  3506. constructor() {
  3507. super();
  3508. this._soundVolumeScale = 0;
  3509. this._downEffect = 0;
  3510. this._mode = fgui.ButtonMode.Common;
  3511. this._title = "";
  3512. this._icon = "";
  3513. this._sound = fgui.UIConfig.buttonSound;
  3514. this._soundVolumeScale = fgui.UIConfig.buttonSoundVolumeScale;
  3515. this._changeStateOnClick = true;
  3516. this._downEffectValue = 0.8;
  3517. }
  3518. get icon() {
  3519. return this._icon;
  3520. }
  3521. set icon(value) {
  3522. this._icon = value;
  3523. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3524. if (this._iconObject)
  3525. this._iconObject.icon = value;
  3526. this.updateGear(7);
  3527. }
  3528. get selectedIcon() {
  3529. return this._selectedIcon;
  3530. }
  3531. set selectedIcon(value) {
  3532. this._selectedIcon = value;
  3533. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3534. if (this._iconObject)
  3535. this._iconObject.icon = value;
  3536. }
  3537. get title() {
  3538. return this._title;
  3539. }
  3540. set title(value) {
  3541. this._title = value;
  3542. if (this._titleObject)
  3543. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3544. this.updateGear(6);
  3545. }
  3546. get text() {
  3547. return this.title;
  3548. }
  3549. set text(value) {
  3550. this.title = value;
  3551. }
  3552. get selectedTitle() {
  3553. return this._selectedTitle;
  3554. }
  3555. set selectedTitle(value) {
  3556. this._selectedTitle = value;
  3557. if (this._titleObject)
  3558. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3559. }
  3560. get titleColor() {
  3561. var tf = this.getTextField();
  3562. if (tf)
  3563. return tf.color;
  3564. else
  3565. return "#000000";
  3566. }
  3567. set titleColor(value) {
  3568. var tf = this.getTextField();
  3569. if (tf)
  3570. tf.color = value;
  3571. this.updateGear(4);
  3572. }
  3573. get titleFontSize() {
  3574. var tf = this.getTextField();
  3575. if (tf)
  3576. return tf.fontSize;
  3577. else
  3578. return 0;
  3579. }
  3580. set titleFontSize(value) {
  3581. var tf = this.getTextField();
  3582. if (tf)
  3583. tf.fontSize = value;
  3584. }
  3585. get sound() {
  3586. return this._sound;
  3587. }
  3588. set sound(val) {
  3589. this._sound = val;
  3590. }
  3591. get soundVolumeScale() {
  3592. return this._soundVolumeScale;
  3593. }
  3594. set soundVolumeScale(value) {
  3595. this._soundVolumeScale = value;
  3596. }
  3597. set selected(val) {
  3598. if (this._mode == fgui.ButtonMode.Common)
  3599. return;
  3600. if (this._selected != val) {
  3601. this._selected = val;
  3602. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3603. if (this._selected)
  3604. this.setState(GButton.SELECTED_DISABLED);
  3605. else
  3606. this.setState(GButton.DISABLED);
  3607. }
  3608. else {
  3609. if (this._selected)
  3610. this.setState(this._over ? GButton.SELECTED_OVER : GButton.DOWN);
  3611. else
  3612. this.setState(this._over ? GButton.OVER : GButton.UP);
  3613. }
  3614. if (this._selectedTitle && this._titleObject)
  3615. this._titleObject.text = this._selected ? this._selectedTitle : this._title;
  3616. if (this._selectedIcon) {
  3617. var str = this._selected ? this._selectedIcon : this._icon;
  3618. if (this._iconObject)
  3619. this._iconObject.icon = str;
  3620. }
  3621. if (this._relatedController
  3622. && this._parent
  3623. && !this._parent._buildingDisplayList) {
  3624. if (this._selected) {
  3625. this._relatedController.selectedPageId = this._relatedPageId;
  3626. if (this._relatedController.autoRadioGroupDepth)
  3627. this._parent.adjustRadioGroupDepth(this, this._relatedController);
  3628. }
  3629. else if (this._mode == fgui.ButtonMode.Check && this._relatedController.selectedPageId == this._relatedPageId)
  3630. this._relatedController.oppositePageId = this._relatedPageId;
  3631. }
  3632. }
  3633. }
  3634. get selected() {
  3635. return this._selected;
  3636. }
  3637. get mode() {
  3638. return this._mode;
  3639. }
  3640. set mode(value) {
  3641. if (this._mode != value) {
  3642. if (value == fgui.ButtonMode.Common)
  3643. this.selected = false;
  3644. this._mode = value;
  3645. }
  3646. }
  3647. get relatedController() {
  3648. return this._relatedController;
  3649. }
  3650. set relatedController(val) {
  3651. if (val != this._relatedController) {
  3652. this._relatedController = val;
  3653. this._relatedPageId = null;
  3654. }
  3655. }
  3656. get relatedPageId() {
  3657. return this._relatedPageId;
  3658. }
  3659. set relatedPageId(val) {
  3660. this._relatedPageId = val;
  3661. }
  3662. get changeStateOnClick() {
  3663. return this._changeStateOnClick;
  3664. }
  3665. set changeStateOnClick(value) {
  3666. this._changeStateOnClick = value;
  3667. }
  3668. get linkedPopup() {
  3669. return this._linkedPopup;
  3670. }
  3671. set linkedPopup(value) {
  3672. this._linkedPopup = value;
  3673. }
  3674. getTextField() {
  3675. if (this._titleObject instanceof fgui.GTextField)
  3676. return this._titleObject;
  3677. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof GButton))
  3678. return this._titleObject.getTextField();
  3679. else
  3680. return null;
  3681. }
  3682. fireClick(downEffect) {
  3683. if (downEffect == null)
  3684. downEffect = true;
  3685. if (downEffect && this._mode == fgui.ButtonMode.Common) {
  3686. this.setState(GButton.OVER);
  3687. Laya.timer.once(100, this, this.setState, [GButton.DOWN], false);
  3688. Laya.timer.once(200, this, this.setState, [GButton.UP], false);
  3689. }
  3690. this.__click(fgui.Events.createEvent(Laya.Event.CLICK, this.displayObject));
  3691. }
  3692. setState(val) {
  3693. if (this._buttonController)
  3694. this._buttonController.selectedPage = val;
  3695. if (this._downEffect == 1) {
  3696. var cnt = this.numChildren;
  3697. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3698. var r = this._downEffectValue * 255;
  3699. var color = Laya.Utils.toHexColor((r << 16) + (r << 8) + r);
  3700. for (var i = 0; i < cnt; i++) {
  3701. var obj = this.getChildAt(i);
  3702. if (!(obj instanceof fgui.GTextField))
  3703. obj.setProp(fgui.ObjectPropID.Color, color);
  3704. }
  3705. }
  3706. else {
  3707. for (i = 0; i < cnt; i++) {
  3708. obj = this.getChildAt(i);
  3709. if (!(obj instanceof fgui.GTextField))
  3710. obj.setProp(fgui.ObjectPropID.Color, "#FFFFFF");
  3711. }
  3712. }
  3713. }
  3714. else if (this._downEffect == 2) {
  3715. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3716. if (!this._downScaled) {
  3717. this.setScale(this.scaleX * this._downEffectValue, this.scaleY * this._downEffectValue);
  3718. this._downScaled = true;
  3719. }
  3720. }
  3721. else {
  3722. if (this._downScaled) {
  3723. this.setScale(this.scaleX / this._downEffectValue, this.scaleY / this._downEffectValue);
  3724. this._downScaled = false;
  3725. }
  3726. }
  3727. }
  3728. }
  3729. handleControllerChanged(c) {
  3730. super.handleControllerChanged(c);
  3731. if (this._relatedController == c)
  3732. this.selected = this._relatedPageId == c.selectedPageId;
  3733. }
  3734. handleGrayedChanged() {
  3735. if (this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3736. if (this.grayed) {
  3737. if (this._selected && this._buttonController.hasPage(GButton.SELECTED_DISABLED))
  3738. this.setState(GButton.SELECTED_DISABLED);
  3739. else
  3740. this.setState(GButton.DISABLED);
  3741. }
  3742. else if (this._selected)
  3743. this.setState(GButton.DOWN);
  3744. else
  3745. this.setState(GButton.UP);
  3746. }
  3747. else
  3748. super.handleGrayedChanged();
  3749. }
  3750. getProp(index) {
  3751. switch (index) {
  3752. case fgui.ObjectPropID.Color:
  3753. return this.titleColor;
  3754. case fgui.ObjectPropID.OutlineColor:
  3755. {
  3756. var tf = this.getTextField();
  3757. if (tf)
  3758. return tf.strokeColor;
  3759. else
  3760. return 0;
  3761. }
  3762. case fgui.ObjectPropID.FontSize:
  3763. return this.titleFontSize;
  3764. case fgui.ObjectPropID.Selected:
  3765. return this.selected;
  3766. default:
  3767. return super.getProp(index);
  3768. }
  3769. }
  3770. setProp(index, value) {
  3771. switch (index) {
  3772. case fgui.ObjectPropID.Color:
  3773. this.titleColor = value;
  3774. break;
  3775. case fgui.ObjectPropID.OutlineColor:
  3776. {
  3777. var tf = this.getTextField();
  3778. if (tf)
  3779. tf.strokeColor = value;
  3780. }
  3781. break;
  3782. case fgui.ObjectPropID.FontSize:
  3783. this.titleFontSize = value;
  3784. break;
  3785. case fgui.ObjectPropID.Selected:
  3786. this.selected = value;
  3787. break;
  3788. default:
  3789. super.setProp(index, value);
  3790. break;
  3791. }
  3792. }
  3793. constructExtension(buffer) {
  3794. buffer.seek(0, 6);
  3795. this._mode = buffer.readByte();
  3796. var str = buffer.readS();
  3797. if (str)
  3798. this._sound = str;
  3799. this._soundVolumeScale = buffer.getFloat32();
  3800. this._downEffect = buffer.readByte();
  3801. this._downEffectValue = buffer.getFloat32();
  3802. if (this._downEffect == 2)
  3803. this.setPivot(0.5, 0.5, this.pivotAsAnchor);
  3804. this._buttonController = this.getController("button");
  3805. this._titleObject = this.getChild("title");
  3806. this._iconObject = this.getChild("icon");
  3807. if (this._titleObject)
  3808. this._title = this._titleObject.text;
  3809. if (this._iconObject)
  3810. this._icon = this._iconObject.icon;
  3811. if (this._mode == fgui.ButtonMode.Common)
  3812. this.setState(GButton.UP);
  3813. this.on(Laya.Event.ROLL_OVER, this, this.__rollover);
  3814. this.on(Laya.Event.ROLL_OUT, this, this.__rollout);
  3815. this.on(Laya.Event.MOUSE_DOWN, this, this.__mousedown);
  3816. this.on(Laya.Event.CLICK, this, this.__click);
  3817. }
  3818. setup_afterAdd(buffer, beginPos) {
  3819. super.setup_afterAdd(buffer, beginPos);
  3820. if (!buffer.seek(beginPos, 6))
  3821. return;
  3822. if (buffer.readByte() != this.packageItem.objectType)
  3823. return;
  3824. var str;
  3825. var iv;
  3826. str = buffer.readS();
  3827. if (str != null)
  3828. this.title = str;
  3829. str = buffer.readS();
  3830. if (str != null)
  3831. this.selectedTitle = str;
  3832. str = buffer.readS();
  3833. if (str != null)
  3834. this.icon = str;
  3835. str = buffer.readS();
  3836. if (str != null)
  3837. this.selectedIcon = str;
  3838. if (buffer.readBool())
  3839. this.titleColor = buffer.readColorS();
  3840. iv = buffer.getInt32();
  3841. if (iv != 0)
  3842. this.titleFontSize = iv;
  3843. iv = buffer.getInt16();
  3844. if (iv >= 0)
  3845. this._relatedController = this.parent.getControllerAt(iv);
  3846. this._relatedPageId = buffer.readS();
  3847. str = buffer.readS();
  3848. if (str != null)
  3849. this._sound = str;
  3850. if (buffer.readBool())
  3851. this._soundVolumeScale = buffer.getFloat32();
  3852. this.selected = buffer.readBool();
  3853. }
  3854. __rollover() {
  3855. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3856. return;
  3857. this._over = true;
  3858. if (this._down)
  3859. return;
  3860. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3861. return;
  3862. this.setState(this._selected ? GButton.SELECTED_OVER : GButton.OVER);
  3863. }
  3864. __rollout() {
  3865. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3866. return;
  3867. this._over = false;
  3868. if (this._down)
  3869. return;
  3870. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3871. return;
  3872. this.setState(this._selected ? GButton.DOWN : GButton.UP);
  3873. }
  3874. __mousedown(evt) {
  3875. this._down = true;
  3876. fgui.GRoot.inst.checkPopups(evt.target);
  3877. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.__mouseup);
  3878. if (this._mode == fgui.ButtonMode.Common) {
  3879. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3880. this.setState(GButton.SELECTED_DISABLED);
  3881. else
  3882. this.setState(GButton.DOWN);
  3883. }
  3884. if (this._linkedPopup) {
  3885. if (this._linkedPopup instanceof fgui.Window)
  3886. this._linkedPopup.toggleStatus();
  3887. else
  3888. this.root.togglePopup(this._linkedPopup, this);
  3889. }
  3890. }
  3891. __mouseup() {
  3892. if (this._down) {
  3893. Laya.stage.off(Laya.Event.MOUSE_UP, this, this.__mouseup);
  3894. this._down = false;
  3895. if (this._displayObject == null)
  3896. return;
  3897. if (this._mode == fgui.ButtonMode.Common) {
  3898. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3899. this.setState(GButton.DISABLED);
  3900. else if (this._over)
  3901. this.setState(GButton.OVER);
  3902. else
  3903. this.setState(GButton.UP);
  3904. }
  3905. }
  3906. }
  3907. __click(evt) {
  3908. if (this._sound) {
  3909. var pi = fgui.UIPackage.getItemByURL(this._sound);
  3910. if (pi)
  3911. fgui.GRoot.inst.playOneShotSound(pi.file);
  3912. else
  3913. fgui.GRoot.inst.playOneShotSound(this._sound);
  3914. }
  3915. if (this._mode == fgui.ButtonMode.Check) {
  3916. if (this._changeStateOnClick) {
  3917. this.selected = !this._selected;
  3918. fgui.Events.dispatch(fgui.Events.STATE_CHANGED, this.displayObject, evt);
  3919. }
  3920. }
  3921. else if (this._mode == fgui.ButtonMode.Radio) {
  3922. if (this._changeStateOnClick && !this._selected) {
  3923. this.selected = true;
  3924. fgui.Events.dispatch(fgui.Events.STATE_CHANGED, this.displayObject, evt);
  3925. }
  3926. }
  3927. else {
  3928. if (this._relatedController)
  3929. this._relatedController.selectedPageId = this._relatedPageId;
  3930. }
  3931. }
  3932. }
  3933. GButton.UP = "up";
  3934. GButton.DOWN = "down";
  3935. GButton.OVER = "over";
  3936. GButton.SELECTED_OVER = "selectedOver";
  3937. GButton.DISABLED = "disabled";
  3938. GButton.SELECTED_DISABLED = "selectedDisabled";
  3939. fgui.GButton = GButton;
  3940. })(fgui);
  3941. (function (fgui) {
  3942. class GComboBox extends fgui.GComponent {
  3943. constructor() {
  3944. super();
  3945. this._visibleItemCount = fgui.UIConfig.defaultComboBoxVisibleItemCount;
  3946. this._itemsUpdated = true;
  3947. this._selectedIndex = -1;
  3948. this._popupDirection = 0;
  3949. this._items = [];
  3950. this._values = [];
  3951. }
  3952. get text() {
  3953. if (this._titleObject)
  3954. return this._titleObject.text;
  3955. else
  3956. return null;
  3957. }
  3958. set text(value) {
  3959. if (this._titleObject)
  3960. this._titleObject.text = value;
  3961. this.updateGear(6);
  3962. }
  3963. get titleColor() {
  3964. var tf = this.getTextField();
  3965. if (tf)
  3966. return tf.color;
  3967. else
  3968. return "#000000";
  3969. }
  3970. set titleColor(value) {
  3971. var tf = this.getTextField();
  3972. if (tf)
  3973. tf.color = value;
  3974. this.updateGear(4);
  3975. }
  3976. get titleFontSize() {
  3977. var tf = this.getTextField();
  3978. if (tf)
  3979. return tf.fontSize;
  3980. else
  3981. return 0;
  3982. }
  3983. set titleFontSize(value) {
  3984. var tf = this.getTextField();
  3985. if (tf)
  3986. tf.fontSize = value;
  3987. }
  3988. get icon() {
  3989. if (this._iconObject)
  3990. return this._iconObject.icon;
  3991. else
  3992. return null;
  3993. }
  3994. set icon(value) {
  3995. if (this._iconObject)
  3996. this._iconObject.icon = value;
  3997. this.updateGear(7);
  3998. }
  3999. get visibleItemCount() {
  4000. return this._visibleItemCount;
  4001. }
  4002. set visibleItemCount(value) {
  4003. this._visibleItemCount = value;
  4004. }
  4005. get popupDirection() {
  4006. return this._popupDirection;
  4007. }
  4008. set popupDirection(value) {
  4009. this._popupDirection = value;
  4010. }
  4011. get items() {
  4012. return this._items;
  4013. }
  4014. set items(value) {
  4015. if (!value)
  4016. this._items.length = 0;
  4017. else
  4018. this._items = value.concat();
  4019. if (this._items.length > 0) {
  4020. if (this._selectedIndex >= this._items.length)
  4021. this._selectedIndex = this._items.length - 1;
  4022. else if (this._selectedIndex == -1)
  4023. this._selectedIndex = 0;
  4024. this.text = this._items[this._selectedIndex];
  4025. if (this._icons && this._selectedIndex < this._icons.length)
  4026. this.icon = this._icons[this._selectedIndex];
  4027. }
  4028. else {
  4029. this.text = "";
  4030. if (this._icons)
  4031. this.icon = null;
  4032. this._selectedIndex = -1;
  4033. }
  4034. this._itemsUpdated = true;
  4035. }
  4036. get icons() {
  4037. return this._icons;
  4038. }
  4039. set icons(value) {
  4040. this._icons = value;
  4041. if (this._icons && this._selectedIndex != -1 && this._selectedIndex < this._icons.length)
  4042. this.icon = this._icons[this._selectedIndex];
  4043. }
  4044. get values() {
  4045. return this._values;
  4046. }
  4047. set values(value) {
  4048. if (!value)
  4049. this._values.length = 0;
  4050. else
  4051. this._values = value.concat();
  4052. }
  4053. get selectedIndex() {
  4054. return this._selectedIndex;
  4055. }
  4056. set selectedIndex(val) {
  4057. if (this._selectedIndex == val)
  4058. return;
  4059. this._selectedIndex = val;
  4060. if (this._selectedIndex >= 0 && this._selectedIndex < this._items.length) {
  4061. this.text = this._items[this._selectedIndex];
  4062. if (this._icons && this._selectedIndex < this._icons.length)
  4063. this.icon = this._icons[this._selectedIndex];
  4064. }
  4065. else {
  4066. this.text = "";
  4067. if (this._icons)
  4068. this.icon = null;
  4069. }
  4070. this.updateSelectionController();
  4071. }
  4072. get value() {
  4073. return this._values[this._selectedIndex];
  4074. }
  4075. set value(val) {
  4076. var index = this._values.indexOf(val);
  4077. if (index == -1 && val == null)
  4078. index = this._values.indexOf("");
  4079. this.selectedIndex = index;
  4080. }
  4081. getTextField() {
  4082. if (this._titleObject instanceof fgui.GTextField)
  4083. return this._titleObject;
  4084. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof fgui.GButton))
  4085. return this._titleObject.getTextField();
  4086. else
  4087. return null;
  4088. }
  4089. setState(val) {
  4090. if (this._buttonController)
  4091. this._buttonController.selectedPage = val;
  4092. }
  4093. get selectionController() {
  4094. return this._selectionController;
  4095. }
  4096. set selectionController(value) {
  4097. this._selectionController = value;
  4098. }
  4099. handleControllerChanged(c) {
  4100. super.handleControllerChanged(c);
  4101. if (this._selectionController == c)
  4102. this.selectedIndex = c.selectedIndex;
  4103. }
  4104. updateSelectionController() {
  4105. if (this._selectionController && !this._selectionController.changing
  4106. && this._selectedIndex < this._selectionController.pageCount) {
  4107. var c = this._selectionController;
  4108. this._selectionController = null;
  4109. c.selectedIndex = this._selectedIndex;
  4110. this._selectionController = c;
  4111. }
  4112. }
  4113. dispose() {
  4114. if (this.dropdown) {
  4115. this.dropdown.dispose();
  4116. this.dropdown = null;
  4117. }
  4118. this._selectionController = null;
  4119. super.dispose();
  4120. }
  4121. getProp(index) {
  4122. switch (index) {
  4123. case fgui.ObjectPropID.Color:
  4124. return this.titleColor;
  4125. case fgui.ObjectPropID.OutlineColor:
  4126. {
  4127. var tf = this.getTextField();
  4128. if (tf)
  4129. return tf.strokeColor;
  4130. else
  4131. return 0;
  4132. }
  4133. case fgui.ObjectPropID.FontSize:
  4134. {
  4135. tf = this.getTextField();
  4136. if (tf)
  4137. return tf.fontSize;
  4138. else
  4139. return 0;
  4140. }
  4141. default:
  4142. return super.getProp(index);
  4143. }
  4144. }
  4145. setProp(index, value) {
  4146. switch (index) {
  4147. case fgui.ObjectPropID.Color:
  4148. this.titleColor = value;
  4149. break;
  4150. case fgui.ObjectPropID.OutlineColor:
  4151. {
  4152. var tf = this.getTextField();
  4153. if (tf)
  4154. tf.strokeColor = value;
  4155. }
  4156. break;
  4157. case fgui.ObjectPropID.FontSize:
  4158. {
  4159. tf = this.getTextField();
  4160. if (tf)
  4161. tf.fontSize = value;
  4162. }
  4163. break;
  4164. default:
  4165. super.setProp(index, value);
  4166. break;
  4167. }
  4168. }
  4169. constructExtension(buffer) {
  4170. var str;
  4171. this._buttonController = this.getController("button");
  4172. this._titleObject = this.getChild("title");
  4173. this._iconObject = this.getChild("icon");
  4174. str = buffer.readS();
  4175. if (str) {
  4176. this.dropdown = (fgui.UIPackage.createObjectFromURL(str));
  4177. if (!this.dropdown) {
  4178. Laya.Log.print("下拉框必须为元件");
  4179. return;
  4180. }
  4181. this.dropdown.name = "this._dropdownObject";
  4182. this._list = this.dropdown.getChild("list");
  4183. if (!this._list) {
  4184. Laya.Log.print(this.resourceURL + ": 下拉框的弹出元件里必须包含名为list的列表");
  4185. return;
  4186. }
  4187. this._list.on(fgui.Events.CLICK_ITEM, this, this.__clickItem);
  4188. this._list.addRelation(this.dropdown, fgui.RelationType.Width);
  4189. this._list.removeRelation(this.dropdown, fgui.RelationType.Height);
  4190. this.dropdown.addRelation(this._list, fgui.RelationType.Height);
  4191. this.dropdown.removeRelation(this._list, fgui.RelationType.Width);
  4192. this.dropdown.displayObject.on(Laya.Event.UNDISPLAY, this, this.__popupWinClosed);
  4193. }
  4194. this.on(Laya.Event.ROLL_OVER, this, this.__rollover);
  4195. this.on(Laya.Event.ROLL_OUT, this, this.__rollout);
  4196. this.on(Laya.Event.MOUSE_DOWN, this, this.__mousedown);
  4197. }
  4198. setup_afterAdd(buffer, beginPos) {
  4199. super.setup_afterAdd(buffer, beginPos);
  4200. if (!buffer.seek(beginPos, 6))
  4201. return;
  4202. if (buffer.readByte() != this.packageItem.objectType)
  4203. return;
  4204. var i;
  4205. var iv;
  4206. var nextPos;
  4207. var str;
  4208. var itemCount = buffer.getInt16();
  4209. for (i = 0; i < itemCount; i++) {
  4210. nextPos = buffer.getInt16();
  4211. nextPos += buffer.pos;
  4212. this._items[i] = buffer.readS();
  4213. this._values[i] = buffer.readS();
  4214. str = buffer.readS();
  4215. if (str != null) {
  4216. if (!this._icons)
  4217. this._icons = [];
  4218. this._icons[i] = str;
  4219. }
  4220. buffer.pos = nextPos;
  4221. }
  4222. str = buffer.readS();
  4223. if (str != null) {
  4224. this.text = str;
  4225. this._selectedIndex = this._items.indexOf(str);
  4226. }
  4227. else if (this._items.length > 0) {
  4228. this._selectedIndex = 0;
  4229. this.text = this._items[0];
  4230. }
  4231. else
  4232. this._selectedIndex = -1;
  4233. str = buffer.readS();
  4234. if (str != null)
  4235. this.icon = str;
  4236. if (buffer.readBool())
  4237. this.titleColor = buffer.readColorS();
  4238. iv = buffer.getInt32();
  4239. if (iv > 0)
  4240. this._visibleItemCount = iv;
  4241. this._popupDirection = buffer.readByte();
  4242. iv = buffer.getInt16();
  4243. if (iv >= 0)
  4244. this._selectionController = this.parent.getControllerAt(iv);
  4245. }
  4246. showDropdown() {
  4247. if (this._itemsUpdated) {
  4248. this._itemsUpdated = false;
  4249. this._list.removeChildrenToPool();
  4250. var cnt = this._items.length;
  4251. for (var i = 0; i < cnt; i++) {
  4252. var item = this._list.addItemFromPool();
  4253. item.name = i < this._values.length ? this._values[i] : "";
  4254. item.text = this._items[i];
  4255. item.icon = (this._icons && i < this._icons.length) ? this._icons[i] : null;
  4256. }
  4257. this._list.resizeToFit(this._visibleItemCount);
  4258. }
  4259. this._list.selectedIndex = -1;
  4260. this.dropdown.width = this.width;
  4261. this._list.ensureBoundsCorrect();
  4262. var downward = null;
  4263. if (this._popupDirection == fgui.PopupDirection.Down)
  4264. downward = true;
  4265. else if (this._popupDirection == fgui.PopupDirection.Up)
  4266. downward = false;
  4267. this.root.togglePopup(this.dropdown, this, downward);
  4268. if (this.dropdown.parent)
  4269. this.setState(fgui.GButton.DOWN);
  4270. }
  4271. __popupWinClosed() {
  4272. if (this._over)
  4273. this.setState(fgui.GButton.OVER);
  4274. else
  4275. this.setState(fgui.GButton.UP);
  4276. }
  4277. __clickItem(itemObject, evt) {
  4278. Laya.timer.callLater(this, this.__clickItem2, [this._list.getChildIndex(itemObject), evt]);
  4279. }
  4280. __clickItem2(index, evt) {
  4281. if (this.dropdown.parent instanceof fgui.GRoot)
  4282. this.dropdown.parent.hidePopup();
  4283. this._selectedIndex = -1;
  4284. this.selectedIndex = index;
  4285. fgui.Events.dispatch(fgui.Events.STATE_CHANGED, this.displayObject, evt);
  4286. }
  4287. __rollover() {
  4288. this._over = true;
  4289. if (this._down || this.dropdown && this.dropdown.parent)
  4290. return;
  4291. this.setState(fgui.GButton.OVER);
  4292. }
  4293. __rollout() {
  4294. this._over = false;
  4295. if (this._down || this.dropdown && this.dropdown.parent)
  4296. return;
  4297. this.setState(fgui.GButton.UP);
  4298. }
  4299. __mousedown(evt) {
  4300. if (evt.target instanceof Laya.Input)
  4301. return;
  4302. this._down = true;
  4303. fgui.GRoot.inst.checkPopups(evt.target);
  4304. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.__mouseup);
  4305. if (this.dropdown)
  4306. this.showDropdown();
  4307. }
  4308. __mouseup() {
  4309. if (this._down) {
  4310. this._down = false;
  4311. Laya.stage.off(Laya.Event.MOUSE_UP, this, this.__mouseup);
  4312. if (this.dropdown && !this.dropdown.parent) {
  4313. if (this._over)
  4314. this.setState(fgui.GButton.OVER);
  4315. else
  4316. this.setState(fgui.GButton.UP);
  4317. }
  4318. }
  4319. }
  4320. }
  4321. fgui.GComboBox = GComboBox;
  4322. })(fgui);
  4323. (function (fgui) {
  4324. class GGraph extends fgui.GObject {
  4325. constructor() {
  4326. super();
  4327. this._type = 0;
  4328. this._lineSize = 1;
  4329. this._lineColor = "#000000";
  4330. this._fillColor = "#FFFFFF";
  4331. }
  4332. drawRect(lineSize, lineColor, fillColor, cornerRadius) {
  4333. this._type = 1;
  4334. this._lineSize = lineSize;
  4335. this._lineColor = lineColor;
  4336. this._fillColor = fillColor;
  4337. this._cornerRadius = cornerRadius;
  4338. this.updateGraph();
  4339. }
  4340. drawEllipse(lineSize, lineColor, fillColor) {
  4341. this._type = 2;
  4342. this._lineSize = lineSize;
  4343. this._lineColor = lineColor;
  4344. this._fillColor = fillColor;
  4345. this.updateGraph();
  4346. }
  4347. drawRegularPolygon(lineSize, lineColor, fillColor, sides, startAngle, distances) {
  4348. this._type = 4;
  4349. this._lineSize = lineSize;
  4350. this._lineColor = lineColor;
  4351. this._fillColor = fillColor;
  4352. this._sides = sides;
  4353. this._startAngle = startAngle || 0;
  4354. this._distances = distances;
  4355. this.updateGraph();
  4356. }
  4357. drawPolygon(lineSize, lineColor, fillColor, points) {
  4358. this._type = 3;
  4359. this._lineSize = lineSize;
  4360. this._lineColor = lineColor;
  4361. this._fillColor = fillColor;
  4362. this._polygonPoints = points;
  4363. this.updateGraph();
  4364. }
  4365. get distances() {
  4366. return this._distances;
  4367. }
  4368. set distances(value) {
  4369. this._distances = value;
  4370. if (this._type == 3)
  4371. this.updateGraph();
  4372. }
  4373. get color() {
  4374. return this._fillColor;
  4375. }
  4376. set color(value) {
  4377. this._fillColor = value;
  4378. this.updateGear(4);
  4379. if (this._type != 0)
  4380. this.updateGraph();
  4381. }
  4382. updateGraph() {
  4383. this._displayObject.mouseEnabled = this.touchable;
  4384. var gr = this._displayObject.graphics;
  4385. gr.clear();
  4386. var w = this.width;
  4387. var h = this.height;
  4388. if (w == 0 || h == 0)
  4389. return;
  4390. var fillColor = this._fillColor;
  4391. var lineColor = this._lineColor;
  4392. if ( /*Render.isWebGL &&*/fgui.ToolSet.startsWith(fillColor, "rgba")) {
  4393. //webgl下laya未支持rgba格式
  4394. var arr = fillColor.substring(5, fillColor.lastIndexOf(")")).split(",");
  4395. var a = parseFloat(arr[3]);
  4396. if (a == 0)
  4397. fillColor = null;
  4398. else {
  4399. fillColor = Laya.Utils.toHexColor((parseInt(arr[0]) << 16) + (parseInt(arr[1]) << 8) + parseInt(arr[2]));
  4400. this.alpha = a;
  4401. }
  4402. }
  4403. if (this._type == 1) {
  4404. if (this._cornerRadius) {
  4405. var paths = [
  4406. ["moveTo", this._cornerRadius[0], 0],
  4407. ["lineTo", w - this._cornerRadius[1], 0],
  4408. ["arcTo", w, 0, w, this._cornerRadius[1], this._cornerRadius[1]],
  4409. ["lineTo", w, h - this._cornerRadius[3]],
  4410. ["arcTo", w, h, w - this._cornerRadius[3], h, this._cornerRadius[3]],
  4411. ["lineTo", this._cornerRadius[2], h],
  4412. ["arcTo", 0, h, 0, h - this._cornerRadius[2], this._cornerRadius[2]],
  4413. ["lineTo", 0, this._cornerRadius[0]],
  4414. ["arcTo", 0, 0, this._cornerRadius[0], 0, this._cornerRadius[0]],
  4415. ["closePath"]
  4416. ];
  4417. gr.drawPath(0, 0, paths, fillColor ? { fillStyle: fillColor } : null, this._lineSize > 0 ? { strokeStyle: lineColor, lineWidth: this._lineSize } : null);
  4418. }
  4419. else
  4420. gr.drawRect(0, 0, w, h, fillColor, this._lineSize > 0 ? lineColor : null, this._lineSize);
  4421. }
  4422. else if (this._type == 2) {
  4423. gr.drawCircle(w / 2, h / 2, w / 2, fillColor, this._lineSize > 0 ? lineColor : null, this._lineSize);
  4424. }
  4425. else if (this._type == 3) {
  4426. gr.drawPoly(0, 0, this._polygonPoints, fillColor, this._lineSize > 0 ? lineColor : null, this._lineSize);
  4427. }
  4428. else if (this._type == 4) {
  4429. if (!this._polygonPoints)
  4430. this._polygonPoints = [];
  4431. var radius = Math.min(this._width, this._height) / 2;
  4432. this._polygonPoints.length = 0;
  4433. var angle = Laya.Utils.toRadian(this._startAngle);
  4434. var deltaAngle = 2 * Math.PI / this._sides;
  4435. var dist;
  4436. for (var i = 0; i < this._sides; i++) {
  4437. if (this._distances) {
  4438. dist = this._distances[i];
  4439. if (isNaN(dist))
  4440. dist = 1;
  4441. }
  4442. else
  4443. dist = 1;
  4444. var xv = radius + radius * dist * Math.cos(angle);
  4445. var yv = radius + radius * dist * Math.sin(angle);
  4446. this._polygonPoints.push(xv, yv);
  4447. angle += deltaAngle;
  4448. }
  4449. gr.drawPoly(0, 0, this._polygonPoints, fillColor, this._lineSize > 0 ? lineColor : null, this._lineSize);
  4450. }
  4451. this._displayObject.repaint();
  4452. }
  4453. replaceMe(target) {
  4454. if (!this._parent)
  4455. throw "parent not set";
  4456. target.name = this.name;
  4457. target.alpha = this.alpha;
  4458. target.rotation = this.rotation;
  4459. target.visible = this.visible;
  4460. target.touchable = this.touchable;
  4461. target.grayed = this.grayed;
  4462. target.setXY(this.x, this.y);
  4463. target.setSize(this.width, this.height);
  4464. var index = this._parent.getChildIndex(this);
  4465. this._parent.addChildAt(target, index);
  4466. target.relations.copyFrom(this.relations);
  4467. this._parent.removeChild(this, true);
  4468. }
  4469. addBeforeMe(target) {
  4470. if (!this._parent)
  4471. throw "parent not set";
  4472. var index = this._parent.getChildIndex(this);
  4473. this._parent.addChildAt(target, index);
  4474. }
  4475. addAfterMe(target) {
  4476. if (!this._parent)
  4477. throw "parent not set";
  4478. var index = this._parent.getChildIndex(this);
  4479. index++;
  4480. this._parent.addChildAt(target, index);
  4481. }
  4482. setNativeObject(obj) {
  4483. this._type = 0;
  4484. this._displayObject.mouseEnabled = this.touchable;
  4485. this._displayObject.graphics.clear();
  4486. this._displayObject.addChild(obj);
  4487. }
  4488. createDisplayObject() {
  4489. super.createDisplayObject();
  4490. this._displayObject.mouseEnabled = false;
  4491. this._hitArea = new Laya.HitArea();
  4492. this._hitArea.hit = this._displayObject.graphics;
  4493. this._displayObject.hitArea = this._hitArea;
  4494. }
  4495. getProp(index) {
  4496. if (index == fgui.ObjectPropID.Color)
  4497. return this.color;
  4498. else
  4499. return super.getProp(index);
  4500. }
  4501. setProp(index, value) {
  4502. if (index == fgui.ObjectPropID.Color)
  4503. this.color = value;
  4504. else
  4505. super.setProp(index, value);
  4506. }
  4507. handleSizeChanged() {
  4508. super.handleSizeChanged();
  4509. if (this._type != 0)
  4510. this.updateGraph();
  4511. }
  4512. setup_beforeAdd(buffer, beginPos) {
  4513. super.setup_beforeAdd(buffer, beginPos);
  4514. buffer.seek(beginPos, 5);
  4515. this._type = buffer.readByte();
  4516. if (this._type != 0) {
  4517. var i;
  4518. var cnt;
  4519. this._lineSize = buffer.getInt32();
  4520. this._lineColor = buffer.readColorS(true);
  4521. this._fillColor = buffer.readColorS(true);
  4522. if (buffer.readBool()) {
  4523. this._cornerRadius = [];
  4524. for (i = 0; i < 4; i++)
  4525. this._cornerRadius[i] = buffer.getFloat32();
  4526. }
  4527. if (this._type == 3) {
  4528. cnt = buffer.getInt16();
  4529. this._polygonPoints = [];
  4530. this._polygonPoints.length = cnt;
  4531. for (i = 0; i < cnt; i++)
  4532. this._polygonPoints[i] = buffer.getFloat32();
  4533. }
  4534. else if (this._type == 4) {
  4535. this._sides = buffer.getInt16();
  4536. this._startAngle = buffer.getFloat32();
  4537. cnt = buffer.getInt16();
  4538. if (cnt > 0) {
  4539. this._distances = [];
  4540. for (i = 0; i < cnt; i++)
  4541. this._distances[i] = buffer.getFloat32();
  4542. }
  4543. }
  4544. this.updateGraph();
  4545. }
  4546. }
  4547. }
  4548. fgui.GGraph = GGraph;
  4549. })(fgui);
  4550. (function (fgui) {
  4551. class GGroup extends fgui.GObject {
  4552. constructor() {
  4553. super();
  4554. this._layout = 0;
  4555. this._lineGap = 0;
  4556. this._columnGap = 0;
  4557. this._mainGridIndex = -1;
  4558. this._mainGridMinSize = 50;
  4559. this._mainChildIndex = -1;
  4560. this._totalSize = 0;
  4561. this._numChildren = 0;
  4562. this._updating = 0;
  4563. }
  4564. dispose() {
  4565. this._boundsChanged = false;
  4566. super.dispose();
  4567. }
  4568. get layout() {
  4569. return this._layout;
  4570. }
  4571. set layout(value) {
  4572. if (this._layout != value) {
  4573. this._layout = value;
  4574. this.setBoundsChangedFlag();
  4575. }
  4576. }
  4577. get lineGap() {
  4578. return this._lineGap;
  4579. }
  4580. set lineGap(value) {
  4581. if (this._lineGap != value) {
  4582. this._lineGap = value;
  4583. this.setBoundsChangedFlag(true);
  4584. }
  4585. }
  4586. get columnGap() {
  4587. return this._columnGap;
  4588. }
  4589. set columnGap(value) {
  4590. if (this._columnGap != value) {
  4591. this._columnGap = value;
  4592. this.setBoundsChangedFlag(true);
  4593. }
  4594. }
  4595. get excludeInvisibles() {
  4596. return this._excludeInvisibles;
  4597. }
  4598. set excludeInvisibles(value) {
  4599. if (this._excludeInvisibles != value) {
  4600. this._excludeInvisibles = value;
  4601. this.setBoundsChangedFlag();
  4602. }
  4603. }
  4604. get autoSizeDisabled() {
  4605. return this._autoSizeDisabled;
  4606. }
  4607. set autoSizeDisabled(value) {
  4608. this._autoSizeDisabled = value;
  4609. }
  4610. get mainGridMinSize() {
  4611. return this._mainGridMinSize;
  4612. }
  4613. set mainGridMinSize(value) {
  4614. if (this._mainGridMinSize != value) {
  4615. this._mainGridMinSize = value;
  4616. this.setBoundsChangedFlag();
  4617. }
  4618. }
  4619. get mainGridIndex() {
  4620. return this._mainGridIndex;
  4621. }
  4622. set mainGridIndex(value) {
  4623. if (this._mainGridIndex != value) {
  4624. this._mainGridIndex = value;
  4625. this.setBoundsChangedFlag();
  4626. }
  4627. }
  4628. setBoundsChangedFlag(positionChangedOnly) {
  4629. if (this._updating == 0 && this._parent) {
  4630. if (!positionChangedOnly)
  4631. this._percentReady = false;
  4632. if (!this._boundsChanged) {
  4633. this._boundsChanged = true;
  4634. if (this._layout != fgui.GroupLayoutType.None)
  4635. Laya.timer.callLater(this, this.ensureBoundsCorrect);
  4636. }
  4637. }
  4638. }
  4639. ensureSizeCorrect() {
  4640. if (!this._parent || !this._boundsChanged || this._layout == 0)
  4641. return;
  4642. this._boundsChanged = false;
  4643. if (this._autoSizeDisabled)
  4644. this.resizeChildren(0, 0);
  4645. else {
  4646. this.handleLayout();
  4647. this.updateBounds();
  4648. }
  4649. }
  4650. ensureBoundsCorrect() {
  4651. if (!this._parent || !this._boundsChanged)
  4652. return;
  4653. this._boundsChanged = false;
  4654. if (this._layout == 0)
  4655. this.updateBounds();
  4656. else {
  4657. if (this._autoSizeDisabled)
  4658. this.resizeChildren(0, 0);
  4659. else {
  4660. this.handleLayout();
  4661. this.updateBounds();
  4662. }
  4663. }
  4664. }
  4665. updateBounds() {
  4666. Laya.timer.clear(this, this.ensureBoundsCorrect);
  4667. var cnt = this._parent.numChildren;
  4668. var i;
  4669. var child;
  4670. var ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  4671. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  4672. var tmp;
  4673. var empty = true;
  4674. for (i = 0; i < cnt; i++) {
  4675. child = this._parent.getChildAt(i);
  4676. if (child.group != this || this._excludeInvisibles && !child.internalVisible3)
  4677. continue;
  4678. tmp = child.xMin;
  4679. if (tmp < ax)
  4680. ax = tmp;
  4681. tmp = child.yMin;
  4682. if (tmp < ay)
  4683. ay = tmp;
  4684. tmp = child.xMin + child.width;
  4685. if (tmp > ar)
  4686. ar = tmp;
  4687. tmp = child.yMin + child.height;
  4688. if (tmp > ab)
  4689. ab = tmp;
  4690. empty = false;
  4691. }
  4692. var w = 0, h = 0;
  4693. if (!empty) {
  4694. this._updating |= 1;
  4695. this.setXY(ax, ay);
  4696. this._updating &= 2;
  4697. w = ar - ax;
  4698. h = ab - ay;
  4699. }
  4700. if ((this._updating & 2) == 0) {
  4701. this._updating |= 2;
  4702. this.setSize(w, h);
  4703. this._updating &= 1;
  4704. }
  4705. else {
  4706. this._updating &= 1;
  4707. this.resizeChildren(this._width - w, this._height - h);
  4708. }
  4709. }
  4710. handleLayout() {
  4711. this._updating |= 1;
  4712. var child;
  4713. var i;
  4714. var cnt;
  4715. if (this._layout == fgui.GroupLayoutType.Horizontal) {
  4716. var curX = this.x;
  4717. cnt = this._parent.numChildren;
  4718. for (i = 0; i < cnt; i++) {
  4719. child = this._parent.getChildAt(i);
  4720. if (child.group != this)
  4721. continue;
  4722. if (this._excludeInvisibles && !child.internalVisible3)
  4723. continue;
  4724. child.xMin = curX;
  4725. if (child.width != 0)
  4726. curX += child.width + this._columnGap;
  4727. }
  4728. }
  4729. else if (this._layout == fgui.GroupLayoutType.Vertical) {
  4730. var curY = this.y;
  4731. cnt = this._parent.numChildren;
  4732. for (i = 0; i < cnt; i++) {
  4733. child = this._parent.getChildAt(i);
  4734. if (child.group != this)
  4735. continue;
  4736. if (this._excludeInvisibles && !child.internalVisible3)
  4737. continue;
  4738. child.yMin = curY;
  4739. if (child.height != 0)
  4740. curY += child.height + this._lineGap;
  4741. }
  4742. }
  4743. this._updating &= 2;
  4744. }
  4745. moveChildren(dx, dy) {
  4746. if ((this._updating & 1) != 0 || !this._parent)
  4747. return;
  4748. this._updating |= 1;
  4749. var cnt = this._parent.numChildren;
  4750. var i;
  4751. var child;
  4752. for (i = 0; i < cnt; i++) {
  4753. child = this._parent.getChildAt(i);
  4754. if (child.group == this) {
  4755. child.setXY(child.x + dx, child.y + dy);
  4756. }
  4757. }
  4758. this._updating &= 2;
  4759. }
  4760. resizeChildren(dw, dh) {
  4761. if (this._layout == fgui.GroupLayoutType.None || (this._updating & 2) != 0 || !this._parent)
  4762. return;
  4763. this._updating |= 2;
  4764. if (this._boundsChanged) {
  4765. this._boundsChanged = false;
  4766. if (!this._autoSizeDisabled) {
  4767. this.updateBounds();
  4768. return;
  4769. }
  4770. }
  4771. var cnt = this._parent.numChildren;
  4772. var i;
  4773. var child;
  4774. if (!this._percentReady) {
  4775. this._percentReady = true;
  4776. this._numChildren = 0;
  4777. this._totalSize = 0;
  4778. this._mainChildIndex = -1;
  4779. var j = 0;
  4780. for (i = 0; i < cnt; i++) {
  4781. child = this._parent.getChildAt(i);
  4782. if (child.group != this)
  4783. continue;
  4784. if (!this._excludeInvisibles || child.internalVisible3) {
  4785. if (j == this._mainGridIndex)
  4786. this._mainChildIndex = i;
  4787. this._numChildren++;
  4788. if (this._layout == 1)
  4789. this._totalSize += child.width;
  4790. else
  4791. this._totalSize += child.height;
  4792. }
  4793. j++;
  4794. }
  4795. if (this._mainChildIndex != -1) {
  4796. if (this._layout == 1) {
  4797. child = this._parent.getChildAt(this._mainChildIndex);
  4798. this._totalSize += this._mainGridMinSize - child.width;
  4799. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4800. }
  4801. else {
  4802. child = this._parent.getChildAt(this._mainChildIndex);
  4803. this._totalSize += this._mainGridMinSize - child.height;
  4804. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4805. }
  4806. }
  4807. for (i = 0; i < cnt; i++) {
  4808. child = this._parent.getChildAt(i);
  4809. if (child.group != this)
  4810. continue;
  4811. if (i == this._mainChildIndex)
  4812. continue;
  4813. if (this._totalSize > 0)
  4814. child._sizePercentInGroup = (this._layout == 1 ? child.width : child.height) / this._totalSize;
  4815. else
  4816. child._sizePercentInGroup = 0;
  4817. }
  4818. }
  4819. var remainSize = 0;
  4820. var remainPercent = 1;
  4821. var priorHandled = false;
  4822. if (this._layout == 1) {
  4823. remainSize = this.width - (this._numChildren - 1) * this._columnGap;
  4824. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4825. child = this._parent.getChildAt(this._mainChildIndex);
  4826. child.setSize(remainSize - (this._totalSize - this._mainGridMinSize), child._rawHeight + dh, true);
  4827. remainSize -= child.width;
  4828. remainPercent -= child._sizePercentInGroup;
  4829. priorHandled = true;
  4830. }
  4831. var curX = this.x;
  4832. for (i = 0; i < cnt; i++) {
  4833. child = this._parent.getChildAt(i);
  4834. if (child.group != this)
  4835. continue;
  4836. if (this._excludeInvisibles && !child.internalVisible3) {
  4837. child.setSize(child._rawWidth, child._rawHeight + dh, true);
  4838. continue;
  4839. }
  4840. if (!priorHandled || i != this._mainChildIndex) {
  4841. child.setSize(Math.round(child._sizePercentInGroup / remainPercent * remainSize), child._rawHeight + dh, true);
  4842. remainPercent -= child._sizePercentInGroup;
  4843. remainSize -= child.width;
  4844. }
  4845. child.xMin = curX;
  4846. if (child.width != 0)
  4847. curX += child.width + this._columnGap;
  4848. }
  4849. }
  4850. else {
  4851. remainSize = this.height - (this._numChildren - 1) * this._lineGap;
  4852. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4853. child = this._parent.getChildAt(this._mainChildIndex);
  4854. child.setSize(child._rawWidth + dw, remainSize - (this._totalSize - this._mainGridMinSize), true);
  4855. remainSize -= child.height;
  4856. remainPercent -= child._sizePercentInGroup;
  4857. priorHandled = true;
  4858. }
  4859. var curY = this.y;
  4860. for (i = 0; i < cnt; i++) {
  4861. child = this._parent.getChildAt(i);
  4862. if (child.group != this)
  4863. continue;
  4864. if (this._excludeInvisibles && !child.internalVisible3) {
  4865. child.setSize(child._rawWidth + dw, child._rawHeight, true);
  4866. continue;
  4867. }
  4868. if (!priorHandled || i != this._mainChildIndex) {
  4869. child.setSize(child._rawWidth + dw, Math.round(child._sizePercentInGroup / remainPercent * remainSize), true);
  4870. remainPercent -= child._sizePercentInGroup;
  4871. remainSize -= child.height;
  4872. }
  4873. child.yMin = curY;
  4874. if (child.height != 0)
  4875. curY += child.height + this._lineGap;
  4876. }
  4877. }
  4878. this._updating &= 1;
  4879. }
  4880. handleAlphaChanged() {
  4881. if (this._underConstruct)
  4882. return;
  4883. var cnt = this._parent.numChildren;
  4884. for (var i = 0; i < cnt; i++) {
  4885. var child = this._parent.getChildAt(i);
  4886. if (child.group == this)
  4887. child.alpha = this.alpha;
  4888. }
  4889. }
  4890. handleVisibleChanged() {
  4891. if (!this._parent)
  4892. return;
  4893. var cnt = this._parent.numChildren;
  4894. for (var i = 0; i < cnt; i++) {
  4895. var child = this._parent.getChildAt(i);
  4896. if (child.group == this)
  4897. child.handleVisibleChanged();
  4898. }
  4899. }
  4900. setup_beforeAdd(buffer, beginPos) {
  4901. super.setup_beforeAdd(buffer, beginPos);
  4902. buffer.seek(beginPos, 5);
  4903. this._layout = buffer.readByte();
  4904. this._lineGap = buffer.getInt32();
  4905. this._columnGap = buffer.getInt32();
  4906. if (buffer.version >= 2) {
  4907. this._excludeInvisibles = buffer.readBool();
  4908. this._autoSizeDisabled = buffer.readBool();
  4909. this._mainGridIndex = buffer.getInt16();
  4910. }
  4911. }
  4912. setup_afterAdd(buffer, beginPos) {
  4913. super.setup_afterAdd(buffer, beginPos);
  4914. if (!this.visible)
  4915. this.handleVisibleChanged();
  4916. }
  4917. }
  4918. fgui.GGroup = GGroup;
  4919. })(fgui);
  4920. (function (fgui) {
  4921. class GImage extends fgui.GObject {
  4922. constructor() {
  4923. super();
  4924. this._flip = 0;
  4925. }
  4926. get image() {
  4927. return this._image;
  4928. }
  4929. get color() {
  4930. return this.image.color;
  4931. }
  4932. set color(value) {
  4933. if (this.image.color != value) {
  4934. this.image.color = value;
  4935. this.updateGear(4);
  4936. }
  4937. }
  4938. get flip() {
  4939. return this._flip;
  4940. }
  4941. set flip(value) {
  4942. if (this._flip != value) {
  4943. this._flip = value;
  4944. var sx = 1, sy = 1;
  4945. if (this._flip == fgui.FlipType.Horizontal || this._flip == fgui.FlipType.Both)
  4946. sx = -1;
  4947. if (this._flip == fgui.FlipType.Vertical || this._flip == fgui.FlipType.Both)
  4948. sy = -1;
  4949. this.setScale(sx, sy);
  4950. this.handleXYChanged();
  4951. }
  4952. }
  4953. get fillMethod() {
  4954. return this.image.fillMethod;
  4955. }
  4956. set fillMethod(value) {
  4957. this.image.fillMethod = value;
  4958. }
  4959. get fillOrigin() {
  4960. return this.image.fillOrigin;
  4961. }
  4962. set fillOrigin(value) {
  4963. this.image.fillOrigin = value;
  4964. }
  4965. get fillClockwise() {
  4966. return this.image.fillClockwise;
  4967. }
  4968. set fillClockwise(value) {
  4969. this.image.fillClockwise = value;
  4970. }
  4971. get fillAmount() {
  4972. return this.image.fillAmount;
  4973. }
  4974. set fillAmount(value) {
  4975. this.image.fillAmount = value;
  4976. }
  4977. createDisplayObject() {
  4978. this._displayObject = this._image = new fgui.Image();
  4979. this.image.mouseEnabled = false;
  4980. this._displayObject["$owner"] = this;
  4981. }
  4982. constructFromResource() {
  4983. this._contentItem = this.packageItem.getBranch();
  4984. this.sourceWidth = this._contentItem.width;
  4985. this.sourceHeight = this._contentItem.height;
  4986. this.initWidth = this.sourceWidth;
  4987. this.initHeight = this.sourceHeight;
  4988. this._contentItem = this._contentItem.getHighResolution();
  4989. this._contentItem.load();
  4990. this.image.scale9Grid = this._contentItem.scale9Grid;
  4991. this.image.scaleByTile = this._contentItem.scaleByTile;
  4992. this.image.tileGridIndice = this._contentItem.tileGridIndice;
  4993. this.image.texture = this._contentItem.texture;
  4994. this.setSize(this.sourceWidth, this.sourceHeight);
  4995. }
  4996. handleXYChanged() {
  4997. super.handleXYChanged();
  4998. if (this._flip != fgui.FlipType.None) {
  4999. if (this.scaleX == -1)
  5000. this.image.x += this.width;
  5001. if (this.scaleY == -1)
  5002. this.image.y += this.height;
  5003. }
  5004. }
  5005. getProp(index) {
  5006. if (index == fgui.ObjectPropID.Color)
  5007. return this.color;
  5008. else
  5009. return super.getProp(index);
  5010. }
  5011. setProp(index, value) {
  5012. if (index == fgui.ObjectPropID.Color)
  5013. this.color = value;
  5014. else
  5015. super.setProp(index, value);
  5016. }
  5017. setup_beforeAdd(buffer, beginPos) {
  5018. super.setup_beforeAdd(buffer, beginPos);
  5019. buffer.seek(beginPos, 5);
  5020. if (buffer.readBool())
  5021. this.color = buffer.readColorS();
  5022. this.flip = buffer.readByte();
  5023. this.image.fillMethod = buffer.readByte();
  5024. if (this.image.fillMethod != 0) {
  5025. this.image.fillOrigin = buffer.readByte();
  5026. this.image.fillClockwise = buffer.readBool();
  5027. this.image.fillAmount = buffer.getFloat32();
  5028. }
  5029. }
  5030. }
  5031. fgui.GImage = GImage;
  5032. })(fgui);
  5033. (function (fgui) {
  5034. class GLabel extends fgui.GComponent {
  5035. constructor() {
  5036. super();
  5037. }
  5038. get icon() {
  5039. if (this._iconObject)
  5040. return this._iconObject.icon;
  5041. else
  5042. return null;
  5043. }
  5044. set icon(value) {
  5045. if (this._iconObject)
  5046. this._iconObject.icon = value;
  5047. this.updateGear(7);
  5048. }
  5049. get title() {
  5050. if (this._titleObject)
  5051. return this._titleObject.text;
  5052. else
  5053. return null;
  5054. }
  5055. set title(value) {
  5056. if (this._titleObject)
  5057. this._titleObject.text = value;
  5058. this.updateGear(6);
  5059. }
  5060. get text() {
  5061. return this.title;
  5062. }
  5063. set text(value) {
  5064. this.title = value;
  5065. }
  5066. get titleColor() {
  5067. var tf = this.getTextField();
  5068. if (tf)
  5069. return tf.color;
  5070. else
  5071. return "#000000";
  5072. }
  5073. set titleColor(value) {
  5074. var tf = this.getTextField();
  5075. if (tf)
  5076. tf.color = value;
  5077. this.updateGear(4);
  5078. }
  5079. get titleFontSize() {
  5080. var tf = this.getTextField();
  5081. if (tf)
  5082. return tf.fontSize;
  5083. else
  5084. return 0;
  5085. }
  5086. set titleFontSize(value) {
  5087. var tf = this.getTextField();
  5088. if (tf)
  5089. tf.fontSize = value;
  5090. }
  5091. get color() {
  5092. return this.titleColor;
  5093. }
  5094. set color(value) {
  5095. this.titleColor = value;
  5096. }
  5097. set editable(val) {
  5098. if (this._titleObject)
  5099. this._titleObject.asTextInput.editable = val;
  5100. }
  5101. get editable() {
  5102. if (this._titleObject instanceof fgui.GTextInput)
  5103. return this._titleObject.asTextInput.editable;
  5104. else
  5105. return false;
  5106. }
  5107. getTextField() {
  5108. if (this._titleObject instanceof fgui.GTextField)
  5109. return this._titleObject;
  5110. else if ((this._titleObject instanceof GLabel) || (this._titleObject instanceof fgui.GButton))
  5111. return this._titleObject.getTextField();
  5112. else
  5113. return null;
  5114. }
  5115. getProp(index) {
  5116. switch (index) {
  5117. case fgui.ObjectPropID.Color:
  5118. return this.titleColor;
  5119. case fgui.ObjectPropID.OutlineColor:
  5120. {
  5121. var tf = this.getTextField();
  5122. if (tf)
  5123. return tf.strokeColor;
  5124. else
  5125. return 0;
  5126. }
  5127. case fgui.ObjectPropID.FontSize:
  5128. return this.titleFontSize;
  5129. default:
  5130. return super.getProp(index);
  5131. }
  5132. }
  5133. setProp(index, value) {
  5134. switch (index) {
  5135. case fgui.ObjectPropID.Color:
  5136. this.titleColor = value;
  5137. break;
  5138. case fgui.ObjectPropID.OutlineColor:
  5139. {
  5140. var tf = this.getTextField();
  5141. if (tf)
  5142. tf.strokeColor = value;
  5143. }
  5144. break;
  5145. case fgui.ObjectPropID.FontSize:
  5146. this.titleFontSize = value;
  5147. break;
  5148. default:
  5149. super.setProp(index, value);
  5150. break;
  5151. }
  5152. }
  5153. constructExtension(buffer) {
  5154. this._titleObject = this.getChild("title");
  5155. this._iconObject = this.getChild("icon");
  5156. }
  5157. setup_afterAdd(buffer, beginPos) {
  5158. super.setup_afterAdd(buffer, beginPos);
  5159. if (!buffer.seek(beginPos, 6))
  5160. return;
  5161. if (buffer.readByte() != this.packageItem.objectType)
  5162. return;
  5163. var str;
  5164. str = buffer.readS();
  5165. if (str != null)
  5166. this.title = str;
  5167. str = buffer.readS();
  5168. if (str != null)
  5169. this.icon = str;
  5170. if (buffer.readBool())
  5171. this.titleColor = buffer.readColorS();
  5172. var iv = buffer.getInt32();
  5173. if (iv != 0)
  5174. this.titleFontSize = iv;
  5175. if (buffer.readBool()) {
  5176. var input = this.getTextField();
  5177. if (input instanceof fgui.GTextInput) {
  5178. str = buffer.readS();
  5179. if (str != null)
  5180. input.promptText = str;
  5181. str = buffer.readS();
  5182. if (str != null)
  5183. input.restrict = str;
  5184. iv = buffer.getInt32();
  5185. if (iv != 0)
  5186. input.maxLength = iv;
  5187. iv = buffer.getInt32();
  5188. if (iv != 0) {
  5189. if (iv == 4)
  5190. input.keyboardType = Laya.Input.TYPE_NUMBER;
  5191. else if (iv == 3)
  5192. input.keyboardType = Laya.Input.TYPE_URL;
  5193. }
  5194. if (buffer.readBool())
  5195. input.password = true;
  5196. }
  5197. else
  5198. buffer.skip(13);
  5199. }
  5200. }
  5201. }
  5202. fgui.GLabel = GLabel;
  5203. })(fgui);
  5204. (function (fgui) {
  5205. class GList extends fgui.GComponent {
  5206. constructor() {
  5207. super();
  5208. this._lineCount = 0;
  5209. this._columnCount = 0;
  5210. this._lineGap = 0;
  5211. this._columnGap = 0;
  5212. this._lastSelectedIndex = 0;
  5213. this._numItems = 0;
  5214. this._firstIndex = 0; //the top left index
  5215. this._curLineItemCount = 0; //item count in one line
  5216. this._virtualListChanged = 0; //1-content changed, 2-size changed
  5217. this.itemInfoVer = 0; //用来标志item是否在本次处理中已经被重用了
  5218. this._trackBounds = true;
  5219. this._pool = new fgui.GObjectPool();
  5220. this._layout = fgui.ListLayoutType.SingleColumn;
  5221. this._autoResizeItem = true;
  5222. this._lastSelectedIndex = -1;
  5223. this._selectionMode = fgui.ListSelectionMode.Single;
  5224. this.opaque = true;
  5225. this.scrollItemToViewOnClick = true;
  5226. this._align = "left";
  5227. this._verticalAlign = "top";
  5228. this._container = new Laya.Sprite();
  5229. this._displayObject.addChild(this._container);
  5230. }
  5231. dispose() {
  5232. this._pool.clear();
  5233. super.dispose();
  5234. }
  5235. get layout() {
  5236. return this._layout;
  5237. }
  5238. set layout(value) {
  5239. if (this._layout != value) {
  5240. this._layout = value;
  5241. this.setBoundsChangedFlag();
  5242. if (this._virtual)
  5243. this.setVirtualListChangedFlag(true);
  5244. }
  5245. }
  5246. get lineCount() {
  5247. return this._lineCount;
  5248. }
  5249. set lineCount(value) {
  5250. if (this._lineCount != value) {
  5251. this._lineCount = value;
  5252. if (this._layout == fgui.ListLayoutType.FlowVertical || this._layout == fgui.ListLayoutType.Pagination) {
  5253. this.setBoundsChangedFlag();
  5254. if (this._virtual)
  5255. this.setVirtualListChangedFlag(true);
  5256. }
  5257. }
  5258. }
  5259. get columnCount() {
  5260. return this._columnCount;
  5261. }
  5262. set columnCount(value) {
  5263. if (this._columnCount != value) {
  5264. this._columnCount = value;
  5265. if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5266. this.setBoundsChangedFlag();
  5267. if (this._virtual)
  5268. this.setVirtualListChangedFlag(true);
  5269. }
  5270. }
  5271. }
  5272. get lineGap() {
  5273. return this._lineGap;
  5274. }
  5275. set lineGap(value) {
  5276. if (this._lineGap != value) {
  5277. this._lineGap = value;
  5278. this.setBoundsChangedFlag();
  5279. if (this._virtual)
  5280. this.setVirtualListChangedFlag(true);
  5281. }
  5282. }
  5283. get columnGap() {
  5284. return this._columnGap;
  5285. }
  5286. set columnGap(value) {
  5287. if (this._columnGap != value) {
  5288. this._columnGap = value;
  5289. this.setBoundsChangedFlag();
  5290. if (this._virtual)
  5291. this.setVirtualListChangedFlag(true);
  5292. }
  5293. }
  5294. get align() {
  5295. return this._align;
  5296. }
  5297. set align(value) {
  5298. if (this._align != value) {
  5299. this._align = value;
  5300. this.setBoundsChangedFlag();
  5301. if (this._virtual)
  5302. this.setVirtualListChangedFlag(true);
  5303. }
  5304. }
  5305. get verticalAlign() {
  5306. return this._verticalAlign;
  5307. }
  5308. set verticalAlign(value) {
  5309. if (this._verticalAlign != value) {
  5310. this._verticalAlign = value;
  5311. this.setBoundsChangedFlag();
  5312. if (this._virtual)
  5313. this.setVirtualListChangedFlag(true);
  5314. }
  5315. }
  5316. get virtualItemSize() {
  5317. return this._itemSize;
  5318. }
  5319. set virtualItemSize(value) {
  5320. if (this._virtual) {
  5321. if (this._itemSize == null)
  5322. this._itemSize = new Laya.Point();
  5323. this._itemSize.setTo(value.x, value.y);
  5324. this.setVirtualListChangedFlag(true);
  5325. }
  5326. }
  5327. get defaultItem() {
  5328. return this._defaultItem;
  5329. }
  5330. set defaultItem(val) {
  5331. this._defaultItem = val;
  5332. }
  5333. get autoResizeItem() {
  5334. return this._autoResizeItem;
  5335. }
  5336. set autoResizeItem(value) {
  5337. if (this._autoResizeItem != value) {
  5338. this._autoResizeItem = value;
  5339. this.setBoundsChangedFlag();
  5340. if (this._virtual)
  5341. this.setVirtualListChangedFlag(true);
  5342. }
  5343. }
  5344. get selectionMode() {
  5345. return this._selectionMode;
  5346. }
  5347. set selectionMode(value) {
  5348. this._selectionMode = value;
  5349. }
  5350. get selectionController() {
  5351. return this._selectionController;
  5352. }
  5353. set selectionController(value) {
  5354. this._selectionController = value;
  5355. }
  5356. get itemPool() {
  5357. return this._pool;
  5358. }
  5359. getFromPool(url) {
  5360. if (!url)
  5361. url = this._defaultItem;
  5362. var obj = this._pool.getObject(url);
  5363. if (obj)
  5364. obj.visible = true;
  5365. return obj;
  5366. }
  5367. returnToPool(obj) {
  5368. obj.displayObject.cacheAs = "none";
  5369. this._pool.returnObject(obj);
  5370. }
  5371. addChildAt(child, index) {
  5372. super.addChildAt(child, index);
  5373. if (child instanceof fgui.GButton) {
  5374. child.selected = false;
  5375. child.changeStateOnClick = false;
  5376. }
  5377. child.on(Laya.Event.CLICK, this, this.__clickItem);
  5378. return child;
  5379. }
  5380. addItem(url) {
  5381. if (!url)
  5382. url = this._defaultItem;
  5383. return this.addChild(fgui.UIPackage.createObjectFromURL(url));
  5384. }
  5385. addItemFromPool(url) {
  5386. return this.addChild(this.getFromPool(url));
  5387. }
  5388. removeChildAt(index, dispose) {
  5389. var child = super.removeChildAt(index);
  5390. if (dispose)
  5391. child.dispose();
  5392. else
  5393. child.off(Laya.Event.CLICK, this, this.__clickItem);
  5394. return child;
  5395. }
  5396. removeChildToPoolAt(index) {
  5397. var child = super.removeChildAt(index);
  5398. this.returnToPool(child);
  5399. }
  5400. removeChildToPool(child) {
  5401. super.removeChild(child);
  5402. this.returnToPool(child);
  5403. }
  5404. removeChildrenToPool(beginIndex, endIndex) {
  5405. if (beginIndex == undefined)
  5406. beginIndex = 0;
  5407. if (endIndex == undefined)
  5408. endIndex = -1;
  5409. if (endIndex < 0 || endIndex >= this._children.length)
  5410. endIndex = this._children.length - 1;
  5411. for (var i = beginIndex; i <= endIndex; ++i)
  5412. this.removeChildToPoolAt(beginIndex);
  5413. }
  5414. get selectedIndex() {
  5415. var i;
  5416. if (this._virtual) {
  5417. for (i = 0; i < this._realNumItems; i++) {
  5418. var ii = this._virtualItems[i];
  5419. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected
  5420. || ii.obj == null && ii.selected) {
  5421. if (this._loop)
  5422. return i % this._numItems;
  5423. else
  5424. return i;
  5425. }
  5426. }
  5427. }
  5428. else {
  5429. var cnt = this._children.length;
  5430. for (i = 0; i < cnt; i++) {
  5431. var obj = this._children[i];
  5432. if ((obj instanceof fgui.GButton) && obj.selected)
  5433. return i;
  5434. }
  5435. }
  5436. return -1;
  5437. }
  5438. set selectedIndex(value) {
  5439. if (value >= 0 && value < this.numItems) {
  5440. if (this._selectionMode != fgui.ListSelectionMode.Single)
  5441. this.clearSelection();
  5442. this.addSelection(value);
  5443. }
  5444. else
  5445. this.clearSelection();
  5446. }
  5447. getSelection(result) {
  5448. if (!result)
  5449. result = new Array();
  5450. var i;
  5451. if (this._virtual) {
  5452. for (i = 0; i < this._realNumItems; i++) {
  5453. var ii = this._virtualItems[i];
  5454. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected
  5455. || ii.obj == null && ii.selected) {
  5456. var j = i;
  5457. if (this._loop) {
  5458. j = i % this._numItems;
  5459. if (result.indexOf(j) != -1)
  5460. continue;
  5461. }
  5462. result.push(j);
  5463. }
  5464. }
  5465. }
  5466. else {
  5467. var cnt = this._children.length;
  5468. for (i = 0; i < cnt; i++) {
  5469. var obj = this._children[i];
  5470. if ((obj instanceof fgui.GButton) && obj.selected)
  5471. result.push(i);
  5472. }
  5473. }
  5474. return result;
  5475. }
  5476. addSelection(index, scrollItToView) {
  5477. if (this._selectionMode == fgui.ListSelectionMode.None)
  5478. return;
  5479. this.checkVirtualList();
  5480. if (this._selectionMode == fgui.ListSelectionMode.Single)
  5481. this.clearSelection();
  5482. if (scrollItToView)
  5483. this.scrollToView(index);
  5484. this._lastSelectedIndex = index;
  5485. var obj;
  5486. if (this._virtual) {
  5487. var ii = this._virtualItems[index];
  5488. if (ii.obj)
  5489. obj = ii.obj;
  5490. ii.selected = true;
  5491. }
  5492. else
  5493. obj = this.getChildAt(index);
  5494. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5495. obj.selected = true;
  5496. this.updateSelectionController(index);
  5497. }
  5498. }
  5499. removeSelection(index) {
  5500. if (this._selectionMode == fgui.ListSelectionMode.None)
  5501. return;
  5502. var obj;
  5503. if (this._virtual) {
  5504. var ii = this._virtualItems[index];
  5505. if (ii.obj)
  5506. obj = ii.obj;
  5507. ii.selected = false;
  5508. }
  5509. else
  5510. obj = this.getChildAt(index);
  5511. if (obj instanceof fgui.GButton)
  5512. obj.selected = false;
  5513. }
  5514. clearSelection() {
  5515. var i;
  5516. if (this._virtual) {
  5517. for (i = 0; i < this._realNumItems; i++) {
  5518. var ii = this._virtualItems[i];
  5519. if (ii.obj instanceof fgui.GButton)
  5520. ii.obj.selected = false;
  5521. ii.selected = false;
  5522. }
  5523. }
  5524. else {
  5525. var cnt = this._children.length;
  5526. for (i = 0; i < cnt; i++) {
  5527. var obj = this._children[i];
  5528. if (obj instanceof fgui.GButton)
  5529. obj.selected = false;
  5530. }
  5531. }
  5532. }
  5533. clearSelectionExcept(g) {
  5534. var i;
  5535. if (this._virtual) {
  5536. for (i = 0; i < this._realNumItems; i++) {
  5537. var ii = this._virtualItems[i];
  5538. if (ii.obj != g) {
  5539. if (ii.obj instanceof fgui.GButton)
  5540. ii.obj.selected = false;
  5541. ii.selected = false;
  5542. }
  5543. }
  5544. }
  5545. else {
  5546. var cnt = this._children.length;
  5547. for (i = 0; i < cnt; i++) {
  5548. var obj = this._children[i];
  5549. if ((obj instanceof fgui.GButton) && obj != g)
  5550. obj.selected = false;
  5551. }
  5552. }
  5553. }
  5554. selectAll() {
  5555. this.checkVirtualList();
  5556. var last = -1;
  5557. var i;
  5558. if (this._virtual) {
  5559. for (i = 0; i < this._realNumItems; i++) {
  5560. var ii = this._virtualItems[i];
  5561. if ((ii.obj instanceof fgui.GButton) && !ii.obj.selected) {
  5562. ii.obj.selected = true;
  5563. last = i;
  5564. }
  5565. ii.selected = true;
  5566. }
  5567. }
  5568. else {
  5569. var cnt = this._children.length;
  5570. for (i = 0; i < cnt; i++) {
  5571. var obj = this._children[i];
  5572. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5573. obj.selected = true;
  5574. last = i;
  5575. }
  5576. }
  5577. }
  5578. if (last != -1)
  5579. this.updateSelectionController(last);
  5580. }
  5581. selectNone() {
  5582. this.clearSelection();
  5583. }
  5584. selectReverse() {
  5585. this.checkVirtualList();
  5586. var last = -1;
  5587. var i;
  5588. if (this._virtual) {
  5589. for (i = 0; i < this._realNumItems; i++) {
  5590. var ii = this._virtualItems[i];
  5591. if (ii.obj instanceof fgui.GButton) {
  5592. ii.obj.selected = !ii.obj.selected;
  5593. if (ii.obj.selected)
  5594. last = i;
  5595. }
  5596. ii.selected = !ii.selected;
  5597. }
  5598. }
  5599. else {
  5600. var cnt = this._children.length;
  5601. for (i = 0; i < cnt; i++) {
  5602. var obj = this._children[i];
  5603. if (obj instanceof fgui.GButton) {
  5604. obj.selected = !obj.selected;
  5605. if (obj.selected)
  5606. last = i;
  5607. }
  5608. }
  5609. }
  5610. if (last != -1)
  5611. this.updateSelectionController(last);
  5612. }
  5613. handleArrowKey(dir) {
  5614. var index = this.selectedIndex;
  5615. if (index == -1)
  5616. return;
  5617. switch (dir) {
  5618. case 1: //up
  5619. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5620. index--;
  5621. if (index >= 0) {
  5622. this.clearSelection();
  5623. this.addSelection(index, true);
  5624. }
  5625. }
  5626. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5627. var current = this._children[index];
  5628. var k = 0;
  5629. for (var i = index - 1; i >= 0; i--) {
  5630. var obj = this._children[i];
  5631. if (obj.y != current.y) {
  5632. current = obj;
  5633. break;
  5634. }
  5635. k++;
  5636. }
  5637. for (; i >= 0; i--) {
  5638. obj = this._children[i];
  5639. if (obj.y != current.y) {
  5640. this.clearSelection();
  5641. this.addSelection(i + k + 1, true);
  5642. break;
  5643. }
  5644. }
  5645. }
  5646. break;
  5647. case 3: //right
  5648. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5649. index++;
  5650. if (index < this.numItems) {
  5651. this.clearSelection();
  5652. this.addSelection(index, true);
  5653. }
  5654. }
  5655. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5656. current = this._children[index];
  5657. k = 0;
  5658. var cnt = this._children.length;
  5659. for (i = index + 1; i < cnt; i++) {
  5660. obj = this._children[i];
  5661. if (obj.x != current.x) {
  5662. current = obj;
  5663. break;
  5664. }
  5665. k++;
  5666. }
  5667. for (; i < cnt; i++) {
  5668. obj = this._children[i];
  5669. if (obj.x != current.x) {
  5670. this.clearSelection();
  5671. this.addSelection(i - k - 1, true);
  5672. break;
  5673. }
  5674. }
  5675. }
  5676. break;
  5677. case 5: //down
  5678. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5679. index++;
  5680. if (index < this.numItems) {
  5681. this.clearSelection();
  5682. this.addSelection(index, true);
  5683. }
  5684. }
  5685. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5686. current = this._children[index];
  5687. k = 0;
  5688. cnt = this._children.length;
  5689. for (i = index + 1; i < cnt; i++) {
  5690. obj = this._children[i];
  5691. if (obj.y != current.y) {
  5692. current = obj;
  5693. break;
  5694. }
  5695. k++;
  5696. }
  5697. for (; i < cnt; i++) {
  5698. obj = this._children[i];
  5699. if (obj.y != current.y) {
  5700. this.clearSelection();
  5701. this.addSelection(i - k - 1, true);
  5702. break;
  5703. }
  5704. }
  5705. }
  5706. break;
  5707. case 7: //left
  5708. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5709. index--;
  5710. if (index >= 0) {
  5711. this.clearSelection();
  5712. this.addSelection(index, true);
  5713. }
  5714. }
  5715. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5716. current = this._children[index];
  5717. k = 0;
  5718. for (i = index - 1; i >= 0; i--) {
  5719. obj = this._children[i];
  5720. if (obj.x != current.x) {
  5721. current = obj;
  5722. break;
  5723. }
  5724. k++;
  5725. }
  5726. for (; i >= 0; i--) {
  5727. obj = this._children[i];
  5728. if (obj.x != current.x) {
  5729. this.clearSelection();
  5730. this.addSelection(i + k + 1, true);
  5731. break;
  5732. }
  5733. }
  5734. }
  5735. break;
  5736. }
  5737. }
  5738. __clickItem(evt) {
  5739. if (this._scrollPane && this._scrollPane.isDragged)
  5740. return;
  5741. var item = fgui.GObject.cast(evt.currentTarget);
  5742. this.setSelectionOnEvent(item, evt);
  5743. if (this._scrollPane && this.scrollItemToViewOnClick)
  5744. this._scrollPane.scrollToView(item, true);
  5745. this.dispatchItemEvent(item, fgui.Events.createEvent(fgui.Events.CLICK_ITEM, this.displayObject, evt));
  5746. }
  5747. dispatchItemEvent(item, evt) {
  5748. this.displayObject.event(fgui.Events.CLICK_ITEM, [item, evt]);
  5749. }
  5750. setSelectionOnEvent(item, evt) {
  5751. if (!(item instanceof fgui.GButton) || this._selectionMode == fgui.ListSelectionMode.None)
  5752. return;
  5753. var dontChangeLastIndex = false;
  5754. var index = this.childIndexToItemIndex(this.getChildIndex(item));
  5755. if (this._selectionMode == fgui.ListSelectionMode.Single) {
  5756. if (!item.selected) {
  5757. this.clearSelectionExcept(item);
  5758. item.selected = true;
  5759. }
  5760. }
  5761. else {
  5762. if (evt.shiftKey) {
  5763. if (!item.selected) {
  5764. if (this._lastSelectedIndex != -1) {
  5765. var min = Math.min(this._lastSelectedIndex, index);
  5766. var max = Math.max(this._lastSelectedIndex, index);
  5767. max = Math.min(max, this.numItems - 1);
  5768. var i;
  5769. if (this._virtual) {
  5770. for (i = min; i <= max; i++) {
  5771. var ii = this._virtualItems[i];
  5772. if (ii.obj instanceof fgui.GButton)
  5773. ii.obj.selected = true;
  5774. ii.selected = true;
  5775. }
  5776. }
  5777. else {
  5778. for (i = min; i <= max; i++) {
  5779. var obj = this.getChildAt(i);
  5780. if (obj instanceof fgui.GButton)
  5781. obj.selected = true;
  5782. }
  5783. }
  5784. dontChangeLastIndex = true;
  5785. }
  5786. else {
  5787. item.selected = true;
  5788. }
  5789. }
  5790. }
  5791. else if (evt.ctrlKey || this._selectionMode == fgui.ListSelectionMode.Multiple_SingleClick) {
  5792. item.selected = !item.selected;
  5793. }
  5794. else {
  5795. if (!item.selected) {
  5796. this.clearSelectionExcept(item);
  5797. item.selected = true;
  5798. }
  5799. else
  5800. this.clearSelectionExcept(item);
  5801. }
  5802. }
  5803. if (!dontChangeLastIndex)
  5804. this._lastSelectedIndex = index;
  5805. if (item.selected)
  5806. this.updateSelectionController(index);
  5807. }
  5808. resizeToFit(itemCount, minSize) {
  5809. if (itemCount == null)
  5810. itemCount = 100000;
  5811. minSize = minSize || 0;
  5812. this.ensureBoundsCorrect();
  5813. var curCount = this.numItems;
  5814. if (itemCount > curCount)
  5815. itemCount = curCount;
  5816. if (this._virtual) {
  5817. var lineCount = Math.ceil(itemCount / this._curLineItemCount);
  5818. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5819. this.viewHeight = lineCount * this._itemSize.y + Math.max(0, lineCount - 1) * this._lineGap;
  5820. else
  5821. this.viewWidth = lineCount * this._itemSize.x + Math.max(0, lineCount - 1) * this._columnGap;
  5822. }
  5823. else if (itemCount == 0) {
  5824. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5825. this.viewHeight = minSize;
  5826. else
  5827. this.viewWidth = minSize;
  5828. }
  5829. else {
  5830. var i = itemCount - 1;
  5831. var obj = null;
  5832. while (i >= 0) {
  5833. obj = this.getChildAt(i);
  5834. if (!this.foldInvisibleItems || obj.visible)
  5835. break;
  5836. i--;
  5837. }
  5838. if (i < 0) {
  5839. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5840. this.viewHeight = minSize;
  5841. else
  5842. this.viewWidth = minSize;
  5843. }
  5844. else {
  5845. var size = 0;
  5846. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5847. size = obj.y + obj.height;
  5848. if (size < minSize)
  5849. size = minSize;
  5850. this.viewHeight = size;
  5851. }
  5852. else {
  5853. size = obj.x + obj.width;
  5854. if (size < minSize)
  5855. size = minSize;
  5856. this.viewWidth = size;
  5857. }
  5858. }
  5859. }
  5860. }
  5861. getMaxItemWidth() {
  5862. var cnt = this._children.length;
  5863. var max = 0;
  5864. for (var i = 0; i < cnt; i++) {
  5865. var child = this.getChildAt(i);
  5866. if (child.width > max)
  5867. max = child.width;
  5868. }
  5869. return max;
  5870. }
  5871. handleSizeChanged() {
  5872. super.handleSizeChanged();
  5873. this.setBoundsChangedFlag();
  5874. if (this._virtual)
  5875. this.setVirtualListChangedFlag(true);
  5876. }
  5877. handleControllerChanged(c) {
  5878. super.handleControllerChanged(c);
  5879. if (this._selectionController == c)
  5880. this.selectedIndex = c.selectedIndex;
  5881. }
  5882. updateSelectionController(index) {
  5883. if (this._selectionController && !this._selectionController.changing
  5884. && index < this._selectionController.pageCount) {
  5885. var c = this._selectionController;
  5886. this._selectionController = null;
  5887. c.selectedIndex = index;
  5888. this._selectionController = c;
  5889. }
  5890. }
  5891. shouldSnapToNext(dir, delta, size) {
  5892. return dir < 0 && delta > fgui.UIConfig.defaultScrollSnappingThreshold * size
  5893. || dir > 0 && delta > (1 - fgui.UIConfig.defaultScrollSnappingThreshold) * size
  5894. || dir == 0 && delta > size / 2;
  5895. }
  5896. getSnappingPositionWithDir(xValue, yValue, xDir, yDir, result) {
  5897. if (this._virtual) {
  5898. if (!result)
  5899. result = new Laya.Point();
  5900. var saved;
  5901. var index;
  5902. var size;
  5903. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5904. saved = yValue;
  5905. s_n = yValue;
  5906. index = this.getIndexOnPos1(false);
  5907. yValue = s_n;
  5908. if (index < this._virtualItems.length && index < this._realNumItems) {
  5909. size = this._virtualItems[index].height;
  5910. if (this.shouldSnapToNext(yDir, saved - yValue, size))
  5911. yValue += size + this._lineGap;
  5912. }
  5913. }
  5914. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5915. saved = xValue;
  5916. s_n = xValue;
  5917. index = this.getIndexOnPos2(false);
  5918. xValue = s_n;
  5919. if (index < this._virtualItems.length && index < this._realNumItems) {
  5920. size = this._virtualItems[index].width;
  5921. if (this.shouldSnapToNext(xDir, saved - xValue, size))
  5922. xValue += size + this._columnGap;
  5923. }
  5924. }
  5925. else {
  5926. saved = xValue;
  5927. s_n = xValue;
  5928. index = this.getIndexOnPos3(false);
  5929. xValue = s_n;
  5930. if (index < this._virtualItems.length && index < this._realNumItems) {
  5931. size = this._virtualItems[index].width;
  5932. if (this.shouldSnapToNext(xDir, saved - xValue, size))
  5933. xValue += size + this._columnGap;
  5934. }
  5935. }
  5936. result.x = xValue;
  5937. result.y = yValue;
  5938. return result;
  5939. }
  5940. else
  5941. return super.getSnappingPositionWithDir(xValue, yValue, xDir, yDir, result);
  5942. }
  5943. scrollToView(index, ani, setFirst) {
  5944. if (this._virtual) {
  5945. if (this._numItems == 0)
  5946. return;
  5947. this.checkVirtualList();
  5948. if (index >= this._virtualItems.length)
  5949. throw new Error("Invalid child index: " + index + ">" + this._virtualItems.length);
  5950. if (this._loop)
  5951. index = Math.floor(this._firstIndex / this._numItems) * this._numItems + index;
  5952. var rect;
  5953. var ii = this._virtualItems[index];
  5954. var pos = 0;
  5955. var i;
  5956. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5957. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5958. pos += this._virtualItems[i].height + this._lineGap;
  5959. rect = new Laya.Rectangle(0, pos, this._itemSize.x, ii.height);
  5960. }
  5961. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5962. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5963. pos += this._virtualItems[i].width + this._columnGap;
  5964. rect = new Laya.Rectangle(pos, 0, ii.width, this._itemSize.y);
  5965. }
  5966. else {
  5967. var page = index / (this._curLineItemCount * this._curLineItemCount2);
  5968. rect = new Laya.Rectangle(page * this.viewWidth + (index % this._curLineItemCount) * (ii.width + this._columnGap), (index / this._curLineItemCount) % this._curLineItemCount2 * (ii.height + this._lineGap), ii.width, ii.height);
  5969. }
  5970. if (this._scrollPane)
  5971. this._scrollPane.scrollToView(rect, ani, setFirst);
  5972. }
  5973. else {
  5974. var obj = this.getChildAt(index);
  5975. if (this._scrollPane)
  5976. this._scrollPane.scrollToView(obj, ani, setFirst);
  5977. else if (this._parent && this._parent.scrollPane)
  5978. this._parent.scrollPane.scrollToView(obj, ani, setFirst);
  5979. }
  5980. }
  5981. getFirstChildInView() {
  5982. return this.childIndexToItemIndex(super.getFirstChildInView());
  5983. }
  5984. childIndexToItemIndex(index) {
  5985. if (!this._virtual)
  5986. return index;
  5987. if (this._layout == fgui.ListLayoutType.Pagination) {
  5988. for (var i = this._firstIndex; i < this._realNumItems; i++) {
  5989. if (this._virtualItems[i].obj) {
  5990. index--;
  5991. if (index < 0)
  5992. return i;
  5993. }
  5994. }
  5995. return index;
  5996. }
  5997. else {
  5998. index += this._firstIndex;
  5999. if (this._loop && this._numItems > 0)
  6000. index = index % this._numItems;
  6001. return index;
  6002. }
  6003. }
  6004. itemIndexToChildIndex(index) {
  6005. if (!this._virtual)
  6006. return index;
  6007. if (this._layout == fgui.ListLayoutType.Pagination) {
  6008. return this.getChildIndex(this._virtualItems[index].obj);
  6009. }
  6010. else {
  6011. if (this._loop && this._numItems > 0) {
  6012. var j = this._firstIndex % this._numItems;
  6013. if (index >= j)
  6014. index = index - j;
  6015. else
  6016. index = this._numItems - j + index;
  6017. }
  6018. else
  6019. index -= this._firstIndex;
  6020. return index;
  6021. }
  6022. }
  6023. setVirtual() {
  6024. this._setVirtual(false);
  6025. }
  6026. /**
  6027. * Set the list to be virtual list, and has loop behavior.
  6028. */
  6029. setVirtualAndLoop() {
  6030. this._setVirtual(true);
  6031. }
  6032. _setVirtual(loop) {
  6033. if (!this._virtual) {
  6034. if (this._scrollPane == null)
  6035. throw new Error("Virtual list must be scrollable!");
  6036. if (loop) {
  6037. if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.FlowVertical)
  6038. throw new Error("Loop list instanceof not supported for FlowHorizontal or FlowVertical this.layout!");
  6039. this._scrollPane.bouncebackEffect = false;
  6040. }
  6041. this._virtual = true;
  6042. this._loop = loop;
  6043. this._virtualItems = new Array();
  6044. this.removeChildrenToPool();
  6045. if (this._itemSize == null) {
  6046. this._itemSize = new Laya.Point();
  6047. var obj = this.getFromPool(null);
  6048. if (obj == null) {
  6049. throw new Error("Virtual List must have a default list item resource.");
  6050. }
  6051. else {
  6052. this._itemSize.x = obj.width;
  6053. this._itemSize.y = obj.height;
  6054. }
  6055. this.returnToPool(obj);
  6056. }
  6057. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6058. this._scrollPane.scrollStep = this._itemSize.y;
  6059. if (this._loop)
  6060. this._scrollPane._loop = 2;
  6061. }
  6062. else {
  6063. this._scrollPane.scrollStep = this._itemSize.x;
  6064. if (this._loop)
  6065. this._scrollPane._loop = 1;
  6066. }
  6067. this.on(fgui.Events.SCROLL, this, this.__scrolled);
  6068. this.setVirtualListChangedFlag(true);
  6069. }
  6070. }
  6071. /**
  6072. * Set the list item count.
  6073. * If the list instanceof not virtual, specified number of items will be created.
  6074. * If the list instanceof virtual, only items in view will be created.
  6075. */
  6076. get numItems() {
  6077. if (this._virtual)
  6078. return this._numItems;
  6079. else
  6080. return this._children.length;
  6081. }
  6082. set numItems(value) {
  6083. var i;
  6084. if (this._virtual) {
  6085. if (this.itemRenderer == null)
  6086. throw new Error("set itemRenderer first!");
  6087. this._numItems = value;
  6088. if (this._loop)
  6089. this._realNumItems = this._numItems * 6; //设置6倍数量,用于循环滚动
  6090. else
  6091. this._realNumItems = this._numItems;
  6092. //_virtualItems的设计是只增不减的
  6093. var oldCount = this._virtualItems.length;
  6094. if (this._realNumItems > oldCount) {
  6095. for (i = oldCount; i < this._realNumItems; i++) {
  6096. var ii = {
  6097. width: this._itemSize.x,
  6098. height: this._itemSize.y,
  6099. updateFlag: 0
  6100. };
  6101. this._virtualItems.push(ii);
  6102. }
  6103. }
  6104. else {
  6105. for (i = this._realNumItems; i < oldCount; i++)
  6106. this._virtualItems[i].selected = false;
  6107. }
  6108. if (this._virtualListChanged != 0)
  6109. Laya.timer.clear(this, this._refreshVirtualList);
  6110. //立即刷新
  6111. this._refreshVirtualList();
  6112. }
  6113. else {
  6114. var cnt = this._children.length;
  6115. if (value > cnt) {
  6116. for (i = cnt; i < value; i++) {
  6117. if (this.itemProvider == null)
  6118. this.addItemFromPool();
  6119. else
  6120. this.addItemFromPool(this.itemProvider.runWith(i));
  6121. }
  6122. }
  6123. else {
  6124. this.removeChildrenToPool(value, cnt);
  6125. }
  6126. if (this.itemRenderer != null) {
  6127. for (i = 0; i < value; i++)
  6128. this.itemRenderer.runWith([i, this.getChildAt(i)]);
  6129. }
  6130. }
  6131. }
  6132. refreshVirtualList() {
  6133. this.setVirtualListChangedFlag(false);
  6134. }
  6135. checkVirtualList() {
  6136. if (this._virtualListChanged != 0) {
  6137. this._refreshVirtualList();
  6138. Laya.timer.clear(this, this._refreshVirtualList);
  6139. }
  6140. }
  6141. setVirtualListChangedFlag(layoutChanged) {
  6142. if (layoutChanged)
  6143. this._virtualListChanged = 2;
  6144. else if (this._virtualListChanged == 0)
  6145. this._virtualListChanged = 1;
  6146. Laya.timer.callLater(this, this._refreshVirtualList);
  6147. }
  6148. _refreshVirtualList() {
  6149. if (!this._displayObject)
  6150. return;
  6151. var layoutChanged = this._virtualListChanged == 2;
  6152. this._virtualListChanged = 0;
  6153. this._eventLocked = true;
  6154. if (layoutChanged) {
  6155. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.SingleRow)
  6156. this._curLineItemCount = 1;
  6157. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6158. if (this._columnCount > 0)
  6159. this._curLineItemCount = this._columnCount;
  6160. else {
  6161. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.x + this._columnGap));
  6162. if (this._curLineItemCount <= 0)
  6163. this._curLineItemCount = 1;
  6164. }
  6165. }
  6166. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  6167. if (this._lineCount > 0)
  6168. this._curLineItemCount = this._lineCount;
  6169. else {
  6170. this._curLineItemCount = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.y + this._lineGap));
  6171. if (this._curLineItemCount <= 0)
  6172. this._curLineItemCount = 1;
  6173. }
  6174. }
  6175. else //pagination
  6176. {
  6177. if (this._columnCount > 0)
  6178. this._curLineItemCount = this._columnCount;
  6179. else {
  6180. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.x + this._columnGap));
  6181. if (this._curLineItemCount <= 0)
  6182. this._curLineItemCount = 1;
  6183. }
  6184. if (this._lineCount > 0)
  6185. this._curLineItemCount2 = this._lineCount;
  6186. else {
  6187. this._curLineItemCount2 = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.y + this._lineGap));
  6188. if (this._curLineItemCount2 <= 0)
  6189. this._curLineItemCount2 = 1;
  6190. }
  6191. }
  6192. }
  6193. var ch = 0, cw = 0;
  6194. if (this._realNumItems > 0) {
  6195. var i;
  6196. var len = Math.ceil(this._realNumItems / this._curLineItemCount) * this._curLineItemCount;
  6197. var len2 = Math.min(this._curLineItemCount, this._realNumItems);
  6198. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6199. for (i = 0; i < len; i += this._curLineItemCount)
  6200. ch += this._virtualItems[i].height + this._lineGap;
  6201. if (ch > 0)
  6202. ch -= this._lineGap;
  6203. if (this._autoResizeItem)
  6204. cw = this._scrollPane.viewWidth;
  6205. else {
  6206. for (i = 0; i < len2; i++)
  6207. cw += this._virtualItems[i].width + this._columnGap;
  6208. if (cw > 0)
  6209. cw -= this._columnGap;
  6210. }
  6211. }
  6212. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  6213. for (i = 0; i < len; i += this._curLineItemCount)
  6214. cw += this._virtualItems[i].width + this._columnGap;
  6215. if (cw > 0)
  6216. cw -= this._columnGap;
  6217. if (this._autoResizeItem)
  6218. ch = this._scrollPane.viewHeight;
  6219. else {
  6220. for (i = 0; i < len2; i++)
  6221. ch += this._virtualItems[i].height + this._lineGap;
  6222. if (ch > 0)
  6223. ch -= this._lineGap;
  6224. }
  6225. }
  6226. else {
  6227. var pageCount = Math.ceil(len / (this._curLineItemCount * this._curLineItemCount2));
  6228. cw = pageCount * this.viewWidth;
  6229. ch = this.viewHeight;
  6230. }
  6231. }
  6232. this.handleAlign(cw, ch);
  6233. this._scrollPane.setContentSize(cw, ch);
  6234. this._eventLocked = false;
  6235. this.handleScroll(true);
  6236. }
  6237. __scrolled(evt) {
  6238. this.handleScroll(false);
  6239. }
  6240. getIndexOnPos1(forceUpdate) {
  6241. if (this._realNumItems < this._curLineItemCount) {
  6242. s_n = 0;
  6243. return 0;
  6244. }
  6245. var i;
  6246. var pos2;
  6247. var pos3;
  6248. if (this.numChildren > 0 && !forceUpdate) {
  6249. pos2 = this.getChildAt(0).y;
  6250. if (pos2 > s_n) {
  6251. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6252. pos2 -= (this._virtualItems[i].height + this._lineGap);
  6253. if (pos2 <= s_n) {
  6254. s_n = pos2;
  6255. return i;
  6256. }
  6257. }
  6258. s_n = 0;
  6259. return 0;
  6260. }
  6261. else {
  6262. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6263. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6264. if (pos3 > s_n) {
  6265. s_n = pos2;
  6266. return i;
  6267. }
  6268. pos2 = pos3;
  6269. }
  6270. s_n = pos2;
  6271. return this._realNumItems - this._curLineItemCount;
  6272. }
  6273. }
  6274. else {
  6275. pos2 = 0;
  6276. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6277. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6278. if (pos3 > s_n) {
  6279. s_n = pos2;
  6280. return i;
  6281. }
  6282. pos2 = pos3;
  6283. }
  6284. s_n = pos2;
  6285. return this._realNumItems - this._curLineItemCount;
  6286. }
  6287. }
  6288. getIndexOnPos2(forceUpdate) {
  6289. if (this._realNumItems < this._curLineItemCount) {
  6290. s_n = 0;
  6291. return 0;
  6292. }
  6293. var i;
  6294. var pos2;
  6295. var pos3;
  6296. if (this.numChildren > 0 && !forceUpdate) {
  6297. pos2 = this.getChildAt(0).x;
  6298. if (pos2 > s_n) {
  6299. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6300. pos2 -= (this._virtualItems[i].width + this._columnGap);
  6301. if (pos2 <= s_n) {
  6302. s_n = pos2;
  6303. return i;
  6304. }
  6305. }
  6306. s_n = 0;
  6307. return 0;
  6308. }
  6309. else {
  6310. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6311. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6312. if (pos3 > s_n) {
  6313. s_n = pos2;
  6314. return i;
  6315. }
  6316. pos2 = pos3;
  6317. }
  6318. s_n = pos2;
  6319. return this._realNumItems - this._curLineItemCount;
  6320. }
  6321. }
  6322. else {
  6323. pos2 = 0;
  6324. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6325. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6326. if (pos3 > s_n) {
  6327. s_n = pos2;
  6328. return i;
  6329. }
  6330. pos2 = pos3;
  6331. }
  6332. s_n = pos2;
  6333. return this._realNumItems - this._curLineItemCount;
  6334. }
  6335. }
  6336. getIndexOnPos3(forceUpdate) {
  6337. if (this._realNumItems < this._curLineItemCount) {
  6338. s_n = 0;
  6339. return 0;
  6340. }
  6341. var viewWidth = this.viewWidth;
  6342. var page = Math.floor(s_n / viewWidth);
  6343. var startIndex = page * (this._curLineItemCount * this._curLineItemCount2);
  6344. var pos2 = page * viewWidth;
  6345. var i;
  6346. var pos3;
  6347. for (i = 0; i < this._curLineItemCount; i++) {
  6348. pos3 = pos2 + this._virtualItems[startIndex + i].width + this._columnGap;
  6349. if (pos3 > s_n) {
  6350. s_n = pos2;
  6351. return startIndex + i;
  6352. }
  6353. pos2 = pos3;
  6354. }
  6355. s_n = pos2;
  6356. return startIndex + this._curLineItemCount - 1;
  6357. }
  6358. handleScroll(forceUpdate) {
  6359. if (this._eventLocked)
  6360. return;
  6361. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6362. var enterCounter = 0;
  6363. while (this.handleScroll1(forceUpdate)) {
  6364. enterCounter++;
  6365. forceUpdate = false;
  6366. if (enterCounter > 20) {
  6367. console.log("FairyGUI: list will never be <the> filled item renderer function always returns a different size.");
  6368. break;
  6369. }
  6370. }
  6371. this.handleArchOrder1();
  6372. }
  6373. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  6374. enterCounter = 0;
  6375. while (this.handleScroll2(forceUpdate)) {
  6376. enterCounter++;
  6377. forceUpdate = false;
  6378. if (enterCounter > 20) {
  6379. console.log("FairyGUI: list will never be <the> filled item renderer function always returns a different size.");
  6380. break;
  6381. }
  6382. }
  6383. this.handleArchOrder2();
  6384. }
  6385. else {
  6386. this.handleScroll3(forceUpdate);
  6387. }
  6388. this._boundsChanged = false;
  6389. }
  6390. handleScroll1(forceUpdate) {
  6391. var pos = this._scrollPane.scrollingPosY;
  6392. var max = pos + this._scrollPane.viewHeight;
  6393. var end = max == this._scrollPane.contentHeight; //这个标志表示当前需要滚动到最末,无论内容变化大小
  6394. //寻找当前位置的第一条项目
  6395. s_n = pos;
  6396. var newFirstIndex = this.getIndexOnPos1(forceUpdate);
  6397. pos = s_n;
  6398. if (newFirstIndex == this._firstIndex && !forceUpdate)
  6399. return false;
  6400. var oldFirstIndex = this._firstIndex;
  6401. this._firstIndex = newFirstIndex;
  6402. var curIndex = newFirstIndex;
  6403. var forward = oldFirstIndex > newFirstIndex;
  6404. var childCount = this.numChildren;
  6405. var lastIndex = oldFirstIndex + childCount - 1;
  6406. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6407. var curX = 0, curY = pos;
  6408. var needRender;
  6409. var deltaSize = 0;
  6410. var firstItemDeltaSize = 0;
  6411. var url = this.defaultItem;
  6412. var ii, ii2;
  6413. var i, j;
  6414. var partSize = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6415. this.itemInfoVer++;
  6416. while (curIndex < this._realNumItems && (end || curY < max)) {
  6417. ii = this._virtualItems[curIndex];
  6418. if (ii.obj == null || forceUpdate) {
  6419. if (this.itemProvider != null) {
  6420. url = this.itemProvider.runWith(curIndex % this._numItems);
  6421. if (url == null)
  6422. url = this._defaultItem;
  6423. url = fgui.UIPackage.normalizeURL(url);
  6424. }
  6425. if (ii.obj && ii.obj.resourceURL != url) {
  6426. if (ii.obj instanceof fgui.GButton)
  6427. ii.selected = ii.obj.selected;
  6428. this.removeChildToPool(ii.obj);
  6429. ii.obj = null;
  6430. }
  6431. }
  6432. if (ii.obj == null) {
  6433. //搜索最适合的重用item,保证每次刷新需要新建或者重新render的item最少
  6434. if (forward) {
  6435. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6436. ii2 = this._virtualItems[j];
  6437. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6438. if (ii2.obj instanceof fgui.GButton)
  6439. ii2.selected = ii2.obj.selected;
  6440. ii.obj = ii2.obj;
  6441. ii2.obj = null;
  6442. if (j == reuseIndex)
  6443. reuseIndex--;
  6444. break;
  6445. }
  6446. }
  6447. }
  6448. else {
  6449. for (j = reuseIndex; j <= lastIndex; j++) {
  6450. ii2 = this._virtualItems[j];
  6451. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6452. if (ii2.obj instanceof fgui.GButton)
  6453. ii2.selected = ii2.obj.selected;
  6454. ii.obj = ii2.obj;
  6455. ii2.obj = null;
  6456. if (j == reuseIndex)
  6457. reuseIndex++;
  6458. break;
  6459. }
  6460. }
  6461. }
  6462. if (ii.obj) {
  6463. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6464. }
  6465. else {
  6466. ii.obj = this._pool.getObject(url);
  6467. if (forward)
  6468. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6469. else
  6470. this.addChild(ii.obj);
  6471. }
  6472. if (ii.obj instanceof fgui.GButton)
  6473. ii.obj.selected = ii.selected;
  6474. needRender = true;
  6475. }
  6476. else
  6477. needRender = forceUpdate;
  6478. if (needRender) {
  6479. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleColumn || this._columnCount > 0))
  6480. ii.obj.setSize(partSize, ii.obj.height, true);
  6481. this.itemRenderer.runWith([curIndex % this._numItems, ii.obj]);
  6482. if (curIndex % this._curLineItemCount == 0) {
  6483. deltaSize += Math.ceil(ii.obj.height) - ii.height;
  6484. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6485. //当内容向下滚动时,如果新出现的项目大小发生变化,需要做一个位置补偿,才不会导致滚动跳动
  6486. firstItemDeltaSize = Math.ceil(ii.obj.height) - ii.height;
  6487. }
  6488. }
  6489. ii.width = Math.ceil(ii.obj.width);
  6490. ii.height = Math.ceil(ii.obj.height);
  6491. }
  6492. ii.updateFlag = this.itemInfoVer;
  6493. ii.obj.setXY(curX, curY);
  6494. if (curIndex == newFirstIndex) //要显示多一条才不会穿帮
  6495. max += ii.height;
  6496. curX += ii.width + this._columnGap;
  6497. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6498. curX = 0;
  6499. curY += ii.height + this._lineGap;
  6500. }
  6501. curIndex++;
  6502. }
  6503. for (i = 0; i < childCount; i++) {
  6504. ii = this._virtualItems[oldFirstIndex + i];
  6505. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6506. if (ii.obj instanceof fgui.GButton)
  6507. ii.selected = ii.obj.selected;
  6508. this.removeChildToPool(ii.obj);
  6509. ii.obj = null;
  6510. }
  6511. }
  6512. childCount = this._children.length;
  6513. for (i = 0; i < childCount; i++) {
  6514. var obj = this._virtualItems[newFirstIndex + i].obj;
  6515. if (this._children[i] != obj)
  6516. this.setChildIndex(obj, i);
  6517. }
  6518. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6519. this._scrollPane.changeContentSizeOnScrolling(0, deltaSize, 0, firstItemDeltaSize);
  6520. if (curIndex > 0 && this.numChildren > 0 && this._container.y <= 0 && this.getChildAt(0).y > -this._container.y) //最后一页没填满!
  6521. return true;
  6522. else
  6523. return false;
  6524. }
  6525. handleScroll2(forceUpdate) {
  6526. var pos = this._scrollPane.scrollingPosX;
  6527. var max = pos + this._scrollPane.viewWidth;
  6528. var end = pos == this._scrollPane.contentWidth; //这个标志表示当前需要滚动到最末,无论内容变化大小
  6529. //寻找当前位置的第一条项目
  6530. s_n = pos;
  6531. var newFirstIndex = this.getIndexOnPos2(forceUpdate);
  6532. pos = s_n;
  6533. if (newFirstIndex == this._firstIndex && !forceUpdate)
  6534. return false;
  6535. var oldFirstIndex = this._firstIndex;
  6536. this._firstIndex = newFirstIndex;
  6537. var curIndex = newFirstIndex;
  6538. var forward = oldFirstIndex > newFirstIndex;
  6539. var childCount = this.numChildren;
  6540. var lastIndex = oldFirstIndex + childCount - 1;
  6541. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6542. var curX = pos, curY = 0;
  6543. var needRender;
  6544. var deltaSize = 0;
  6545. var firstItemDeltaSize = 0;
  6546. var url = this.defaultItem;
  6547. var ii, ii2;
  6548. var i, j;
  6549. var partSize = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6550. this.itemInfoVer++;
  6551. while (curIndex < this._realNumItems && (end || curX < max)) {
  6552. ii = this._virtualItems[curIndex];
  6553. if (ii.obj == null || forceUpdate) {
  6554. if (this.itemProvider != null) {
  6555. url = this.itemProvider.runWith(curIndex % this._numItems);
  6556. if (url == null)
  6557. url = this._defaultItem;
  6558. url = fgui.UIPackage.normalizeURL(url);
  6559. }
  6560. if (ii.obj && ii.obj.resourceURL != url) {
  6561. if (ii.obj instanceof fgui.GButton)
  6562. ii.selected = ii.obj.selected;
  6563. this.removeChildToPool(ii.obj);
  6564. ii.obj = null;
  6565. }
  6566. }
  6567. if (ii.obj == null) {
  6568. if (forward) {
  6569. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6570. ii2 = this._virtualItems[j];
  6571. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6572. if (ii2.obj instanceof fgui.GButton)
  6573. ii2.selected = ii2.obj.selected;
  6574. ii.obj = ii2.obj;
  6575. ii2.obj = null;
  6576. if (j == reuseIndex)
  6577. reuseIndex--;
  6578. break;
  6579. }
  6580. }
  6581. }
  6582. else {
  6583. for (j = reuseIndex; j <= lastIndex; j++) {
  6584. ii2 = this._virtualItems[j];
  6585. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6586. if (ii2.obj instanceof fgui.GButton)
  6587. ii2.selected = ii2.obj.selected;
  6588. ii.obj = ii2.obj;
  6589. ii2.obj = null;
  6590. if (j == reuseIndex)
  6591. reuseIndex++;
  6592. break;
  6593. }
  6594. }
  6595. }
  6596. if (ii.obj) {
  6597. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6598. }
  6599. else {
  6600. ii.obj = this._pool.getObject(url);
  6601. if (forward)
  6602. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6603. else
  6604. this.addChild(ii.obj);
  6605. }
  6606. if (ii.obj instanceof fgui.GButton)
  6607. ii.obj.selected = ii.selected;
  6608. needRender = true;
  6609. }
  6610. else
  6611. needRender = forceUpdate;
  6612. if (needRender) {
  6613. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleRow || this._lineCount > 0))
  6614. ii.obj.setSize(ii.obj.width, partSize, true);
  6615. this.itemRenderer.runWith([curIndex % this._numItems, ii.obj]);
  6616. if (curIndex % this._curLineItemCount == 0) {
  6617. deltaSize += Math.ceil(ii.obj.width) - ii.width;
  6618. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6619. //当内容向下滚动时,如果新出现的一个项目大小发生变化,需要做一个位置补偿,才不会导致滚动跳动
  6620. firstItemDeltaSize = Math.ceil(ii.obj.width) - ii.width;
  6621. }
  6622. }
  6623. ii.width = Math.ceil(ii.obj.width);
  6624. ii.height = Math.ceil(ii.obj.height);
  6625. }
  6626. ii.updateFlag = this.itemInfoVer;
  6627. ii.obj.setXY(curX, curY);
  6628. if (curIndex == newFirstIndex) //要显示多一条才不会穿帮
  6629. max += ii.width;
  6630. curY += ii.height + this._lineGap;
  6631. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6632. curY = 0;
  6633. curX += ii.width + this._columnGap;
  6634. }
  6635. curIndex++;
  6636. }
  6637. for (i = 0; i < childCount; i++) {
  6638. ii = this._virtualItems[oldFirstIndex + i];
  6639. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6640. if (ii.obj instanceof fgui.GButton)
  6641. ii.selected = ii.obj.selected;
  6642. this.removeChildToPool(ii.obj);
  6643. ii.obj = null;
  6644. }
  6645. }
  6646. childCount = this._children.length;
  6647. for (i = 0; i < childCount; i++) {
  6648. var obj = this._virtualItems[newFirstIndex + i].obj;
  6649. if (this._children[i] != obj)
  6650. this.setChildIndex(obj, i);
  6651. }
  6652. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6653. this._scrollPane.changeContentSizeOnScrolling(deltaSize, 0, firstItemDeltaSize, 0);
  6654. if (curIndex > 0 && this.numChildren > 0 && this._container.x <= 0 && this.getChildAt(0).x > -this._container.x) //最后一页没填满!
  6655. return true;
  6656. else
  6657. return false;
  6658. }
  6659. handleScroll3(forceUpdate) {
  6660. var pos = this._scrollPane.scrollingPosX;
  6661. //寻找当前位置的第一条项目
  6662. s_n = pos;
  6663. var newFirstIndex = this.getIndexOnPos3(forceUpdate);
  6664. pos = s_n;
  6665. if (newFirstIndex == this._firstIndex && !forceUpdate)
  6666. return;
  6667. var oldFirstIndex = this._firstIndex;
  6668. this._firstIndex = newFirstIndex;
  6669. //分页模式不支持不等高,所以渲染满一页就好了
  6670. var reuseIndex = oldFirstIndex;
  6671. var virtualItemCount = this._virtualItems.length;
  6672. var pageSize = this._curLineItemCount * this._curLineItemCount2;
  6673. var startCol = newFirstIndex % this._curLineItemCount;
  6674. var viewWidth = this.viewWidth;
  6675. var page = Math.floor(newFirstIndex / pageSize);
  6676. var startIndex = page * pageSize;
  6677. var lastIndex = startIndex + pageSize * 2; //测试两页
  6678. var needRender;
  6679. var i;
  6680. var ii, ii2;
  6681. var col;
  6682. var url = this._defaultItem;
  6683. var partWidth = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6684. var partHeight = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount2 - 1)) / this._curLineItemCount2;
  6685. this.itemInfoVer++;
  6686. //先标记这次要用到的项目
  6687. for (i = startIndex; i < lastIndex; i++) {
  6688. if (i >= this._realNumItems)
  6689. continue;
  6690. col = i % this._curLineItemCount;
  6691. if (i - startIndex < pageSize) {
  6692. if (col < startCol)
  6693. continue;
  6694. }
  6695. else {
  6696. if (col > startCol)
  6697. continue;
  6698. }
  6699. ii = this._virtualItems[i];
  6700. ii.updateFlag = this.itemInfoVer;
  6701. }
  6702. var lastObj = null;
  6703. var insertIndex = 0;
  6704. for (i = startIndex; i < lastIndex; i++) {
  6705. if (i >= this._realNumItems)
  6706. continue;
  6707. ii = this._virtualItems[i];
  6708. if (ii.updateFlag != this.itemInfoVer)
  6709. continue;
  6710. if (ii.obj == null) {
  6711. //寻找看有没有可重用的
  6712. while (reuseIndex < virtualItemCount) {
  6713. ii2 = this._virtualItems[reuseIndex];
  6714. if (ii2.obj && ii2.updateFlag != this.itemInfoVer) {
  6715. if (ii2.obj instanceof fgui.GButton)
  6716. ii2.selected = ii2.obj.selected;
  6717. ii.obj = ii2.obj;
  6718. ii2.obj = null;
  6719. break;
  6720. }
  6721. reuseIndex++;
  6722. }
  6723. if (insertIndex == -1)
  6724. insertIndex = this.getChildIndex(lastObj) + 1;
  6725. if (ii.obj == null) {
  6726. if (this.itemProvider != null) {
  6727. url = this.itemProvider.runWith(i % this._numItems);
  6728. if (url == null)
  6729. url = this._defaultItem;
  6730. url = fgui.UIPackage.normalizeURL(url);
  6731. }
  6732. ii.obj = this._pool.getObject(url);
  6733. this.addChildAt(ii.obj, insertIndex);
  6734. }
  6735. else {
  6736. insertIndex = this.setChildIndexBefore(ii.obj, insertIndex);
  6737. }
  6738. insertIndex++;
  6739. if (ii.obj instanceof fgui.GButton)
  6740. ii.obj.selected = ii.selected;
  6741. needRender = true;
  6742. }
  6743. else {
  6744. needRender = forceUpdate;
  6745. insertIndex = -1;
  6746. lastObj = ii.obj;
  6747. }
  6748. if (needRender) {
  6749. if (this._autoResizeItem) {
  6750. if (this._curLineItemCount == this._columnCount && this._curLineItemCount2 == this._lineCount)
  6751. ii.obj.setSize(partWidth, partHeight, true);
  6752. else if (this._curLineItemCount == this._columnCount)
  6753. ii.obj.setSize(partWidth, ii.obj.height, true);
  6754. else if (this._curLineItemCount2 == this._lineCount)
  6755. ii.obj.setSize(ii.obj.width, partHeight, true);
  6756. }
  6757. this.itemRenderer.runWith([i % this._numItems, ii.obj]);
  6758. ii.width = Math.ceil(ii.obj.width);
  6759. ii.height = Math.ceil(ii.obj.height);
  6760. }
  6761. }
  6762. //排列item
  6763. var borderX = (startIndex / pageSize) * viewWidth;
  6764. var xx = borderX;
  6765. var yy = 0;
  6766. var lineHeight = 0;
  6767. for (i = startIndex; i < lastIndex; i++) {
  6768. if (i >= this._realNumItems)
  6769. continue;
  6770. ii = this._virtualItems[i];
  6771. if (ii.updateFlag == this.itemInfoVer)
  6772. ii.obj.setXY(xx, yy);
  6773. if (ii.height > lineHeight)
  6774. lineHeight = ii.height;
  6775. if (i % this._curLineItemCount == this._curLineItemCount - 1) {
  6776. xx = borderX;
  6777. yy += lineHeight + this._lineGap;
  6778. lineHeight = 0;
  6779. if (i == startIndex + pageSize - 1) {
  6780. borderX += viewWidth;
  6781. xx = borderX;
  6782. yy = 0;
  6783. }
  6784. }
  6785. else
  6786. xx += ii.width + this._columnGap;
  6787. }
  6788. //释放未使用的
  6789. for (i = reuseIndex; i < virtualItemCount; i++) {
  6790. ii = this._virtualItems[i];
  6791. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6792. if (ii.obj instanceof fgui.GButton)
  6793. ii.selected = ii.obj.selected;
  6794. this.removeChildToPool(ii.obj);
  6795. ii.obj = null;
  6796. }
  6797. }
  6798. }
  6799. handleArchOrder1() {
  6800. if (this.childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6801. var mid = this._scrollPane.posY + this.viewHeight / 2;
  6802. var minDist = Number.POSITIVE_INFINITY;
  6803. var dist = 0;
  6804. var apexIndex = 0;
  6805. var cnt = this.numChildren;
  6806. for (var i = 0; i < cnt; i++) {
  6807. var obj = this.getChildAt(i);
  6808. if (!this.foldInvisibleItems || obj.visible) {
  6809. dist = Math.abs(mid - obj.y - obj.height / 2);
  6810. if (dist < minDist) {
  6811. minDist = dist;
  6812. apexIndex = i;
  6813. }
  6814. }
  6815. }
  6816. this.apexIndex = apexIndex;
  6817. }
  6818. }
  6819. handleArchOrder2() {
  6820. if (this.childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6821. var mid = this._scrollPane.posX + this.viewWidth / 2;
  6822. var minDist = Number.POSITIVE_INFINITY;
  6823. var dist = 0;
  6824. var apexIndex = 0;
  6825. var cnt = this.numChildren;
  6826. for (var i = 0; i < cnt; i++) {
  6827. var obj = this.getChildAt(i);
  6828. if (!this.foldInvisibleItems || obj.visible) {
  6829. dist = Math.abs(mid - obj.x - obj.width / 2);
  6830. if (dist < minDist) {
  6831. minDist = dist;
  6832. apexIndex = i;
  6833. }
  6834. }
  6835. }
  6836. this.apexIndex = apexIndex;
  6837. }
  6838. }
  6839. handleAlign(contentWidth, contentHeight) {
  6840. var newOffsetX = 0;
  6841. var newOffsetY = 0;
  6842. if (contentHeight < this.viewHeight) {
  6843. if (this._verticalAlign == "middle")
  6844. newOffsetY = Math.floor((this.viewHeight - contentHeight) / 2);
  6845. else if (this._verticalAlign == "bottom")
  6846. newOffsetY = this.viewHeight - contentHeight;
  6847. }
  6848. if (contentWidth < this.viewWidth) {
  6849. if (this._align == "center")
  6850. newOffsetX = Math.floor((this.viewWidth - contentWidth) / 2);
  6851. else if (this._align == "right")
  6852. newOffsetX = this.viewWidth - contentWidth;
  6853. }
  6854. if (newOffsetX != this._alignOffset.x || newOffsetY != this._alignOffset.y) {
  6855. this._alignOffset.setTo(newOffsetX, newOffsetY);
  6856. if (this._scrollPane)
  6857. this._scrollPane.adjustMaskContainer();
  6858. else
  6859. this._container.pos(this._margin.left + this._alignOffset.x, this._margin.top + this._alignOffset.y);
  6860. }
  6861. }
  6862. updateBounds() {
  6863. if (this._virtual)
  6864. return;
  6865. var i;
  6866. var child;
  6867. var curX = 0;
  6868. var curY = 0;
  6869. var maxWidth = 0;
  6870. var maxHeight = 0;
  6871. var cw, ch;
  6872. var j = 0;
  6873. var page = 0;
  6874. var k = 0;
  6875. var cnt = this._children.length;
  6876. var viewWidth = this.viewWidth;
  6877. var viewHeight = this.viewHeight;
  6878. var lineSize = 0;
  6879. var lineStart = 0;
  6880. var ratio;
  6881. if (this._layout == fgui.ListLayoutType.SingleColumn) {
  6882. for (i = 0; i < cnt; i++) {
  6883. child = this.getChildAt(i);
  6884. if (this.foldInvisibleItems && !child.visible)
  6885. continue;
  6886. if (curY != 0)
  6887. curY += this._lineGap;
  6888. child.y = curY;
  6889. if (this._autoResizeItem)
  6890. child.setSize(viewWidth, child.height, true);
  6891. curY += Math.ceil(child.height);
  6892. if (child.width > maxWidth)
  6893. maxWidth = child.width;
  6894. }
  6895. ch = curY;
  6896. if (ch <= viewHeight && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.vtScrollBar) {
  6897. viewWidth += this._scrollPane.vtScrollBar.width;
  6898. for (i = 0; i < cnt; i++) {
  6899. child = this.getChildAt(i);
  6900. if (this.foldInvisibleItems && !child.visible)
  6901. continue;
  6902. child.setSize(viewWidth, child.height, true);
  6903. if (child.width > maxWidth)
  6904. maxWidth = child.width;
  6905. }
  6906. }
  6907. cw = Math.ceil(maxWidth);
  6908. }
  6909. else if (this._layout == fgui.ListLayoutType.SingleRow) {
  6910. for (i = 0; i < cnt; i++) {
  6911. child = this.getChildAt(i);
  6912. if (this.foldInvisibleItems && !child.visible)
  6913. continue;
  6914. if (curX != 0)
  6915. curX += this._columnGap;
  6916. child.x = curX;
  6917. if (this._autoResizeItem)
  6918. child.setSize(child.width, viewHeight, true);
  6919. curX += Math.ceil(child.width);
  6920. if (child.height > maxHeight)
  6921. maxHeight = child.height;
  6922. }
  6923. cw = curX;
  6924. if (cw <= viewWidth && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.hzScrollBar) {
  6925. viewHeight += this._scrollPane.hzScrollBar.height;
  6926. for (i = 0; i < cnt; i++) {
  6927. child = this.getChildAt(i);
  6928. if (this.foldInvisibleItems && !child.visible)
  6929. continue;
  6930. child.setSize(child.width, viewHeight, true);
  6931. if (child.height > maxHeight)
  6932. maxHeight = child.height;
  6933. }
  6934. }
  6935. ch = Math.ceil(maxHeight);
  6936. }
  6937. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6938. if (this._autoResizeItem && this._columnCount > 0) {
  6939. for (i = 0; i < cnt; i++) {
  6940. child = this.getChildAt(i);
  6941. if (this.foldInvisibleItems && !child.visible)
  6942. continue;
  6943. lineSize += child.sourceWidth;
  6944. j++;
  6945. if (j == this._columnCount || i == cnt - 1) {
  6946. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6947. curX = 0;
  6948. for (j = lineStart; j <= i; j++) {
  6949. child = this.getChildAt(j);
  6950. if (this.foldInvisibleItems && !child.visible)
  6951. continue;
  6952. child.setXY(curX, curY);
  6953. if (j < i) {
  6954. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), child.height, true);
  6955. curX += Math.ceil(child.width) + this._columnGap;
  6956. }
  6957. else {
  6958. child.setSize(viewWidth - curX, child.height, true);
  6959. }
  6960. if (child.height > maxHeight)
  6961. maxHeight = child.height;
  6962. }
  6963. //new line
  6964. curY += Math.ceil(maxHeight) + this._lineGap;
  6965. maxHeight = 0;
  6966. j = 0;
  6967. lineStart = i + 1;
  6968. lineSize = 0;
  6969. }
  6970. }
  6971. ch = curY + Math.ceil(maxHeight);
  6972. cw = viewWidth;
  6973. }
  6974. else {
  6975. for (i = 0; i < cnt; i++) {
  6976. child = this.getChildAt(i);
  6977. if (this.foldInvisibleItems && !child.visible)
  6978. continue;
  6979. if (curX != 0)
  6980. curX += this._columnGap;
  6981. if (this._columnCount != 0 && j >= this._columnCount
  6982. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  6983. //new line
  6984. curX = 0;
  6985. curY += Math.ceil(maxHeight) + this._lineGap;
  6986. maxHeight = 0;
  6987. j = 0;
  6988. }
  6989. child.setXY(curX, curY);
  6990. curX += Math.ceil(child.width);
  6991. if (curX > maxWidth)
  6992. maxWidth = curX;
  6993. if (child.height > maxHeight)
  6994. maxHeight = child.height;
  6995. j++;
  6996. }
  6997. ch = curY + Math.ceil(maxHeight);
  6998. cw = Math.ceil(maxWidth);
  6999. }
  7000. }
  7001. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  7002. if (this._autoResizeItem && this._lineCount > 0) {
  7003. for (i = 0; i < cnt; i++) {
  7004. child = this.getChildAt(i);
  7005. if (this.foldInvisibleItems && !child.visible)
  7006. continue;
  7007. lineSize += child.sourceHeight;
  7008. j++;
  7009. if (j == this._lineCount || i == cnt - 1) {
  7010. ratio = (viewHeight - lineSize - (j - 1) * this._lineGap) / lineSize;
  7011. curY = 0;
  7012. for (j = lineStart; j <= i; j++) {
  7013. child = this.getChildAt(j);
  7014. if (this.foldInvisibleItems && !child.visible)
  7015. continue;
  7016. child.setXY(curX, curY);
  7017. if (j < i) {
  7018. child.setSize(child.width, child.sourceHeight + Math.round(child.sourceHeight * ratio), true);
  7019. curY += Math.ceil(child.height) + this._lineGap;
  7020. }
  7021. else {
  7022. child.setSize(child.width, viewHeight - curY, true);
  7023. }
  7024. if (child.width > maxWidth)
  7025. maxWidth = child.width;
  7026. }
  7027. //new line
  7028. curX += Math.ceil(maxWidth) + this._columnGap;
  7029. maxWidth = 0;
  7030. j = 0;
  7031. lineStart = i + 1;
  7032. lineSize = 0;
  7033. }
  7034. }
  7035. cw = curX + Math.ceil(maxWidth);
  7036. ch = viewHeight;
  7037. }
  7038. else {
  7039. for (i = 0; i < cnt; i++) {
  7040. child = this.getChildAt(i);
  7041. if (this.foldInvisibleItems && !child.visible)
  7042. continue;
  7043. if (curY != 0)
  7044. curY += this._lineGap;
  7045. if (this._lineCount != 0 && j >= this._lineCount
  7046. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) {
  7047. curY = 0;
  7048. curX += Math.ceil(maxWidth) + this._columnGap;
  7049. maxWidth = 0;
  7050. j = 0;
  7051. }
  7052. child.setXY(curX, curY);
  7053. curY += Math.ceil(child.height);
  7054. if (curY > maxHeight)
  7055. maxHeight = curY;
  7056. if (child.width > maxWidth)
  7057. maxWidth = child.width;
  7058. j++;
  7059. }
  7060. cw = curX + Math.ceil(maxWidth);
  7061. ch = Math.ceil(maxHeight);
  7062. }
  7063. }
  7064. else //pagination
  7065. {
  7066. var eachHeight;
  7067. if (this._autoResizeItem && this._lineCount > 0)
  7068. eachHeight = Math.floor((viewHeight - (this._lineCount - 1) * this._lineGap) / this._lineCount);
  7069. if (this._autoResizeItem && this._columnCount > 0) {
  7070. for (i = 0; i < cnt; i++) {
  7071. child = this.getChildAt(i);
  7072. if (this.foldInvisibleItems && !child.visible)
  7073. continue;
  7074. if (j == 0 && (this._lineCount != 0 && k >= this._lineCount
  7075. || this._lineCount == 0 && curY + child.height > viewHeight)) {
  7076. //new page
  7077. page++;
  7078. curY = 0;
  7079. k = 0;
  7080. }
  7081. lineSize += child.sourceWidth;
  7082. j++;
  7083. if (j == this._columnCount || i == cnt - 1) {
  7084. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  7085. curX = 0;
  7086. for (j = lineStart; j <= i; j++) {
  7087. child = this.getChildAt(j);
  7088. if (this.foldInvisibleItems && !child.visible)
  7089. continue;
  7090. child.setXY(page * viewWidth + curX, curY);
  7091. if (j < i) {
  7092. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), this._lineCount > 0 ? eachHeight : child.height, true);
  7093. curX += Math.ceil(child.width) + this._columnGap;
  7094. }
  7095. else {
  7096. child.setSize(viewWidth - curX, this._lineCount > 0 ? eachHeight : child.height, true);
  7097. }
  7098. if (child.height > maxHeight)
  7099. maxHeight = child.height;
  7100. }
  7101. //new line
  7102. curY += Math.ceil(maxHeight) + this._lineGap;
  7103. maxHeight = 0;
  7104. j = 0;
  7105. lineStart = i + 1;
  7106. lineSize = 0;
  7107. k++;
  7108. }
  7109. }
  7110. }
  7111. else {
  7112. for (i = 0; i < cnt; i++) {
  7113. child = this.getChildAt(i);
  7114. if (this.foldInvisibleItems && !child.visible)
  7115. continue;
  7116. if (curX != 0)
  7117. curX += this._columnGap;
  7118. if (this._autoResizeItem && this._lineCount > 0)
  7119. child.setSize(child.width, eachHeight, true);
  7120. if (this._columnCount != 0 && j >= this._columnCount
  7121. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  7122. //new line
  7123. curX = 0;
  7124. curY += Math.ceil(maxHeight) + this._lineGap;
  7125. maxHeight = 0;
  7126. j = 0;
  7127. k++;
  7128. if (this._lineCount != 0 && k >= this._lineCount
  7129. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) //new page
  7130. {
  7131. page++;
  7132. curY = 0;
  7133. k = 0;
  7134. }
  7135. }
  7136. child.setXY(page * viewWidth + curX, curY);
  7137. curX += Math.ceil(child.width);
  7138. if (curX > maxWidth)
  7139. maxWidth = curX;
  7140. if (child.height > maxHeight)
  7141. maxHeight = child.height;
  7142. j++;
  7143. }
  7144. }
  7145. ch = page > 0 ? viewHeight : curY + Math.ceil(maxHeight);
  7146. cw = (page + 1) * viewWidth;
  7147. }
  7148. this.handleAlign(cw, ch);
  7149. this.setBounds(0, 0, cw, ch);
  7150. }
  7151. setup_beforeAdd(buffer, beginPos) {
  7152. super.setup_beforeAdd(buffer, beginPos);
  7153. buffer.seek(beginPos, 5);
  7154. var i1;
  7155. this._layout = buffer.readByte();
  7156. this._selectionMode = buffer.readByte();
  7157. i1 = buffer.readByte();
  7158. this._align = i1 == 0 ? "left" : (i1 == 1 ? "center" : "right");
  7159. i1 = buffer.readByte();
  7160. this._verticalAlign = i1 == 0 ? "top" : (i1 == 1 ? "middle" : "bottom");
  7161. this._lineGap = buffer.getInt16();
  7162. this._columnGap = buffer.getInt16();
  7163. this._lineCount = buffer.getInt16();
  7164. this._columnCount = buffer.getInt16();
  7165. this._autoResizeItem = buffer.readBool();
  7166. this._childrenRenderOrder = buffer.readByte();
  7167. this._apexIndex = buffer.getInt16();
  7168. if (buffer.readBool()) {
  7169. this._margin.top = buffer.getInt32();
  7170. this._margin.bottom = buffer.getInt32();
  7171. this._margin.left = buffer.getInt32();
  7172. this._margin.right = buffer.getInt32();
  7173. }
  7174. var overflow = buffer.readByte();
  7175. if (overflow == fgui.OverflowType.Scroll) {
  7176. var savedPos = buffer.pos;
  7177. buffer.seek(beginPos, 7);
  7178. this.setupScroll(buffer);
  7179. buffer.pos = savedPos;
  7180. }
  7181. else
  7182. this.setupOverflow(overflow);
  7183. if (buffer.readBool()) //clipSoftness
  7184. buffer.skip(8);
  7185. if (buffer.version >= 2) {
  7186. this.scrollItemToViewOnClick = buffer.readBool();
  7187. this.foldInvisibleItems = buffer.readBool();
  7188. }
  7189. buffer.seek(beginPos, 8);
  7190. this._defaultItem = buffer.readS();
  7191. this.readItems(buffer);
  7192. }
  7193. readItems(buffer) {
  7194. var cnt;
  7195. var i;
  7196. var nextPos;
  7197. var str;
  7198. cnt = buffer.getInt16();
  7199. for (i = 0; i < cnt; i++) {
  7200. nextPos = buffer.getInt16();
  7201. nextPos += buffer.pos;
  7202. str = buffer.readS();
  7203. if (str == null) {
  7204. str = this.defaultItem;
  7205. if (!str) {
  7206. buffer.pos = nextPos;
  7207. continue;
  7208. }
  7209. }
  7210. var obj = this.getFromPool(str);
  7211. if (obj) {
  7212. this.addChild(obj);
  7213. this.setupItem(buffer, obj);
  7214. }
  7215. buffer.pos = nextPos;
  7216. }
  7217. }
  7218. setupItem(buffer, obj) {
  7219. var str;
  7220. str = buffer.readS();
  7221. if (str != null)
  7222. obj.text = str;
  7223. str = buffer.readS();
  7224. if (str != null && (obj instanceof fgui.GButton))
  7225. obj.selectedTitle = str;
  7226. str = buffer.readS();
  7227. if (str != null)
  7228. obj.icon = str;
  7229. str = buffer.readS();
  7230. if (str != null && (obj instanceof fgui.GButton))
  7231. obj.selectedIcon = str;
  7232. str = buffer.readS();
  7233. if (str != null)
  7234. obj.name = str;
  7235. var cnt;
  7236. var i;
  7237. if (obj instanceof fgui.GComponent) {
  7238. cnt = buffer.getInt16();
  7239. for (i = 0; i < cnt; i++) {
  7240. var cc = obj.getController(buffer.readS());
  7241. str = buffer.readS();
  7242. if (cc)
  7243. cc.selectedPageId = str;
  7244. }
  7245. if (buffer.version >= 2) {
  7246. cnt = buffer.getInt16();
  7247. for (i = 0; i < cnt; i++) {
  7248. var target = buffer.readS();
  7249. var propertyId = buffer.getInt16();
  7250. var value = buffer.readS();
  7251. var obj2 = obj.getChildByPath(target);
  7252. if (obj2)
  7253. obj2.setProp(propertyId, value);
  7254. }
  7255. }
  7256. }
  7257. }
  7258. setup_afterAdd(buffer, beginPos) {
  7259. super.setup_afterAdd(buffer, beginPos);
  7260. buffer.seek(beginPos, 6);
  7261. var i = buffer.getInt16();
  7262. if (i != -1)
  7263. this._selectionController = this._parent.getControllerAt(i);
  7264. }
  7265. }
  7266. fgui.GList = GList;
  7267. var s_n = 0;
  7268. })(fgui);
  7269. (function (fgui) {
  7270. class GObjectPool {
  7271. constructor() {
  7272. this._count = 0;
  7273. this._pool = {};
  7274. }
  7275. clear() {
  7276. for (var i1 in this._pool) {
  7277. var arr = this._pool[i1];
  7278. var cnt = arr.length;
  7279. for (var i = 0; i < cnt; i++)
  7280. arr[i].dispose();
  7281. }
  7282. this._pool = {};
  7283. this._count = 0;
  7284. }
  7285. get count() {
  7286. return this._count;
  7287. }
  7288. getObject(url) {
  7289. url = fgui.UIPackage.normalizeURL(url);
  7290. if (url == null)
  7291. return null;
  7292. var arr = this._pool[url];
  7293. if (arr && arr.length > 0) {
  7294. this._count--;
  7295. return arr.shift();
  7296. }
  7297. var child = fgui.UIPackage.createObjectFromURL(url);
  7298. return child;
  7299. }
  7300. returnObject(obj) {
  7301. var url = obj.resourceURL;
  7302. if (!url)
  7303. return;
  7304. var arr = this._pool[url];
  7305. if (arr == null) {
  7306. arr = [];
  7307. this._pool[url] = arr;
  7308. }
  7309. this._count++;
  7310. arr.push(obj);
  7311. }
  7312. }
  7313. fgui.GObjectPool = GObjectPool;
  7314. })(fgui);
  7315. ///<reference path="GObjectPool.ts"/>
  7316. ///<reference path="GObjectPool.ts"/>
  7317. (function (fgui) {
  7318. class GLoader extends fgui.GObject {
  7319. constructor() {
  7320. super();
  7321. this._url = "";
  7322. this._fill = fgui.LoaderFillType.None;
  7323. this._align = "left";
  7324. this._valign = "top";
  7325. this._showErrorSign = true;
  7326. }
  7327. createDisplayObject() {
  7328. super.createDisplayObject();
  7329. this._content = new fgui.MovieClip();
  7330. this._displayObject.addChild(this._content);
  7331. this._displayObject.mouseEnabled = true;
  7332. }
  7333. dispose() {
  7334. if (!this._contentItem && this._content.texture) {
  7335. this.freeExternal(this._content.texture);
  7336. }
  7337. if (this._content2)
  7338. this._content2.dispose();
  7339. super.dispose();
  7340. }
  7341. get url() {
  7342. return this._url;
  7343. }
  7344. set url(value) {
  7345. if (this._url == value)
  7346. return;
  7347. this._url = value;
  7348. this.loadContent();
  7349. this.updateGear(7);
  7350. }
  7351. get icon() {
  7352. return this._url;
  7353. }
  7354. set icon(value) {
  7355. this.url = value;
  7356. }
  7357. get align() {
  7358. return this._align;
  7359. }
  7360. set align(value) {
  7361. if (this._align != value) {
  7362. this._align = value;
  7363. this.updateLayout();
  7364. }
  7365. }
  7366. get verticalAlign() {
  7367. return this._valign;
  7368. }
  7369. set verticalAlign(value) {
  7370. if (this._valign != value) {
  7371. this._valign = value;
  7372. this.updateLayout();
  7373. }
  7374. }
  7375. get fill() {
  7376. return this._fill;
  7377. }
  7378. set fill(value) {
  7379. if (this._fill != value) {
  7380. this._fill = value;
  7381. this.updateLayout();
  7382. }
  7383. }
  7384. get shrinkOnly() {
  7385. return this._shrinkOnly;
  7386. }
  7387. set shrinkOnly(value) {
  7388. if (this._shrinkOnly != value) {
  7389. this._shrinkOnly = value;
  7390. this.updateLayout();
  7391. }
  7392. }
  7393. get autoSize() {
  7394. return this._autoSize;
  7395. }
  7396. set autoSize(value) {
  7397. if (this._autoSize != value) {
  7398. this._autoSize = value;
  7399. this.updateLayout();
  7400. }
  7401. }
  7402. get playing() {
  7403. return this._content.playing;
  7404. }
  7405. set playing(value) {
  7406. if (this._content.playing != value) {
  7407. this._content.playing = value;
  7408. this.updateGear(5);
  7409. }
  7410. }
  7411. get frame() {
  7412. return this._content.frame;
  7413. }
  7414. set frame(value) {
  7415. if (this._content.frame != value) {
  7416. this._content.frame = value;
  7417. this.updateGear(5);
  7418. }
  7419. }
  7420. get color() {
  7421. return this._content.color;
  7422. }
  7423. set color(value) {
  7424. if (this._content.color != value) {
  7425. this._content.color = value;
  7426. this.updateGear(4);
  7427. }
  7428. }
  7429. get fillMethod() {
  7430. return this._content.fillMethod;
  7431. }
  7432. set fillMethod(value) {
  7433. this._content.fillMethod = value;
  7434. }
  7435. get fillOrigin() {
  7436. return this._content.fillOrigin;
  7437. }
  7438. set fillOrigin(value) {
  7439. this._content.fillOrigin = value;
  7440. }
  7441. get fillClockwise() {
  7442. return this._content.fillClockwise;
  7443. }
  7444. set fillClockwise(value) {
  7445. this._content.fillClockwise = value;
  7446. }
  7447. get fillAmount() {
  7448. return this._content.fillAmount;
  7449. }
  7450. set fillAmount(value) {
  7451. this._content.fillAmount = value;
  7452. }
  7453. get showErrorSign() {
  7454. return this._showErrorSign;
  7455. }
  7456. set showErrorSign(value) {
  7457. this._showErrorSign = value;
  7458. }
  7459. get content() {
  7460. return this._content;
  7461. }
  7462. get component() {
  7463. return this._content2;
  7464. }
  7465. loadContent() {
  7466. this.clearContent();
  7467. if (!this._url)
  7468. return;
  7469. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7470. this.loadFromPackage(this._url);
  7471. else
  7472. this.loadExternal();
  7473. }
  7474. loadFromPackage(itemURL) {
  7475. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7476. if (this._contentItem) {
  7477. this._contentItem = this._contentItem.getBranch();
  7478. this.sourceWidth = this._contentItem.width;
  7479. this.sourceHeight = this._contentItem.height;
  7480. this._contentItem = this._contentItem.getHighResolution();
  7481. this._contentItem.load();
  7482. if (this._autoSize)
  7483. this.setSize(this.sourceWidth, this.sourceHeight);
  7484. if (this._contentItem.type == fgui.PackageItemType.Image) {
  7485. if (!this._contentItem.texture) {
  7486. this.setErrorState();
  7487. }
  7488. else {
  7489. this._content.texture = this._contentItem.texture;
  7490. this._content.scale9Grid = this._contentItem.scale9Grid;
  7491. this._content.scaleByTile = this._contentItem.scaleByTile;
  7492. this._content.tileGridIndice = this._contentItem.tileGridIndice;
  7493. this.sourceWidth = this._contentItem.width;
  7494. this.sourceHeight = this._contentItem.height;
  7495. this.updateLayout();
  7496. }
  7497. }
  7498. else if (this._contentItem.type == fgui.PackageItemType.MovieClip) {
  7499. this.sourceWidth = this._contentItem.width;
  7500. this.sourceHeight = this._contentItem.height;
  7501. this._content.interval = this._contentItem.interval;
  7502. this._content.swing = this._contentItem.swing;
  7503. this._content.repeatDelay = this._contentItem.repeatDelay;
  7504. this._content.frames = this._contentItem.frames;
  7505. this.updateLayout();
  7506. }
  7507. else if (this._contentItem.type == fgui.PackageItemType.Component) {
  7508. var obj = fgui.UIPackage.createObjectFromURL(itemURL);
  7509. if (!obj)
  7510. this.setErrorState();
  7511. else if (!(obj instanceof fgui.GComponent)) {
  7512. obj.dispose();
  7513. this.setErrorState();
  7514. }
  7515. else {
  7516. this._content2 = obj.asCom;
  7517. this._displayObject.addChild(this._content2.displayObject);
  7518. this.updateLayout();
  7519. }
  7520. }
  7521. else
  7522. this.setErrorState();
  7523. }
  7524. else
  7525. this.setErrorState();
  7526. }
  7527. loadExternal() {
  7528. fgui.AssetProxy.inst.load(this._url, Laya.Handler.create(this, this.__getResCompleted), null, Laya.Loader.IMAGE);
  7529. }
  7530. freeExternal(texture) {
  7531. }
  7532. onExternalLoadSuccess(texture) {
  7533. this._content.texture = texture;
  7534. this._content.scale9Grid = null;
  7535. this._content.scaleByTile = false;
  7536. this.sourceWidth = texture.width;
  7537. this.sourceHeight = texture.height;
  7538. this.updateLayout();
  7539. }
  7540. onExternalLoadFailed() {
  7541. this.setErrorState();
  7542. }
  7543. __getResCompleted(tex) {
  7544. if (tex != null)
  7545. this.onExternalLoadSuccess(tex);
  7546. else
  7547. this.onExternalLoadFailed();
  7548. }
  7549. setErrorState() {
  7550. if (!this._showErrorSign)
  7551. return;
  7552. if (!this._errorSign) {
  7553. if (fgui.UIConfig.loaderErrorSign != null) {
  7554. this._errorSign = GLoader._errorSignPool.getObject(fgui.UIConfig.loaderErrorSign);
  7555. }
  7556. }
  7557. if (this._errorSign) {
  7558. this._errorSign.setSize(this.width, this.height);
  7559. this._displayObject.addChild(this._errorSign.displayObject);
  7560. }
  7561. }
  7562. clearErrorState() {
  7563. if (this._errorSign) {
  7564. this._displayObject.removeChild(this._errorSign.displayObject);
  7565. GLoader._errorSignPool.returnObject(this._errorSign);
  7566. this._errorSign = null;
  7567. }
  7568. }
  7569. updateLayout() {
  7570. if (!this._content2 && !this._content.texture && !this._content.frames) {
  7571. if (this._autoSize) {
  7572. this._updatingLayout = true;
  7573. this.setSize(50, 30);
  7574. this._updatingLayout = false;
  7575. }
  7576. return;
  7577. }
  7578. let cw = this.sourceWidth;
  7579. let ch = this.sourceHeight;
  7580. if (this._autoSize) {
  7581. this._updatingLayout = true;
  7582. if (cw == 0)
  7583. cw = 50;
  7584. if (ch == 0)
  7585. ch = 30;
  7586. this.setSize(cw, ch);
  7587. this._updatingLayout = false;
  7588. if (cw == this._width && ch == this._height) {
  7589. if (this._content2) {
  7590. this._content2.setXY(0, 0);
  7591. this._content2.setScale(1, 1);
  7592. }
  7593. else {
  7594. this._content.size(cw, ch);
  7595. this._content.pos(0, 0);
  7596. }
  7597. return;
  7598. }
  7599. }
  7600. var sx = 1, sy = 1;
  7601. if (this._fill != fgui.LoaderFillType.None) {
  7602. sx = this.width / this.sourceWidth;
  7603. sy = this.height / this.sourceHeight;
  7604. if (sx != 1 || sy != 1) {
  7605. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7606. sx = sy;
  7607. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7608. sy = sx;
  7609. else if (this._fill == fgui.LoaderFillType.Scale) {
  7610. if (sx > sy)
  7611. sx = sy;
  7612. else
  7613. sy = sx;
  7614. }
  7615. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7616. if (sx > sy)
  7617. sy = sx;
  7618. else
  7619. sx = sy;
  7620. }
  7621. if (this._shrinkOnly) {
  7622. if (sx > 1)
  7623. sx = 1;
  7624. if (sy > 1)
  7625. sy = 1;
  7626. }
  7627. cw = this.sourceWidth * sx;
  7628. ch = this.sourceHeight * sy;
  7629. }
  7630. }
  7631. if (this._content2)
  7632. this._content2.setScale(sx, sy);
  7633. else
  7634. this._content.size(cw, ch);
  7635. var nx, ny;
  7636. if (this._align == "center")
  7637. nx = Math.floor((this.width - cw) / 2);
  7638. else if (this._align == "right")
  7639. nx = this.width - cw;
  7640. else
  7641. nx = 0;
  7642. if (this._valign == "middle")
  7643. ny = Math.floor((this.height - ch) / 2);
  7644. else if (this._valign == "bottom")
  7645. ny = this.height - ch;
  7646. else
  7647. ny = 0;
  7648. if (this._content2)
  7649. this._content2.setXY(nx, ny);
  7650. else
  7651. this._content.pos(nx, ny);
  7652. }
  7653. clearContent() {
  7654. this.clearErrorState();
  7655. if (!this._contentItem && this._content.texture) {
  7656. this.freeExternal(this._content.texture);
  7657. }
  7658. this._content.texture = null;
  7659. this._content.frames = null;
  7660. if (this._content2) {
  7661. this._content2.dispose();
  7662. this._content2 = null;
  7663. }
  7664. this._contentItem = null;
  7665. }
  7666. handleSizeChanged() {
  7667. super.handleSizeChanged();
  7668. if (!this._updatingLayout)
  7669. this.updateLayout();
  7670. }
  7671. getProp(index) {
  7672. switch (index) {
  7673. case fgui.ObjectPropID.Color:
  7674. return this.color;
  7675. case fgui.ObjectPropID.Playing:
  7676. return this.playing;
  7677. case fgui.ObjectPropID.Frame:
  7678. return this.frame;
  7679. case fgui.ObjectPropID.TimeScale:
  7680. return this._content.timeScale;
  7681. default:
  7682. return super.getProp(index);
  7683. }
  7684. }
  7685. setProp(index, value) {
  7686. switch (index) {
  7687. case fgui.ObjectPropID.Color:
  7688. this.color = value;
  7689. break;
  7690. case fgui.ObjectPropID.Playing:
  7691. this.playing = value;
  7692. break;
  7693. case fgui.ObjectPropID.Frame:
  7694. this.frame = value;
  7695. break;
  7696. case fgui.ObjectPropID.TimeScale:
  7697. this._content.timeScale = value;
  7698. break;
  7699. case fgui.ObjectPropID.DeltaTime:
  7700. this._content.advance(value);
  7701. break;
  7702. default:
  7703. super.setProp(index, value);
  7704. break;
  7705. }
  7706. }
  7707. setup_beforeAdd(buffer, beginPos) {
  7708. super.setup_beforeAdd(buffer, beginPos);
  7709. buffer.seek(beginPos, 5);
  7710. var iv;
  7711. this._url = buffer.readS();
  7712. iv = buffer.readByte();
  7713. this._align = iv == 0 ? "left" : (iv == 1 ? "center" : "right");
  7714. iv = buffer.readByte();
  7715. this._valign = iv == 0 ? "top" : (iv == 1 ? "middle" : "bottom");
  7716. this._fill = buffer.readByte();
  7717. this._shrinkOnly = buffer.readBool();
  7718. this._autoSize = buffer.readBool();
  7719. this._showErrorSign = buffer.readBool();
  7720. this._content.playing = buffer.readBool();
  7721. this._content.frame = buffer.getInt32();
  7722. if (buffer.readBool())
  7723. this.color = buffer.readColorS();
  7724. this._content.fillMethod = buffer.readByte();
  7725. if (this._content.fillMethod != 0) {
  7726. this._content.fillOrigin = buffer.readByte();
  7727. this._content.fillClockwise = buffer.readBool();
  7728. this._content.fillAmount = buffer.getFloat32();
  7729. }
  7730. if (this._url)
  7731. this.loadContent();
  7732. }
  7733. }
  7734. GLoader._errorSignPool = new fgui.GObjectPool();
  7735. fgui.GLoader = GLoader;
  7736. })(fgui);
  7737. (function (fgui) {
  7738. class GLoader3D extends fgui.GObject {
  7739. constructor() {
  7740. super();
  7741. this._frame = 0;
  7742. this._playing = true;
  7743. this._url = "";
  7744. this._fill = fgui.LoaderFillType.None;
  7745. this._align = fgui.AlignType.Left;
  7746. this._verticalAlign = fgui.VertAlignType.Top;
  7747. this._color = "#FFFFFF";
  7748. }
  7749. createDisplayObject() {
  7750. super.createDisplayObject();
  7751. this._container = new Laya.Sprite();
  7752. this._displayObject.addChild(this._container);
  7753. }
  7754. dispose() {
  7755. super.dispose();
  7756. }
  7757. get url() {
  7758. return this._url;
  7759. }
  7760. set url(value) {
  7761. if (this._url == value)
  7762. return;
  7763. this._url = value;
  7764. this.loadContent();
  7765. this.updateGear(7);
  7766. }
  7767. get icon() {
  7768. return this._url;
  7769. }
  7770. set icon(value) {
  7771. this.url = value;
  7772. }
  7773. get align() {
  7774. return this._align;
  7775. }
  7776. set align(value) {
  7777. if (this._align != value) {
  7778. this._align = value;
  7779. this.updateLayout();
  7780. }
  7781. }
  7782. get verticalAlign() {
  7783. return this._verticalAlign;
  7784. }
  7785. set verticalAlign(value) {
  7786. if (this._verticalAlign != value) {
  7787. this._verticalAlign = value;
  7788. this.updateLayout();
  7789. }
  7790. }
  7791. get fill() {
  7792. return this._fill;
  7793. }
  7794. set fill(value) {
  7795. if (this._fill != value) {
  7796. this._fill = value;
  7797. this.updateLayout();
  7798. }
  7799. }
  7800. get shrinkOnly() {
  7801. return this._shrinkOnly;
  7802. }
  7803. set shrinkOnly(value) {
  7804. if (this._shrinkOnly != value) {
  7805. this._shrinkOnly = value;
  7806. this.updateLayout();
  7807. }
  7808. }
  7809. get autoSize() {
  7810. return this._autoSize;
  7811. }
  7812. set autoSize(value) {
  7813. if (this._autoSize != value) {
  7814. this._autoSize = value;
  7815. this.updateLayout();
  7816. }
  7817. }
  7818. get playing() {
  7819. return this._playing;
  7820. }
  7821. set playing(value) {
  7822. if (this._playing != value) {
  7823. this._playing = value;
  7824. this.updateGear(5);
  7825. this.onChange();
  7826. }
  7827. }
  7828. get frame() {
  7829. return this._frame;
  7830. }
  7831. set frame(value) {
  7832. if (this._frame != value) {
  7833. this._frame = value;
  7834. this.updateGear(5);
  7835. this.onChange();
  7836. }
  7837. }
  7838. get animationName() {
  7839. return this._animationName;
  7840. }
  7841. set animationName(value) {
  7842. if (this._animationName != value) {
  7843. this._animationName = value;
  7844. this.onChange();
  7845. }
  7846. }
  7847. get skinName() {
  7848. return this._skinName;
  7849. }
  7850. set skinName(value) {
  7851. if (this._skinName != value) {
  7852. this._skinName = value;
  7853. this.onChange();
  7854. }
  7855. }
  7856. get loop() {
  7857. return this._loop;
  7858. }
  7859. set loop(value) {
  7860. if (this._loop != value) {
  7861. this._loop = value;
  7862. this.onChange();
  7863. }
  7864. }
  7865. get color() {
  7866. return this._color;
  7867. }
  7868. set color(value) {
  7869. if (this._color != value) {
  7870. this._color = value;
  7871. this.updateGear(4);
  7872. if (this._content)
  7873. fgui.ToolSet.setColorFilter(this._content, this._color);
  7874. }
  7875. }
  7876. get content() {
  7877. return;
  7878. }
  7879. loadContent() {
  7880. this.clearContent();
  7881. if (!this._url)
  7882. return;
  7883. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7884. this.loadFromPackage(this._url);
  7885. else
  7886. this.loadExternal();
  7887. }
  7888. loadFromPackage(itemURL) {
  7889. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7890. if (this._contentItem) {
  7891. this._contentItem = this._contentItem.getBranch();
  7892. this.sourceWidth = this._contentItem.width;
  7893. this.sourceHeight = this._contentItem.height;
  7894. this._contentItem = this._contentItem.getHighResolution();
  7895. if (this._autoSize)
  7896. this.setSize(this.sourceWidth, this.sourceHeight);
  7897. if (this._contentItem.type == fgui.PackageItemType.Spine || this._contentItem.type == fgui.PackageItemType.DragonBones)
  7898. this._contentItem.owner.getItemAssetAsync(this._contentItem, this.onLoaded.bind(this));
  7899. }
  7900. }
  7901. onLoaded(err, item) {
  7902. if (this._contentItem != item)
  7903. return;
  7904. if (err)
  7905. console.warn(err);
  7906. if (!this._contentItem.templet)
  7907. return;
  7908. this.setSkeleton(this._contentItem.templet.buildArmature(1), this._contentItem.skeletonAnchor);
  7909. }
  7910. setSkeleton(skeleton, anchor) {
  7911. this.url = null;
  7912. this._content = skeleton;
  7913. this._container.addChild(this._content);
  7914. this._content.pos(anchor.x, anchor.y);
  7915. fgui.ToolSet.setColorFilter(this._content, this._color);
  7916. this.onChange();
  7917. this.updateLayout();
  7918. }
  7919. onChange() {
  7920. if (!this._content)
  7921. return;
  7922. if (this._animationName) {
  7923. if (this._playing)
  7924. this._content.play(this._animationName, this._loop);
  7925. else
  7926. this._content.play(this._animationName, false, true, this._frame, this._frame);
  7927. }
  7928. else
  7929. this._content.stop();
  7930. if (this._skinName)
  7931. this._content.showSkinByName(this._skinName);
  7932. else
  7933. this._content.showSkinByIndex(0);
  7934. }
  7935. loadExternal() {
  7936. }
  7937. updateLayout() {
  7938. let cw = this.sourceWidth;
  7939. let ch = this.sourceHeight;
  7940. if (this._autoSize) {
  7941. this._updatingLayout = true;
  7942. if (cw == 0)
  7943. cw = 50;
  7944. if (ch == 0)
  7945. ch = 30;
  7946. this.setSize(cw, ch);
  7947. this._updatingLayout = false;
  7948. if (cw == this._width && ch == this._height) {
  7949. this._container.scale(1, 1);
  7950. this._container.pos(0, 0);
  7951. return;
  7952. }
  7953. }
  7954. var sx = 1, sy = 1;
  7955. if (this._fill != fgui.LoaderFillType.None) {
  7956. sx = this.width / this.sourceWidth;
  7957. sy = this.height / this.sourceHeight;
  7958. if (sx != 1 || sy != 1) {
  7959. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7960. sx = sy;
  7961. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7962. sy = sx;
  7963. else if (this._fill == fgui.LoaderFillType.Scale) {
  7964. if (sx > sy)
  7965. sx = sy;
  7966. else
  7967. sy = sx;
  7968. }
  7969. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7970. if (sx > sy)
  7971. sy = sx;
  7972. else
  7973. sx = sy;
  7974. }
  7975. if (this._shrinkOnly) {
  7976. if (sx > 1)
  7977. sx = 1;
  7978. if (sy > 1)
  7979. sy = 1;
  7980. }
  7981. cw = this.sourceWidth * sx;
  7982. ch = this.sourceHeight * sy;
  7983. }
  7984. }
  7985. this._container.scale(sx, sy);
  7986. var nx, ny;
  7987. if (this._align == fgui.AlignType.Center)
  7988. nx = Math.floor((this.width - cw) / 2);
  7989. else if (this._align == fgui.AlignType.Right)
  7990. nx = this.width - cw;
  7991. else
  7992. nx = 0;
  7993. if (this._verticalAlign == fgui.VertAlignType.Middle)
  7994. ny = Math.floor((this.height - ch) / 2);
  7995. else if (this._verticalAlign == fgui.VertAlignType.Bottom)
  7996. ny = this.height - ch;
  7997. else
  7998. ny = 0;
  7999. this._container.pos(nx, ny);
  8000. }
  8001. clearContent() {
  8002. this._contentItem = null;
  8003. if (this._content) {
  8004. this._container.removeChild(this._content);
  8005. this._content.destroy();
  8006. this._content = null;
  8007. }
  8008. }
  8009. handleSizeChanged() {
  8010. super.handleSizeChanged();
  8011. if (!this._updatingLayout)
  8012. this.updateLayout();
  8013. }
  8014. handleGrayedChanged() {
  8015. }
  8016. getProp(index) {
  8017. switch (index) {
  8018. case fgui.ObjectPropID.Color:
  8019. return this.color;
  8020. case fgui.ObjectPropID.Playing:
  8021. return this.playing;
  8022. case fgui.ObjectPropID.Frame:
  8023. return this.frame;
  8024. case fgui.ObjectPropID.TimeScale:
  8025. return 1;
  8026. default:
  8027. return super.getProp(index);
  8028. }
  8029. }
  8030. setProp(index, value) {
  8031. switch (index) {
  8032. case fgui.ObjectPropID.Color:
  8033. this.color = value;
  8034. break;
  8035. case fgui.ObjectPropID.Playing:
  8036. this.playing = value;
  8037. break;
  8038. case fgui.ObjectPropID.Frame:
  8039. this.frame = value;
  8040. break;
  8041. case fgui.ObjectPropID.TimeScale:
  8042. break;
  8043. case fgui.ObjectPropID.DeltaTime:
  8044. break;
  8045. default:
  8046. super.setProp(index, value);
  8047. break;
  8048. }
  8049. }
  8050. setup_beforeAdd(buffer, beginPos) {
  8051. super.setup_beforeAdd(buffer, beginPos);
  8052. buffer.seek(beginPos, 5);
  8053. this._url = buffer.readS();
  8054. this._align = buffer.readByte();
  8055. this._verticalAlign = buffer.readByte();
  8056. this._fill = buffer.readByte();
  8057. this._shrinkOnly = buffer.readBool();
  8058. this._autoSize = buffer.readBool();
  8059. this._animationName = buffer.readS();
  8060. this._skinName = buffer.readS();
  8061. this._playing = buffer.readBool();
  8062. this._frame = buffer.getInt32();
  8063. this._loop = buffer.readBool();
  8064. if (buffer.readBool())
  8065. this.color = buffer.readColorS();
  8066. if (this._url)
  8067. this.loadContent();
  8068. }
  8069. }
  8070. fgui.GLoader3D = GLoader3D;
  8071. })(fgui);
  8072. (function (fgui) {
  8073. class GMovieClip extends fgui.GObject {
  8074. constructor() {
  8075. super();
  8076. }
  8077. get color() {
  8078. return this._movieClip.color;
  8079. }
  8080. set color(value) {
  8081. this._movieClip.color = value;
  8082. }
  8083. createDisplayObject() {
  8084. this._displayObject = this._movieClip = new fgui.MovieClip();
  8085. this._movieClip.mouseEnabled = false;
  8086. this._displayObject["$owner"] = this;
  8087. }
  8088. get playing() {
  8089. return this._movieClip.playing;
  8090. }
  8091. set playing(value) {
  8092. if (this._movieClip.playing != value) {
  8093. this._movieClip.playing = value;
  8094. this.updateGear(5);
  8095. }
  8096. }
  8097. get frame() {
  8098. return this._movieClip.frame;
  8099. }
  8100. set frame(value) {
  8101. if (this._movieClip.frame != value) {
  8102. this._movieClip.frame = value;
  8103. this.updateGear(5);
  8104. }
  8105. }
  8106. get timeScale() {
  8107. return this._movieClip.timeScale;
  8108. }
  8109. set timeScale(value) {
  8110. this._movieClip.timeScale = value;
  8111. }
  8112. rewind() {
  8113. this._movieClip.rewind();
  8114. }
  8115. syncStatus(anotherMc) {
  8116. this._movieClip.syncStatus(anotherMc._movieClip);
  8117. }
  8118. advance(timeInMiniseconds) {
  8119. this._movieClip.advance(timeInMiniseconds);
  8120. }
  8121. //从start帧开始,播放到end帧(-1表示结尾),重复times次(0表示无限循环),循环结束后,停止在endAt帧(-1表示参数end)
  8122. setPlaySettings(start, end, times, endAt, endHandler) {
  8123. this._movieClip.setPlaySettings(start, end, times, endAt, endHandler);
  8124. }
  8125. getProp(index) {
  8126. switch (index) {
  8127. case fgui.ObjectPropID.Color:
  8128. return this.color;
  8129. case fgui.ObjectPropID.Playing:
  8130. return this.playing;
  8131. case fgui.ObjectPropID.Frame:
  8132. return this.frame;
  8133. case fgui.ObjectPropID.TimeScale:
  8134. return this.timeScale;
  8135. default:
  8136. return super.getProp(index);
  8137. }
  8138. }
  8139. setProp(index, value) {
  8140. switch (index) {
  8141. case fgui.ObjectPropID.Color:
  8142. this.color = value;
  8143. break;
  8144. case fgui.ObjectPropID.Playing:
  8145. this.playing = value;
  8146. break;
  8147. case fgui.ObjectPropID.Frame:
  8148. this.frame = value;
  8149. break;
  8150. case fgui.ObjectPropID.TimeScale:
  8151. this.timeScale = value;
  8152. break;
  8153. case fgui.ObjectPropID.DeltaTime:
  8154. this.advance(value);
  8155. break;
  8156. default:
  8157. super.setProp(index, value);
  8158. break;
  8159. }
  8160. }
  8161. constructFromResource() {
  8162. var displayItem = this.packageItem.getBranch();
  8163. this.sourceWidth = displayItem.width;
  8164. this.sourceHeight = displayItem.height;
  8165. this.initWidth = this.sourceWidth;
  8166. this.initHeight = this.sourceHeight;
  8167. this.setSize(this.sourceWidth, this.sourceHeight);
  8168. displayItem = displayItem.getHighResolution();
  8169. displayItem.load();
  8170. this._movieClip.interval = displayItem.interval;
  8171. this._movieClip.swing = displayItem.swing;
  8172. this._movieClip.repeatDelay = displayItem.repeatDelay;
  8173. this._movieClip.frames = displayItem.frames;
  8174. }
  8175. setup_beforeAdd(buffer, beginPos) {
  8176. super.setup_beforeAdd(buffer, beginPos);
  8177. buffer.seek(beginPos, 5);
  8178. if (buffer.readBool())
  8179. this.color = buffer.readColorS();
  8180. buffer.readByte(); //flip
  8181. this._movieClip.frame = buffer.getInt32();
  8182. this._movieClip.playing = buffer.readBool();
  8183. }
  8184. }
  8185. fgui.GMovieClip = GMovieClip;
  8186. })(fgui);
  8187. (function (fgui) {
  8188. class GProgressBar extends fgui.GComponent {
  8189. constructor() {
  8190. super();
  8191. this._min = 0;
  8192. this._max = 0;
  8193. this._value = 0;
  8194. this._barMaxWidth = 0;
  8195. this._barMaxHeight = 0;
  8196. this._barMaxWidthDelta = 0;
  8197. this._barMaxHeightDelta = 0;
  8198. this._barStartX = 0;
  8199. this._barStartY = 0;
  8200. this._titleType = fgui.ProgressTitleType.Percent;
  8201. this._value = 50;
  8202. this._max = 100;
  8203. }
  8204. get titleType() {
  8205. return this._titleType;
  8206. }
  8207. set titleType(value) {
  8208. if (this._titleType != value) {
  8209. this._titleType = value;
  8210. this.update(value);
  8211. }
  8212. }
  8213. get min() {
  8214. return this._min;
  8215. }
  8216. set min(value) {
  8217. if (this._min != value) {
  8218. this._min = value;
  8219. this.update(this._value);
  8220. }
  8221. }
  8222. get max() {
  8223. return this._max;
  8224. }
  8225. set max(value) {
  8226. if (this._max != value) {
  8227. this._max = value;
  8228. this.update(this._value);
  8229. }
  8230. }
  8231. get value() {
  8232. return this._value;
  8233. }
  8234. set value(value) {
  8235. if (this._value != value) {
  8236. fgui.GTween.kill(this, false, this.update);
  8237. this._value = value;
  8238. this.update(value);
  8239. }
  8240. }
  8241. tweenValue(value, duration) {
  8242. var oldValule;
  8243. var tweener = fgui.GTween.getTween(this, this.update);
  8244. if (tweener) {
  8245. oldValule = tweener.value.x;
  8246. tweener.kill();
  8247. }
  8248. else
  8249. oldValule = this._value;
  8250. this._value = value;
  8251. return fgui.GTween.to(oldValule, this._value, duration).setTarget(this, this.update).setEase(fgui.EaseType.Linear);
  8252. }
  8253. update(newValue) {
  8254. var percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  8255. if (this._titleObject) {
  8256. switch (this._titleType) {
  8257. case fgui.ProgressTitleType.Percent:
  8258. this._titleObject.text = Math.floor(percent * 100) + "%";
  8259. break;
  8260. case fgui.ProgressTitleType.ValueAndMax:
  8261. this._titleObject.text = Math.floor(newValue) + "/" + Math.floor(this._max);
  8262. break;
  8263. case fgui.ProgressTitleType.Value:
  8264. this._titleObject.text = "" + Math.floor(newValue);
  8265. break;
  8266. case fgui.ProgressTitleType.Max:
  8267. this._titleObject.text = "" + Math.floor(this._max);
  8268. break;
  8269. }
  8270. }
  8271. var fullWidth = this.width - this._barMaxWidthDelta;
  8272. var fullHeight = this.height - this._barMaxHeightDelta;
  8273. if (!this._reverse) {
  8274. if (this._barObjectH) {
  8275. if (!this.setFillAmount(this._barObjectH, percent))
  8276. this._barObjectH.width = Math.round(fullWidth * percent);
  8277. }
  8278. if (this._barObjectV) {
  8279. if (!this.setFillAmount(this._barObjectV, percent))
  8280. this._barObjectV.height = Math.round(fullHeight * percent);
  8281. }
  8282. }
  8283. else {
  8284. if (this._barObjectH) {
  8285. if (!this.setFillAmount(this._barObjectH, 1 - percent)) {
  8286. this._barObjectH.width = Math.round(fullWidth * percent);
  8287. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  8288. }
  8289. }
  8290. if (this._barObjectV) {
  8291. if (!this.setFillAmount(this._barObjectV, 1 - percent)) {
  8292. this._barObjectV.height = Math.round(fullHeight * percent);
  8293. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  8294. }
  8295. }
  8296. }
  8297. if (this._aniObject)
  8298. this._aniObject.setProp(fgui.ObjectPropID.Frame, Math.floor(percent * 100));
  8299. }
  8300. setFillAmount(bar, percent) {
  8301. if (((bar instanceof fgui.GImage) || (bar instanceof fgui.GLoader)) && bar.fillMethod != fgui.FillMethod.None) {
  8302. bar.fillAmount = percent;
  8303. return true;
  8304. }
  8305. else
  8306. return false;
  8307. }
  8308. constructExtension(buffer) {
  8309. buffer.seek(0, 6);
  8310. this._titleType = buffer.readByte();
  8311. this._reverse = buffer.readBool();
  8312. this._titleObject = this.getChild("title");
  8313. this._barObjectH = this.getChild("bar");
  8314. this._barObjectV = this.getChild("bar_v");
  8315. this._aniObject = this.getChild("ani");
  8316. if (this._barObjectH) {
  8317. this._barMaxWidth = this._barObjectH.width;
  8318. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  8319. this._barStartX = this._barObjectH.x;
  8320. }
  8321. if (this._barObjectV) {
  8322. this._barMaxHeight = this._barObjectV.height;
  8323. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  8324. this._barStartY = this._barObjectV.y;
  8325. }
  8326. }
  8327. handleSizeChanged() {
  8328. super.handleSizeChanged();
  8329. if (this._barObjectH)
  8330. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  8331. if (this._barObjectV)
  8332. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  8333. if (!this._underConstruct)
  8334. this.update(this._value);
  8335. }
  8336. setup_afterAdd(buffer, beginPos) {
  8337. super.setup_afterAdd(buffer, beginPos);
  8338. if (!buffer.seek(beginPos, 6)) {
  8339. this.update(this._value);
  8340. return;
  8341. }
  8342. if (buffer.readByte() != this.packageItem.objectType) {
  8343. this.update(this._value);
  8344. return;
  8345. }
  8346. this._value = buffer.getInt32();
  8347. this._max = buffer.getInt32();
  8348. if (buffer.version >= 2)
  8349. this._min = buffer.getInt32();
  8350. this.update(this._value);
  8351. }
  8352. }
  8353. fgui.GProgressBar = GProgressBar;
  8354. })(fgui);
  8355. (function (fgui) {
  8356. class GRichTextField extends fgui.GTextField {
  8357. constructor() {
  8358. super();
  8359. this._text = "";
  8360. }
  8361. createDisplayObject() {
  8362. this._displayObject = this._div = new Laya.HTMLDivElement();
  8363. this._displayObject.mouseEnabled = true;
  8364. this._displayObject["$owner"] = this;
  8365. }
  8366. get div() {
  8367. return this._div;
  8368. }
  8369. set text(value) {
  8370. this._text = value;
  8371. var text2 = this._text;
  8372. if (this._templateVars)
  8373. text2 = this.parseTemplate(text2);
  8374. try {
  8375. this._div.size(this._width, this._height);
  8376. if (this._ubbEnabled)
  8377. this._div.innerHTML = fgui.UBBParser.inst.parse(text2);
  8378. else
  8379. this._div.innerHTML = text2;
  8380. if (this._widthAutoSize || this._heightAutoSize) {
  8381. var w, h = 0;
  8382. if (this._widthAutoSize) {
  8383. w = this._div.contextWidth;
  8384. if (w > 0)
  8385. w += 8;
  8386. }
  8387. else
  8388. w = this._width;
  8389. if (this._heightAutoSize)
  8390. h = this._div.contextHeight;
  8391. else
  8392. h = this._height;
  8393. this._updatingSize = true;
  8394. this.setSize(w, h);
  8395. this._updatingSize = false;
  8396. }
  8397. }
  8398. catch (err) {
  8399. console.log("laya reports html error:" + err);
  8400. }
  8401. }
  8402. get text() {
  8403. return this._text;
  8404. }
  8405. get font() {
  8406. return this._div.style.font;
  8407. }
  8408. set font(value) {
  8409. if (value)
  8410. this._div.style.font = value;
  8411. else
  8412. this._div.style.font = fgui.UIConfig.defaultFont;
  8413. }
  8414. get fontSize() {
  8415. return this._div.style.fontSize;
  8416. }
  8417. set fontSize(value) {
  8418. this._div.style.fontSize = value;
  8419. }
  8420. get color() {
  8421. return this._div.style.color;
  8422. }
  8423. set color(value) {
  8424. if (this._div.style.color != value) {
  8425. this._div.style.color = value;
  8426. this.refresh();
  8427. this.updateGear(4);
  8428. }
  8429. }
  8430. get align() {
  8431. return this._div.style.align;
  8432. }
  8433. set align(value) {
  8434. if (this._div.style.align != value) {
  8435. this._div.style.align = value;
  8436. this.refresh();
  8437. }
  8438. }
  8439. get valign() {
  8440. return this._div.style.valign;
  8441. }
  8442. set valign(value) {
  8443. if (this._div.style.valign != value) {
  8444. this._div.style.valign = value;
  8445. this.refresh();
  8446. }
  8447. }
  8448. get leading() {
  8449. return this._div.style.leading;
  8450. }
  8451. set leading(value) {
  8452. if (this._div.style.leading != value) {
  8453. this._div.style.leading = value;
  8454. this.refresh();
  8455. }
  8456. }
  8457. get bold() {
  8458. return this._div.style.bold;
  8459. }
  8460. set bold(value) {
  8461. if (this._div.style.bold != value) {
  8462. this._div.style.bold = value;
  8463. this.refresh();
  8464. }
  8465. }
  8466. get italic() {
  8467. return this._div.style.italic;
  8468. }
  8469. set italic(value) {
  8470. if (this._div.style.italic != value) {
  8471. this._div.style.italic = value;
  8472. this.refresh();
  8473. }
  8474. }
  8475. get stroke() {
  8476. return this._div.style.stroke;
  8477. }
  8478. set stroke(value) {
  8479. if (this._div.style.stroke != value) {
  8480. this._div.style.stroke = value;
  8481. this.refresh();
  8482. }
  8483. }
  8484. get strokeColor() {
  8485. return this._div.style.strokeColor;
  8486. }
  8487. set strokeColor(value) {
  8488. if (this._div.style.strokeColor != value) {
  8489. this._div.style.strokeColor = value;
  8490. this.refresh();
  8491. this.updateGear(4);
  8492. }
  8493. }
  8494. set ubbEnabled(value) {
  8495. this._ubbEnabled = value;
  8496. }
  8497. get ubbEnabled() {
  8498. return this._ubbEnabled;
  8499. }
  8500. get textWidth() {
  8501. var w = this._div.contextWidth;
  8502. if (w > 0)
  8503. w += 8;
  8504. return w;
  8505. }
  8506. refresh() {
  8507. if (this._text.length > 0 && this._div._refresh)
  8508. this._div._refresh();
  8509. }
  8510. updateAutoSize() {
  8511. this._div.style.wordWrap = !this._widthAutoSize;
  8512. }
  8513. handleSizeChanged() {
  8514. if (this._updatingSize)
  8515. return;
  8516. this._div.size(this._width, this._height);
  8517. this._div.style.width = this._width;
  8518. this._div.style.height = this._height;
  8519. }
  8520. }
  8521. fgui.GRichTextField = GRichTextField;
  8522. })(fgui);
  8523. (function (fgui) {
  8524. class GRoot extends fgui.GComponent {
  8525. constructor() {
  8526. super();
  8527. if (!GRoot._inst)
  8528. GRoot._inst = this;
  8529. this.opaque = false;
  8530. this._popupStack = [];
  8531. this._justClosedPopups = [];
  8532. this.displayObject.once(Laya.Event.DISPLAY, this, this.__addedToStage);
  8533. }
  8534. static get inst() {
  8535. if (!GRoot._inst)
  8536. new GRoot();
  8537. return GRoot._inst;
  8538. }
  8539. showWindow(win) {
  8540. this.addChild(win);
  8541. win.requestFocus();
  8542. if (win.x > this.width)
  8543. win.x = this.width - win.width;
  8544. else if (win.x + win.width < 0)
  8545. win.x = 0;
  8546. if (win.y > this.height)
  8547. win.y = this.height - win.height;
  8548. else if (win.y + win.height < 0)
  8549. win.y = 0;
  8550. this.adjustModalLayer();
  8551. }
  8552. hideWindow(win) {
  8553. win.hide();
  8554. }
  8555. hideWindowImmediately(win) {
  8556. if (win.parent == this)
  8557. this.removeChild(win);
  8558. this.adjustModalLayer();
  8559. }
  8560. bringToFront(win) {
  8561. var cnt = this.numChildren;
  8562. var i;
  8563. if (this._modalLayer.parent && !win.modal)
  8564. i = this.getChildIndex(this._modalLayer) - 1;
  8565. else
  8566. i = cnt - 1;
  8567. for (; i >= 0; i--) {
  8568. var g = this.getChildAt(i);
  8569. if (g == win)
  8570. return;
  8571. if (g instanceof fgui.Window)
  8572. break;
  8573. }
  8574. if (i >= 0)
  8575. this.setChildIndex(win, i);
  8576. }
  8577. showModalWait(msg) {
  8578. if (fgui.UIConfig.globalModalWaiting != null) {
  8579. if (this._modalWaitPane == null)
  8580. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.globalModalWaiting);
  8581. this._modalWaitPane.setSize(this.width, this.height);
  8582. this._modalWaitPane.addRelation(this, fgui.RelationType.Size);
  8583. this.addChild(this._modalWaitPane);
  8584. this._modalWaitPane.text = msg;
  8585. }
  8586. }
  8587. closeModalWait() {
  8588. if (this._modalWaitPane && this._modalWaitPane.parent)
  8589. this.removeChild(this._modalWaitPane);
  8590. }
  8591. closeAllExceptModals() {
  8592. var arr = this._children.slice();
  8593. var cnt = arr.length;
  8594. for (var i = 0; i < cnt; i++) {
  8595. var g = arr[i];
  8596. if ((g instanceof fgui.Window) && !g.modal)
  8597. g.hide();
  8598. }
  8599. }
  8600. closeAllWindows() {
  8601. var arr = this._children.slice();
  8602. var cnt = arr.length;
  8603. for (var i = 0; i < cnt; i++) {
  8604. var g = arr[i];
  8605. if (g instanceof fgui.Window)
  8606. g.hide();
  8607. }
  8608. }
  8609. getTopWindow() {
  8610. var cnt = this.numChildren;
  8611. for (var i = cnt - 1; i >= 0; i--) {
  8612. var g = this.getChildAt(i);
  8613. if (g instanceof fgui.Window) {
  8614. return g;
  8615. }
  8616. }
  8617. return null;
  8618. }
  8619. get modalLayer() {
  8620. return this._modalLayer;
  8621. }
  8622. get hasModalWindow() {
  8623. return this._modalLayer.parent != null;
  8624. }
  8625. get modalWaiting() {
  8626. return this._modalWaitPane && this._modalWaitPane.inContainer;
  8627. }
  8628. showPopup(popup, target, dir) {
  8629. if (this._popupStack.length > 0) {
  8630. var k = this._popupStack.indexOf(popup);
  8631. if (k != -1) {
  8632. for (var i = this._popupStack.length - 1; i >= k; i--)
  8633. this.removeChild(this._popupStack.pop());
  8634. }
  8635. }
  8636. this._popupStack.push(popup);
  8637. if (target) {
  8638. var p = target;
  8639. while (p) {
  8640. if (p.parent == this) {
  8641. if (popup.sortingOrder < p.sortingOrder) {
  8642. popup.sortingOrder = p.sortingOrder;
  8643. }
  8644. break;
  8645. }
  8646. p = p.parent;
  8647. }
  8648. }
  8649. this.addChild(popup);
  8650. this.adjustModalLayer();
  8651. var pos;
  8652. var sizeW = 0, sizeH = 0;
  8653. if (target) {
  8654. pos = target.localToGlobal();
  8655. sizeW = target.width;
  8656. sizeH = target.height;
  8657. }
  8658. else {
  8659. pos = this.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY);
  8660. }
  8661. var xx, yy;
  8662. xx = pos.x;
  8663. if (xx + popup.width > this.width)
  8664. xx = xx + sizeW - popup.width;
  8665. yy = pos.y + sizeH;
  8666. if (((dir === undefined || dir === fgui.PopupDirection.Auto) && pos.y + popup.height > this.height)
  8667. || dir === false || dir === fgui.PopupDirection.Up) {
  8668. yy = pos.y - popup.height - 1;
  8669. if (yy < 0) {
  8670. yy = 0;
  8671. xx += sizeW / 2;
  8672. }
  8673. }
  8674. popup.x = xx;
  8675. popup.y = yy;
  8676. }
  8677. togglePopup(popup, target, dir) {
  8678. if (this._justClosedPopups.indexOf(popup) != -1)
  8679. return;
  8680. this.showPopup(popup, target, dir);
  8681. }
  8682. hidePopup(popup) {
  8683. if (popup) {
  8684. var k = this._popupStack.indexOf(popup);
  8685. if (k != -1) {
  8686. for (var i = this._popupStack.length - 1; i >= k; i--)
  8687. this.closePopup(this._popupStack.pop());
  8688. }
  8689. }
  8690. else {
  8691. var cnt = this._popupStack.length;
  8692. for (i = cnt - 1; i >= 0; i--)
  8693. this.closePopup(this._popupStack[i]);
  8694. this._popupStack.length = 0;
  8695. }
  8696. }
  8697. get hasAnyPopup() {
  8698. return this._popupStack.length != 0;
  8699. }
  8700. closePopup(target) {
  8701. if (target.parent) {
  8702. if (target instanceof fgui.Window)
  8703. target.hide();
  8704. else
  8705. this.removeChild(target);
  8706. }
  8707. }
  8708. showTooltips(msg) {
  8709. if (this._defaultTooltipWin == null) {
  8710. var resourceURL = fgui.UIConfig.tooltipsWin;
  8711. if (!resourceURL) {
  8712. Laya.Log.print("UIConfig.tooltipsWin not defined");
  8713. return;
  8714. }
  8715. this._defaultTooltipWin = fgui.UIPackage.createObjectFromURL(resourceURL);
  8716. }
  8717. this._defaultTooltipWin.text = msg;
  8718. this.showTooltipsWin(this._defaultTooltipWin);
  8719. }
  8720. showTooltipsWin(tooltipWin, position) {
  8721. this.hideTooltips();
  8722. this._tooltipWin = tooltipWin;
  8723. var xx = 0;
  8724. var yy = 0;
  8725. if (position == null) {
  8726. xx = Laya.stage.mouseX + 10;
  8727. yy = Laya.stage.mouseY + 20;
  8728. }
  8729. else {
  8730. xx = position.x;
  8731. yy = position.y;
  8732. }
  8733. var pt = this.globalToLocal(xx, yy);
  8734. xx = pt.x;
  8735. yy = pt.y;
  8736. if (xx + this._tooltipWin.width > this.width) {
  8737. xx = xx - this._tooltipWin.width - 1;
  8738. if (xx < 0)
  8739. xx = 10;
  8740. }
  8741. if (yy + this._tooltipWin.height > this.height) {
  8742. yy = yy - this._tooltipWin.height - 1;
  8743. if (xx - this._tooltipWin.width - 1 > 0)
  8744. xx = xx - this._tooltipWin.width - 1;
  8745. if (yy < 0)
  8746. yy = 10;
  8747. }
  8748. this._tooltipWin.x = xx;
  8749. this._tooltipWin.y = yy;
  8750. this.addChild(this._tooltipWin);
  8751. }
  8752. hideTooltips() {
  8753. if (this._tooltipWin) {
  8754. if (this._tooltipWin.parent)
  8755. this.removeChild(this._tooltipWin);
  8756. this._tooltipWin = null;
  8757. }
  8758. }
  8759. get focus() {
  8760. return null;
  8761. }
  8762. set focus(value) {
  8763. this.setFocus(value);
  8764. }
  8765. setFocus(value) {
  8766. }
  8767. get volumeScale() {
  8768. return Laya.SoundManager.soundVolume;
  8769. }
  8770. set volumeScale(value) {
  8771. Laya.SoundManager.soundVolume = value;
  8772. }
  8773. playOneShotSound(url, volumeScale) {
  8774. if (fgui.ToolSet.startsWith(url, "ui://"))
  8775. return;
  8776. Laya.SoundManager.playSound(url);
  8777. }
  8778. adjustModalLayer() {
  8779. var cnt = this.numChildren;
  8780. if (this._modalWaitPane != null && this._modalWaitPane.parent != null)
  8781. this.setChildIndex(this._modalWaitPane, cnt - 1);
  8782. for (var i = cnt - 1; i >= 0; i--) {
  8783. var g = this.getChildAt(i);
  8784. if ((g instanceof fgui.Window) && g.modal) {
  8785. if (this._modalLayer.parent == null)
  8786. this.addChildAt(this._modalLayer, i);
  8787. else
  8788. this.setChildIndexBefore(this._modalLayer, i);
  8789. return;
  8790. }
  8791. }
  8792. if (this._modalLayer.parent)
  8793. this.removeChild(this._modalLayer);
  8794. }
  8795. __addedToStage() {
  8796. Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.__stageMouseDown);
  8797. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.__stageMouseUp);
  8798. this._modalLayer = new fgui.GGraph();
  8799. this._modalLayer.setSize(this.width, this.height);
  8800. this._modalLayer.drawRect(0, null, fgui.UIConfig.modalLayerColor);
  8801. this._modalLayer.addRelation(this, fgui.RelationType.Size);
  8802. this.displayObject.stage.on(Laya.Event.RESIZE, this, this.__winResize);
  8803. this.__winResize();
  8804. }
  8805. checkPopups(clickTarget) {
  8806. if (this._checkPopups)
  8807. return;
  8808. this._checkPopups = true;
  8809. this._justClosedPopups.length = 0;
  8810. if (this._popupStack.length > 0) {
  8811. var mc = clickTarget;
  8812. while (mc != this.displayObject.stage && mc) {
  8813. if (mc["$owner"]) {
  8814. var pindex = this._popupStack.indexOf(mc["$owner"]);
  8815. if (pindex != -1) {
  8816. for (var i = this._popupStack.length - 1; i > pindex; i--) {
  8817. var popup = this._popupStack.pop();
  8818. this.closePopup(popup);
  8819. this._justClosedPopups.push(popup);
  8820. }
  8821. return;
  8822. }
  8823. }
  8824. mc = mc.parent;
  8825. }
  8826. var cnt = this._popupStack.length;
  8827. for (i = cnt - 1; i >= 0; i--) {
  8828. popup = this._popupStack[i];
  8829. this.closePopup(popup);
  8830. this._justClosedPopups.push(popup);
  8831. }
  8832. this._popupStack.length = 0;
  8833. }
  8834. }
  8835. __stageMouseDown(evt) {
  8836. if (this._tooltipWin)
  8837. this.hideTooltips();
  8838. this.checkPopups(evt.target);
  8839. }
  8840. __stageMouseUp() {
  8841. this._checkPopups = false;
  8842. }
  8843. __winResize() {
  8844. this.setSize(Laya.stage.width, Laya.stage.height);
  8845. this.updateContentScaleLevel();
  8846. }
  8847. updateContentScaleLevel() {
  8848. var mat = Laya.stage._canvasTransform;
  8849. var ss = Math.max(mat.getScaleX(), mat.getScaleY());
  8850. if (ss >= 3.5)
  8851. GRoot.contentScaleLevel = 3; //x4
  8852. else if (ss >= 2.5)
  8853. GRoot.contentScaleLevel = 2; //x3
  8854. else if (ss >= 1.5)
  8855. GRoot.contentScaleLevel = 1; //x2
  8856. else
  8857. GRoot.contentScaleLevel = 0;
  8858. }
  8859. }
  8860. GRoot.contentScaleLevel = 0;
  8861. fgui.GRoot = GRoot;
  8862. })(fgui);
  8863. (function (fgui) {
  8864. class GScrollBar extends fgui.GComponent {
  8865. constructor() {
  8866. super();
  8867. this._dragOffset = new Laya.Point();
  8868. this._scrollPerc = 0;
  8869. }
  8870. setScrollPane(target, vertical) {
  8871. this._target = target;
  8872. this._vertical = vertical;
  8873. }
  8874. setDisplayPerc(value) {
  8875. if (this._vertical) {
  8876. if (!this._fixedGripSize)
  8877. this._grip.height = Math.floor(value * this._bar.height);
  8878. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  8879. }
  8880. else {
  8881. if (!this._fixedGripSize)
  8882. this._grip.width = Math.floor(value * this._bar.width);
  8883. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  8884. }
  8885. this._grip.visible = value != 0 && value != 1;
  8886. }
  8887. setScrollPerc(val) {
  8888. this._scrollPerc = val;
  8889. if (this._vertical)
  8890. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  8891. else
  8892. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  8893. }
  8894. get minSize() {
  8895. if (this._vertical)
  8896. return (this._arrowButton1 ? this._arrowButton1.height : 0) + (this._arrowButton2 ? this._arrowButton2.height : 0);
  8897. else
  8898. return (this._arrowButton1 ? this._arrowButton1.width : 0) + (this._arrowButton2 ? this._arrowButton2.width : 0);
  8899. }
  8900. get gripDragging() {
  8901. return this._gripDragging;
  8902. }
  8903. constructExtension(buffer) {
  8904. buffer.seek(0, 6);
  8905. this._fixedGripSize = buffer.readBool();
  8906. this._grip = this.getChild("grip");
  8907. if (!this._grip) {
  8908. Laya.Log.print("需要定义grip");
  8909. return;
  8910. }
  8911. this._bar = this.getChild("bar");
  8912. if (!this._bar) {
  8913. Laya.Log.print("需要定义bar");
  8914. return;
  8915. }
  8916. this._arrowButton1 = this.getChild("arrow1");
  8917. this._arrowButton2 = this.getChild("arrow2");
  8918. this._grip.on(Laya.Event.MOUSE_DOWN, this, this.__gripMouseDown);
  8919. if (this._arrowButton1)
  8920. this._arrowButton1.on(Laya.Event.MOUSE_DOWN, this, this.__arrowButton1Click);
  8921. if (this._arrowButton2)
  8922. this._arrowButton2.on(Laya.Event.MOUSE_DOWN, this, this.__arrowButton2Click);
  8923. this.on(Laya.Event.MOUSE_DOWN, this, this.__barMouseDown);
  8924. }
  8925. __gripMouseDown(evt) {
  8926. evt.stopPropagation();
  8927. this._gripDragging = true;
  8928. this._target.updateScrollBarVisible();
  8929. Laya.stage.on(Laya.Event.MOUSE_MOVE, this, this.__gripMouseMove);
  8930. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.__gripMouseUp);
  8931. this.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY, this._dragOffset);
  8932. this._dragOffset.x -= this._grip.x;
  8933. this._dragOffset.y -= this._grip.y;
  8934. }
  8935. __gripMouseMove() {
  8936. if (!this.onStage)
  8937. return;
  8938. var pt = this.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY, s_vec2);
  8939. if (this._vertical) {
  8940. var curY = pt.y - this._dragOffset.y;
  8941. this._target.setPercY((curY - this._bar.y) / (this._bar.height - this._grip.height), false);
  8942. }
  8943. else {
  8944. var curX = pt.x - this._dragOffset.x;
  8945. this._target.setPercX((curX - this._bar.x) / (this._bar.width - this._grip.width), false);
  8946. }
  8947. }
  8948. __gripMouseUp(evt) {
  8949. if (!this.onStage)
  8950. return;
  8951. Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.__gripMouseMove);
  8952. Laya.stage.off(Laya.Event.MOUSE_UP, this, this.__gripMouseUp);
  8953. this._gripDragging = false;
  8954. this._target.updateScrollBarVisible();
  8955. }
  8956. __arrowButton1Click(evt) {
  8957. evt.stopPropagation();
  8958. if (this._vertical)
  8959. this._target.scrollUp();
  8960. else
  8961. this._target.scrollLeft();
  8962. }
  8963. __arrowButton2Click(evt) {
  8964. evt.stopPropagation();
  8965. if (this._vertical)
  8966. this._target.scrollDown();
  8967. else
  8968. this._target.scrollRight();
  8969. }
  8970. __barMouseDown(evt) {
  8971. var pt = this._grip.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY, s_vec2);
  8972. if (this._vertical) {
  8973. if (pt.y < 0)
  8974. this._target.scrollUp(4);
  8975. else
  8976. this._target.scrollDown(4);
  8977. }
  8978. else {
  8979. if (pt.x < 0)
  8980. this._target.scrollLeft(4);
  8981. else
  8982. this._target.scrollRight(4);
  8983. }
  8984. }
  8985. }
  8986. fgui.GScrollBar = GScrollBar;
  8987. var s_vec2 = new Laya.Point();
  8988. })(fgui);
  8989. (function (fgui) {
  8990. class GSlider extends fgui.GComponent {
  8991. constructor() {
  8992. super();
  8993. this._min = 0;
  8994. this._max = 0;
  8995. this._value = 0;
  8996. this._barMaxWidth = 0;
  8997. this._barMaxHeight = 0;
  8998. this._barMaxWidthDelta = 0;
  8999. this._barMaxHeightDelta = 0;
  9000. this._clickPercent = 0;
  9001. this._barStartX = 0;
  9002. this._barStartY = 0;
  9003. this.changeOnClick = true;
  9004. /**是否可拖动开关**/
  9005. this.canDrag = true;
  9006. this._titleType = fgui.ProgressTitleType.Percent;
  9007. this._value = 50;
  9008. this._max = 100;
  9009. this._clickPos = new Laya.Point();
  9010. }
  9011. get titleType() {
  9012. return this._titleType;
  9013. }
  9014. set titleType(value) {
  9015. this._titleType = value;
  9016. }
  9017. get wholeNumbers() {
  9018. return this._wholeNumbers;
  9019. }
  9020. set wholeNumbers(value) {
  9021. if (this._wholeNumbers != value) {
  9022. this._wholeNumbers = value;
  9023. this.update();
  9024. }
  9025. }
  9026. get min() {
  9027. return this._min;
  9028. }
  9029. set min(value) {
  9030. if (this._min != value) {
  9031. this._min = value;
  9032. this.update();
  9033. }
  9034. }
  9035. get max() {
  9036. return this._max;
  9037. }
  9038. set max(value) {
  9039. if (this._max != value) {
  9040. this._max = value;
  9041. this.update();
  9042. }
  9043. }
  9044. get value() {
  9045. return this._value;
  9046. }
  9047. set value(value) {
  9048. if (this._value != value) {
  9049. this._value = value;
  9050. this.update();
  9051. }
  9052. }
  9053. update() {
  9054. this.updateWithPercent((this._value - this._min) / (this._max - this._min));
  9055. }
  9056. updateWithPercent(percent, evt) {
  9057. percent = fgui.ToolSet.clamp01(percent);
  9058. if (evt) {
  9059. var newValue = fgui.ToolSet.clamp(this._min + (this._max - this._min) * percent, this._min, this._max);
  9060. if (this._wholeNumbers) {
  9061. newValue = Math.round(newValue);
  9062. percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  9063. }
  9064. if (newValue != this._value) {
  9065. this._value = newValue;
  9066. fgui.Events.dispatch(fgui.Events.STATE_CHANGED, this.displayObject, evt);
  9067. }
  9068. }
  9069. if (this._titleObject) {
  9070. switch (this._titleType) {
  9071. case fgui.ProgressTitleType.Percent:
  9072. this._titleObject.text = Math.floor(percent * 100) + "%";
  9073. break;
  9074. case fgui.ProgressTitleType.ValueAndMax:
  9075. this._titleObject.text = this._value + "/" + this._max;
  9076. break;
  9077. case fgui.ProgressTitleType.Value:
  9078. this._titleObject.text = "" + this._value;
  9079. break;
  9080. case fgui.ProgressTitleType.Max:
  9081. this._titleObject.text = "" + this._max;
  9082. break;
  9083. }
  9084. }
  9085. var fullWidth = this.width - this._barMaxWidthDelta;
  9086. var fullHeight = this.height - this._barMaxHeightDelta;
  9087. if (!this._reverse) {
  9088. if (this._barObjectH)
  9089. this._barObjectH.width = Math.round(fullWidth * percent);
  9090. if (this._barObjectV)
  9091. this._barObjectV.height = Math.round(fullHeight * percent);
  9092. }
  9093. else {
  9094. if (this._barObjectH) {
  9095. this._barObjectH.width = Math.round(fullWidth * percent);
  9096. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  9097. }
  9098. if (this._barObjectV) {
  9099. this._barObjectV.height = Math.round(fullHeight * percent);
  9100. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  9101. }
  9102. }
  9103. }
  9104. constructExtension(buffer) {
  9105. buffer.seek(0, 6);
  9106. this._titleType = buffer.readByte();
  9107. this._reverse = buffer.readBool();
  9108. if (buffer.version >= 2) {
  9109. this._wholeNumbers = buffer.readBool();
  9110. this.changeOnClick = buffer.readBool();
  9111. }
  9112. this._titleObject = this.getChild("title");
  9113. this._barObjectH = this.getChild("bar");
  9114. this._barObjectV = this.getChild("bar_v");
  9115. this._gripObject = this.getChild("grip");
  9116. if (this._barObjectH) {
  9117. this._barMaxWidth = this._barObjectH.width;
  9118. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  9119. this._barStartX = this._barObjectH.x;
  9120. }
  9121. if (this._barObjectV) {
  9122. this._barMaxHeight = this._barObjectV.height;
  9123. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  9124. this._barStartY = this._barObjectV.y;
  9125. }
  9126. if (this._gripObject) {
  9127. this._gripObject.on(Laya.Event.MOUSE_DOWN, this, this.__gripMouseDown);
  9128. }
  9129. this.displayObject.on(Laya.Event.MOUSE_DOWN, this, this.__barMouseDown);
  9130. }
  9131. handleSizeChanged() {
  9132. super.handleSizeChanged();
  9133. if (this._barObjectH)
  9134. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  9135. if (this._barObjectV)
  9136. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  9137. if (!this._underConstruct)
  9138. this.update();
  9139. }
  9140. setup_afterAdd(buffer, beginPos) {
  9141. super.setup_afterAdd(buffer, beginPos);
  9142. if (!buffer.seek(beginPos, 6)) {
  9143. this.update();
  9144. return;
  9145. }
  9146. if (buffer.readByte() != this.packageItem.objectType) {
  9147. this.update();
  9148. return;
  9149. }
  9150. this._value = buffer.getInt32();
  9151. this._max = buffer.getInt32();
  9152. if (buffer.version >= 2)
  9153. this._min = buffer.getInt32();
  9154. this.update();
  9155. }
  9156. __gripMouseDown(evt) {
  9157. this.canDrag = true;
  9158. evt.stopPropagation();
  9159. this._clickPos = this.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY);
  9160. this._clickPercent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9161. Laya.stage.on(Laya.Event.MOUSE_MOVE, this, this.__gripMouseMove);
  9162. Laya.stage.on(Laya.Event.MOUSE_UP, this, this.__gripMouseUp);
  9163. }
  9164. __gripMouseMove(evt) {
  9165. if (!this.canDrag) {
  9166. return;
  9167. }
  9168. var pt = this.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY, s_vec2);
  9169. var deltaX = pt.x - this._clickPos.x;
  9170. var deltaY = pt.y - this._clickPos.y;
  9171. if (this._reverse) {
  9172. deltaX = -deltaX;
  9173. deltaY = -deltaY;
  9174. }
  9175. var percent;
  9176. if (this._barObjectH)
  9177. percent = this._clickPercent + deltaX / this._barMaxWidth;
  9178. else
  9179. percent = this._clickPercent + deltaY / this._barMaxHeight;
  9180. this.updateWithPercent(percent, evt);
  9181. }
  9182. __gripMouseUp(evt) {
  9183. Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.__gripMouseMove);
  9184. Laya.stage.off(Laya.Event.MOUSE_UP, this, this.__gripMouseUp);
  9185. }
  9186. __barMouseDown(evt) {
  9187. if (!this.changeOnClick)
  9188. return;
  9189. var pt = this._gripObject.globalToLocal(evt.stageX, evt.stageY, s_vec2);
  9190. var percent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9191. var delta;
  9192. if (this._barObjectH)
  9193. delta = pt.x / this._barMaxWidth;
  9194. if (this._barObjectV)
  9195. delta = pt.y / this._barMaxHeight;
  9196. if (this._reverse)
  9197. percent -= delta;
  9198. else
  9199. percent += delta;
  9200. this.updateWithPercent(percent, evt);
  9201. }
  9202. }
  9203. fgui.GSlider = GSlider;
  9204. var s_vec2 = new Laya.Point();
  9205. })(fgui);
  9206. (function (fgui) {
  9207. class GTextInput extends fgui.GTextField {
  9208. constructor() {
  9209. super();
  9210. }
  9211. createDisplayObject() {
  9212. this._displayObject = this._input = new Laya.Input();
  9213. this._displayObject.mouseEnabled = true;
  9214. this._displayObject["$owner"] = this;
  9215. }
  9216. get nativeInput() {
  9217. return this._input;
  9218. }
  9219. set text(value) {
  9220. this._input.text = value;
  9221. }
  9222. get text() {
  9223. return this._input.text;
  9224. }
  9225. get font() {
  9226. return this._input.font;
  9227. }
  9228. set font(value) {
  9229. if (value)
  9230. this._input.font = value;
  9231. else
  9232. this._input.font = fgui.UIConfig.defaultFont;
  9233. }
  9234. get fontSize() {
  9235. return this._input.fontSize;
  9236. }
  9237. set fontSize(value) {
  9238. this._input.fontSize = value;
  9239. }
  9240. get color() {
  9241. return this._input.color;
  9242. }
  9243. set color(value) {
  9244. this._input.color = value;
  9245. }
  9246. get align() {
  9247. return this._input.align;
  9248. }
  9249. set align(value) {
  9250. this._input.align = value;
  9251. }
  9252. get valign() {
  9253. return this._input.valign;
  9254. }
  9255. set valign(value) {
  9256. this._input.valign = value;
  9257. }
  9258. get leading() {
  9259. return this._input.leading;
  9260. }
  9261. set leading(value) {
  9262. this._input.leading = value;
  9263. }
  9264. get bold() {
  9265. return this._input.bold;
  9266. }
  9267. set bold(value) {
  9268. this._input.bold = value;
  9269. }
  9270. get italic() {
  9271. return this._input.italic;
  9272. }
  9273. set italic(value) {
  9274. this._input.italic = value;
  9275. }
  9276. get singleLine() {
  9277. return !this._input.multiline;
  9278. }
  9279. set singleLine(value) {
  9280. this._input.multiline = !value;
  9281. }
  9282. get stroke() {
  9283. return this._input.stroke;
  9284. }
  9285. set stroke(value) {
  9286. this._input.stroke = value;
  9287. }
  9288. get strokeColor() {
  9289. return this._input.strokeColor;
  9290. }
  9291. set strokeColor(value) {
  9292. this._input.strokeColor = value;
  9293. this.updateGear(4);
  9294. }
  9295. get password() {
  9296. return this._input.type == "password";
  9297. }
  9298. set password(value) {
  9299. if (value)
  9300. this._input.type = "password";
  9301. else
  9302. this._input.type = "text";
  9303. }
  9304. get keyboardType() {
  9305. return this._input.type;
  9306. }
  9307. set keyboardType(value) {
  9308. this._input.type = value;
  9309. }
  9310. set editable(value) {
  9311. this._input.editable = value;
  9312. }
  9313. get editable() {
  9314. return this._input.editable;
  9315. }
  9316. set maxLength(value) {
  9317. this._input.maxChars = value;
  9318. }
  9319. get maxLength() {
  9320. return this._input.maxChars;
  9321. }
  9322. set promptText(value) {
  9323. this._prompt = value;
  9324. var str = fgui.UBBParser.inst.parse(value, true);
  9325. this._input.prompt = str;
  9326. if (fgui.UBBParser.inst.lastColor)
  9327. this._input.promptColor = fgui.UBBParser.inst.lastColor;
  9328. }
  9329. get promptText() {
  9330. return this._prompt;
  9331. }
  9332. set restrict(value) {
  9333. this._input.restrict = value;
  9334. }
  9335. get restrict() {
  9336. return this._input.restrict;
  9337. }
  9338. get textWidth() {
  9339. return this._input.textWidth;
  9340. }
  9341. requestFocus() {
  9342. this._input.focus = true;
  9343. super.requestFocus();
  9344. }
  9345. handleSizeChanged() {
  9346. this._input.size(this._width, this._height);
  9347. }
  9348. setup_beforeAdd(buffer, beginPos) {
  9349. super.setup_beforeAdd(buffer, beginPos);
  9350. buffer.seek(beginPos, 4);
  9351. var str = buffer.readS();
  9352. if (str != null)
  9353. this.promptText = str;
  9354. str = buffer.readS();
  9355. if (str != null)
  9356. this._input.restrict = str;
  9357. var iv = buffer.getInt32();
  9358. if (iv != 0)
  9359. this._input.maxChars = iv;
  9360. iv = buffer.getInt32();
  9361. if (iv != 0) {
  9362. if (iv == 4)
  9363. this.keyboardType = Laya.Input.TYPE_NUMBER;
  9364. else if (iv == 3)
  9365. this.keyboardType = Laya.Input.TYPE_URL;
  9366. }
  9367. if (buffer.readBool())
  9368. this.password = true;
  9369. }
  9370. }
  9371. fgui.GTextInput = GTextInput;
  9372. })(fgui);
  9373. (function (fgui) {
  9374. class GTree extends fgui.GList {
  9375. constructor() {
  9376. super();
  9377. this._indent = 15;
  9378. this._rootNode = new fgui.GTreeNode(true);
  9379. this._rootNode._setTree(this);
  9380. this._rootNode.expanded = true;
  9381. }
  9382. get rootNode() {
  9383. return this._rootNode;
  9384. }
  9385. get indent() {
  9386. return this._indent;
  9387. }
  9388. set indent(value) {
  9389. this._indent = value;
  9390. }
  9391. get clickToExpand() {
  9392. return this._clickToExpand;
  9393. }
  9394. set clickToExpand(value) {
  9395. this._clickToExpand = value;
  9396. }
  9397. getSelectedNode() {
  9398. if (this.selectedIndex != -1)
  9399. return this.getChildAt(this.selectedIndex)._treeNode;
  9400. else
  9401. return null;
  9402. }
  9403. getSelectedNodes(result) {
  9404. if (!result)
  9405. result = new Array();
  9406. s_list.length = 0;
  9407. super.getSelection(s_list);
  9408. var cnt = s_list.length;
  9409. var ret = new Array();
  9410. for (var i = 0; i < cnt; i++) {
  9411. var node = this.getChildAt(s_list[i])._treeNode;
  9412. ret.push(node);
  9413. }
  9414. return ret;
  9415. }
  9416. selectNode(node, scrollItToView) {
  9417. var parentNode = node.parent;
  9418. while (parentNode && parentNode != this._rootNode) {
  9419. parentNode.expanded = true;
  9420. parentNode = parentNode.parent;
  9421. }
  9422. if (!node._cell)
  9423. return;
  9424. this.addSelection(this.getChildIndex(node._cell), scrollItToView);
  9425. }
  9426. unselectNode(node) {
  9427. if (!node._cell)
  9428. return;
  9429. this.removeSelection(this.getChildIndex(node._cell));
  9430. }
  9431. expandAll(folderNode) {
  9432. if (!folderNode)
  9433. folderNode = this._rootNode;
  9434. folderNode.expanded = true;
  9435. var cnt = folderNode.numChildren;
  9436. for (var i = 0; i < cnt; i++) {
  9437. var node = folderNode.getChildAt(i);
  9438. if (node.isFolder)
  9439. this.expandAll(node);
  9440. }
  9441. }
  9442. collapseAll(folderNode) {
  9443. if (!folderNode)
  9444. folderNode = this._rootNode;
  9445. if (folderNode != this._rootNode)
  9446. folderNode.expanded = false;
  9447. var cnt = folderNode.numChildren;
  9448. for (var i = 0; i < cnt; i++) {
  9449. var node = folderNode.getChildAt(i);
  9450. if (node.isFolder)
  9451. this.collapseAll(node);
  9452. }
  9453. }
  9454. createCell(node) {
  9455. var child = this.getFromPool(node._resURL ? node._resURL : this.defaultItem);
  9456. if (!child)
  9457. throw new Error("cannot create tree node object.");
  9458. child._treeNode = node;
  9459. node._cell = child;
  9460. var indentObj = child.getChild("indent");
  9461. if (indentObj)
  9462. indentObj.width = (node.level - 1) * this._indent;
  9463. var cc;
  9464. cc = child.getController("expanded");
  9465. if (cc) {
  9466. cc.on(fgui.Events.STATE_CHANGED, this, this.__expandedStateChanged);
  9467. cc.selectedIndex = node.expanded ? 1 : 0;
  9468. }
  9469. cc = child.getController("leaf");
  9470. if (cc)
  9471. cc.selectedIndex = node.isFolder ? 0 : 1;
  9472. if (node.isFolder)
  9473. child.on(Laya.Event.MOUSE_DOWN, this, this.__cellMouseDown);
  9474. if (this.treeNodeRender)
  9475. this.treeNodeRender.runWith([node, child]);
  9476. }
  9477. _afterInserted(node) {
  9478. if (!node._cell)
  9479. this.createCell(node);
  9480. var index = this.getInsertIndexForNode(node);
  9481. this.addChildAt(node._cell, index);
  9482. if (this.treeNodeRender)
  9483. this.treeNodeRender.runWith([node, node._cell]);
  9484. if (node.isFolder && node.expanded)
  9485. this.checkChildren(node, index);
  9486. }
  9487. getInsertIndexForNode(node) {
  9488. var prevNode = node.getPrevSibling();
  9489. if (!prevNode)
  9490. prevNode = node.parent;
  9491. var insertIndex = this.getChildIndex(prevNode._cell) + 1;
  9492. var myLevel = node.level;
  9493. var cnt = this.numChildren;
  9494. for (var i = insertIndex; i < cnt; i++) {
  9495. var testNode = this.getChildAt(i)._treeNode;
  9496. if (testNode.level <= myLevel)
  9497. break;
  9498. insertIndex++;
  9499. }
  9500. return insertIndex;
  9501. }
  9502. _afterRemoved(node) {
  9503. this.removeNode(node);
  9504. }
  9505. _afterExpanded(node) {
  9506. if (node == this._rootNode) {
  9507. this.checkChildren(this._rootNode, 0);
  9508. return;
  9509. }
  9510. if (this.treeNodeWillExpand != null)
  9511. this.treeNodeWillExpand.runWith([node, true]);
  9512. if (!node._cell)
  9513. return;
  9514. if (this.treeNodeRender)
  9515. this.treeNodeRender.runWith([node, node._cell]);
  9516. var cc = node._cell.getController("expanded");
  9517. if (cc)
  9518. cc.selectedIndex = 1;
  9519. if (node._cell.parent)
  9520. this.checkChildren(node, this.getChildIndex(node._cell));
  9521. }
  9522. _afterCollapsed(node) {
  9523. if (node == this._rootNode) {
  9524. this.checkChildren(this._rootNode, 0);
  9525. return;
  9526. }
  9527. if (this.treeNodeWillExpand)
  9528. this.treeNodeWillExpand.runWith([node, false]);
  9529. if (!node._cell)
  9530. return;
  9531. if (this.treeNodeRender)
  9532. this.treeNodeRender.runWith([node, node._cell]);
  9533. var cc = node._cell.getController("expanded");
  9534. if (cc)
  9535. cc.selectedIndex = 0;
  9536. if (node._cell.parent)
  9537. this.hideFolderNode(node);
  9538. }
  9539. _afterMoved(node) {
  9540. var startIndex = this.getChildIndex(node._cell);
  9541. var endIndex;
  9542. if (node.isFolder)
  9543. endIndex = this.getFolderEndIndex(startIndex, node.level);
  9544. else
  9545. endIndex = startIndex + 1;
  9546. var insertIndex = this.getInsertIndexForNode(node);
  9547. var i;
  9548. var cnt = endIndex - startIndex;
  9549. var obj;
  9550. if (insertIndex < startIndex) {
  9551. for (i = 0; i < cnt; i++) {
  9552. obj = this.getChildAt(startIndex + i);
  9553. this.setChildIndex(obj, insertIndex + i);
  9554. }
  9555. }
  9556. else {
  9557. for (i = 0; i < cnt; i++) {
  9558. obj = this.getChildAt(startIndex);
  9559. this.setChildIndex(obj, insertIndex);
  9560. }
  9561. }
  9562. }
  9563. getFolderEndIndex(startIndex, level) {
  9564. var cnt = this.numChildren;
  9565. for (var i = startIndex + 1; i < cnt; i++) {
  9566. var node = this.getChildAt(i)._treeNode;
  9567. if (node.level <= level)
  9568. return i;
  9569. }
  9570. return cnt;
  9571. }
  9572. checkChildren(folderNode, index) {
  9573. var cnt = folderNode.numChildren;
  9574. for (var i = 0; i < cnt; i++) {
  9575. index++;
  9576. var node = folderNode.getChildAt(i);
  9577. if (!node._cell)
  9578. this.createCell(node);
  9579. if (!node._cell.parent)
  9580. this.addChildAt(node._cell, index);
  9581. if (node.isFolder && node.expanded)
  9582. index = this.checkChildren(node, index);
  9583. }
  9584. return index;
  9585. }
  9586. hideFolderNode(folderNode) {
  9587. var cnt = folderNode.numChildren;
  9588. for (var i = 0; i < cnt; i++) {
  9589. var node = folderNode.getChildAt(i);
  9590. if (node._cell)
  9591. this.removeChild(node._cell);
  9592. if (node.isFolder && node.expanded)
  9593. this.hideFolderNode(node);
  9594. }
  9595. }
  9596. removeNode(node) {
  9597. if (node._cell) {
  9598. if (node._cell.parent)
  9599. this.removeChild(node._cell);
  9600. this.returnToPool(node._cell);
  9601. node._cell._treeNode = null;
  9602. node._cell = null;
  9603. }
  9604. if (node.isFolder) {
  9605. var cnt = node.numChildren;
  9606. for (var i = 0; i < cnt; i++) {
  9607. var node2 = node.getChildAt(i);
  9608. this.removeNode(node2);
  9609. }
  9610. }
  9611. }
  9612. __cellMouseDown(evt) {
  9613. var node = fgui.GObject.cast(evt.currentTarget)._treeNode;
  9614. this._expandedStatusInEvt = node.expanded;
  9615. }
  9616. __expandedStateChanged(cc) {
  9617. var node = cc.parent._treeNode;
  9618. node.expanded = cc.selectedIndex == 1;
  9619. }
  9620. dispatchItemEvent(item, evt) {
  9621. if (this._clickToExpand != 0) {
  9622. var node = item._treeNode;
  9623. if (node && node.isFolder && this._expandedStatusInEvt == node.expanded) {
  9624. if (this._clickToExpand == 2) {
  9625. //if (evt.clickCount == 2)
  9626. // node.expanded = !node.expanded;
  9627. }
  9628. else
  9629. node.expanded = !node.expanded;
  9630. }
  9631. }
  9632. super.dispatchItemEvent(item, evt);
  9633. }
  9634. setup_beforeAdd(buffer, beginPos) {
  9635. super.setup_beforeAdd(buffer, beginPos);
  9636. buffer.seek(beginPos, 9);
  9637. this._indent = buffer.getInt32();
  9638. this._clickToExpand = buffer.getUint8();
  9639. }
  9640. readItems(buffer) {
  9641. var cnt;
  9642. var i;
  9643. var nextPos;
  9644. var str;
  9645. var isFolder;
  9646. var lastNode;
  9647. var level;
  9648. var prevLevel = 0;
  9649. cnt = buffer.getInt16();
  9650. for (i = 0; i < cnt; i++) {
  9651. nextPos = buffer.getInt16();
  9652. nextPos += buffer.pos;
  9653. str = buffer.readS();
  9654. if (str == null) {
  9655. str = this.defaultItem;
  9656. if (!str) {
  9657. buffer.pos = nextPos;
  9658. continue;
  9659. }
  9660. }
  9661. isFolder = buffer.readBool();
  9662. level = buffer.getUint8();
  9663. var node = new fgui.GTreeNode(isFolder, str);
  9664. node.expanded = true;
  9665. if (i == 0)
  9666. this._rootNode.addChild(node);
  9667. else {
  9668. if (level > prevLevel)
  9669. lastNode.addChild(node);
  9670. else if (level < prevLevel) {
  9671. for (var j = level; j <= prevLevel; j++)
  9672. lastNode = lastNode.parent;
  9673. lastNode.addChild(node);
  9674. }
  9675. else
  9676. lastNode.parent.addChild(node);
  9677. }
  9678. lastNode = node;
  9679. prevLevel = level;
  9680. this.setupItem(buffer, node.cell);
  9681. buffer.pos = nextPos;
  9682. }
  9683. }
  9684. }
  9685. fgui.GTree = GTree;
  9686. var s_list = new Array();
  9687. })(fgui);
  9688. (function (fgui) {
  9689. class GTreeNode {
  9690. constructor(hasChild, resURL) {
  9691. this._level = 0;
  9692. this._resURL = resURL;
  9693. if (hasChild)
  9694. this._children = new Array();
  9695. }
  9696. set expanded(value) {
  9697. if (this._children == null)
  9698. return;
  9699. if (this._expanded != value) {
  9700. this._expanded = value;
  9701. if (this._tree) {
  9702. if (this._expanded)
  9703. this._tree._afterExpanded(this);
  9704. else
  9705. this._tree._afterCollapsed(this);
  9706. }
  9707. }
  9708. }
  9709. get expanded() {
  9710. return this._expanded;
  9711. }
  9712. get isFolder() {
  9713. return this._children != null;
  9714. }
  9715. get parent() {
  9716. return this._parent;
  9717. }
  9718. get text() {
  9719. if (this._cell)
  9720. return this._cell.text;
  9721. else
  9722. return null;
  9723. }
  9724. set text(value) {
  9725. if (this._cell)
  9726. this._cell.text = value;
  9727. }
  9728. get icon() {
  9729. if (this._cell)
  9730. return this._cell.icon;
  9731. else
  9732. return null;
  9733. }
  9734. set icon(value) {
  9735. if (this._cell)
  9736. this._cell.icon = value;
  9737. }
  9738. get cell() {
  9739. return this._cell;
  9740. }
  9741. get level() {
  9742. return this._level;
  9743. }
  9744. _setLevel(value) {
  9745. this._level = value;
  9746. }
  9747. addChild(child) {
  9748. this.addChildAt(child, this._children.length);
  9749. return child;
  9750. }
  9751. addChildAt(child, index) {
  9752. if (!child)
  9753. throw new Error("child is null");
  9754. var numChildren = this._children.length;
  9755. if (index >= 0 && index <= numChildren) {
  9756. if (child._parent == this) {
  9757. this.setChildIndex(child, index);
  9758. }
  9759. else {
  9760. if (child._parent)
  9761. child._parent.removeChild(child);
  9762. var cnt = this._children.length;
  9763. if (index == cnt)
  9764. this._children.push(child);
  9765. else
  9766. this._children.splice(index, 0, child);
  9767. child._parent = this;
  9768. child._level = this._level + 1;
  9769. child._setTree(this._tree);
  9770. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  9771. this._tree._afterInserted(child);
  9772. }
  9773. return child;
  9774. }
  9775. else {
  9776. throw new RangeError("Invalid child index");
  9777. }
  9778. }
  9779. removeChild(child) {
  9780. var childIndex = this._children.indexOf(child);
  9781. if (childIndex != -1) {
  9782. this.removeChildAt(childIndex);
  9783. }
  9784. return child;
  9785. }
  9786. removeChildAt(index) {
  9787. if (index >= 0 && index < this.numChildren) {
  9788. var child = this._children[index];
  9789. this._children.splice(index, 1);
  9790. child._parent = null;
  9791. if (this._tree) {
  9792. child._setTree(null);
  9793. this._tree._afterRemoved(child);
  9794. }
  9795. return child;
  9796. }
  9797. else {
  9798. throw "Invalid child index";
  9799. }
  9800. }
  9801. removeChildren(beginIndex, endIndex) {
  9802. beginIndex = beginIndex || 0;
  9803. if (endIndex == null)
  9804. endIndex = -1;
  9805. if (endIndex < 0 || endIndex >= this.numChildren)
  9806. endIndex = this.numChildren - 1;
  9807. for (var i = beginIndex; i <= endIndex; ++i)
  9808. this.removeChildAt(beginIndex);
  9809. }
  9810. getChildAt(index) {
  9811. if (index >= 0 && index < this.numChildren)
  9812. return this._children[index];
  9813. else
  9814. throw "Invalid child index";
  9815. }
  9816. getChildIndex(child) {
  9817. return this._children.indexOf(child);
  9818. }
  9819. getPrevSibling() {
  9820. if (this._parent == null)
  9821. return null;
  9822. var i = this._parent._children.indexOf(this);
  9823. if (i <= 0)
  9824. return null;
  9825. return this._parent._children[i - 1];
  9826. }
  9827. getNextSibling() {
  9828. if (this._parent == null)
  9829. return null;
  9830. var i = this._parent._children.indexOf(this);
  9831. if (i < 0 || i >= this._parent._children.length - 1)
  9832. return null;
  9833. return this._parent._children[i + 1];
  9834. }
  9835. setChildIndex(child, index) {
  9836. var oldIndex = this._children.indexOf(child);
  9837. if (oldIndex == -1)
  9838. throw "Not a child of this container";
  9839. var cnt = this._children.length;
  9840. if (index < 0)
  9841. index = 0;
  9842. else if (index > cnt)
  9843. index = cnt;
  9844. if (oldIndex == index)
  9845. return;
  9846. this._children.splice(oldIndex, 1);
  9847. this._children.splice(index, 0, child);
  9848. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  9849. this._tree._afterMoved(child);
  9850. }
  9851. swapChildren(child1, child2) {
  9852. var index1 = this._children.indexOf(child1);
  9853. var index2 = this._children.indexOf(child2);
  9854. if (index1 == -1 || index2 == -1)
  9855. throw "Not a child of this container";
  9856. this.swapChildrenAt(index1, index2);
  9857. }
  9858. swapChildrenAt(index1, index2) {
  9859. var child1 = this._children[index1];
  9860. var child2 = this._children[index2];
  9861. this.setChildIndex(child1, index2);
  9862. this.setChildIndex(child2, index1);
  9863. }
  9864. get numChildren() {
  9865. return this._children.length;
  9866. }
  9867. expandToRoot() {
  9868. var p = this;
  9869. while (p) {
  9870. p.expanded = true;
  9871. p = p.parent;
  9872. }
  9873. }
  9874. get tree() {
  9875. return this._tree;
  9876. }
  9877. _setTree(value) {
  9878. this._tree = value;
  9879. if (this._tree && this._tree.treeNodeWillExpand && this._expanded)
  9880. this._tree.treeNodeWillExpand.runWith([this, true]);
  9881. if (this._children) {
  9882. var cnt = this._children.length;
  9883. for (var i = 0; i < cnt; i++) {
  9884. var node = this._children[i];
  9885. node._level = this._level + 1;
  9886. node._setTree(value);
  9887. }
  9888. }
  9889. }
  9890. }
  9891. fgui.GTreeNode = GTreeNode;
  9892. })(fgui);
  9893. (function (fgui) {
  9894. class PackageItem {
  9895. constructor() {
  9896. this.width = 0;
  9897. this.height = 0;
  9898. }
  9899. load() {
  9900. return this.owner.getItemAsset(this);
  9901. }
  9902. getBranch() {
  9903. if (this.branches && this.owner._branchIndex != -1) {
  9904. var itemId = this.branches[this.owner._branchIndex];
  9905. if (itemId)
  9906. return this.owner.getItemById(itemId);
  9907. }
  9908. return this;
  9909. }
  9910. getHighResolution() {
  9911. if (this.highResolution && fgui.GRoot.contentScaleLevel > 0) {
  9912. var itemId = this.highResolution[fgui.GRoot.contentScaleLevel - 1];
  9913. if (itemId)
  9914. return this.owner.getItemById(itemId);
  9915. }
  9916. return this;
  9917. }
  9918. toString() {
  9919. return this.name;
  9920. }
  9921. }
  9922. fgui.PackageItem = PackageItem;
  9923. })(fgui);
  9924. (function (fgui) {
  9925. class PopupMenu {
  9926. constructor(resourceURL) {
  9927. if (!resourceURL) {
  9928. resourceURL = fgui.UIConfig.popupMenu;
  9929. if (!resourceURL)
  9930. throw "UIConfig.popupMenu not defined";
  9931. }
  9932. this._contentPane = fgui.UIPackage.createObjectFromURL(resourceURL).asCom;
  9933. this._contentPane.on(Laya.Event.DISPLAY, this, this.__addedToStage);
  9934. this._list = (this._contentPane.getChild("list"));
  9935. this._list.removeChildrenToPool();
  9936. this._list.addRelation(this._contentPane, fgui.RelationType.Width);
  9937. this._list.removeRelation(this._contentPane, fgui.RelationType.Height);
  9938. this._contentPane.addRelation(this._list, fgui.RelationType.Height);
  9939. this._list.on(fgui.Events.CLICK_ITEM, this, this.__clickItem);
  9940. }
  9941. dispose() {
  9942. this._contentPane.dispose();
  9943. }
  9944. addItem(caption, handler) {
  9945. var item = this._list.addItemFromPool().asButton;
  9946. item.title = caption;
  9947. item.data = handler;
  9948. item.grayed = false;
  9949. var c = item.getController("checked");
  9950. if (c)
  9951. c.selectedIndex = 0;
  9952. return item;
  9953. }
  9954. addItemAt(caption, index, handler) {
  9955. var item = this._list.getFromPool().asButton;
  9956. this._list.addChildAt(item, index);
  9957. item.title = caption;
  9958. item.data = handler;
  9959. item.grayed = false;
  9960. var c = item.getController("checked");
  9961. if (c)
  9962. c.selectedIndex = 0;
  9963. return item;
  9964. }
  9965. addSeperator() {
  9966. if (fgui.UIConfig.popupMenu_seperator == null)
  9967. throw "UIConfig.popupMenu_seperator not defined";
  9968. this.list.addItemFromPool(fgui.UIConfig.popupMenu_seperator);
  9969. }
  9970. getItemName(index) {
  9971. var item = this._list.getChildAt(index);
  9972. return item.name;
  9973. }
  9974. setItemText(name, caption) {
  9975. var item = this._list.getChild(name).asButton;
  9976. item.title = caption;
  9977. }
  9978. setItemVisible(name, visible) {
  9979. var item = this._list.getChild(name).asButton;
  9980. if (item.visible != visible) {
  9981. item.visible = visible;
  9982. this._list.setBoundsChangedFlag();
  9983. }
  9984. }
  9985. setItemGrayed(name, grayed) {
  9986. var item = this._list.getChild(name).asButton;
  9987. item.grayed = grayed;
  9988. }
  9989. setItemCheckable(name, checkable) {
  9990. var item = this._list.getChild(name).asButton;
  9991. var c = item.getController("checked");
  9992. if (c) {
  9993. if (checkable) {
  9994. if (c.selectedIndex == 0)
  9995. c.selectedIndex = 1;
  9996. }
  9997. else
  9998. c.selectedIndex = 0;
  9999. }
  10000. }
  10001. setItemChecked(name, checked) {
  10002. var item = this._list.getChild(name).asButton;
  10003. var c = item.getController("checked");
  10004. if (c)
  10005. c.selectedIndex = checked ? 2 : 1;
  10006. }
  10007. isItemChecked(name) {
  10008. var item = this._list.getChild(name).asButton;
  10009. var c = item.getController("checked");
  10010. if (c)
  10011. return c.selectedIndex == 2;
  10012. else
  10013. return false;
  10014. }
  10015. removeItem(name) {
  10016. var item = this._list.getChild(name);
  10017. if (item) {
  10018. var index = this._list.getChildIndex(item);
  10019. this._list.removeChildToPoolAt(index);
  10020. return true;
  10021. }
  10022. else
  10023. return false;
  10024. }
  10025. clearItems() {
  10026. this._list.removeChildrenToPool();
  10027. }
  10028. get itemCount() {
  10029. return this._list.numChildren;
  10030. }
  10031. get contentPane() {
  10032. return this._contentPane;
  10033. }
  10034. get list() {
  10035. return this._list;
  10036. }
  10037. show(target = null, dir) {
  10038. var r = target != null ? target.root : fgui.GRoot.inst;
  10039. r.showPopup(this.contentPane, (target instanceof fgui.GRoot) ? null : target, dir);
  10040. }
  10041. __clickItem(itemObject) {
  10042. Laya.timer.once(100, this, this.__clickItem2, [itemObject]);
  10043. }
  10044. __clickItem2(itemObject) {
  10045. if (!(itemObject instanceof fgui.GButton))
  10046. return;
  10047. if (itemObject.grayed) {
  10048. this._list.selectedIndex = -1;
  10049. return;
  10050. }
  10051. var c = itemObject.asCom.getController("checked");
  10052. if (c && c.selectedIndex != 0) {
  10053. if (c.selectedIndex == 1)
  10054. c.selectedIndex = 2;
  10055. else
  10056. c.selectedIndex = 1;
  10057. }
  10058. var r = (this._contentPane.parent);
  10059. r.hidePopup(this.contentPane);
  10060. if (itemObject.data != null) {
  10061. itemObject.data.run();
  10062. }
  10063. }
  10064. __addedToStage() {
  10065. this._list.selectedIndex = -1;
  10066. this._list.resizeToFit(100000, 10);
  10067. }
  10068. }
  10069. fgui.PopupMenu = PopupMenu;
  10070. })(fgui);
  10071. (function (fgui) {
  10072. class RelationItem {
  10073. constructor(owner) {
  10074. this._owner = owner;
  10075. this._defs = new Array();
  10076. }
  10077. get owner() {
  10078. return this._owner;
  10079. }
  10080. set target(value) {
  10081. if (this._target != value) {
  10082. if (this._target)
  10083. this.releaseRefTarget();
  10084. this._target = value;
  10085. if (this._target)
  10086. this.addRefTarget();
  10087. }
  10088. }
  10089. get target() {
  10090. return this._target;
  10091. }
  10092. add(relationType, usePercent) {
  10093. if (relationType == fgui.RelationType.Size) {
  10094. this.add(fgui.RelationType.Width, usePercent);
  10095. this.add(fgui.RelationType.Height, usePercent);
  10096. return;
  10097. }
  10098. var cnt = this._defs.length;
  10099. for (var i = 0; i < cnt; i++) {
  10100. if (this._defs[i].type == relationType)
  10101. return;
  10102. }
  10103. this.internalAdd(relationType, usePercent);
  10104. }
  10105. internalAdd(relationType, usePercent) {
  10106. if (relationType == fgui.RelationType.Size) {
  10107. this.internalAdd(fgui.RelationType.Width, usePercent);
  10108. this.internalAdd(fgui.RelationType.Height, usePercent);
  10109. return;
  10110. }
  10111. var info = new RelationDef();
  10112. info.percent = usePercent;
  10113. info.type = relationType;
  10114. info.axis = (relationType <= fgui.RelationType.Right_Right || relationType == fgui.RelationType.Width || relationType >= fgui.RelationType.LeftExt_Left && relationType <= fgui.RelationType.RightExt_Right) ? 0 : 1;
  10115. this._defs.push(info);
  10116. }
  10117. remove(relationType) {
  10118. if (relationType == fgui.RelationType.Size) {
  10119. this.remove(fgui.RelationType.Width);
  10120. this.remove(fgui.RelationType.Height);
  10121. return;
  10122. }
  10123. var dc = this._defs.length;
  10124. for (var k = 0; k < dc; k++) {
  10125. if (this._defs[k].type == relationType) {
  10126. this._defs.splice(k, 1);
  10127. break;
  10128. }
  10129. }
  10130. }
  10131. copyFrom(source) {
  10132. this._target = source.target;
  10133. this._defs.length = 0;
  10134. var cnt = source._defs.length;
  10135. for (var i = 0; i < cnt; i++) {
  10136. var info = source._defs[i];
  10137. var info2 = new RelationDef();
  10138. info2.copyFrom(info);
  10139. this._defs.push(info2);
  10140. }
  10141. }
  10142. dispose() {
  10143. if (this._target) {
  10144. this.releaseRefTarget();
  10145. this._target = null;
  10146. }
  10147. }
  10148. get isEmpty() {
  10149. return this._defs.length == 0;
  10150. }
  10151. applyOnSelfResized(dWidth, dHeight, applyPivot) {
  10152. var cnt = this._defs.length;
  10153. if (cnt == 0)
  10154. return;
  10155. var ox = this._owner.x;
  10156. var oy = this._owner.y;
  10157. for (var i = 0; i < cnt; i++) {
  10158. var info = this._defs[i];
  10159. switch (info.type) {
  10160. case fgui.RelationType.Center_Center:
  10161. this._owner.x -= (0.5 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10162. break;
  10163. case fgui.RelationType.Right_Center:
  10164. case fgui.RelationType.Right_Left:
  10165. case fgui.RelationType.Right_Right:
  10166. this._owner.x -= (1 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10167. break;
  10168. case fgui.RelationType.Middle_Middle:
  10169. this._owner.y -= (0.5 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10170. break;
  10171. case fgui.RelationType.Bottom_Middle:
  10172. case fgui.RelationType.Bottom_Top:
  10173. case fgui.RelationType.Bottom_Bottom:
  10174. this._owner.y -= (1 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10175. break;
  10176. }
  10177. }
  10178. if (ox != this._owner.x || oy != this._owner.y) {
  10179. ox = this._owner.x - ox;
  10180. oy = this._owner.y - oy;
  10181. this._owner.updateGearFromRelations(1, ox, oy);
  10182. if (this._owner.parent && this._owner.parent._transitions.length > 0) {
  10183. cnt = this._owner.parent._transitions.length;
  10184. for (var j = 0; j < cnt; j++) {
  10185. var trans = this._owner.parent._transitions[j];
  10186. trans.updateFromRelations(this._owner.id, ox, oy);
  10187. }
  10188. }
  10189. }
  10190. }
  10191. applyOnXYChanged(info, dx, dy) {
  10192. var tmp;
  10193. switch (info.type) {
  10194. case fgui.RelationType.Left_Left:
  10195. case fgui.RelationType.Left_Center:
  10196. case fgui.RelationType.Left_Right:
  10197. case fgui.RelationType.Center_Center:
  10198. case fgui.RelationType.Right_Left:
  10199. case fgui.RelationType.Right_Center:
  10200. case fgui.RelationType.Right_Right:
  10201. this._owner.x += dx;
  10202. break;
  10203. case fgui.RelationType.Top_Top:
  10204. case fgui.RelationType.Top_Middle:
  10205. case fgui.RelationType.Top_Bottom:
  10206. case fgui.RelationType.Middle_Middle:
  10207. case fgui.RelationType.Bottom_Top:
  10208. case fgui.RelationType.Bottom_Middle:
  10209. case fgui.RelationType.Bottom_Bottom:
  10210. this._owner.y += dy;
  10211. break;
  10212. case fgui.RelationType.Width:
  10213. case fgui.RelationType.Height:
  10214. break;
  10215. case fgui.RelationType.LeftExt_Left:
  10216. case fgui.RelationType.LeftExt_Right:
  10217. if (this._owner != this._target.parent) {
  10218. tmp = this._owner.xMin;
  10219. this._owner.width = this._owner._rawWidth - dx;
  10220. this._owner.xMin = tmp + dx;
  10221. }
  10222. else
  10223. this._owner.width = this._owner._rawWidth - dx;
  10224. break;
  10225. case fgui.RelationType.RightExt_Left:
  10226. case fgui.RelationType.RightExt_Right:
  10227. if (this._owner != this._target.parent) {
  10228. tmp = this._owner.xMin;
  10229. this._owner.width = this._owner._rawWidth + dx;
  10230. this._owner.xMin = tmp;
  10231. }
  10232. else
  10233. this._owner.width = this._owner._rawWidth + dx;
  10234. break;
  10235. case fgui.RelationType.TopExt_Top:
  10236. case fgui.RelationType.TopExt_Bottom:
  10237. if (this._owner != this._target.parent) {
  10238. tmp = this._owner.yMin;
  10239. this._owner.height = this._owner._rawHeight - dy;
  10240. this._owner.yMin = tmp + dy;
  10241. }
  10242. else
  10243. this._owner.height = this._owner._rawHeight - dy;
  10244. break;
  10245. case fgui.RelationType.BottomExt_Top:
  10246. case fgui.RelationType.BottomExt_Bottom:
  10247. if (this._owner != this._target.parent) {
  10248. tmp = this._owner.yMin;
  10249. this._owner.height = this._owner._rawHeight + dy;
  10250. this._owner.yMin = tmp;
  10251. }
  10252. else
  10253. this._owner.height = this._owner._rawHeight + dy;
  10254. break;
  10255. }
  10256. }
  10257. applyOnSizeChanged(info) {
  10258. var pos = 0, pivot = 0, delta = 0;
  10259. var v, tmp;
  10260. if (info.axis == 0) {
  10261. if (this._target != this._owner.parent) {
  10262. pos = this._target.x;
  10263. if (this._target.pivotAsAnchor)
  10264. pivot = this._target.pivotX;
  10265. }
  10266. if (info.percent) {
  10267. if (this._targetWidth != 0)
  10268. delta = this._target._width / this._targetWidth;
  10269. }
  10270. else
  10271. delta = this._target._width - this._targetWidth;
  10272. }
  10273. else {
  10274. if (this._target != this._owner.parent) {
  10275. pos = this._target.y;
  10276. if (this._target.pivotAsAnchor)
  10277. pivot = this._target.pivotY;
  10278. }
  10279. if (info.percent) {
  10280. if (this._targetHeight != 0)
  10281. delta = this._target._height / this._targetHeight;
  10282. }
  10283. else
  10284. delta = this._target._height - this._targetHeight;
  10285. }
  10286. switch (info.type) {
  10287. case fgui.RelationType.Left_Left:
  10288. if (info.percent)
  10289. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  10290. else if (pivot != 0)
  10291. this._owner.x += delta * (-pivot);
  10292. break;
  10293. case fgui.RelationType.Left_Center:
  10294. if (info.percent)
  10295. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  10296. else
  10297. this._owner.x += delta * (0.5 - pivot);
  10298. break;
  10299. case fgui.RelationType.Left_Right:
  10300. if (info.percent)
  10301. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  10302. else
  10303. this._owner.x += delta * (1 - pivot);
  10304. break;
  10305. case fgui.RelationType.Center_Center:
  10306. if (info.percent)
  10307. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth * 0.5 - pos) * delta - this._owner._rawWidth * 0.5;
  10308. else
  10309. this._owner.x += delta * (0.5 - pivot);
  10310. break;
  10311. case fgui.RelationType.Right_Left:
  10312. if (info.percent)
  10313. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  10314. else if (pivot != 0)
  10315. this._owner.x += delta * (-pivot);
  10316. break;
  10317. case fgui.RelationType.Right_Center:
  10318. if (info.percent)
  10319. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  10320. else
  10321. this._owner.x += delta * (0.5 - pivot);
  10322. break;
  10323. case fgui.RelationType.Right_Right:
  10324. if (info.percent)
  10325. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  10326. else
  10327. this._owner.x += delta * (1 - pivot);
  10328. break;
  10329. case fgui.RelationType.Top_Top:
  10330. if (info.percent)
  10331. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  10332. else if (pivot != 0)
  10333. this._owner.y += delta * (-pivot);
  10334. break;
  10335. case fgui.RelationType.Top_Middle:
  10336. if (info.percent)
  10337. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  10338. else
  10339. this._owner.y += delta * (0.5 - pivot);
  10340. break;
  10341. case fgui.RelationType.Top_Bottom:
  10342. if (info.percent)
  10343. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  10344. else
  10345. this._owner.y += delta * (1 - pivot);
  10346. break;
  10347. case fgui.RelationType.Middle_Middle:
  10348. if (info.percent)
  10349. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight * 0.5 - pos) * delta - this._owner._rawHeight * 0.5;
  10350. else
  10351. this._owner.y += delta * (0.5 - pivot);
  10352. break;
  10353. case fgui.RelationType.Bottom_Top:
  10354. if (info.percent)
  10355. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  10356. else if (pivot != 0)
  10357. this._owner.y += delta * (-pivot);
  10358. break;
  10359. case fgui.RelationType.Bottom_Middle:
  10360. if (info.percent)
  10361. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  10362. else
  10363. this._owner.y += delta * (0.5 - pivot);
  10364. break;
  10365. case fgui.RelationType.Bottom_Bottom:
  10366. if (info.percent)
  10367. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  10368. else
  10369. this._owner.y += delta * (1 - pivot);
  10370. break;
  10371. case fgui.RelationType.Width:
  10372. if (this._owner._underConstruct && this._owner == this._target.parent)
  10373. v = this._owner.sourceWidth - this._target.initWidth;
  10374. else
  10375. v = this._owner._rawWidth - this._targetWidth;
  10376. if (info.percent)
  10377. v = v * delta;
  10378. if (this._target == this._owner.parent) {
  10379. if (this._owner.pivotAsAnchor) {
  10380. tmp = this._owner.xMin;
  10381. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  10382. this._owner.xMin = tmp;
  10383. }
  10384. else
  10385. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  10386. }
  10387. else
  10388. this._owner.width = this._target._width + v;
  10389. break;
  10390. case fgui.RelationType.Height:
  10391. if (this._owner._underConstruct && this._owner == this._target.parent)
  10392. v = this._owner.sourceHeight - this._target.initHeight;
  10393. else
  10394. v = this._owner._rawHeight - this._targetHeight;
  10395. if (info.percent)
  10396. v = v * delta;
  10397. if (this._target == this._owner.parent) {
  10398. if (this._owner.pivotAsAnchor) {
  10399. tmp = this._owner.yMin;
  10400. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  10401. this._owner.yMin = tmp;
  10402. }
  10403. else
  10404. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  10405. }
  10406. else
  10407. this._owner.height = this._target._height + v;
  10408. break;
  10409. case fgui.RelationType.LeftExt_Left:
  10410. tmp = this._owner.xMin;
  10411. if (info.percent)
  10412. v = pos + (tmp - pos) * delta - tmp;
  10413. else
  10414. v = delta * (-pivot);
  10415. this._owner.width = this._owner._rawWidth - v;
  10416. this._owner.xMin = tmp + v;
  10417. break;
  10418. case fgui.RelationType.LeftExt_Right:
  10419. tmp = this._owner.xMin;
  10420. if (info.percent)
  10421. v = pos + (tmp - pos) * delta - tmp;
  10422. else
  10423. v = delta * (1 - pivot);
  10424. this._owner.width = this._owner._rawWidth - v;
  10425. this._owner.xMin = tmp + v;
  10426. break;
  10427. case fgui.RelationType.RightExt_Left:
  10428. tmp = this._owner.xMin;
  10429. if (info.percent)
  10430. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  10431. else
  10432. v = delta * (-pivot);
  10433. this._owner.width = this._owner._rawWidth + v;
  10434. this._owner.xMin = tmp;
  10435. break;
  10436. case fgui.RelationType.RightExt_Right:
  10437. tmp = this._owner.xMin;
  10438. if (info.percent) {
  10439. if (this._owner == this._target.parent) {
  10440. if (this._owner._underConstruct)
  10441. this._owner.width = pos + this._target._width - this._target._width * pivot +
  10442. (this._owner.sourceWidth - pos - this._target.initWidth + this._target.initWidth * pivot) * delta;
  10443. else
  10444. this._owner.width = pos + (this._owner._rawWidth - pos) * delta;
  10445. }
  10446. else {
  10447. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  10448. this._owner.width = this._owner._rawWidth + v;
  10449. this._owner.xMin = tmp;
  10450. }
  10451. }
  10452. else {
  10453. if (this._owner == this._target.parent) {
  10454. if (this._owner._underConstruct)
  10455. this._owner.width = this._owner.sourceWidth + (this._target._width - this._target.initWidth) * (1 - pivot);
  10456. else
  10457. this._owner.width = this._owner._rawWidth + delta * (1 - pivot);
  10458. }
  10459. else {
  10460. v = delta * (1 - pivot);
  10461. this._owner.width = this._owner._rawWidth + v;
  10462. this._owner.xMin = tmp;
  10463. }
  10464. }
  10465. break;
  10466. case fgui.RelationType.TopExt_Top:
  10467. tmp = this._owner.yMin;
  10468. if (info.percent)
  10469. v = pos + (tmp - pos) * delta - tmp;
  10470. else
  10471. v = delta * (-pivot);
  10472. this._owner.height = this._owner._rawHeight - v;
  10473. this._owner.yMin = tmp + v;
  10474. break;
  10475. case fgui.RelationType.TopExt_Bottom:
  10476. tmp = this._owner.yMin;
  10477. if (info.percent)
  10478. v = pos + (tmp - pos) * delta - tmp;
  10479. else
  10480. v = delta * (1 - pivot);
  10481. this._owner.height = this._owner._rawHeight - v;
  10482. this._owner.yMin = tmp + v;
  10483. break;
  10484. case fgui.RelationType.BottomExt_Top:
  10485. tmp = this._owner.yMin;
  10486. if (info.percent)
  10487. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  10488. else
  10489. v = delta * (-pivot);
  10490. this._owner.height = this._owner._rawHeight + v;
  10491. this._owner.yMin = tmp;
  10492. break;
  10493. case fgui.RelationType.BottomExt_Bottom:
  10494. tmp = this._owner.yMin;
  10495. if (info.percent) {
  10496. if (this._owner == this._target.parent) {
  10497. if (this._owner._underConstruct)
  10498. this._owner.height = pos + this._target._height - this._target._height * pivot +
  10499. (this._owner.sourceHeight - pos - this._target.initHeight + this._target.initHeight * pivot) * delta;
  10500. else
  10501. this._owner.height = pos + (this._owner._rawHeight - pos) * delta;
  10502. }
  10503. else {
  10504. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  10505. this._owner.height = this._owner._rawHeight + v;
  10506. this._owner.yMin = tmp;
  10507. }
  10508. }
  10509. else {
  10510. if (this._owner == this._target.parent) {
  10511. if (this._owner._underConstruct)
  10512. this._owner.height = this._owner.sourceHeight + (this._target._height - this._target.initHeight) * (1 - pivot);
  10513. else
  10514. this._owner.height = this._owner._rawHeight + delta * (1 - pivot);
  10515. }
  10516. else {
  10517. v = delta * (1 - pivot);
  10518. this._owner.height = this._owner._rawHeight + v;
  10519. this._owner.yMin = tmp;
  10520. }
  10521. }
  10522. break;
  10523. }
  10524. }
  10525. addRefTarget() {
  10526. if (this._target != this._owner.parent)
  10527. this._target.on(fgui.Events.XY_CHANGED, this, this.__targetXYChanged);
  10528. this._target.on(fgui.Events.SIZE_CHANGED, this, this.__targetSizeChanged);
  10529. this._target.on(fgui.Events.SIZE_DELAY_CHANGE, this, this.__targetSizeWillChange);
  10530. this._targetX = this._target.x;
  10531. this._targetY = this._target.y;
  10532. this._targetWidth = this._target._width;
  10533. this._targetHeight = this._target._height;
  10534. }
  10535. releaseRefTarget() {
  10536. if (this._target.displayObject == null)
  10537. return;
  10538. this._target.off(fgui.Events.XY_CHANGED, this, this.__targetXYChanged);
  10539. this._target.off(fgui.Events.SIZE_CHANGED, this, this.__targetSizeChanged);
  10540. this._target.off(fgui.Events.SIZE_DELAY_CHANGE, this, this.__targetSizeWillChange);
  10541. }
  10542. __targetXYChanged() {
  10543. if (this._owner.relations.handling != null || this._owner.group != null && this._owner.group._updating) {
  10544. this._targetX = this._target.x;
  10545. this._targetY = this._target.y;
  10546. return;
  10547. }
  10548. this._owner.relations.handling = this._target;
  10549. var ox = this._owner.x;
  10550. var oy = this._owner.y;
  10551. var dx = this._target.x - this._targetX;
  10552. var dy = this._target.y - this._targetY;
  10553. var cnt = this._defs.length;
  10554. for (var i = 0; i < cnt; i++) {
  10555. this.applyOnXYChanged(this._defs[i], dx, dy);
  10556. }
  10557. this._targetX = this._target.x;
  10558. this._targetY = this._target.y;
  10559. if (ox != this._owner.x || oy != this._owner.y) {
  10560. ox = this._owner.x - ox;
  10561. oy = this._owner.y - oy;
  10562. this._owner.updateGearFromRelations(1, ox, oy);
  10563. if (this._owner.parent && this._owner.parent._transitions.length > 0) {
  10564. cnt = this._owner.parent._transitions.length;
  10565. for (var j = 0; j < cnt; j++) {
  10566. var trans = this._owner.parent._transitions[j];
  10567. trans.updateFromRelations(this._owner.id, ox, oy);
  10568. }
  10569. }
  10570. }
  10571. this._owner.relations.handling = null;
  10572. }
  10573. __targetSizeChanged() {
  10574. if (this._owner.relations.sizeDirty)
  10575. this._owner.relations.ensureRelationsSizeCorrect();
  10576. if (this._owner.relations.handling != null) {
  10577. this._targetWidth = this._target._width;
  10578. this._targetHeight = this._target._height;
  10579. return;
  10580. }
  10581. this._owner.relations.handling = this._target;
  10582. var ox = this._owner.x;
  10583. var oy = this._owner.y;
  10584. var ow = this._owner._rawWidth;
  10585. var oh = this._owner._rawHeight;
  10586. var cnt = this._defs.length;
  10587. for (var i = 0; i < cnt; i++) {
  10588. this.applyOnSizeChanged(this._defs[i]);
  10589. }
  10590. this._targetWidth = this._target._width;
  10591. this._targetHeight = this._target._height;
  10592. if (ox != this._owner.x || oy != this._owner.y) {
  10593. ox = this._owner.x - ox;
  10594. oy = this._owner.y - oy;
  10595. this._owner.updateGearFromRelations(1, ox, oy);
  10596. if (this._owner.parent && this._owner.parent._transitions.length > 0) {
  10597. cnt = this._owner.parent._transitions.length;
  10598. for (var j = 0; j < cnt; j++) {
  10599. var trans = this._owner.parent._transitions[j];
  10600. trans.updateFromRelations(this._owner.id, ox, oy);
  10601. }
  10602. }
  10603. }
  10604. if (ow != this._owner._rawWidth || oh != this._owner._rawHeight) {
  10605. ow = this._owner._rawWidth - ow;
  10606. oh = this._owner._rawHeight - oh;
  10607. this._owner.updateGearFromRelations(2, ow, oh);
  10608. }
  10609. this._owner.relations.handling = null;
  10610. }
  10611. __targetSizeWillChange() {
  10612. this._owner.relations.sizeDirty = true;
  10613. }
  10614. }
  10615. fgui.RelationItem = RelationItem;
  10616. class RelationDef {
  10617. constructor() {
  10618. }
  10619. copyFrom(source) {
  10620. this.percent = source.percent;
  10621. this.type = source.type;
  10622. this.axis = source.axis;
  10623. }
  10624. }
  10625. })(fgui);
  10626. (function (fgui) {
  10627. class Relations {
  10628. constructor(owner) {
  10629. this._owner = owner;
  10630. this._items = [];
  10631. }
  10632. add(target, relationType, usePercent) {
  10633. var length = this._items.length;
  10634. for (var i = 0; i < length; i++) {
  10635. var item = this._items[i];
  10636. if (item.target == target) {
  10637. item.add(relationType, usePercent);
  10638. return;
  10639. }
  10640. }
  10641. var newItem = new fgui.RelationItem(this._owner);
  10642. newItem.target = target;
  10643. newItem.add(relationType, usePercent);
  10644. this._items.push(newItem);
  10645. }
  10646. remove(target, relationType) {
  10647. relationType = relationType || 0;
  10648. var cnt = this._items.length;
  10649. var i = 0;
  10650. while (i < cnt) {
  10651. var item = this._items[i];
  10652. if (item.target == target) {
  10653. item.remove(relationType);
  10654. if (item.isEmpty) {
  10655. item.dispose();
  10656. this._items.splice(i, 1);
  10657. cnt--;
  10658. }
  10659. else
  10660. i++;
  10661. }
  10662. else
  10663. i++;
  10664. }
  10665. }
  10666. contains(target) {
  10667. var length = this._items.length;
  10668. for (var i = 0; i < length; i++) {
  10669. var item = this._items[i];
  10670. if (item.target == target)
  10671. return true;
  10672. }
  10673. return false;
  10674. }
  10675. clearFor(target) {
  10676. var cnt = this._items.length;
  10677. var i = 0;
  10678. while (i < cnt) {
  10679. var item = this._items[i];
  10680. if (item.target == target) {
  10681. item.dispose();
  10682. this._items.splice(i, 1);
  10683. cnt--;
  10684. }
  10685. else
  10686. i++;
  10687. }
  10688. }
  10689. clearAll() {
  10690. var length = this._items.length;
  10691. for (var i = 0; i < length; i++) {
  10692. var item = this._items[i];
  10693. item.dispose();
  10694. }
  10695. this._items.length = 0;
  10696. }
  10697. copyFrom(source) {
  10698. this.clearAll();
  10699. var arr = source._items;
  10700. var length = arr.length;
  10701. for (var i = 0; i < length; i++) {
  10702. var ri = arr[i];
  10703. var item = new fgui.RelationItem(this._owner);
  10704. item.copyFrom(ri);
  10705. this._items.push(item);
  10706. }
  10707. }
  10708. dispose() {
  10709. this.clearAll();
  10710. }
  10711. onOwnerSizeChanged(dWidth, dHeight, applyPivot) {
  10712. if (this._items.length == 0)
  10713. return;
  10714. var length = this._items.length;
  10715. for (var i = 0; i < length; i++) {
  10716. var item = this._items[i];
  10717. item.applyOnSelfResized(dWidth, dHeight, applyPivot);
  10718. }
  10719. }
  10720. ensureRelationsSizeCorrect() {
  10721. if (this._items.length == 0)
  10722. return;
  10723. this.sizeDirty = false;
  10724. var length = this._items.length;
  10725. for (var i = 0; i < length; i++) {
  10726. var item = this._items[i];
  10727. item.target.ensureSizeCorrect();
  10728. }
  10729. }
  10730. get empty() {
  10731. return this._items.length == 0;
  10732. }
  10733. setup(buffer, parentToChild) {
  10734. var cnt = buffer.readByte();
  10735. var target;
  10736. for (var i = 0; i < cnt; i++) {
  10737. var targetIndex = buffer.getInt16();
  10738. if (targetIndex == -1)
  10739. target = this._owner.parent;
  10740. else if (parentToChild)
  10741. target = (this._owner).getChildAt(targetIndex);
  10742. else
  10743. target = this._owner.parent.getChildAt(targetIndex);
  10744. var newItem = new fgui.RelationItem(this._owner);
  10745. newItem.target = target;
  10746. this._items.push(newItem);
  10747. var cnt2 = buffer.readByte();
  10748. for (var j = 0; j < cnt2; j++) {
  10749. var rt = buffer.readByte();
  10750. var usePercent = buffer.readBool();
  10751. newItem.internalAdd(rt, usePercent);
  10752. }
  10753. }
  10754. }
  10755. }
  10756. fgui.Relations = Relations;
  10757. })(fgui);
  10758. (function (fgui) {
  10759. class ScrollPane {
  10760. constructor(owner) {
  10761. this._owner = owner;
  10762. this._maskContainer = new Laya.Sprite();
  10763. this._owner.displayObject.addChild(this._maskContainer);
  10764. this._container = this._owner._container;
  10765. this._container.pos(0, 0);
  10766. this._maskContainer.addChild(this._container);
  10767. this._mouseWheelEnabled = true;
  10768. this._xPos = 0;
  10769. this._yPos = 0;
  10770. this._aniFlag = 0;
  10771. this._tweening = 0;
  10772. this._loop = 0;
  10773. this._footerLockedSize = 0;
  10774. this._headerLockedSize = 0;
  10775. this._scrollBarMargin = new fgui.Margin();
  10776. this._viewSize = new Laya.Point();
  10777. this._contentSize = new Laya.Point();
  10778. this._pageSize = new Laya.Point(1, 1);
  10779. this._overlapSize = new Laya.Point();
  10780. this._tweenTime = new Laya.Point();
  10781. this._tweenStart = new Laya.Point();
  10782. this._tweenDuration = new Laya.Point();
  10783. this._tweenChange = new Laya.Point();
  10784. this._velocity = new Laya.Point();
  10785. this._containerPos = new Laya.Point();
  10786. this._beginTouchPos = new Laya.Point();
  10787. this._lastTouchPos = new Laya.Point();
  10788. this._lastTouchGlobalPos = new Laya.Point();
  10789. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  10790. this._mouseWheelStep = this._scrollStep * 2;
  10791. this._decelerationRate = fgui.UIConfig.defaultScrollDecelerationRate;
  10792. this._owner.on(Laya.Event.MOUSE_DOWN, this, this.__mouseDown);
  10793. this._owner.on(Laya.Event.MOUSE_WHEEL, this, this.__mouseWheel);
  10794. }
  10795. setup(buffer) {
  10796. this._scrollType = buffer.readByte();
  10797. var scrollBarDisplay = buffer.readByte();
  10798. var flags = buffer.getInt32();
  10799. if (buffer.readBool()) {
  10800. this._scrollBarMargin.top = buffer.getInt32();
  10801. this._scrollBarMargin.bottom = buffer.getInt32();
  10802. this._scrollBarMargin.left = buffer.getInt32();
  10803. this._scrollBarMargin.right = buffer.getInt32();
  10804. }
  10805. var vtScrollBarRes = buffer.readS();
  10806. var hzScrollBarRes = buffer.readS();
  10807. var headerRes = buffer.readS();
  10808. var footerRes = buffer.readS();
  10809. if ((flags & 1) != 0)
  10810. this._displayOnLeft = true;
  10811. if ((flags & 2) != 0)
  10812. this._snapToItem = true;
  10813. if ((flags & 4) != 0)
  10814. this._displayInDemand = true;
  10815. if ((flags & 8) != 0)
  10816. this._pageMode = true;
  10817. if (flags & 16)
  10818. this._touchEffect = true;
  10819. else if (flags & 32)
  10820. this._touchEffect = false;
  10821. else
  10822. this._touchEffect = fgui.UIConfig.defaultScrollTouchEffect;
  10823. if (flags & 64)
  10824. this._bouncebackEffect = true;
  10825. else if (flags & 128)
  10826. this._bouncebackEffect = false;
  10827. else
  10828. this._bouncebackEffect = fgui.UIConfig.defaultScrollBounceEffect;
  10829. if ((flags & 256) != 0)
  10830. this._inertiaDisabled = true;
  10831. if ((flags & 512) == 0)
  10832. this._maskContainer.scrollRect = new Laya.Rectangle();
  10833. if ((flags & 1024) != 0)
  10834. this._floating = true;
  10835. if ((flags & 2048) != 0)
  10836. this._dontClipMargin = true;
  10837. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Default)
  10838. scrollBarDisplay = fgui.UIConfig.defaultScrollBarDisplay;
  10839. if (scrollBarDisplay != fgui.ScrollBarDisplayType.Hidden) {
  10840. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) {
  10841. var res = vtScrollBarRes ? vtScrollBarRes : fgui.UIConfig.verticalScrollBar;
  10842. if (res) {
  10843. this._vtScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  10844. if (!this._vtScrollBar)
  10845. throw "cannot create scrollbar from " + res;
  10846. this._vtScrollBar.setScrollPane(this, true);
  10847. this._owner.displayObject.addChild(this._vtScrollBar.displayObject);
  10848. }
  10849. }
  10850. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Horizontal) {
  10851. res = hzScrollBarRes ? hzScrollBarRes : fgui.UIConfig.horizontalScrollBar;
  10852. if (res) {
  10853. this._hzScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  10854. if (!this._hzScrollBar)
  10855. throw "cannot create scrollbar from " + res;
  10856. this._hzScrollBar.setScrollPane(this, false);
  10857. this._owner.displayObject.addChild(this._hzScrollBar.displayObject);
  10858. }
  10859. }
  10860. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Auto)
  10861. this._scrollBarDisplayAuto = true;
  10862. if (this._scrollBarDisplayAuto) {
  10863. if (this._vtScrollBar)
  10864. this._vtScrollBar.displayObject.visible = false;
  10865. if (this._hzScrollBar)
  10866. this._hzScrollBar.displayObject.visible = false;
  10867. }
  10868. }
  10869. else
  10870. this._mouseWheelEnabled = false;
  10871. if (headerRes) {
  10872. this._header = fgui.UIPackage.createObjectFromURL(headerRes);
  10873. if (!this._header)
  10874. throw new Error("FairyGUI: cannot create scrollPane this.header from " + headerRes);
  10875. }
  10876. if (footerRes) {
  10877. this._footer = fgui.UIPackage.createObjectFromURL(footerRes);
  10878. if (!this._footer)
  10879. throw new Error("FairyGUI: cannot create scrollPane this.footer from " + footerRes);
  10880. }
  10881. if (this._header || this._footer)
  10882. this._refreshBarAxis = (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) ? "y" : "x";
  10883. this.setSize(this.owner.width, this.owner.height);
  10884. }
  10885. dispose() {
  10886. if (ScrollPane.draggingPane == this) {
  10887. ScrollPane.draggingPane = null;
  10888. }
  10889. if (this._tweening != 0)
  10890. Laya.timer.clear(this, this.tweenUpdate);
  10891. this._pageController = null;
  10892. if (this._hzScrollBar)
  10893. this._hzScrollBar.dispose();
  10894. if (this._vtScrollBar)
  10895. this._vtScrollBar.dispose();
  10896. if (this._header)
  10897. this._header.dispose();
  10898. if (this._footer)
  10899. this._footer.dispose();
  10900. }
  10901. get owner() {
  10902. return this._owner;
  10903. }
  10904. get hzScrollBar() {
  10905. return this._hzScrollBar;
  10906. }
  10907. get vtScrollBar() {
  10908. return this._vtScrollBar;
  10909. }
  10910. get header() {
  10911. return this._header;
  10912. }
  10913. get footer() {
  10914. return this._footer;
  10915. }
  10916. get bouncebackEffect() {
  10917. return this._bouncebackEffect;
  10918. }
  10919. set bouncebackEffect(sc) {
  10920. this._bouncebackEffect = sc;
  10921. }
  10922. get touchEffect() {
  10923. return this._touchEffect;
  10924. }
  10925. set touchEffect(sc) {
  10926. this._touchEffect = sc;
  10927. }
  10928. set scrollStep(val) {
  10929. this._scrollStep = val;
  10930. if (this._scrollStep == 0)
  10931. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  10932. this._mouseWheelStep = this._scrollStep * 2;
  10933. }
  10934. get scrollStep() {
  10935. return this._scrollStep;
  10936. }
  10937. get snapToItem() {
  10938. return this._snapToItem;
  10939. }
  10940. set snapToItem(value) {
  10941. this._snapToItem = value;
  10942. }
  10943. get mouseWheelEnabled() {
  10944. return this._mouseWheelEnabled;
  10945. }
  10946. set mouseWheelEnabled(value) {
  10947. this._mouseWheelEnabled = value;
  10948. }
  10949. get decelerationRate() {
  10950. return this._decelerationRate;
  10951. }
  10952. set decelerationRate(value) {
  10953. this._decelerationRate = value;
  10954. }
  10955. get isDragged() {
  10956. return this._dragged;
  10957. }
  10958. get percX() {
  10959. return this._overlapSize.x == 0 ? 0 : this._xPos / this._overlapSize.x;
  10960. }
  10961. set percX(value) {
  10962. this.setPercX(value, false);
  10963. }
  10964. setPercX(value, ani) {
  10965. this._owner.ensureBoundsCorrect();
  10966. this.setPosX(this._overlapSize.x * fgui.ToolSet.clamp01(value), ani);
  10967. }
  10968. get percY() {
  10969. return this._overlapSize.y == 0 ? 0 : this._yPos / this._overlapSize.y;
  10970. }
  10971. set percY(value) {
  10972. this.setPercY(value, false);
  10973. }
  10974. setPercY(value, ani) {
  10975. this._owner.ensureBoundsCorrect();
  10976. this.setPosY(this._overlapSize.y * fgui.ToolSet.clamp01(value), ani);
  10977. }
  10978. get posX() {
  10979. return this._xPos;
  10980. }
  10981. set posX(value) {
  10982. this.setPosX(value, false);
  10983. }
  10984. setPosX(value, ani) {
  10985. this._owner.ensureBoundsCorrect();
  10986. if (this._loop == 1)
  10987. value = this.loopCheckingNewPos(value, "x");
  10988. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.x);
  10989. if (value != this._xPos) {
  10990. this._xPos = value;
  10991. this.posChanged(ani);
  10992. }
  10993. }
  10994. get posY() {
  10995. return this._yPos;
  10996. }
  10997. set posY(value) {
  10998. this.setPosY(value, false);
  10999. }
  11000. setPosY(value, ani) {
  11001. this._owner.ensureBoundsCorrect();
  11002. if (this._loop == 1)
  11003. value = this.loopCheckingNewPos(value, "y");
  11004. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.y);
  11005. if (value != this._yPos) {
  11006. this._yPos = value;
  11007. this.posChanged(ani);
  11008. }
  11009. }
  11010. get contentWidth() {
  11011. return this._contentSize.x;
  11012. }
  11013. get contentHeight() {
  11014. return this._contentSize.y;
  11015. }
  11016. get viewWidth() {
  11017. return this._viewSize.x;
  11018. }
  11019. set viewWidth(value) {
  11020. value = value + this._owner.margin.left + this._owner.margin.right;
  11021. if (this._vtScrollBar && !this._floating)
  11022. value += this._vtScrollBar.width;
  11023. this._owner.width = value;
  11024. }
  11025. get viewHeight() {
  11026. return this._viewSize.y;
  11027. }
  11028. set viewHeight(value) {
  11029. value = value + this._owner.margin.top + this._owner.margin.bottom;
  11030. if (this._hzScrollBar && !this._floating)
  11031. value += this._hzScrollBar.height;
  11032. this._owner.height = value;
  11033. }
  11034. get currentPageX() {
  11035. if (!this._pageMode)
  11036. return 0;
  11037. var page = Math.floor(this._xPos / this._pageSize.x);
  11038. if (this._xPos - page * this._pageSize.x > this._pageSize.x * 0.5)
  11039. page++;
  11040. return page;
  11041. }
  11042. set currentPageX(value) {
  11043. this.setCurrentPageX(value, false);
  11044. }
  11045. get currentPageY() {
  11046. if (!this._pageMode)
  11047. return 0;
  11048. var page = Math.floor(this._yPos / this._pageSize.y);
  11049. if (this._yPos - page * this._pageSize.y > this._pageSize.y * 0.5)
  11050. page++;
  11051. return page;
  11052. }
  11053. set currentPageY(value) {
  11054. this.setCurrentPageY(value, false);
  11055. }
  11056. setCurrentPageX(value, ani) {
  11057. if (!this._pageMode)
  11058. return;
  11059. this._owner.ensureBoundsCorrect();
  11060. if (this._overlapSize.x > 0)
  11061. this.setPosX(value * this._pageSize.x, ani);
  11062. }
  11063. setCurrentPageY(value, ani) {
  11064. if (!this._pageMode)
  11065. return;
  11066. this._owner.ensureBoundsCorrect();
  11067. if (this._overlapSize.y > 0)
  11068. this.setPosY(value * this._pageSize.y, ani);
  11069. }
  11070. get isBottomMost() {
  11071. return this._yPos == this._overlapSize.y || this._overlapSize.y == 0;
  11072. }
  11073. get isRightMost() {
  11074. return this._xPos == this._overlapSize.x || this._overlapSize.x == 0;
  11075. }
  11076. get pageController() {
  11077. return this._pageController;
  11078. }
  11079. set pageController(value) {
  11080. this._pageController = value;
  11081. }
  11082. get scrollingPosX() {
  11083. return fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  11084. }
  11085. get scrollingPosY() {
  11086. return fgui.ToolSet.clamp(-this._container.y, 0, this._overlapSize.y);
  11087. }
  11088. scrollTop(ani) {
  11089. this.setPercY(0, ani);
  11090. }
  11091. scrollBottom(ani) {
  11092. this.setPercY(1, ani);
  11093. }
  11094. scrollUp(ratio, ani) {
  11095. ratio = ratio || 1;
  11096. if (this._pageMode)
  11097. this.setPosY(this._yPos - this._pageSize.y * ratio, ani);
  11098. else
  11099. this.setPosY(this._yPos - this._scrollStep * ratio, ani);
  11100. ;
  11101. }
  11102. scrollDown(ratio, ani) {
  11103. ratio = ratio || 1;
  11104. if (this._pageMode)
  11105. this.setPosY(this._yPos + this._pageSize.y * ratio, ani);
  11106. else
  11107. this.setPosY(this._yPos + this._scrollStep * ratio, ani);
  11108. }
  11109. scrollLeft(ratio, ani) {
  11110. ratio = ratio || 1;
  11111. if (this._pageMode)
  11112. this.setPosX(this._xPos - this._pageSize.x * ratio, ani);
  11113. else
  11114. this.setPosX(this._xPos - this._scrollStep * ratio, ani);
  11115. }
  11116. scrollRight(ratio, ani) {
  11117. ratio = ratio || 1;
  11118. if (this._pageMode)
  11119. this.setPosX(this._xPos + this._pageSize.x * ratio, ani);
  11120. else
  11121. this.setPosX(this._xPos + this._scrollStep * ratio, ani);
  11122. }
  11123. scrollToView(target, ani, setFirst) {
  11124. this._owner.ensureBoundsCorrect();
  11125. if (this._needRefresh)
  11126. this.refresh();
  11127. var rect;
  11128. if (target instanceof fgui.GObject) {
  11129. if (target.parent != this._owner) {
  11130. target.parent.localToGlobalRect(target.x, target.y, target.width, target.height, s_rect);
  11131. rect = this._owner.globalToLocalRect(s_rect.x, s_rect.y, s_rect.width, s_rect.height, s_rect);
  11132. }
  11133. else {
  11134. rect = s_rect;
  11135. rect.setTo(target.x, target.y, target.width, target.height);
  11136. }
  11137. }
  11138. else
  11139. rect = target;
  11140. if (this._overlapSize.y > 0) {
  11141. var bottom = this._yPos + this._viewSize.y;
  11142. if (setFirst || rect.y <= this._yPos || rect.height >= this._viewSize.y) {
  11143. if (this._pageMode)
  11144. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  11145. else
  11146. this.setPosY(rect.y, ani);
  11147. }
  11148. else if (rect.y + rect.height > bottom) {
  11149. if (this._pageMode)
  11150. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  11151. else if (rect.height <= this._viewSize.y / 2)
  11152. this.setPosY(rect.y + rect.height * 2 - this._viewSize.y, ani);
  11153. else
  11154. this.setPosY(rect.y + rect.height - this._viewSize.y, ani);
  11155. }
  11156. }
  11157. if (this._overlapSize.x > 0) {
  11158. var right = this._xPos + this._viewSize.x;
  11159. if (setFirst || rect.x <= this._xPos || rect.width >= this._viewSize.x) {
  11160. if (this._pageMode)
  11161. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  11162. else
  11163. this.setPosX(rect.x, ani);
  11164. }
  11165. else if (rect.x + rect.width > right) {
  11166. if (this._pageMode)
  11167. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  11168. else if (rect.width <= this._viewSize.x / 2)
  11169. this.setPosX(rect.x + rect.width * 2 - this._viewSize.x, ani);
  11170. else
  11171. this.setPosX(rect.x + rect.width - this._viewSize.x, ani);
  11172. }
  11173. }
  11174. if (!ani && this._needRefresh)
  11175. this.refresh();
  11176. }
  11177. isChildInView(obj) {
  11178. if (this._overlapSize.y > 0) {
  11179. var dist = obj.y + this._container.y;
  11180. if (dist < -obj.height || dist > this._viewSize.y)
  11181. return false;
  11182. }
  11183. if (this._overlapSize.x > 0) {
  11184. dist = obj.x + this._container.x;
  11185. if (dist < -obj.width || dist > this._viewSize.x)
  11186. return false;
  11187. }
  11188. return true;
  11189. }
  11190. cancelDragging() {
  11191. this._owner.displayObject.stage.off(Laya.Event.MOUSE_MOVE, this, this.__mouseMove);
  11192. this._owner.displayObject.stage.off(Laya.Event.MOUSE_UP, this, this.__mouseUp);
  11193. this._owner.displayObject.stage.off(Laya.Event.CLICK, this, this.__click);
  11194. if (ScrollPane.draggingPane == this)
  11195. ScrollPane.draggingPane = null;
  11196. _gestureFlag = 0;
  11197. this._dragged = false;
  11198. this._maskContainer.mouseEnabled = true;
  11199. }
  11200. lockHeader(size) {
  11201. if (this._headerLockedSize == size)
  11202. return;
  11203. this._headerLockedSize = size;
  11204. if (!this._refreshEventDispatching && this._container[this._refreshBarAxis] >= 0) {
  11205. this._tweenStart.setTo(this._container.x, this._container.y);
  11206. this._tweenChange.setTo(0, 0);
  11207. this._tweenChange[this._refreshBarAxis] = this._headerLockedSize - this._tweenStart[this._refreshBarAxis];
  11208. this._tweenDuration.setTo(TWEEN_TIME_DEFAULT, TWEEN_TIME_DEFAULT);
  11209. this.startTween(2);
  11210. }
  11211. }
  11212. lockFooter(size) {
  11213. if (this._footerLockedSize == size)
  11214. return;
  11215. this._footerLockedSize = size;
  11216. if (!this._refreshEventDispatching && this._container[this._refreshBarAxis] <= -this._overlapSize[this._refreshBarAxis]) {
  11217. this._tweenStart.setTo(this._container.x, this._container.y);
  11218. this._tweenChange.setTo(0, 0);
  11219. var max = this._overlapSize[this._refreshBarAxis];
  11220. if (max == 0)
  11221. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  11222. else
  11223. max += this._footerLockedSize;
  11224. this._tweenChange[this._refreshBarAxis] = -max - this._tweenStart[this._refreshBarAxis];
  11225. this._tweenDuration.setTo(TWEEN_TIME_DEFAULT, TWEEN_TIME_DEFAULT);
  11226. this.startTween(2);
  11227. }
  11228. }
  11229. onOwnerSizeChanged() {
  11230. this.setSize(this._owner.width, this._owner.height);
  11231. this.posChanged(false);
  11232. }
  11233. handleControllerChanged(c) {
  11234. if (this._pageController == c) {
  11235. if (this._scrollType == fgui.ScrollType.Horizontal)
  11236. this.setCurrentPageX(c.selectedIndex, true);
  11237. else
  11238. this.setCurrentPageY(c.selectedIndex, true);
  11239. }
  11240. }
  11241. updatePageController() {
  11242. if (this._pageController != null && !this._pageController.changing) {
  11243. var index;
  11244. if (this._scrollType == fgui.ScrollType.Horizontal)
  11245. index = this.currentPageX;
  11246. else
  11247. index = this.currentPageY;
  11248. if (index < this._pageController.pageCount) {
  11249. var c = this._pageController;
  11250. this._pageController = null; //防止HandleControllerChanged的调用
  11251. c.selectedIndex = index;
  11252. this._pageController = c;
  11253. }
  11254. }
  11255. }
  11256. adjustMaskContainer() {
  11257. var mx = 0, my = 0;
  11258. if (this._dontClipMargin) {
  11259. if (this._displayOnLeft && this._vtScrollBar && !this._floating)
  11260. mx = this._vtScrollBar.width;
  11261. }
  11262. else {
  11263. if (this._displayOnLeft && this._vtScrollBar && !this._floating)
  11264. mx = this._owner.margin.left + this._vtScrollBar.width;
  11265. else
  11266. mx = this._owner.margin.left;
  11267. my = this._owner.margin.top;
  11268. }
  11269. this._maskContainer.pos(mx, my);
  11270. mx = this._owner._alignOffset.x;
  11271. my = this._owner._alignOffset.y;
  11272. if (mx != 0 || my != 0 || this._dontClipMargin) {
  11273. if (!this._alignContainer) {
  11274. this._alignContainer = new Laya.Sprite();
  11275. this._maskContainer.addChild(this._alignContainer);
  11276. this._alignContainer.addChild(this._container);
  11277. }
  11278. }
  11279. if (this._alignContainer) {
  11280. if (this._dontClipMargin) {
  11281. mx += this._owner.margin.left;
  11282. my += this._owner.margin.top;
  11283. }
  11284. this._alignContainer.pos(mx, my);
  11285. }
  11286. }
  11287. setSize(aWidth, aHeight) {
  11288. this.adjustMaskContainer();
  11289. if (this._hzScrollBar) {
  11290. this._hzScrollBar.y = aHeight - this._hzScrollBar.height;
  11291. if (this._vtScrollBar) {
  11292. this._hzScrollBar.width = aWidth - this._vtScrollBar.width - this._scrollBarMargin.left - this._scrollBarMargin.right;
  11293. if (this._displayOnLeft)
  11294. this._hzScrollBar.x = this._scrollBarMargin.left + this._vtScrollBar.width;
  11295. else
  11296. this._hzScrollBar.x = this._scrollBarMargin.left;
  11297. }
  11298. else {
  11299. this._hzScrollBar.width = aWidth - this._scrollBarMargin.left - this._scrollBarMargin.right;
  11300. this._hzScrollBar.x = this._scrollBarMargin.left;
  11301. }
  11302. }
  11303. if (this._vtScrollBar) {
  11304. if (!this._displayOnLeft)
  11305. this._vtScrollBar.x = aWidth - this._vtScrollBar.width;
  11306. if (this._hzScrollBar)
  11307. this._vtScrollBar.height = aHeight - this._hzScrollBar.height - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  11308. else
  11309. this._vtScrollBar.height = aHeight - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  11310. this._vtScrollBar.y = this._scrollBarMargin.top;
  11311. }
  11312. this._viewSize.x = aWidth;
  11313. this._viewSize.y = aHeight;
  11314. if (this._hzScrollBar && !this._floating)
  11315. this._viewSize.y -= this._hzScrollBar.height;
  11316. if (this._vtScrollBar && !this._floating)
  11317. this._viewSize.x -= this._vtScrollBar.width;
  11318. this._viewSize.x -= (this._owner.margin.left + this._owner.margin.right);
  11319. this._viewSize.y -= (this._owner.margin.top + this._owner.margin.bottom);
  11320. this._viewSize.x = Math.max(1, this._viewSize.x);
  11321. this._viewSize.y = Math.max(1, this._viewSize.y);
  11322. this._pageSize.x = this._viewSize.x;
  11323. this._pageSize.y = this._viewSize.y;
  11324. this.handleSizeChanged();
  11325. }
  11326. setContentSize(aWidth, aHeight) {
  11327. if (this._contentSize.x == aWidth && this._contentSize.y == aHeight)
  11328. return;
  11329. this._contentSize.x = aWidth;
  11330. this._contentSize.y = aHeight;
  11331. this.handleSizeChanged();
  11332. }
  11333. changeContentSizeOnScrolling(deltaWidth, deltaHeight, deltaPosX, deltaPosY) {
  11334. var isRightmost = this._xPos == this._overlapSize.x;
  11335. var isBottom = this._yPos == this._overlapSize.y;
  11336. this._contentSize.x += deltaWidth;
  11337. this._contentSize.y += deltaHeight;
  11338. this.handleSizeChanged();
  11339. if (this._tweening == 1) {
  11340. //如果原来滚动位置是贴边,加入处理继续贴边。
  11341. if (deltaWidth != 0 && isRightmost && this._tweenChange.x < 0) {
  11342. this._xPos = this._overlapSize.x;
  11343. this._tweenChange.x = -this._xPos - this._tweenStart.x;
  11344. }
  11345. if (deltaHeight != 0 && isBottom && this._tweenChange.y < 0) {
  11346. this._yPos = this._overlapSize.y;
  11347. this._tweenChange.y = -this._yPos - this._tweenStart.y;
  11348. }
  11349. }
  11350. else if (this._tweening == 2) {
  11351. //重新调整起始位置,确保能够顺滑滚下去
  11352. if (deltaPosX != 0) {
  11353. this._container.x -= deltaPosX;
  11354. this._tweenStart.x -= deltaPosX;
  11355. this._xPos = -this._container.x;
  11356. }
  11357. if (deltaPosY != 0) {
  11358. this._container.y -= deltaPosY;
  11359. this._tweenStart.y -= deltaPosY;
  11360. this._yPos = -this._container.y;
  11361. }
  11362. }
  11363. else if (this._dragged) {
  11364. if (deltaPosX != 0) {
  11365. this._container.x -= deltaPosX;
  11366. this._containerPos.x -= deltaPosX;
  11367. this._xPos = -this._container.x;
  11368. }
  11369. if (deltaPosY != 0) {
  11370. this._container.y -= deltaPosY;
  11371. this._containerPos.y -= deltaPosY;
  11372. this._yPos = -this._container.y;
  11373. }
  11374. }
  11375. else {
  11376. //如果原来滚动位置是贴边,加入处理继续贴边。
  11377. if (deltaWidth != 0 && isRightmost) {
  11378. this._xPos = this._overlapSize.x;
  11379. this._container.x = -this._xPos;
  11380. }
  11381. if (deltaHeight != 0 && isBottom) {
  11382. this._yPos = this._overlapSize.y;
  11383. this._container.y = -this._yPos;
  11384. }
  11385. }
  11386. if (this._pageMode)
  11387. this.updatePageController();
  11388. }
  11389. handleSizeChanged() {
  11390. if (this._displayInDemand) {
  11391. this._vScrollNone = this._contentSize.y <= this._viewSize.y;
  11392. this._hScrollNone = this._contentSize.x <= this._viewSize.x;
  11393. }
  11394. if (this._vtScrollBar) {
  11395. if (this._contentSize.y == 0)
  11396. this._vtScrollBar.setDisplayPerc(0);
  11397. else
  11398. this._vtScrollBar.setDisplayPerc(Math.min(1, this._viewSize.y / this._contentSize.y));
  11399. }
  11400. if (this._hzScrollBar) {
  11401. if (this._contentSize.x == 0)
  11402. this._hzScrollBar.setDisplayPerc(0);
  11403. else
  11404. this._hzScrollBar.setDisplayPerc(Math.min(1, this._viewSize.x / this._contentSize.x));
  11405. }
  11406. this.updateScrollBarVisible();
  11407. var rect = this._maskContainer.scrollRect;
  11408. if (rect) {
  11409. rect.width = this._viewSize.x;
  11410. rect.height = this._viewSize.y;
  11411. if (this._vScrollNone && this._vtScrollBar)
  11412. rect.width += this._vtScrollBar.width;
  11413. if (this._hScrollNone && this._hzScrollBar)
  11414. rect.height += this._hzScrollBar.height;
  11415. if (this._dontClipMargin) {
  11416. rect.width += (this._owner.margin.left + this._owner.margin.right);
  11417. rect.height += (this._owner.margin.top + this._owner.margin.bottom);
  11418. }
  11419. this._maskContainer.scrollRect = rect;
  11420. }
  11421. if (this._scrollType == fgui.ScrollType.Horizontal || this._scrollType == fgui.ScrollType.Both)
  11422. this._overlapSize.x = Math.ceil(Math.max(0, this._contentSize.x - this._viewSize.x));
  11423. else
  11424. this._overlapSize.x = 0;
  11425. if (this._scrollType == fgui.ScrollType.Vertical || this._scrollType == fgui.ScrollType.Both)
  11426. this._overlapSize.y = Math.ceil(Math.max(0, this._contentSize.y - this._viewSize.y));
  11427. else
  11428. this._overlapSize.y = 0;
  11429. //边界检查
  11430. this._xPos = fgui.ToolSet.clamp(this._xPos, 0, this._overlapSize.x);
  11431. this._yPos = fgui.ToolSet.clamp(this._yPos, 0, this._overlapSize.y);
  11432. if (this._refreshBarAxis != null) {
  11433. var max = this._overlapSize[this._refreshBarAxis];
  11434. if (max == 0)
  11435. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  11436. else
  11437. max += this._footerLockedSize;
  11438. if (this._refreshBarAxis == "x") {
  11439. this._container.pos(fgui.ToolSet.clamp(this._container.x, -max, this._headerLockedSize), fgui.ToolSet.clamp(this._container.y, -this._overlapSize.y, 0));
  11440. }
  11441. else {
  11442. this._container.pos(fgui.ToolSet.clamp(this._container.x, -this._overlapSize.x, 0), fgui.ToolSet.clamp(this._container.y, -max, this._headerLockedSize));
  11443. }
  11444. if (this._header) {
  11445. if (this._refreshBarAxis == "x")
  11446. this._header.height = this._viewSize.y;
  11447. else
  11448. this._header.width = this._viewSize.x;
  11449. }
  11450. if (this._footer) {
  11451. if (this._refreshBarAxis == "y")
  11452. this._footer.height = this._viewSize.y;
  11453. else
  11454. this._footer.width = this._viewSize.x;
  11455. }
  11456. }
  11457. else {
  11458. this._container.pos(fgui.ToolSet.clamp(this._container.x, -this._overlapSize.x, 0), fgui.ToolSet.clamp(this._container.y, -this._overlapSize.y, 0));
  11459. }
  11460. this.updateScrollBarPos();
  11461. if (this._pageMode)
  11462. this.updatePageController();
  11463. }
  11464. posChanged(ani) {
  11465. if (this._aniFlag == 0)
  11466. this._aniFlag = ani ? 1 : -1;
  11467. else if (this._aniFlag == 1 && !ani)
  11468. this._aniFlag = -1;
  11469. this._needRefresh = true;
  11470. Laya.timer.callLater(this, this.refresh);
  11471. }
  11472. refresh() {
  11473. if (!this._owner.displayObject) {
  11474. return;
  11475. }
  11476. this._needRefresh = false;
  11477. Laya.timer.clear(this, this.refresh);
  11478. if (this._pageMode || this._snapToItem) {
  11479. sEndPos.setTo(-this._xPos, -this._yPos);
  11480. this.alignPosition(sEndPos, false);
  11481. this._xPos = -sEndPos.x;
  11482. this._yPos = -sEndPos.y;
  11483. }
  11484. this.refresh2();
  11485. fgui.Events.dispatch(fgui.Events.SCROLL, this._owner.displayObject);
  11486. if (this._needRefresh) //在onScroll事件里开发者可能修改位置,这里再刷新一次,避免闪烁
  11487. {
  11488. this._needRefresh = false;
  11489. Laya.timer.clear(this, this.refresh);
  11490. this.refresh2();
  11491. }
  11492. this.updateScrollBarPos();
  11493. this._aniFlag = 0;
  11494. }
  11495. refresh2() {
  11496. if (this._aniFlag == 1 && !this._dragged) {
  11497. var posX;
  11498. var posY;
  11499. if (this._overlapSize.x > 0)
  11500. posX = -Math.floor(this._xPos);
  11501. else {
  11502. if (this._container.x != 0)
  11503. this._container.x = 0;
  11504. posX = 0;
  11505. }
  11506. if (this._overlapSize.y > 0)
  11507. posY = -Math.floor(this._yPos);
  11508. else {
  11509. if (this._container.y != 0)
  11510. this._container.y = 0;
  11511. posY = 0;
  11512. }
  11513. if (posX != this._container.x || posY != this._container.y) {
  11514. this._tweenDuration.setTo(TWEEN_TIME_GO, TWEEN_TIME_GO);
  11515. this._tweenStart.setTo(this._container.x, this._container.y);
  11516. this._tweenChange.setTo(posX - this._tweenStart.x, posY - this._tweenStart.y);
  11517. this.startTween(1);
  11518. }
  11519. else if (this._tweening != 0)
  11520. this.killTween();
  11521. }
  11522. else {
  11523. if (this._tweening != 0)
  11524. this.killTween();
  11525. this._container.pos(Math.floor(-this._xPos), Math.floor(-this._yPos));
  11526. this.loopCheckingCurrent();
  11527. }
  11528. if (this._pageMode)
  11529. this.updatePageController();
  11530. }
  11531. __mouseDown() {
  11532. if (!this._touchEffect)
  11533. return;
  11534. if (this._tweening != 0) {
  11535. this.killTween();
  11536. this._dragged = true;
  11537. }
  11538. else
  11539. this._dragged = false;
  11540. var pt = this._owner.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY, s_vec2);
  11541. this._containerPos.setTo(this._container.x, this._container.y);
  11542. this._beginTouchPos.setTo(pt.x, pt.y);
  11543. this._lastTouchPos.setTo(pt.x, pt.y);
  11544. this._lastTouchGlobalPos.setTo(Laya.stage.mouseX, Laya.stage.mouseY);
  11545. this._isHoldAreaDone = false;
  11546. this._velocity.setTo(0, 0);
  11547. this._velocityScale = 1;
  11548. this._lastMoveTime = Laya.timer.currTimer / 1000;
  11549. this._owner.displayObject.stage.on(Laya.Event.MOUSE_MOVE, this, this.__mouseMove);
  11550. this._owner.displayObject.stage.on(Laya.Event.MOUSE_UP, this, this.__mouseUp);
  11551. this._owner.displayObject.stage.on(Laya.Event.CLICK, this, this.__click);
  11552. }
  11553. __mouseMove() {
  11554. if (!this._touchEffect || this.owner.isDisposed)
  11555. return;
  11556. if (ScrollPane.draggingPane && ScrollPane.draggingPane != this || fgui.GObject.draggingObject) //已经有其他拖动
  11557. return;
  11558. var sensitivity = fgui.UIConfig.touchScrollSensitivity;
  11559. var pt = this._owner.globalToLocal(Laya.stage.mouseX, Laya.stage.mouseY, s_vec2);
  11560. var diff, diff2;
  11561. var sv, sh, st;
  11562. if (this._scrollType == fgui.ScrollType.Vertical) {
  11563. if (!this._isHoldAreaDone) {
  11564. //表示正在监测垂直方向的手势
  11565. _gestureFlag |= 1;
  11566. diff = Math.abs(this._beginTouchPos.y - pt.y);
  11567. if (diff < sensitivity)
  11568. return;
  11569. if ((_gestureFlag & 2) != 0) //已经有水平方向的手势在监测,那么我们用严格的方式检查是不是按垂直方向移动,避免冲突
  11570. {
  11571. diff2 = Math.abs(this._beginTouchPos.x - pt.x);
  11572. if (diff < diff2) //不通过则不允许滚动了
  11573. return;
  11574. }
  11575. }
  11576. sv = true;
  11577. }
  11578. else if (this._scrollType == fgui.ScrollType.Horizontal) {
  11579. if (!this._isHoldAreaDone) {
  11580. _gestureFlag |= 2;
  11581. diff = Math.abs(this._beginTouchPos.x - pt.x);
  11582. if (diff < sensitivity)
  11583. return;
  11584. if ((_gestureFlag & 1) != 0) {
  11585. diff2 = Math.abs(this._beginTouchPos.y - pt.y);
  11586. if (diff < diff2)
  11587. return;
  11588. }
  11589. }
  11590. sh = true;
  11591. }
  11592. else {
  11593. _gestureFlag = 3;
  11594. if (!this._isHoldAreaDone) {
  11595. diff = Math.abs(this._beginTouchPos.y - pt.y);
  11596. if (diff < sensitivity) {
  11597. diff = Math.abs(this._beginTouchPos.x - pt.x);
  11598. if (diff < sensitivity)
  11599. return;
  11600. }
  11601. }
  11602. sv = sh = true;
  11603. }
  11604. var newPosX = Math.floor(this._containerPos.x + pt.x - this._beginTouchPos.x);
  11605. var newPosY = Math.floor(this._containerPos.y + pt.y - this._beginTouchPos.y);
  11606. if (sv) {
  11607. if (newPosY > 0) {
  11608. if (!this._bouncebackEffect)
  11609. this._container.y = 0;
  11610. else if (this._header && this._header.maxHeight != 0)
  11611. this._container.y = Math.floor(Math.min(newPosY * 0.5, this._header.maxHeight));
  11612. else
  11613. this._container.y = Math.floor(Math.min(newPosY * 0.5, this._viewSize.y * PULL_RATIO));
  11614. }
  11615. else if (newPosY < -this._overlapSize.y) {
  11616. if (!this._bouncebackEffect)
  11617. this._container.y = -this._overlapSize.y;
  11618. else if (this._footer && this._footer.maxHeight > 0)
  11619. this._container.y = Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._footer.maxHeight) - this._overlapSize.y);
  11620. else
  11621. this._container.y = Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._viewSize.y * PULL_RATIO) - this._overlapSize.y);
  11622. }
  11623. else
  11624. this._container.y = newPosY;
  11625. }
  11626. if (sh) {
  11627. if (newPosX > 0) {
  11628. if (!this._bouncebackEffect)
  11629. this._container.x = 0;
  11630. else if (this._header && this._header.maxWidth != 0)
  11631. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._header.maxWidth));
  11632. else
  11633. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._viewSize.x * PULL_RATIO));
  11634. }
  11635. else if (newPosX < 0 - this._overlapSize.x) {
  11636. if (!this._bouncebackEffect)
  11637. this._container.x = -this._overlapSize.x;
  11638. else if (this._footer && this._footer.maxWidth > 0)
  11639. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._footer.maxWidth) - this._overlapSize.x);
  11640. else
  11641. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._viewSize.x * PULL_RATIO) - this._overlapSize.x);
  11642. }
  11643. else
  11644. this._container.x = newPosX;
  11645. }
  11646. //更新速度
  11647. var frameRate = Laya.stage.frameRate == Laya.Stage.FRAME_SLOW ? 30 : 60;
  11648. var now = Laya.timer.currTimer / 1000;
  11649. var deltaTime = Math.max(now - this._lastMoveTime, 1 / frameRate);
  11650. var deltaPositionX = pt.x - this._lastTouchPos.x;
  11651. var deltaPositionY = pt.y - this._lastTouchPos.y;
  11652. if (!sh)
  11653. deltaPositionX = 0;
  11654. if (!sv)
  11655. deltaPositionY = 0;
  11656. if (deltaTime != 0) {
  11657. var elapsed = deltaTime * frameRate - 1;
  11658. if (elapsed > 1) //速度衰减
  11659. {
  11660. var factor = Math.pow(0.833, elapsed);
  11661. this._velocity.x = this._velocity.x * factor;
  11662. this._velocity.y = this._velocity.y * factor;
  11663. }
  11664. this._velocity.x = fgui.ToolSet.lerp(this._velocity.x, deltaPositionX * 60 / frameRate / deltaTime, deltaTime * 10);
  11665. this._velocity.y = fgui.ToolSet.lerp(this._velocity.y, deltaPositionY * 60 / frameRate / deltaTime, deltaTime * 10);
  11666. }
  11667. /*速度计算使用的是本地位移,但在后续的惯性滚动判断中需要用到屏幕位移,所以这里要记录一个位移的比例。
  11668. */
  11669. var deltaGlobalPositionX = this._lastTouchGlobalPos.x - Laya.stage.mouseX;
  11670. var deltaGlobalPositionY = this._lastTouchGlobalPos.y - Laya.stage.mouseY;
  11671. if (deltaPositionX != 0)
  11672. this._velocityScale = Math.abs(deltaGlobalPositionX / deltaPositionX);
  11673. else if (deltaPositionY != 0)
  11674. this._velocityScale = Math.abs(deltaGlobalPositionY / deltaPositionY);
  11675. this._lastTouchPos.setTo(pt.x, pt.y);
  11676. this._lastTouchGlobalPos.setTo(Laya.stage.mouseX, Laya.stage.mouseY);
  11677. this._lastMoveTime = now;
  11678. //同步更新pos值
  11679. if (this._overlapSize.x > 0)
  11680. this._xPos = fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  11681. if (this._overlapSize.y > 0)
  11682. this._yPos = fgui.ToolSet.clamp(-this._container.y, 0, this._overlapSize.y);
  11683. //循环滚动特别检查
  11684. if (this._loop != 0) {
  11685. newPosX = this._container.x;
  11686. newPosY = this._container.y;
  11687. if (this.loopCheckingCurrent()) {
  11688. this._containerPos.x += this._container.x - newPosX;
  11689. this._containerPos.y += this._container.y - newPosY;
  11690. }
  11691. }
  11692. ScrollPane.draggingPane = this;
  11693. this._isHoldAreaDone = true;
  11694. this._dragged = true;
  11695. this._maskContainer.mouseEnabled = false;
  11696. this.updateScrollBarPos();
  11697. this.updateScrollBarVisible();
  11698. if (this._pageMode)
  11699. this.updatePageController();
  11700. fgui.Events.dispatch(fgui.Events.SCROLL, this._owner.displayObject);
  11701. }
  11702. __mouseUp() {
  11703. if (this._owner.isDisposed)
  11704. return;
  11705. this._owner.displayObject.stage.off(Laya.Event.MOUSE_MOVE, this, this.__mouseMove);
  11706. this._owner.displayObject.stage.off(Laya.Event.MOUSE_UP, this, this.__mouseUp);
  11707. this._owner.displayObject.stage.off(Laya.Event.CLICK, this, this.__click);
  11708. if (ScrollPane.draggingPane == this)
  11709. ScrollPane.draggingPane = null;
  11710. _gestureFlag = 0;
  11711. if (!this._dragged || !this._touchEffect) {
  11712. this._dragged = false;
  11713. this._maskContainer.mouseEnabled = true;
  11714. return;
  11715. }
  11716. this._dragged = false;
  11717. this._maskContainer.mouseEnabled = true;
  11718. this._tweenStart.setTo(this._container.x, this._container.y);
  11719. sEndPos.setTo(this._tweenStart.x, this._tweenStart.y);
  11720. var flag = false;
  11721. if (this._container.x > 0) {
  11722. sEndPos.x = 0;
  11723. flag = true;
  11724. }
  11725. else if (this._container.x < -this._overlapSize.x) {
  11726. sEndPos.x = -this._overlapSize.x;
  11727. flag = true;
  11728. }
  11729. if (this._container.y > 0) {
  11730. sEndPos.y = 0;
  11731. flag = true;
  11732. }
  11733. else if (this._container.y < -this._overlapSize.y) {
  11734. sEndPos.y = -this._overlapSize.y;
  11735. flag = true;
  11736. }
  11737. if (flag) {
  11738. this._tweenChange.setTo(sEndPos.x - this._tweenStart.x, sEndPos.y - this._tweenStart.y);
  11739. if (this._tweenChange.x < -fgui.UIConfig.touchDragSensitivity || this._tweenChange.y < -fgui.UIConfig.touchDragSensitivity) {
  11740. this._refreshEventDispatching = true;
  11741. fgui.Events.dispatch(fgui.Events.PULL_DOWN_RELEASE, this._owner.displayObject);
  11742. this._refreshEventDispatching = false;
  11743. }
  11744. else if (this._tweenChange.x > fgui.UIConfig.touchDragSensitivity || this._tweenChange.y > fgui.UIConfig.touchDragSensitivity) {
  11745. this._refreshEventDispatching = true;
  11746. fgui.Events.dispatch(fgui.Events.PULL_UP_RELEASE, this._owner.displayObject);
  11747. this._refreshEventDispatching = false;
  11748. }
  11749. if (this._headerLockedSize > 0 && sEndPos[this._refreshBarAxis] == 0) {
  11750. sEndPos[this._refreshBarAxis] = this._headerLockedSize;
  11751. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  11752. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  11753. }
  11754. else if (this._footerLockedSize > 0 && sEndPos[this._refreshBarAxis] == -this._overlapSize[this._refreshBarAxis]) {
  11755. var max = this._overlapSize[this._refreshBarAxis];
  11756. if (max == 0)
  11757. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  11758. else
  11759. max += this._footerLockedSize;
  11760. sEndPos[this._refreshBarAxis] = -max;
  11761. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  11762. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  11763. }
  11764. this._tweenDuration.setTo(TWEEN_TIME_DEFAULT, TWEEN_TIME_DEFAULT);
  11765. }
  11766. else {
  11767. //更新速度
  11768. if (!this._inertiaDisabled) {
  11769. var frameRate = Laya.stage.frameRate == Laya.Stage.FRAME_SLOW ? 30 : 60;
  11770. var elapsed = (Laya.timer.currTimer / 1000 - this._lastMoveTime) * frameRate - 1;
  11771. if (elapsed > 1) {
  11772. var factor = Math.pow(0.833, elapsed);
  11773. this._velocity.x = this._velocity.x * factor;
  11774. this._velocity.y = this._velocity.y * factor;
  11775. }
  11776. //根据速度计算目标位置和需要时间
  11777. this.updateTargetAndDuration(this._tweenStart, sEndPos);
  11778. }
  11779. else
  11780. this._tweenDuration.setTo(TWEEN_TIME_DEFAULT, TWEEN_TIME_DEFAULT);
  11781. sOldChange.setTo(sEndPos.x - this._tweenStart.x, sEndPos.y - this._tweenStart.y);
  11782. //调整目标位置
  11783. this.loopCheckingTarget(sEndPos);
  11784. if (this._pageMode || this._snapToItem)
  11785. this.alignPosition(sEndPos, true);
  11786. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  11787. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  11788. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  11789. this.updateScrollBarVisible();
  11790. return;
  11791. }
  11792. //如果目标位置已调整,随之调整需要时间
  11793. if (this._pageMode || this._snapToItem) {
  11794. this.fixDuration("x", sOldChange.x);
  11795. this.fixDuration("y", sOldChange.y);
  11796. }
  11797. }
  11798. this.startTween(2);
  11799. }
  11800. __click() {
  11801. this._dragged = false;
  11802. }
  11803. __mouseWheel(evt) {
  11804. if (!this._mouseWheelEnabled)
  11805. return;
  11806. var delta = evt["delta"];
  11807. delta = delta > 0 ? -1 : (delta < 0 ? 1 : 0);
  11808. if (this._overlapSize.x > 0 && this._overlapSize.y == 0) {
  11809. if (this._pageMode)
  11810. this.setPosX(this._xPos + this._pageSize.x * delta, false);
  11811. else
  11812. this.setPosX(this._xPos + this._mouseWheelStep * delta, false);
  11813. }
  11814. else {
  11815. if (this._pageMode)
  11816. this.setPosY(this._yPos + this._pageSize.y * delta, false);
  11817. else
  11818. this.setPosY(this._yPos + this._mouseWheelStep * delta, false);
  11819. }
  11820. }
  11821. updateScrollBarPos() {
  11822. if (this._vtScrollBar)
  11823. this._vtScrollBar.setScrollPerc(this._overlapSize.y == 0 ? 0 : fgui.ToolSet.clamp(-this._container.y, 0, this._overlapSize.y) / this._overlapSize.y);
  11824. if (this._hzScrollBar)
  11825. this._hzScrollBar.setScrollPerc(this._overlapSize.x == 0 ? 0 : fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x) / this._overlapSize.x);
  11826. this.checkRefreshBar();
  11827. }
  11828. updateScrollBarVisible() {
  11829. if (this._vtScrollBar) {
  11830. if (this._viewSize.y <= this._vtScrollBar.minSize || this._vScrollNone)
  11831. this._vtScrollBar.displayObject.visible = false;
  11832. else
  11833. this.updateScrollBarVisible2(this._vtScrollBar);
  11834. }
  11835. if (this._hzScrollBar) {
  11836. if (this._viewSize.x <= this._hzScrollBar.minSize || this._hScrollNone)
  11837. this._hzScrollBar.displayObject.visible = false;
  11838. else
  11839. this.updateScrollBarVisible2(this._hzScrollBar);
  11840. }
  11841. }
  11842. updateScrollBarVisible2(bar) {
  11843. if (this._scrollBarDisplayAuto)
  11844. fgui.GTween.kill(bar, false, "alpha");
  11845. if (this._scrollBarDisplayAuto && this._tweening == 0 && !this._dragged && !bar.gripDragging) {
  11846. if (bar.displayObject.visible)
  11847. fgui.GTween.to(1, 0, 0.5).setDelay(0.5).onComplete(this.__barTweenComplete, this).setTarget(bar, "alpha");
  11848. }
  11849. else {
  11850. bar.alpha = 1;
  11851. bar.displayObject.visible = true;
  11852. }
  11853. }
  11854. __barTweenComplete(tweener) {
  11855. var bar = (tweener.target);
  11856. bar.alpha = 1;
  11857. bar.displayObject.visible = false;
  11858. }
  11859. getLoopPartSize(division, axis) {
  11860. return (this._contentSize[axis] + (axis == "x" ? (this._owner).columnGap : (this._owner).lineGap)) / division;
  11861. }
  11862. loopCheckingCurrent() {
  11863. var changed = false;
  11864. if (this._loop == 1 && this._overlapSize.x > 0) {
  11865. if (this._xPos < 0.001) {
  11866. this._xPos += this.getLoopPartSize(2, "x");
  11867. changed = true;
  11868. }
  11869. else if (this._xPos >= this._overlapSize.x) {
  11870. this._xPos -= this.getLoopPartSize(2, "x");
  11871. changed = true;
  11872. }
  11873. }
  11874. else if (this._loop == 2 && this._overlapSize.y > 0) {
  11875. if (this._yPos < 0.001) {
  11876. this._yPos += this.getLoopPartSize(2, "y");
  11877. changed = true;
  11878. }
  11879. else if (this._yPos >= this._overlapSize.y) {
  11880. this._yPos -= this.getLoopPartSize(2, "y");
  11881. changed = true;
  11882. }
  11883. }
  11884. if (changed)
  11885. this._container.pos(Math.floor(-this._xPos), Math.floor(-this._yPos));
  11886. return changed;
  11887. }
  11888. loopCheckingTarget(endPos) {
  11889. if (this._loop == 1)
  11890. this.loopCheckingTarget2(endPos, "x");
  11891. if (this._loop == 2)
  11892. this.loopCheckingTarget2(endPos, "y");
  11893. }
  11894. loopCheckingTarget2(endPos, axis) {
  11895. var halfSize;
  11896. var tmp;
  11897. if (endPos[axis] > 0) {
  11898. halfSize = this.getLoopPartSize(2, axis);
  11899. tmp = this._tweenStart[axis] - halfSize;
  11900. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  11901. endPos[axis] -= halfSize;
  11902. this._tweenStart[axis] = tmp;
  11903. }
  11904. }
  11905. else if (endPos[axis] < -this._overlapSize[axis]) {
  11906. halfSize = this.getLoopPartSize(2, axis);
  11907. tmp = this._tweenStart[axis] + halfSize;
  11908. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  11909. endPos[axis] += halfSize;
  11910. this._tweenStart[axis] = tmp;
  11911. }
  11912. }
  11913. }
  11914. loopCheckingNewPos(value, axis) {
  11915. if (this._overlapSize[axis] == 0)
  11916. return value;
  11917. var pos = axis == "x" ? this._xPos : this._yPos;
  11918. var changed = false;
  11919. var v;
  11920. if (value < 0.001) {
  11921. value += this.getLoopPartSize(2, axis);
  11922. if (value > pos) {
  11923. v = this.getLoopPartSize(6, axis);
  11924. v = Math.ceil((value - pos) / v) * v;
  11925. pos = fgui.ToolSet.clamp(pos + v, 0, this._overlapSize[axis]);
  11926. changed = true;
  11927. }
  11928. }
  11929. else if (value >= this._overlapSize[axis]) {
  11930. value -= this.getLoopPartSize(2, axis);
  11931. if (value < pos) {
  11932. v = this.getLoopPartSize(6, axis);
  11933. v = Math.ceil((pos - value) / v) * v;
  11934. pos = fgui.ToolSet.clamp(pos - v, 0, this._overlapSize[axis]);
  11935. changed = true;
  11936. }
  11937. }
  11938. if (changed) {
  11939. if (axis == "x")
  11940. this._container.x = -Math.floor(pos);
  11941. else
  11942. this._container.y = -Math.floor(pos);
  11943. }
  11944. return value;
  11945. }
  11946. alignPosition(pos, inertialScrolling) {
  11947. if (this._pageMode) {
  11948. pos.x = this.alignByPage(pos.x, "x", inertialScrolling);
  11949. pos.y = this.alignByPage(pos.y, "y", inertialScrolling);
  11950. }
  11951. else if (this._snapToItem) {
  11952. var xDir = 0;
  11953. var yDir = 0;
  11954. if (inertialScrolling) {
  11955. xDir = pos.x - this._containerPos.x;
  11956. yDir = pos.y - this._containerPos.y;
  11957. }
  11958. var pt = this._owner.getSnappingPositionWithDir(-pos.x, -pos.y, xDir, yDir, s_vec2);
  11959. if (pos.x < 0 && pos.x > -this._overlapSize.x)
  11960. pos.x = -pt.x;
  11961. if (pos.y < 0 && pos.y > -this._overlapSize.y)
  11962. pos.y = -pt.y;
  11963. }
  11964. }
  11965. alignByPage(pos, axis, inertialScrolling) {
  11966. var page;
  11967. if (pos > 0)
  11968. page = 0;
  11969. else if (pos < -this._overlapSize[axis])
  11970. page = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  11971. else {
  11972. page = Math.floor(-pos / this._pageSize[axis]);
  11973. var change = inertialScrolling ? (pos - this._containerPos[axis]) : (pos - this._container[axis]);
  11974. var testPageSize = Math.min(this._pageSize[axis], this._contentSize[axis] - (page + 1) * this._pageSize[axis]);
  11975. var delta = -pos - page * this._pageSize[axis];
  11976. //页面吸附策略
  11977. if (Math.abs(change) > this._pageSize[axis]) //如果滚动距离超过1页,则需要超过页面的一半,才能到更下一页
  11978. {
  11979. if (delta > testPageSize * 0.5)
  11980. page++;
  11981. }
  11982. else //否则只需要页面的1/3,当然,需要考虑到左移和右移的情况
  11983. {
  11984. if (delta > testPageSize * (change < 0 ? fgui.UIConfig.defaultScrollPagingThreshold : (1 - fgui.UIConfig.defaultScrollPagingThreshold)))
  11985. page++;
  11986. }
  11987. //重新计算终点
  11988. pos = -page * this._pageSize[axis];
  11989. if (pos < -this._overlapSize[axis]) //最后一页未必有pageSize那么大
  11990. pos = -this._overlapSize[axis];
  11991. }
  11992. //惯性滚动模式下,会增加判断尽量不要滚动超过一页
  11993. if (inertialScrolling) {
  11994. var oldPos = this._tweenStart[axis];
  11995. var oldPage;
  11996. if (oldPos > 0)
  11997. oldPage = 0;
  11998. else if (oldPos < -this._overlapSize[axis])
  11999. oldPage = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  12000. else
  12001. oldPage = Math.floor(-oldPos / this._pageSize[axis]);
  12002. var startPage = Math.floor(-this._containerPos[axis] / this._pageSize[axis]);
  12003. if (Math.abs(page - startPage) > 1 && Math.abs(oldPage - startPage) <= 1) {
  12004. if (page > startPage)
  12005. page = startPage + 1;
  12006. else
  12007. page = startPage - 1;
  12008. pos = -page * this._pageSize[axis];
  12009. }
  12010. }
  12011. return pos;
  12012. }
  12013. updateTargetAndDuration(orignPos, resultPos) {
  12014. resultPos.x = this.updateTargetAndDuration2(orignPos.x, "x");
  12015. resultPos.y = this.updateTargetAndDuration2(orignPos.y, "y");
  12016. }
  12017. updateTargetAndDuration2(pos, axis) {
  12018. var v = this._velocity[axis];
  12019. var duration = 0;
  12020. if (pos > 0)
  12021. pos = 0;
  12022. else if (pos < -this._overlapSize[axis])
  12023. pos = -this._overlapSize[axis];
  12024. else {
  12025. //以屏幕像素为基准
  12026. var v2 = Math.abs(v) * this._velocityScale;
  12027. //在移动设备上,需要对不同分辨率做一个适配,我们的速度判断以1136分辨率为基准
  12028. if (Laya.Browser.onMobile)
  12029. v2 *= 1136 / Math.max(Laya.stage.width, Laya.stage.height);
  12030. //这里有一些阈值的处理,因为在低速内,不希望产生较大的滚动(甚至不滚动)
  12031. var ratio = 0;
  12032. if (this._pageMode || !Laya.Browser.onMobile) {
  12033. if (v2 > 500)
  12034. ratio = Math.pow((v2 - 500) / 500, 2);
  12035. }
  12036. else {
  12037. if (v2 > 1000)
  12038. ratio = Math.pow((v2 - 1000) / 1000, 2);
  12039. }
  12040. if (ratio != 0) {
  12041. if (ratio > 1)
  12042. ratio = 1;
  12043. v2 *= ratio;
  12044. v *= ratio;
  12045. this._velocity[axis] = v;
  12046. //算法:v*(_decelerationRate的n次幂)= 60,即在n帧后速度降为60(假设每秒60帧)。
  12047. duration = Math.log(60 / v2) / Math.log(this._decelerationRate) / 60;
  12048. //计算距离要使用本地速度
  12049. //理论公式貌似滚动的距离不够,改为经验公式
  12050. //var change:number = (v/ 60 - 1) / (1 - this._decelerationRate);
  12051. var change = Math.floor(v * duration * 0.4);
  12052. pos += change;
  12053. }
  12054. }
  12055. if (duration < TWEEN_TIME_DEFAULT)
  12056. duration = TWEEN_TIME_DEFAULT;
  12057. this._tweenDuration[axis] = duration;
  12058. return pos;
  12059. }
  12060. fixDuration(axis, oldChange) {
  12061. if (this._tweenChange[axis] == 0 || Math.abs(this._tweenChange[axis]) >= Math.abs(oldChange))
  12062. return;
  12063. var newDuration = Math.abs(this._tweenChange[axis] / oldChange) * this._tweenDuration[axis];
  12064. if (newDuration < TWEEN_TIME_DEFAULT)
  12065. newDuration = TWEEN_TIME_DEFAULT;
  12066. this._tweenDuration[axis] = newDuration;
  12067. }
  12068. startTween(type) {
  12069. this._tweenTime.setTo(0, 0);
  12070. this._tweening = type;
  12071. Laya.timer.frameLoop(1, this, this.tweenUpdate);
  12072. this.updateScrollBarVisible();
  12073. }
  12074. killTween() {
  12075. if (this._tweening == 1) //取消类型为1的tween需立刻设置到终点
  12076. {
  12077. this._container.pos(this._tweenStart.x + this._tweenChange.x, this._tweenStart.y + this._tweenChange.y);
  12078. fgui.Events.dispatch(fgui.Events.SCROLL, this._owner.displayObject);
  12079. }
  12080. this._tweening = 0;
  12081. Laya.timer.clear(this, this.tweenUpdate);
  12082. this.updateScrollBarVisible();
  12083. fgui.Events.dispatch(fgui.Events.SCROLL_END, this._owner.displayObject);
  12084. }
  12085. checkRefreshBar() {
  12086. if (!this._header && !this._footer)
  12087. return;
  12088. var pos = this._container[this._refreshBarAxis];
  12089. if (this._header) {
  12090. if (pos > 0) {
  12091. if (!this._header.displayObject.parent)
  12092. this._maskContainer.addChildAt(this._header.displayObject, 0);
  12093. var pt = s_vec2;
  12094. pt.setTo(this._header.width, this._header.height);
  12095. pt[this._refreshBarAxis] = pos;
  12096. this._header.setSize(pt.x, pt.y);
  12097. }
  12098. else {
  12099. if (this._header.displayObject.parent)
  12100. this._maskContainer.removeChild(this._header.displayObject);
  12101. }
  12102. }
  12103. if (this._footer) {
  12104. var max = this._overlapSize[this._refreshBarAxis];
  12105. if (pos < -max || max == 0 && this._footerLockedSize > 0) {
  12106. if (!this._footer.displayObject.parent)
  12107. this._maskContainer.addChildAt(this._footer.displayObject, 0);
  12108. pt = s_vec2;
  12109. pt.setTo(this._footer.x, this._footer.y);
  12110. if (max > 0)
  12111. pt[this._refreshBarAxis] = pos + this._contentSize[this._refreshBarAxis];
  12112. else
  12113. 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]);
  12114. this._footer.setXY(pt.x, pt.y);
  12115. pt.setTo(this._footer.width, this._footer.height);
  12116. if (max > 0)
  12117. pt[this._refreshBarAxis] = -max - pos;
  12118. else
  12119. pt[this._refreshBarAxis] = this._viewSize[this._refreshBarAxis] - this._footer[this._refreshBarAxis];
  12120. this._footer.setSize(pt.x, pt.y);
  12121. }
  12122. else {
  12123. if (this._footer.displayObject.parent)
  12124. this._maskContainer.removeChild(this._footer.displayObject);
  12125. }
  12126. }
  12127. }
  12128. tweenUpdate() {
  12129. var nx = this.runTween("x");
  12130. var ny = this.runTween("y");
  12131. this._container.pos(nx, ny);
  12132. if (this._tweening == 2) {
  12133. if (this._overlapSize.x > 0)
  12134. this._xPos = fgui.ToolSet.clamp(-nx, 0, this._overlapSize.x);
  12135. if (this._overlapSize.y > 0)
  12136. this._yPos = fgui.ToolSet.clamp(-ny, 0, this._overlapSize.y);
  12137. if (this._pageMode)
  12138. this.updatePageController();
  12139. }
  12140. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  12141. this._tweening = 0;
  12142. Laya.timer.clear(this, this.tweenUpdate);
  12143. this.loopCheckingCurrent();
  12144. this.updateScrollBarPos();
  12145. this.updateScrollBarVisible();
  12146. fgui.Events.dispatch(fgui.Events.SCROLL, this._owner.displayObject);
  12147. fgui.Events.dispatch(fgui.Events.SCROLL_END, this._owner.displayObject);
  12148. }
  12149. else {
  12150. this.updateScrollBarPos();
  12151. fgui.Events.dispatch(fgui.Events.SCROLL, this._owner.displayObject);
  12152. }
  12153. }
  12154. runTween(axis) {
  12155. var newValue;
  12156. if (this._tweenChange[axis] != 0) {
  12157. this._tweenTime[axis] += Laya.timer.delta / 1000;
  12158. if (this._tweenTime[axis] >= this._tweenDuration[axis]) {
  12159. newValue = this._tweenStart[axis] + this._tweenChange[axis];
  12160. this._tweenChange[axis] = 0;
  12161. }
  12162. else {
  12163. var ratio = easeFunc(this._tweenTime[axis], this._tweenDuration[axis]);
  12164. newValue = this._tweenStart[axis] + Math.floor(this._tweenChange[axis] * ratio);
  12165. }
  12166. var threshold1 = 0;
  12167. var threshold2 = -this._overlapSize[axis];
  12168. if (this._headerLockedSize > 0 && this._refreshBarAxis == axis)
  12169. threshold1 = this._headerLockedSize;
  12170. if (this._footerLockedSize > 0 && this._refreshBarAxis == axis) {
  12171. var max = this._overlapSize[this._refreshBarAxis];
  12172. if (max == 0)
  12173. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12174. else
  12175. max += this._footerLockedSize;
  12176. threshold2 = -max;
  12177. }
  12178. if (this._tweening == 2 && this._bouncebackEffect) {
  12179. if (newValue > 20 + threshold1 && this._tweenChange[axis] > 0
  12180. || newValue > threshold1 && this._tweenChange[axis] == 0) //开始回弹
  12181. {
  12182. this._tweenTime[axis] = 0;
  12183. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  12184. this._tweenChange[axis] = -newValue + threshold1;
  12185. this._tweenStart[axis] = newValue;
  12186. }
  12187. else if (newValue < threshold2 - 20 && this._tweenChange[axis] < 0
  12188. || newValue < threshold2 && this._tweenChange[axis] == 0) //开始回弹
  12189. {
  12190. this._tweenTime[axis] = 0;
  12191. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  12192. this._tweenChange[axis] = threshold2 - newValue;
  12193. this._tweenStart[axis] = newValue;
  12194. }
  12195. }
  12196. else {
  12197. if (newValue > threshold1) {
  12198. newValue = threshold1;
  12199. this._tweenChange[axis] = 0;
  12200. }
  12201. else if (newValue < threshold2) {
  12202. newValue = threshold2;
  12203. this._tweenChange[axis] = 0;
  12204. }
  12205. }
  12206. }
  12207. else
  12208. newValue = this._container[axis];
  12209. return newValue;
  12210. }
  12211. }
  12212. fgui.ScrollPane = ScrollPane;
  12213. var _gestureFlag = 0;
  12214. const TWEEN_TIME_GO = 0.5; //调用SetPos(ani)时使用的缓动时间
  12215. const TWEEN_TIME_DEFAULT = 0.3; //惯性滚动的最小缓动时间
  12216. const PULL_RATIO = 0.5; //下拉过顶或者上拉过底时允许超过的距离占显示区域的比例
  12217. var s_vec2 = new Laya.Point();
  12218. var s_rect = new Laya.Rectangle();
  12219. var sEndPos = new Laya.Point();
  12220. var sOldChange = new Laya.Point();
  12221. function easeFunc(t, d) {
  12222. return (t = t / d - 1) * t * t + 1; //cubicOut
  12223. }
  12224. })(fgui);
  12225. (function (fgui) {
  12226. class Transition {
  12227. constructor(owner) {
  12228. this._owner = owner;
  12229. this._items = new Array();
  12230. this._totalDuration = 0;
  12231. this._autoPlayTimes = 1;
  12232. this._autoPlayDelay = 0;
  12233. this._timeScale = 1;
  12234. this._startTime = 0;
  12235. this._endTime = 0;
  12236. }
  12237. play(onComplete, times, delay, startTime, endTime) {
  12238. this._play(onComplete, times, delay, startTime, endTime, false);
  12239. }
  12240. playReverse(onComplete, times, delay, startTime, endTime) {
  12241. this._play(onComplete, 1, delay, startTime, endTime, true);
  12242. }
  12243. changePlayTimes(value) {
  12244. this._totalTimes = value;
  12245. }
  12246. setAutoPlay(value, times, delay) {
  12247. if (times == undefined)
  12248. times = -1;
  12249. if (delay == undefined)
  12250. delay = 0;
  12251. if (this._autoPlay != value) {
  12252. this._autoPlay = value;
  12253. this._autoPlayTimes = times;
  12254. this._autoPlayDelay = delay;
  12255. if (this._autoPlay) {
  12256. if (this._owner.onStage)
  12257. this.play(null, null, this._autoPlayTimes, this._autoPlayDelay);
  12258. }
  12259. else {
  12260. if (!this._owner.onStage)
  12261. this.stop(false, true);
  12262. }
  12263. }
  12264. }
  12265. _play(onComplete, times, delay, startTime, endTime, reversed) {
  12266. if (times == undefined)
  12267. times = 1;
  12268. if (delay == undefined)
  12269. delay = 0;
  12270. if (startTime == undefined)
  12271. startTime = 0;
  12272. if (endTime == undefined)
  12273. endTime = -1;
  12274. this.stop(true, true);
  12275. this._totalTimes = times;
  12276. this._reversed = reversed;
  12277. this._startTime = startTime;
  12278. this._endTime = endTime;
  12279. this._playing = true;
  12280. this._paused = false;
  12281. this._onComplete = onComplete;
  12282. var cnt = this._items.length;
  12283. for (var i = 0; i < cnt; i++) {
  12284. var item = this._items[i];
  12285. if (item.target == null) {
  12286. if (item.targetId)
  12287. item.target = this._owner.getChildById(item.targetId);
  12288. else
  12289. item.target = this._owner;
  12290. }
  12291. else if (item.target != this._owner && item.target.parent != this._owner)
  12292. item.target = null;
  12293. if (item.target && item.type == ActionType.Transition) {
  12294. var trans = item.target.getTransition(item.value.transName);
  12295. if (trans == this)
  12296. trans = null;
  12297. if (trans) {
  12298. if (item.value.playTimes == 0) //this.stop
  12299. {
  12300. var j;
  12301. for (j = i - 1; j >= 0; j--) {
  12302. var item2 = this._items[j];
  12303. if (item2.type == ActionType.Transition) {
  12304. if (item2.value.trans == trans) {
  12305. item2.value.stopTime = item.time - item2.time;
  12306. break;
  12307. }
  12308. }
  12309. }
  12310. if (j < 0)
  12311. item.value.stopTime = 0;
  12312. else
  12313. trans = null; //no need to handle this.stop anymore
  12314. }
  12315. else
  12316. item.value.stopTime = -1;
  12317. }
  12318. item.value.trans = trans;
  12319. }
  12320. }
  12321. if (delay == 0)
  12322. this.onDelayedPlay();
  12323. else
  12324. fgui.GTween.delayedCall(delay).setTarget(this).onComplete(this.onDelayedPlay, this);
  12325. }
  12326. stop(setToComplete, processCallback) {
  12327. if (!this._playing)
  12328. return;
  12329. if (setToComplete == undefined)
  12330. setToComplete = true;
  12331. this._playing = false;
  12332. this._totalTasks = 0;
  12333. this._totalTimes = 0;
  12334. var handler = this._onComplete;
  12335. this._onComplete = null;
  12336. fgui.GTween.kill(this); //delay start
  12337. var cnt = this._items.length;
  12338. if (this._reversed) {
  12339. for (var i = cnt - 1; i >= 0; i--) {
  12340. var item = this._items[i];
  12341. if (item.target == null)
  12342. continue;
  12343. this.stopItem(item, setToComplete);
  12344. }
  12345. }
  12346. else {
  12347. for (i = 0; i < cnt; i++) {
  12348. item = this._items[i];
  12349. if (item.target == null)
  12350. continue;
  12351. this.stopItem(item, setToComplete);
  12352. }
  12353. }
  12354. if (processCallback && handler) {
  12355. handler.run();
  12356. }
  12357. }
  12358. stopItem(item, setToComplete) {
  12359. if (item.displayLockToken != 0) {
  12360. item.target.releaseDisplayLock(item.displayLockToken);
  12361. item.displayLockToken = 0;
  12362. }
  12363. if (item.tweener) {
  12364. item.tweener.kill(setToComplete);
  12365. item.tweener = null;
  12366. if (item.type == ActionType.Shake && !setToComplete) //震动必须归位,否则下次就越震越远了。
  12367. {
  12368. item.target._gearLocked = true;
  12369. item.target.setXY(item.target.x - item.value.lastOffsetX, item.target.y - item.value.lastOffsetY);
  12370. item.target._gearLocked = false;
  12371. }
  12372. }
  12373. if (item.type == ActionType.Transition) {
  12374. var trans = item.value.trans;
  12375. if (trans)
  12376. trans.stop(setToComplete, false);
  12377. }
  12378. }
  12379. setPaused(paused) {
  12380. if (!this._playing || this._paused == paused)
  12381. return;
  12382. this._paused = paused;
  12383. var tweener = fgui.GTween.getTween(this);
  12384. if (tweener)
  12385. tweener.setPaused(paused);
  12386. var cnt = this._items.length;
  12387. for (var i = 0; i < cnt; i++) {
  12388. var item = this._items[i];
  12389. if (item.target == null)
  12390. continue;
  12391. if (item.type == ActionType.Transition) {
  12392. if (item.value.trans)
  12393. item.value.trans.setPaused(paused);
  12394. }
  12395. else if (item.type == ActionType.Animation) {
  12396. if (paused) {
  12397. item.value.flag = item.target.getProp(fgui.ObjectPropID.Playing);
  12398. item.target.setProp(fgui.ObjectPropID.Playing, false);
  12399. }
  12400. else
  12401. item.target.setProp(fgui.ObjectPropID.Playing, item.value.flag);
  12402. }
  12403. if (item.tweener)
  12404. item.tweener.setPaused(paused);
  12405. }
  12406. }
  12407. dispose() {
  12408. if (this._playing)
  12409. fgui.GTween.kill(this); //delay start
  12410. var cnt = this._items.length;
  12411. for (var i = 0; i < cnt; i++) {
  12412. var item = this._items[i];
  12413. if (item.tweener) {
  12414. item.tweener.kill();
  12415. item.tweener = null;
  12416. }
  12417. item.target = null;
  12418. item.hook = null;
  12419. if (item.tweenConfig)
  12420. item.tweenConfig.endHook = null;
  12421. }
  12422. this._items.length = 0;
  12423. this._playing = false;
  12424. this._onComplete = null;
  12425. }
  12426. get playing() {
  12427. return this._playing;
  12428. }
  12429. setValue(label, ...args) {
  12430. var cnt = this._items.length;
  12431. var found = false;
  12432. var value;
  12433. for (var i = 0; i < cnt; i++) {
  12434. var item = this._items[i];
  12435. if (item.label == label) {
  12436. if (item.tweenConfig)
  12437. value = item.tweenConfig.startValue;
  12438. else
  12439. value = item.value;
  12440. found = true;
  12441. }
  12442. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  12443. value = item.tweenConfig.endValue;
  12444. found = true;
  12445. }
  12446. else
  12447. continue;
  12448. switch (item.type) {
  12449. case ActionType.XY:
  12450. case ActionType.Size:
  12451. case ActionType.Pivot:
  12452. case ActionType.Scale:
  12453. case ActionType.Skew:
  12454. value.b1 = true;
  12455. value.b2 = true;
  12456. value.f1 = parseFloat(args[0]);
  12457. value.f2 = parseFloat(args[1]);
  12458. break;
  12459. case ActionType.Alpha:
  12460. value.f1 = parseFloat(args[0]);
  12461. break;
  12462. case ActionType.Rotation:
  12463. value.f1 = parseFloat(args[0]);
  12464. break;
  12465. case ActionType.Color:
  12466. value.f1 = parseFloat(args[0]);
  12467. break;
  12468. case ActionType.Animation:
  12469. value.frame = parseInt(args[0]);
  12470. if (args.length > 1)
  12471. value.playing = args[1];
  12472. break;
  12473. case ActionType.Visible:
  12474. value.visible = args[0];
  12475. break;
  12476. case ActionType.Sound:
  12477. value.sound = args[0];
  12478. if (args.length > 1)
  12479. value.volume = parseFloat(args[1]);
  12480. break;
  12481. case ActionType.Transition:
  12482. value.transName = args[0];
  12483. if (args.length > 1)
  12484. value.playTimes = parseInt(args[1]);
  12485. break;
  12486. case ActionType.Shake:
  12487. value.amplitude = parseFloat(args[0]);
  12488. if (args.length > 1)
  12489. value.duration = parseFloat(args[1]);
  12490. break;
  12491. case ActionType.ColorFilter:
  12492. value.f1 = parseFloat(args[0]);
  12493. value.f2 = parseFloat(args[1]);
  12494. value.f3 = parseFloat(args[2]);
  12495. value.f4 = parseFloat(args[3]);
  12496. break;
  12497. case ActionType.Text:
  12498. case ActionType.Icon:
  12499. value.text = args[0];
  12500. break;
  12501. }
  12502. }
  12503. if (!found)
  12504. throw new Error("this.label not exists");
  12505. }
  12506. setHook(label, callback) {
  12507. var cnt = this._items.length;
  12508. var found = false;
  12509. for (var i = 0; i < cnt; i++) {
  12510. var item = this._items[i];
  12511. if (item.label == label) {
  12512. item.hook = callback;
  12513. found = true;
  12514. break;
  12515. }
  12516. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  12517. item.tweenConfig.endHook = callback;
  12518. found = true;
  12519. break;
  12520. }
  12521. }
  12522. if (!found)
  12523. throw new Error("this.label not exists");
  12524. }
  12525. clearHooks() {
  12526. var cnt = this._items.length;
  12527. for (var i = 0; i < cnt; i++) {
  12528. var item = this._items[i];
  12529. item.hook = null;
  12530. if (item.tweenConfig)
  12531. item.tweenConfig.endHook = null;
  12532. }
  12533. }
  12534. setTarget(label, newTarget) {
  12535. var cnt = this._items.length;
  12536. var found = false;
  12537. for (var i = 0; i < cnt; i++) {
  12538. var item = this._items[i];
  12539. if (item.label == label) {
  12540. item.targetId = (newTarget == this._owner || newTarget == null) ? "" : newTarget.id;
  12541. if (this._playing) {
  12542. if (item.targetId.length > 0)
  12543. item.target = this._owner.getChildById(item.targetId);
  12544. else
  12545. item.target = this._owner;
  12546. }
  12547. else
  12548. item.target = null;
  12549. found = true;
  12550. }
  12551. }
  12552. if (!found)
  12553. throw new Error("this.label not exists");
  12554. }
  12555. setDuration(label, value) {
  12556. var cnt = this._items.length;
  12557. var found = false;
  12558. for (var i = 0; i < cnt; i++) {
  12559. var item = this._items[i];
  12560. if (item.tweenConfig && item.label == label) {
  12561. item.tweenConfig.duration = value;
  12562. found = true;
  12563. }
  12564. }
  12565. if (!found)
  12566. throw new Error("this.label not exists");
  12567. }
  12568. getLabelTime(label) {
  12569. var cnt = this._items.length;
  12570. for (var i = 0; i < cnt; i++) {
  12571. var item = this._items[i];
  12572. if (item.label == label)
  12573. return item.time;
  12574. else if (item.tweenConfig && item.tweenConfig.endLabel == label)
  12575. return item.time + item.tweenConfig.duration;
  12576. }
  12577. return NaN;
  12578. }
  12579. get timeScale() {
  12580. return this._timeScale;
  12581. }
  12582. set timeScale(value) {
  12583. if (this._timeScale != value) {
  12584. this._timeScale = value;
  12585. if (this._playing) {
  12586. var cnt = this._items.length;
  12587. for (var i = 0; i < cnt; i++) {
  12588. var item = this._items[i];
  12589. if (item.tweener)
  12590. item.tweener.setTimeScale(value);
  12591. else if (item.type == ActionType.Transition) {
  12592. if (item.value.trans)
  12593. item.value.trans.timeScale = value;
  12594. }
  12595. else if (item.type == ActionType.Animation) {
  12596. if (item.target)
  12597. item.target.setProp(fgui.ObjectPropID.TimeScale, value);
  12598. }
  12599. }
  12600. }
  12601. }
  12602. }
  12603. updateFromRelations(targetId, dx, dy) {
  12604. var cnt = this._items.length;
  12605. if (cnt == 0)
  12606. return;
  12607. for (var i = 0; i < cnt; i++) {
  12608. var item = this._items[i];
  12609. if (item.type == ActionType.XY && item.targetId == targetId) {
  12610. if (item.tweenConfig) {
  12611. if (!item.tweenConfig.startValue.b3) {
  12612. item.tweenConfig.startValue.f1 += dx;
  12613. item.tweenConfig.startValue.f2 += dy;
  12614. }
  12615. if (!item.tweenConfig.endValue.b3) {
  12616. item.tweenConfig.endValue.f1 += dx;
  12617. item.tweenConfig.endValue.f2 += dy;
  12618. }
  12619. }
  12620. else {
  12621. if (!item.value.b3) {
  12622. item.value.f1 += dx;
  12623. item.value.f2 += dy;
  12624. }
  12625. }
  12626. }
  12627. }
  12628. }
  12629. onOwnerAddedToStage() {
  12630. if (this._autoPlay && !this._playing)
  12631. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  12632. }
  12633. onOwnerRemovedFromStage() {
  12634. if ((this._options & OPTION_AUTO_STOP_DISABLED) == 0)
  12635. this.stop((this._options & OPTION_AUTO_STOP_AT_END) != 0 ? true : false, false);
  12636. }
  12637. onDelayedPlay() {
  12638. this.internalPlay();
  12639. this._playing = this._totalTasks > 0;
  12640. if (this._playing) {
  12641. if ((this._options & OPTION_IGNORE_DISPLAY_CONTROLLER) != 0) {
  12642. var cnt = this._items.length;
  12643. for (var i = 0; i < cnt; i++) {
  12644. var item = this._items[i];
  12645. if (item.target && item.target != this._owner)
  12646. item.displayLockToken = item.target.addDisplayLock();
  12647. }
  12648. }
  12649. }
  12650. else if (this._onComplete) {
  12651. var handler = this._onComplete;
  12652. this._onComplete = null;
  12653. handler.run();
  12654. }
  12655. }
  12656. internalPlay() {
  12657. this._ownerBaseX = this._owner.x;
  12658. this._ownerBaseY = this._owner.y;
  12659. this._totalTasks = 1;
  12660. var cnt = this._items.length;
  12661. var item;
  12662. var needSkipAnimations = false;
  12663. if (!this._reversed) {
  12664. for (var i = 0; i < cnt; i++) {
  12665. item = this._items[i];
  12666. if (item.target == null)
  12667. continue;
  12668. if (item.type == ActionType.Animation && this._startTime != 0 && item.time <= this._startTime) {
  12669. needSkipAnimations = true;
  12670. item.value.flag = false;
  12671. }
  12672. else
  12673. this.playItem(item);
  12674. }
  12675. }
  12676. else {
  12677. for (i = cnt - 1; i >= 0; i--) {
  12678. item = this._items[i];
  12679. if (item.target == null)
  12680. continue;
  12681. this.playItem(item);
  12682. }
  12683. }
  12684. if (needSkipAnimations)
  12685. this.skipAnimations();
  12686. this._totalTasks--;
  12687. }
  12688. playItem(item) {
  12689. var time;
  12690. if (item.tweenConfig) {
  12691. if (this._reversed)
  12692. time = (this._totalDuration - item.time - item.tweenConfig.duration);
  12693. else
  12694. time = item.time;
  12695. if (this._endTime == -1 || time <= this._endTime) {
  12696. var startValue;
  12697. var endValue;
  12698. if (this._reversed) {
  12699. startValue = item.tweenConfig.endValue;
  12700. endValue = item.tweenConfig.startValue;
  12701. }
  12702. else {
  12703. startValue = item.tweenConfig.startValue;
  12704. endValue = item.tweenConfig.endValue;
  12705. }
  12706. item.value.b1 = startValue.b1 || endValue.b1;
  12707. item.value.b2 = startValue.b2 || endValue.b2;
  12708. switch (item.type) {
  12709. case ActionType.XY:
  12710. case ActionType.Size:
  12711. case ActionType.Scale:
  12712. case ActionType.Skew:
  12713. item.tweener = fgui.GTween.to2(startValue.f1, startValue.f2, endValue.f1, endValue.f2, item.tweenConfig.duration);
  12714. break;
  12715. case ActionType.Alpha:
  12716. case ActionType.Rotation:
  12717. item.tweener = fgui.GTween.to(startValue.f1, endValue.f1, item.tweenConfig.duration);
  12718. break;
  12719. case ActionType.Color:
  12720. item.tweener = fgui.GTween.toColor(startValue.f1, endValue.f1, item.tweenConfig.duration);
  12721. break;
  12722. case ActionType.ColorFilter:
  12723. item.tweener = fgui.GTween.to4(startValue.f1, startValue.f2, startValue.f3, startValue.f4, endValue.f1, endValue.f2, endValue.f3, endValue.f4, item.tweenConfig.duration);
  12724. break;
  12725. }
  12726. item.tweener.setDelay(time)
  12727. .setEase(item.tweenConfig.easeType)
  12728. .setRepeat(item.tweenConfig.repeat, item.tweenConfig.yoyo)
  12729. .setTimeScale(this._timeScale)
  12730. .setTarget(item)
  12731. .onStart(this.onTweenStart, this)
  12732. .onUpdate(this.onTweenUpdate, this)
  12733. .onComplete(this.onTweenComplete, this);
  12734. if (this._endTime >= 0)
  12735. item.tweener.setBreakpoint(this._endTime - time);
  12736. this._totalTasks++;
  12737. }
  12738. }
  12739. else if (item.type == ActionType.Shake) {
  12740. if (this._reversed)
  12741. time = (this._totalDuration - item.time - item.value.duration);
  12742. else
  12743. time = item.time;
  12744. item.value.offsetX = item.value.offsetY = 0;
  12745. item.value.lastOffsetX = item.value.lastOffsetY = 0;
  12746. item.tweener = fgui.GTween.shake(0, 0, item.value.amplitude, item.value.duration)
  12747. .setDelay(time)
  12748. .setTimeScale(this._timeScale)
  12749. .setTarget(item)
  12750. .onUpdate(this.onTweenUpdate, this)
  12751. .onComplete(this.onTweenComplete, this);
  12752. if (this._endTime >= 0)
  12753. item.tweener.setBreakpoint(this._endTime - item.time);
  12754. this._totalTasks++;
  12755. }
  12756. else {
  12757. if (this._reversed)
  12758. time = (this._totalDuration - item.time);
  12759. else
  12760. time = item.time;
  12761. if (time <= this._startTime) {
  12762. this.applyValue(item);
  12763. this.callHook(item, false);
  12764. }
  12765. else if (this._endTime == -1 || time <= this._endTime) {
  12766. this._totalTasks++;
  12767. item.tweener = fgui.GTween.delayedCall(time)
  12768. .setTimeScale(this._timeScale)
  12769. .setTarget(item)
  12770. .onComplete(this.onDelayedPlayItem, this);
  12771. }
  12772. }
  12773. if (item.tweener)
  12774. item.tweener.seek(this._startTime);
  12775. }
  12776. skipAnimations() {
  12777. var frame;
  12778. var playStartTime;
  12779. var playTotalTime;
  12780. var value;
  12781. var target;
  12782. var item;
  12783. var cnt = this._items.length;
  12784. for (var i = 0; i < cnt; i++) {
  12785. item = this._items[i];
  12786. if (item.type != ActionType.Animation || item.time > this._startTime)
  12787. continue;
  12788. value = item.value;
  12789. if (value.flag)
  12790. continue;
  12791. target = item.target;
  12792. frame = target.getProp(fgui.ObjectPropID.Frame);
  12793. playStartTime = target.getProp(fgui.ObjectPropID.Playing) ? 0 : -1;
  12794. playTotalTime = 0;
  12795. for (var j = i; j < cnt; j++) {
  12796. item = this._items[j];
  12797. if (item.type != ActionType.Animation || item.target != target || item.time > this._startTime)
  12798. continue;
  12799. value = item.value;
  12800. value.flag = true;
  12801. if (value.frame != -1) {
  12802. frame = value.frame;
  12803. if (value.playing)
  12804. playStartTime = item.time;
  12805. else
  12806. playStartTime = -1;
  12807. playTotalTime = 0;
  12808. }
  12809. else {
  12810. if (value.playing) {
  12811. if (playStartTime < 0)
  12812. playStartTime = item.time;
  12813. }
  12814. else {
  12815. if (playStartTime >= 0)
  12816. playTotalTime += (item.time - playStartTime);
  12817. playStartTime = -1;
  12818. }
  12819. }
  12820. this.callHook(item, false);
  12821. }
  12822. if (playStartTime >= 0)
  12823. playTotalTime += (this._startTime - playStartTime);
  12824. target.setProp(fgui.ObjectPropID.Playing, playStartTime >= 0);
  12825. target.setProp(fgui.ObjectPropID.Frame, frame);
  12826. if (playTotalTime > 0)
  12827. target.setProp(fgui.ObjectPropID.DeltaTime, playTotalTime * 1000);
  12828. }
  12829. }
  12830. onDelayedPlayItem(tweener) {
  12831. var item = tweener.target;
  12832. item.tweener = null;
  12833. this._totalTasks--;
  12834. this.applyValue(item);
  12835. this.callHook(item, false);
  12836. this.checkAllComplete();
  12837. }
  12838. onTweenStart(tweener) {
  12839. var item = tweener.target;
  12840. if (item.type == ActionType.XY || item.type == ActionType.Size) //位置和大小要到start才最终确认起始值
  12841. {
  12842. var startValue;
  12843. var endValue;
  12844. if (this._reversed) {
  12845. startValue = item.tweenConfig.endValue;
  12846. endValue = item.tweenConfig.startValue;
  12847. }
  12848. else {
  12849. startValue = item.tweenConfig.startValue;
  12850. endValue = item.tweenConfig.endValue;
  12851. }
  12852. if (item.type == ActionType.XY) {
  12853. if (item.target != this._owner) {
  12854. if (!startValue.b1)
  12855. tweener.startValue.x = item.target.x;
  12856. else if (startValue.b3) //percent
  12857. tweener.startValue.x = startValue.f1 * this._owner.width;
  12858. if (!startValue.b2)
  12859. tweener.startValue.y = item.target.y;
  12860. else if (startValue.b3) //percent
  12861. tweener.startValue.y = startValue.f2 * this._owner.height;
  12862. if (!endValue.b1)
  12863. tweener.endValue.x = tweener.startValue.x;
  12864. else if (endValue.b3)
  12865. tweener.endValue.x = endValue.f1 * this._owner.width;
  12866. if (!endValue.b2)
  12867. tweener.endValue.y = tweener.startValue.y;
  12868. else if (endValue.b3)
  12869. tweener.endValue.y = endValue.f2 * this._owner.height;
  12870. }
  12871. else {
  12872. if (!startValue.b1)
  12873. tweener.startValue.x = item.target.x - this._ownerBaseX;
  12874. if (!startValue.b2)
  12875. tweener.startValue.y = item.target.y - this._ownerBaseY;
  12876. if (!endValue.b1)
  12877. tweener.endValue.x = tweener.startValue.x;
  12878. if (!endValue.b2)
  12879. tweener.endValue.y = tweener.startValue.y;
  12880. }
  12881. }
  12882. else {
  12883. if (!startValue.b1)
  12884. tweener.startValue.x = item.target.width;
  12885. if (!startValue.b2)
  12886. tweener.startValue.y = item.target.height;
  12887. if (!endValue.b1)
  12888. tweener.endValue.x = tweener.startValue.x;
  12889. if (!endValue.b2)
  12890. tweener.endValue.y = tweener.startValue.y;
  12891. }
  12892. if (item.tweenConfig.path) {
  12893. item.value.b1 = item.value.b2 = true;
  12894. tweener.setPath(item.tweenConfig.path);
  12895. }
  12896. }
  12897. this.callHook(item, false);
  12898. }
  12899. onTweenUpdate(tweener) {
  12900. var item = tweener.target;
  12901. switch (item.type) {
  12902. case ActionType.XY:
  12903. case ActionType.Size:
  12904. case ActionType.Scale:
  12905. case ActionType.Skew:
  12906. item.value.f1 = tweener.value.x;
  12907. item.value.f2 = tweener.value.y;
  12908. if (item.tweenConfig.path) {
  12909. item.value.f1 += tweener.startValue.x;
  12910. item.value.f2 += tweener.startValue.y;
  12911. }
  12912. break;
  12913. case ActionType.Alpha:
  12914. case ActionType.Rotation:
  12915. item.value.f1 = tweener.value.x;
  12916. break;
  12917. case ActionType.Color:
  12918. item.value.f1 = tweener.value.color;
  12919. break;
  12920. case ActionType.ColorFilter:
  12921. item.value.f1 = tweener.value.x;
  12922. item.value.f2 = tweener.value.y;
  12923. item.value.f3 = tweener.value.z;
  12924. item.value.f4 = tweener.value.w;
  12925. break;
  12926. case ActionType.Shake:
  12927. item.value.offsetX = tweener.deltaValue.x;
  12928. item.value.offsetY = tweener.deltaValue.y;
  12929. break;
  12930. }
  12931. this.applyValue(item);
  12932. }
  12933. onTweenComplete(tweener) {
  12934. var item = tweener.target;
  12935. item.tweener = null;
  12936. this._totalTasks--;
  12937. if (tweener.allCompleted) //当整体播放结束时间在这个tween的中间时不应该调用结尾钩子
  12938. this.callHook(item, true);
  12939. this.checkAllComplete();
  12940. }
  12941. onPlayTransCompleted(item) {
  12942. this._totalTasks--;
  12943. this.checkAllComplete();
  12944. }
  12945. callHook(item, tweenEnd) {
  12946. if (tweenEnd) {
  12947. if (item.tweenConfig && item.tweenConfig.endHook)
  12948. item.tweenConfig.endHook.run();
  12949. }
  12950. else {
  12951. if (item.time >= this._startTime && item.hook)
  12952. item.hook.run();
  12953. }
  12954. }
  12955. checkAllComplete() {
  12956. if (this._playing && this._totalTasks == 0) {
  12957. if (this._totalTimes < 0) {
  12958. this.internalPlay();
  12959. if (this._totalTasks == 0)
  12960. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  12961. }
  12962. else {
  12963. this._totalTimes--;
  12964. if (this._totalTimes > 0) {
  12965. this.internalPlay();
  12966. if (this._totalTasks == 0)
  12967. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  12968. }
  12969. else {
  12970. this._playing = false;
  12971. var cnt = this._items.length;
  12972. for (var i = 0; i < cnt; i++) {
  12973. var item = this._items[i];
  12974. if (item.target && item.displayLockToken != 0) {
  12975. item.target.releaseDisplayLock(item.displayLockToken);
  12976. item.displayLockToken = 0;
  12977. }
  12978. }
  12979. if (this._onComplete) {
  12980. var handler = this._onComplete;
  12981. this._onComplete = null;
  12982. handler.run();
  12983. }
  12984. }
  12985. }
  12986. }
  12987. }
  12988. applyValue(item) {
  12989. item.target._gearLocked = true;
  12990. var value = item.value;
  12991. switch (item.type) {
  12992. case ActionType.XY:
  12993. if (item.target == this._owner) {
  12994. if (value.b1 && value.b2)
  12995. item.target.setXY(value.f1 + this._ownerBaseX, value.f2 + this._ownerBaseY);
  12996. else if (value.b1)
  12997. item.target.x = value.f1 + this._ownerBaseX;
  12998. else
  12999. item.target.y = value.f2 + this._ownerBaseY;
  13000. }
  13001. else {
  13002. if (value.b3) //position in percent
  13003. {
  13004. if (value.b1 && value.b2)
  13005. item.target.setXY(value.f1 * this._owner.width, value.f2 * this._owner.height);
  13006. else if (value.b1)
  13007. item.target.x = value.f1 * this._owner.width;
  13008. else if (value.b2)
  13009. item.target.y = value.f2 * this._owner.height;
  13010. }
  13011. else {
  13012. if (value.b1 && value.b2)
  13013. item.target.setXY(value.f1, value.f2);
  13014. else if (value.b1)
  13015. item.target.x = value.f1;
  13016. else if (value.b2)
  13017. item.target.y = value.f2;
  13018. }
  13019. }
  13020. break;
  13021. case ActionType.Size:
  13022. if (!value.b1)
  13023. value.f1 = item.target.width;
  13024. if (!value.b2)
  13025. value.f2 = item.target.height;
  13026. item.target.setSize(value.f1, value.f2);
  13027. break;
  13028. case ActionType.Pivot:
  13029. item.target.setPivot(value.f1, value.f2, item.target.pivotAsAnchor);
  13030. break;
  13031. case ActionType.Alpha:
  13032. item.target.alpha = value.f1;
  13033. break;
  13034. case ActionType.Rotation:
  13035. item.target.rotation = value.f1;
  13036. break;
  13037. case ActionType.Scale:
  13038. item.target.setScale(value.f1, value.f2);
  13039. break;
  13040. case ActionType.Skew:
  13041. item.target.setSkew(value.f1, value.f2);
  13042. break;
  13043. case ActionType.Color:
  13044. item.target.setProp(fgui.ObjectPropID.Color, fgui.ToolSet.convertToHtmlColor(value.f1, false));
  13045. break;
  13046. case ActionType.Animation:
  13047. if (value.frame >= 0)
  13048. item.target.setProp(fgui.ObjectPropID.Frame, value.frame);
  13049. item.target.setProp(fgui.ObjectPropID.Playing, value.playing);
  13050. item.target.setProp(fgui.ObjectPropID.TimeScale, this._timeScale);
  13051. break;
  13052. case ActionType.Visible:
  13053. item.target.visible = value.visible;
  13054. break;
  13055. case ActionType.Transition:
  13056. if (this._playing) {
  13057. var trans = value.trans;
  13058. if (trans) {
  13059. this._totalTasks++;
  13060. var startTime = this._startTime > item.time ? (this._startTime - item.time) : 0;
  13061. var endTime = this._endTime >= 0 ? (this._endTime - item.time) : -1;
  13062. if (value.stopTime >= 0 && (endTime < 0 || endTime > value.stopTime))
  13063. endTime = value.stopTime;
  13064. trans.timeScale = this._timeScale;
  13065. trans._play(Laya.Handler.create(this, this.onPlayTransCompleted, [item]), value.playTimes, 0, startTime, endTime, this._reversed);
  13066. }
  13067. }
  13068. break;
  13069. case ActionType.Sound:
  13070. if (this._playing && item.time >= this._startTime) {
  13071. if (value.audioClip == null) {
  13072. var pi = fgui.UIPackage.getItemByURL(value.sound);
  13073. if (pi)
  13074. value.audioClip = pi.file;
  13075. else
  13076. value.audioClip = value.sound;
  13077. }
  13078. if (value.audioClip)
  13079. fgui.GRoot.inst.playOneShotSound(value.audioClip, value.volume);
  13080. }
  13081. break;
  13082. case ActionType.Shake:
  13083. item.target.setXY(item.target.x - value.lastOffsetX + value.offsetX, item.target.y - value.lastOffsetY + value.offsetY);
  13084. value.lastOffsetX = value.offsetX;
  13085. value.lastOffsetY = value.offsetY;
  13086. break;
  13087. case ActionType.ColorFilter:
  13088. {
  13089. fgui.ToolSet.setColorFilter(item.target.displayObject, [value.f1, value.f2, value.f3, value.f4]);
  13090. break;
  13091. }
  13092. case ActionType.Text:
  13093. item.target.text = value.text;
  13094. break;
  13095. case ActionType.Icon:
  13096. item.target.icon = value.text;
  13097. break;
  13098. }
  13099. item.target._gearLocked = false;
  13100. }
  13101. setup(buffer) {
  13102. this.name = buffer.readS();
  13103. this._options = buffer.getInt32();
  13104. this._autoPlay = buffer.readBool();
  13105. this._autoPlayTimes = buffer.getInt32();
  13106. this._autoPlayDelay = buffer.getFloat32();
  13107. var cnt = buffer.getInt16();
  13108. for (var i = 0; i < cnt; i++) {
  13109. var dataLen = buffer.getInt16();
  13110. var curPos = buffer.pos;
  13111. buffer.seek(curPos, 0);
  13112. var item = new Item(buffer.readByte());
  13113. this._items[i] = item;
  13114. item.time = buffer.getFloat32();
  13115. var targetId = buffer.getInt16();
  13116. if (targetId < 0)
  13117. item.targetId = "";
  13118. else
  13119. item.targetId = this._owner.getChildAt(targetId).id;
  13120. item.label = buffer.readS();
  13121. if (buffer.readBool()) {
  13122. buffer.seek(curPos, 1);
  13123. item.tweenConfig = new TweenConfig();
  13124. item.tweenConfig.duration = buffer.getFloat32();
  13125. if (item.time + item.tweenConfig.duration > this._totalDuration)
  13126. this._totalDuration = item.time + item.tweenConfig.duration;
  13127. item.tweenConfig.easeType = buffer.readByte();
  13128. item.tweenConfig.repeat = buffer.getInt32();
  13129. item.tweenConfig.yoyo = buffer.readBool();
  13130. item.tweenConfig.endLabel = buffer.readS();
  13131. buffer.seek(curPos, 2);
  13132. this.decodeValue(item, buffer, item.tweenConfig.startValue);
  13133. buffer.seek(curPos, 3);
  13134. this.decodeValue(item, buffer, item.tweenConfig.endValue);
  13135. if (buffer.version >= 2) {
  13136. var pathLen = buffer.getInt32();
  13137. if (pathLen > 0) {
  13138. item.tweenConfig.path = new fgui.GPath();
  13139. var pts = new Array();
  13140. for (var j = 0; j < pathLen; j++) {
  13141. var curveType = buffer.getUint8();
  13142. switch (curveType) {
  13143. case fgui.CurveType.Bezier:
  13144. pts.push(fgui.GPathPoint.newBezierPoint(buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32()));
  13145. break;
  13146. case fgui.CurveType.CubicBezier:
  13147. pts.push(fgui.GPathPoint.newCubicBezierPoint(buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32(), buffer.getFloat32()));
  13148. break;
  13149. default:
  13150. pts.push(fgui.GPathPoint.newPoint(buffer.getFloat32(), buffer.getFloat32(), curveType));
  13151. break;
  13152. }
  13153. }
  13154. item.tweenConfig.path.create(pts);
  13155. }
  13156. }
  13157. }
  13158. else {
  13159. if (item.time > this._totalDuration)
  13160. this._totalDuration = item.time;
  13161. buffer.seek(curPos, 2);
  13162. this.decodeValue(item, buffer, item.value);
  13163. }
  13164. buffer.pos = curPos + dataLen;
  13165. }
  13166. }
  13167. decodeValue(item, buffer, value) {
  13168. switch (item.type) {
  13169. case ActionType.XY:
  13170. case ActionType.Size:
  13171. case ActionType.Pivot:
  13172. case ActionType.Skew:
  13173. value.b1 = buffer.readBool();
  13174. value.b2 = buffer.readBool();
  13175. value.f1 = buffer.getFloat32();
  13176. value.f2 = buffer.getFloat32();
  13177. if (buffer.version >= 2 && item.type == ActionType.XY)
  13178. value.b3 = buffer.readBool(); //percent
  13179. break;
  13180. case ActionType.Alpha:
  13181. case ActionType.Rotation:
  13182. value.f1 = buffer.getFloat32();
  13183. break;
  13184. case ActionType.Scale:
  13185. value.f1 = buffer.getFloat32();
  13186. value.f2 = buffer.getFloat32();
  13187. break;
  13188. case ActionType.Color:
  13189. value.f1 = buffer.readColor();
  13190. break;
  13191. case ActionType.Animation:
  13192. value.playing = buffer.readBool();
  13193. value.frame = buffer.getInt32();
  13194. break;
  13195. case ActionType.Visible:
  13196. value.visible = buffer.readBool();
  13197. break;
  13198. case ActionType.Sound:
  13199. value.sound = buffer.readS();
  13200. value.volume = buffer.getFloat32();
  13201. break;
  13202. case ActionType.Transition:
  13203. value.transName = buffer.readS();
  13204. value.playTimes = buffer.getInt32();
  13205. break;
  13206. case ActionType.Shake:
  13207. value.amplitude = buffer.getFloat32();
  13208. value.duration = buffer.getFloat32();
  13209. break;
  13210. case ActionType.ColorFilter:
  13211. value.f1 = buffer.getFloat32();
  13212. value.f2 = buffer.getFloat32();
  13213. value.f3 = buffer.getFloat32();
  13214. value.f4 = buffer.getFloat32();
  13215. break;
  13216. case ActionType.Text:
  13217. case ActionType.Icon:
  13218. value.text = buffer.readS();
  13219. break;
  13220. }
  13221. }
  13222. }
  13223. fgui.Transition = Transition;
  13224. class ActionType {
  13225. }
  13226. ActionType.XY = 0;
  13227. ActionType.Size = 1;
  13228. ActionType.Scale = 2;
  13229. ActionType.Pivot = 3;
  13230. ActionType.Alpha = 4;
  13231. ActionType.Rotation = 5;
  13232. ActionType.Color = 6;
  13233. ActionType.Animation = 7;
  13234. ActionType.Visible = 8;
  13235. ActionType.Sound = 9;
  13236. ActionType.Transition = 10;
  13237. ActionType.Shake = 11;
  13238. ActionType.ColorFilter = 12;
  13239. ActionType.Skew = 13;
  13240. ActionType.Text = 14;
  13241. ActionType.Icon = 15;
  13242. ActionType.Unknown = 16;
  13243. class Item {
  13244. constructor(type) {
  13245. this.type = type;
  13246. this.value = {};
  13247. this.displayLockToken = 0;
  13248. }
  13249. }
  13250. class TweenConfig {
  13251. constructor() {
  13252. this.easeType = fgui.EaseType.QuadOut;
  13253. this.startValue = { b1: true, b2: true };
  13254. this.endValue = { b1: true, b2: true };
  13255. }
  13256. }
  13257. const OPTION_IGNORE_DISPLAY_CONTROLLER = 1;
  13258. const OPTION_AUTO_STOP_DISABLED = 2;
  13259. const OPTION_AUTO_STOP_AT_END = 4;
  13260. })(fgui);
  13261. (function (fgui) {
  13262. class TranslationHelper {
  13263. constructor() {
  13264. }
  13265. static loadFromXML(source) {
  13266. let strings = {};
  13267. TranslationHelper.strings = strings;
  13268. var xml = Laya.Utils.parseXMLFromString(source);
  13269. var resNode = findChildNode(xml, "resources");
  13270. var nodes = resNode.childNodes;
  13271. var length1 = nodes.length;
  13272. for (var i1 = 0; i1 < length1; i1++) {
  13273. var cxml = nodes[i1];
  13274. if (cxml.nodeName == "string") {
  13275. var key = cxml.getAttribute("name");
  13276. var text = cxml.textContent;
  13277. var i = key.indexOf("-");
  13278. if (i == -1)
  13279. continue;
  13280. var key2 = key.substr(0, i);
  13281. var key3 = key.substr(i + 1);
  13282. var col = strings[key2];
  13283. if (!col) {
  13284. col = {};
  13285. strings[key2] = col;
  13286. }
  13287. col[key3] = text;
  13288. }
  13289. }
  13290. }
  13291. static translateComponent(item) {
  13292. if (TranslationHelper.strings == null)
  13293. return;
  13294. var compStrings = TranslationHelper.strings[item.owner.id + item.id];
  13295. if (compStrings == null)
  13296. return;
  13297. var elementId, value;
  13298. var buffer = item.rawData;
  13299. var nextPos;
  13300. var itemCount;
  13301. var i, j, k;
  13302. var dataLen;
  13303. var curPos;
  13304. var valueCnt;
  13305. var page;
  13306. buffer.seek(0, 2);
  13307. var childCount = buffer.getInt16();
  13308. for (i = 0; i < childCount; i++) {
  13309. dataLen = buffer.getInt16();
  13310. curPos = buffer.pos;
  13311. buffer.seek(curPos, 0);
  13312. var baseType = buffer.readByte();
  13313. var type = baseType;
  13314. buffer.skip(4);
  13315. elementId = buffer.readS();
  13316. if (type == fgui.ObjectType.Component) {
  13317. if (buffer.seek(curPos, 6))
  13318. type = buffer.readByte();
  13319. }
  13320. buffer.seek(curPos, 1);
  13321. if ((value = compStrings[elementId + "-tips"]) != null)
  13322. buffer.writeS(value);
  13323. buffer.seek(curPos, 2);
  13324. var gearCnt = buffer.getInt16();
  13325. for (j = 0; j < gearCnt; j++) {
  13326. nextPos = buffer.getInt16();
  13327. nextPos += buffer.pos;
  13328. if (buffer.readByte() == 6) //gearText
  13329. {
  13330. buffer.skip(2); //controller
  13331. valueCnt = buffer.getInt16();
  13332. for (k = 0; k < valueCnt; k++) {
  13333. page = buffer.readS();
  13334. if (page != null) {
  13335. if ((value = compStrings[elementId + "-texts_" + k]) != null)
  13336. buffer.writeS(value);
  13337. else
  13338. buffer.skip(2);
  13339. }
  13340. }
  13341. if (buffer.readBool() && (value = compStrings[elementId + "-texts_def"]) != null)
  13342. buffer.writeS(value);
  13343. }
  13344. buffer.pos = nextPos;
  13345. }
  13346. if (baseType == fgui.ObjectType.Component && buffer.version >= 2) {
  13347. buffer.seek(curPos, 4);
  13348. buffer.skip(2); //pageController
  13349. buffer.skip(4 * buffer.getUint16());
  13350. var cpCount = buffer.getUint16();
  13351. for (var k = 0; k < cpCount; k++) {
  13352. var target = buffer.readS();
  13353. var propertyId = buffer.getUint16();
  13354. if (propertyId == 0 && (value = compStrings[elementId + "-cp-" + target]) != null)
  13355. buffer.writeS(value);
  13356. else
  13357. buffer.skip(2);
  13358. }
  13359. }
  13360. switch (type) {
  13361. case fgui.ObjectType.Text:
  13362. case fgui.ObjectType.RichText:
  13363. case fgui.ObjectType.InputText:
  13364. {
  13365. if ((value = compStrings[elementId]) != null) {
  13366. buffer.seek(curPos, 6);
  13367. buffer.writeS(value);
  13368. }
  13369. if ((value = compStrings[elementId + "-prompt"]) != null) {
  13370. buffer.seek(curPos, 4);
  13371. buffer.writeS(value);
  13372. }
  13373. break;
  13374. }
  13375. case fgui.ObjectType.List:
  13376. case fgui.ObjectType.Tree:
  13377. {
  13378. buffer.seek(curPos, 8);
  13379. buffer.skip(2);
  13380. itemCount = buffer.getUint16();
  13381. for (j = 0; j < itemCount; j++) {
  13382. nextPos = buffer.getUint16();
  13383. nextPos += buffer.pos;
  13384. buffer.skip(2); //url
  13385. if (type == fgui.ObjectType.Tree)
  13386. buffer.skip(2);
  13387. //title
  13388. if ((value = compStrings[elementId + "-" + j]) != null)
  13389. buffer.writeS(value);
  13390. else
  13391. buffer.skip(2);
  13392. //selected title
  13393. if ((value = compStrings[elementId + "-" + j + "-0"]) != null)
  13394. buffer.writeS(value);
  13395. else
  13396. buffer.skip(2);
  13397. if (buffer.version >= 2) {
  13398. buffer.skip(6);
  13399. buffer.skip(buffer.getUint16() * 4); //controllers
  13400. var cpCount = buffer.getUint16();
  13401. for (var k = 0; k < cpCount; k++) {
  13402. var target = buffer.readS();
  13403. var propertyId = buffer.getUint16();
  13404. if (propertyId == 0 && (value = compStrings[elementId + "-" + j + "-" + target]) != null)
  13405. buffer.writeS(value);
  13406. else
  13407. buffer.skip(2);
  13408. }
  13409. }
  13410. buffer.pos = nextPos;
  13411. }
  13412. break;
  13413. }
  13414. case fgui.ObjectType.Label:
  13415. {
  13416. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  13417. if ((value = compStrings[elementId]) != null)
  13418. buffer.writeS(value);
  13419. else
  13420. buffer.skip(2);
  13421. buffer.skip(2);
  13422. if (buffer.readBool())
  13423. buffer.skip(4);
  13424. buffer.skip(4);
  13425. if (buffer.readBool() && (value = compStrings[elementId + "-prompt"]) != null)
  13426. buffer.writeS(value);
  13427. }
  13428. break;
  13429. }
  13430. case fgui.ObjectType.Button:
  13431. {
  13432. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  13433. if ((value = compStrings[elementId]) != null)
  13434. buffer.writeS(value);
  13435. else
  13436. buffer.skip(2);
  13437. if ((value = compStrings[elementId + "-0"]) != null)
  13438. buffer.writeS(value);
  13439. }
  13440. break;
  13441. }
  13442. case fgui.ObjectType.ComboBox:
  13443. {
  13444. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  13445. itemCount = buffer.getInt16();
  13446. for (j = 0; j < itemCount; j++) {
  13447. nextPos = buffer.getInt16();
  13448. nextPos += buffer.pos;
  13449. if ((value = compStrings[elementId + "-" + j]) != null)
  13450. buffer.writeS(value);
  13451. buffer.pos = nextPos;
  13452. }
  13453. if ((value = compStrings[elementId]) != null)
  13454. buffer.writeS(value);
  13455. }
  13456. break;
  13457. }
  13458. }
  13459. buffer.pos = curPos + dataLen;
  13460. }
  13461. }
  13462. }
  13463. fgui.TranslationHelper = TranslationHelper;
  13464. function findChildNode(xml, name) {
  13465. var col = xml.childNodes;
  13466. var length1 = col.length;
  13467. if (length1 > 0) {
  13468. for (var i1 = 0; i1 < length1; i1++) {
  13469. var cxml = col[i1];
  13470. if (cxml.nodeName == name) {
  13471. return cxml;
  13472. }
  13473. }
  13474. }
  13475. return null;
  13476. }
  13477. })(fgui);
  13478. (function (fgui) {
  13479. class UIConfig {
  13480. constructor() {
  13481. }
  13482. }
  13483. //Default font name
  13484. UIConfig.defaultFont = "SimSun";
  13485. //When a modal window is in front, the background becomes dark.
  13486. UIConfig.modalLayerColor = "rgba(33,33,33,0.2)";
  13487. UIConfig.buttonSoundVolumeScale = 1;
  13488. //Scrolling step in pixels
  13489. UIConfig.defaultScrollStep = 25;
  13490. //Deceleration ratio of scrollpane when its in touch dragging.
  13491. UIConfig.defaultScrollDecelerationRate = 0.967;
  13492. //Default scrollbar display mode. Recommened visible for Desktop and Auto for mobile.
  13493. UIConfig.defaultScrollBarDisplay = fgui.ScrollBarDisplayType.Visible;
  13494. //Allow dragging the content to scroll. Recommeded true for mobile.
  13495. UIConfig.defaultScrollTouchEffect = true;
  13496. //The "rebound" effect in the scolling container. Recommeded true for mobile.
  13497. UIConfig.defaultScrollBounceEffect = true;
  13498. /**
  13499. * 当滚动容器设置为“贴近ITEM”时,判定贴近到哪一个ITEM的滚动距离阀值。
  13500. */
  13501. UIConfig.defaultScrollSnappingThreshold = 0.1;
  13502. /**
  13503. * 当滚动容器设置为“页面模式”时,判定翻到哪一页的滚动距离阀值。
  13504. */
  13505. UIConfig.defaultScrollPagingThreshold = 0.3;
  13506. //Max items displayed in combobox without scrolling.
  13507. UIConfig.defaultComboBoxVisibleItemCount = 10;
  13508. // Pixel offsets of finger to trigger scrolling.
  13509. UIConfig.touchScrollSensitivity = 20;
  13510. // Pixel offsets of finger to trigger dragging.
  13511. UIConfig.touchDragSensitivity = 10;
  13512. // Pixel offsets of mouse pointer to trigger dragging.
  13513. UIConfig.clickDragSensitivity = 2;
  13514. // When click the window, brings to front automatically.
  13515. UIConfig.bringWindowToFrontOnClick = true;
  13516. UIConfig.frameTimeForAsyncUIConstruction = 2;
  13517. UIConfig.textureLinearSampling = true;
  13518. UIConfig.packageFileExtension = "fui";
  13519. fgui.UIConfig = UIConfig;
  13520. })(fgui);
  13521. (function (fgui) {
  13522. class UIObjectFactory {
  13523. constructor() {
  13524. }
  13525. static setExtension(url, type) {
  13526. if (url == null)
  13527. throw "Invaild url: " + url;
  13528. var pi = fgui.UIPackage.getItemByURL(url);
  13529. if (pi)
  13530. pi.extensionType = type;
  13531. UIObjectFactory.extensions[url] = type;
  13532. }
  13533. static setPackageItemExtension(url, type) {
  13534. UIObjectFactory.setExtension(url, type);
  13535. }
  13536. static setLoaderExtension(type) {
  13537. UIObjectFactory.loaderType = type;
  13538. }
  13539. static resolvePackageItemExtension(pi) {
  13540. var extensionType = UIObjectFactory.extensions["ui://" + pi.owner.id + pi.id];
  13541. if (!extensionType)
  13542. extensionType = UIObjectFactory.extensions["ui://" + pi.owner.name + "/" + pi.name];
  13543. if (extensionType)
  13544. pi.extensionType = extensionType;
  13545. }
  13546. static newObject(type, userClass) {
  13547. var obj;
  13548. if (typeof type === 'number') {
  13549. switch (type) {
  13550. case fgui.ObjectType.Image:
  13551. return new fgui.GImage();
  13552. case fgui.ObjectType.MovieClip:
  13553. return new fgui.GMovieClip();
  13554. case fgui.ObjectType.Component:
  13555. return new fgui.GComponent();
  13556. case fgui.ObjectType.Text:
  13557. return new fgui.GBasicTextField();
  13558. case fgui.ObjectType.RichText:
  13559. return new fgui.GRichTextField();
  13560. case fgui.ObjectType.InputText:
  13561. return new fgui.GTextInput();
  13562. case fgui.ObjectType.Group:
  13563. return new fgui.GGroup();
  13564. case fgui.ObjectType.List:
  13565. return new fgui.GList();
  13566. case fgui.ObjectType.Graph:
  13567. return new fgui.GGraph();
  13568. case fgui.ObjectType.Loader:
  13569. if (UIObjectFactory.loaderType)
  13570. return new UIObjectFactory.loaderType();
  13571. else
  13572. return new fgui.GLoader();
  13573. case fgui.ObjectType.Button:
  13574. return new fgui.GButton();
  13575. case fgui.ObjectType.Label:
  13576. return new fgui.GLabel();
  13577. case fgui.ObjectType.ProgressBar:
  13578. return new fgui.GProgressBar();
  13579. case fgui.ObjectType.Slider:
  13580. return new fgui.GSlider();
  13581. case fgui.ObjectType.ScrollBar:
  13582. return new fgui.GScrollBar();
  13583. case fgui.ObjectType.ComboBox:
  13584. return new fgui.GComboBox();
  13585. case fgui.ObjectType.Tree:
  13586. return new fgui.GTree();
  13587. case fgui.ObjectType.Loader3D:
  13588. return new fgui.GLoader3D();
  13589. default:
  13590. return null;
  13591. }
  13592. }
  13593. else {
  13594. if (type.type == fgui.PackageItemType.Component) {
  13595. if (userClass)
  13596. obj = new userClass();
  13597. else if (type.extensionType)
  13598. obj = new type.extensionType();
  13599. else
  13600. obj = UIObjectFactory.newObject(type.objectType);
  13601. }
  13602. else
  13603. obj = UIObjectFactory.newObject(type.objectType);
  13604. if (obj)
  13605. obj.packageItem = type;
  13606. }
  13607. return obj;
  13608. }
  13609. }
  13610. UIObjectFactory.extensions = {};
  13611. fgui.UIObjectFactory = UIObjectFactory;
  13612. })(fgui);
  13613. (function (fgui) {
  13614. class UIPackage {
  13615. constructor() {
  13616. this._items = [];
  13617. this._itemsById = {};
  13618. this._itemsByName = {};
  13619. this._sprites = {};
  13620. this._dependencies = [];
  13621. this._branches = [];
  13622. this._branchIndex = -1;
  13623. }
  13624. static get branch() {
  13625. return UIPackage._branch;
  13626. }
  13627. static set branch(value) {
  13628. UIPackage._branch = value;
  13629. for (var pkgId in UIPackage._instById) {
  13630. var pkg = UIPackage._instById[pkgId];
  13631. if (pkg._branches) {
  13632. pkg._branchIndex = pkg._branches.indexOf(value);
  13633. }
  13634. }
  13635. }
  13636. static getVar(key) {
  13637. return UIPackage._vars[key];
  13638. }
  13639. static setVar(key, value) {
  13640. UIPackage._vars[key] = value;
  13641. }
  13642. static getById(id) {
  13643. return UIPackage._instById[id];
  13644. }
  13645. static getByName(name) {
  13646. return UIPackage._instByName[name];
  13647. }
  13648. static addPackage(resKey, descData) {
  13649. if (!descData) {
  13650. descData = fgui.AssetProxy.inst.getRes(resKey + "." + fgui.UIConfig.packageFileExtension);
  13651. if (!descData || descData.byteLength == 0)
  13652. throw new Error("resource '" + resKey + "' not found");
  13653. }
  13654. var buffer = new fgui.ByteBuffer(descData);
  13655. var pkg = new UIPackage();
  13656. pkg._resKey = resKey;
  13657. pkg.loadPackage(buffer);
  13658. UIPackage._instById[pkg.id] = pkg;
  13659. UIPackage._instByName[pkg.name] = pkg;
  13660. UIPackage._instById[resKey] = pkg;
  13661. return pkg;
  13662. }
  13663. /**
  13664. * @param resKey resKey 或 [resKey1,resKey2,resKey3....]
  13665. */
  13666. static loadPackage(resKey, completeHandler, progressHandler) {
  13667. let loadKeyArr = [];
  13668. let keys = [];
  13669. let i;
  13670. if (Array.isArray(resKey)) {
  13671. for (i = 0; i < resKey.length; i++) {
  13672. loadKeyArr.push({ url: resKey[i] + "." + fgui.UIConfig.packageFileExtension, type: Laya.Loader.BUFFER });
  13673. keys.push(resKey[i]);
  13674. }
  13675. }
  13676. else {
  13677. loadKeyArr = [{ url: resKey + "." + fgui.UIConfig.packageFileExtension, type: Laya.Loader.BUFFER }];
  13678. keys = [resKey];
  13679. }
  13680. let pkgArr = [];
  13681. let pkg;
  13682. for (i = 0; i < loadKeyArr.length; i++) {
  13683. pkg = UIPackage._instById[keys[i]];
  13684. if (pkg) {
  13685. pkgArr.push(pkg);
  13686. loadKeyArr.splice(i, 1);
  13687. keys.splice(i, 1);
  13688. i--;
  13689. }
  13690. }
  13691. if (loadKeyArr.length == 0) {
  13692. completeHandler.runWith([pkgArr]);
  13693. return;
  13694. }
  13695. var descCompleteHandler = Laya.Handler.create(this, function () {
  13696. let pkg;
  13697. let urls = [];
  13698. for (i = 0; i < loadKeyArr.length; i++) {
  13699. let asset = fgui.AssetProxy.inst.getRes(loadKeyArr[i].url);
  13700. if (asset) {
  13701. pkg = new UIPackage();
  13702. pkgArr.push(pkg);
  13703. pkg._resKey = keys[i];
  13704. pkg.loadPackage(new fgui.ByteBuffer(asset));
  13705. let cnt = pkg._items.length;
  13706. for (let j = 0; j < cnt; j++) {
  13707. let pi = pkg._items[j];
  13708. if (pi.type == fgui.PackageItemType.Atlas) {
  13709. urls.push({ url: pi.file, type: Laya.Loader.IMAGE });
  13710. }
  13711. else if (pi.type == fgui.PackageItemType.Sound) {
  13712. urls.push({ url: pi.file, type: Laya.Loader.SOUND });
  13713. }
  13714. }
  13715. }
  13716. }
  13717. if (urls.length > 0) {
  13718. fgui.AssetProxy.inst.load(urls, Laya.Handler.create(this, function () {
  13719. for (i = 0; i < pkgArr.length; i++) {
  13720. pkg = pkgArr[i];
  13721. if (!UIPackage._instById[pkg.id]) {
  13722. UIPackage._instById[pkg.id] = pkg;
  13723. UIPackage._instByName[pkg.name] = pkg;
  13724. UIPackage._instById[pkg._resKey] = pkg;
  13725. }
  13726. }
  13727. completeHandler.runWith([pkgArr]);
  13728. }, null, true), progressHandler);
  13729. }
  13730. else {
  13731. for (i = 0; i < pkgArr.length; i++) {
  13732. pkg = pkgArr[i];
  13733. if (!UIPackage._instById[pkg.id]) {
  13734. UIPackage._instById[pkg.id] = pkg;
  13735. UIPackage._instByName[pkg.name] = pkg;
  13736. UIPackage._instById[pkg._resKey] = pkg;
  13737. }
  13738. }
  13739. completeHandler.runWith([pkgArr]);
  13740. }
  13741. }, null, true);
  13742. fgui.AssetProxy.inst.load(loadKeyArr, descCompleteHandler, null, Laya.Loader.BUFFER);
  13743. }
  13744. static removePackage(packageIdOrName) {
  13745. var pkg = UIPackage._instById[packageIdOrName];
  13746. if (!pkg)
  13747. pkg = UIPackage._instByName[packageIdOrName];
  13748. if (!pkg)
  13749. throw new Error("unknown package: " + packageIdOrName);
  13750. pkg.dispose();
  13751. delete UIPackage._instById[pkg.id];
  13752. delete UIPackage._instByName[pkg.name];
  13753. delete UIPackage._instById[pkg._resKey];
  13754. if (pkg._customId)
  13755. delete UIPackage._instById[pkg._customId];
  13756. }
  13757. static createObject(pkgName, resName, userClass) {
  13758. var pkg = UIPackage.getByName(pkgName);
  13759. if (pkg)
  13760. return pkg.createObject(resName, userClass);
  13761. else
  13762. return null;
  13763. }
  13764. static createObjectFromURL(url, userClass) {
  13765. var pi = UIPackage.getItemByURL(url);
  13766. if (pi)
  13767. return pi.owner.internalCreateObject(pi, userClass);
  13768. else
  13769. return null;
  13770. }
  13771. static getItemURL(pkgName, resName) {
  13772. var pkg = UIPackage.getByName(pkgName);
  13773. if (!pkg)
  13774. return null;
  13775. var pi = pkg._itemsByName[resName];
  13776. if (!pi)
  13777. return null;
  13778. return "ui://" + pkg.id + pi.id;
  13779. }
  13780. static getItemByURL(url) {
  13781. var pos1 = url.indexOf("//");
  13782. if (pos1 == -1)
  13783. return null;
  13784. var pos2 = url.indexOf("/", pos1 + 2);
  13785. if (pos2 == -1) {
  13786. if (url.length > 13) {
  13787. var pkgId = url.substr(5, 8);
  13788. var pkg = UIPackage.getById(pkgId);
  13789. if (pkg) {
  13790. var srcId = url.substr(13);
  13791. return pkg.getItemById(srcId);
  13792. }
  13793. }
  13794. }
  13795. else {
  13796. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  13797. pkg = UIPackage.getByName(pkgName);
  13798. if (pkg) {
  13799. var srcName = url.substr(pos2 + 1);
  13800. return pkg.getItemByName(srcName);
  13801. }
  13802. }
  13803. return null;
  13804. }
  13805. static getItemAssetByURL(url) {
  13806. var item = UIPackage.getItemByURL(url);
  13807. if (item == null)
  13808. return null;
  13809. return item.owner.getItemAsset(item);
  13810. }
  13811. static normalizeURL(url) {
  13812. if (url == null)
  13813. return null;
  13814. var pos1 = url.indexOf("//");
  13815. if (pos1 == -1)
  13816. return null;
  13817. var pos2 = url.indexOf("/", pos1 + 2);
  13818. if (pos2 == -1)
  13819. return url;
  13820. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  13821. var srcName = url.substr(pos2 + 1);
  13822. return UIPackage.getItemURL(pkgName, srcName);
  13823. }
  13824. static setStringsSource(source) {
  13825. fgui.TranslationHelper.loadFromXML(source);
  13826. }
  13827. loadPackage(buffer) {
  13828. if (buffer.getUint32() != 0x46475549)
  13829. throw new Error("FairyGUI: old package format found in '" + this._resKey + "'");
  13830. buffer.version = buffer.getInt32();
  13831. var compressed = buffer.readBool();
  13832. this._id = buffer.readUTFString();
  13833. this._name = buffer.readUTFString();
  13834. buffer.skip(20);
  13835. if (compressed) {
  13836. var buf = new Uint8Array(buffer.buffer, buffer.pos, buffer.length - buffer.pos);
  13837. var inflater = new Zlib.RawInflate(buf);
  13838. buf = inflater.decompress();
  13839. let buffer2 = new fgui.ByteBuffer(buf);
  13840. buffer2.version = buffer.version;
  13841. buffer = buffer2;
  13842. }
  13843. var ver2 = buffer.version >= 2;
  13844. var indexTablePos = buffer.pos;
  13845. var cnt;
  13846. var i;
  13847. var j;
  13848. var nextPos;
  13849. var str;
  13850. var branchIncluded;
  13851. buffer.seek(indexTablePos, 4);
  13852. cnt = buffer.getInt32();
  13853. var stringTable = [];
  13854. for (i = 0; i < cnt; i++)
  13855. stringTable[i] = buffer.readUTFString();
  13856. buffer.stringTable = stringTable;
  13857. buffer.seek(indexTablePos, 0);
  13858. cnt = buffer.getInt16();
  13859. for (i = 0; i < cnt; i++)
  13860. this._dependencies.push({ id: buffer.readS(), name: buffer.readS() });
  13861. if (ver2) {
  13862. cnt = buffer.getInt16();
  13863. if (cnt > 0) {
  13864. this._branches = buffer.readSArray(cnt);
  13865. if (UIPackage._branch)
  13866. this._branchIndex = this._branches.indexOf(UIPackage._branch);
  13867. }
  13868. branchIncluded = cnt > 0;
  13869. }
  13870. buffer.seek(indexTablePos, 1);
  13871. var pi;
  13872. var path = this._resKey;
  13873. let pos = path.lastIndexOf('/');
  13874. let shortPath = pos == -1 ? "" : path.substr(0, pos + 1);
  13875. path = path + "_";
  13876. cnt = buffer.getUint16();
  13877. for (i = 0; i < cnt; i++) {
  13878. nextPos = buffer.getInt32();
  13879. nextPos += buffer.pos;
  13880. pi = new fgui.PackageItem();
  13881. pi.owner = this;
  13882. pi.type = buffer.readByte();
  13883. pi.id = buffer.readS();
  13884. pi.name = buffer.readS();
  13885. buffer.readS(); //path
  13886. str = buffer.readS();
  13887. if (str)
  13888. pi.file = str;
  13889. buffer.readBool(); //exported
  13890. pi.width = buffer.getInt32();
  13891. pi.height = buffer.getInt32();
  13892. switch (pi.type) {
  13893. case fgui.PackageItemType.Image:
  13894. {
  13895. pi.objectType = fgui.ObjectType.Image;
  13896. var scaleOption = buffer.readByte();
  13897. if (scaleOption == 1) {
  13898. pi.scale9Grid = new Laya.Rectangle();
  13899. pi.scale9Grid.x = buffer.getInt32();
  13900. pi.scale9Grid.y = buffer.getInt32();
  13901. pi.scale9Grid.width = buffer.getInt32();
  13902. pi.scale9Grid.height = buffer.getInt32();
  13903. pi.tileGridIndice = buffer.getInt32();
  13904. }
  13905. else if (scaleOption == 2)
  13906. pi.scaleByTile = true;
  13907. pi.smoothing = buffer.readBool();
  13908. break;
  13909. }
  13910. case fgui.PackageItemType.MovieClip:
  13911. {
  13912. pi.smoothing = buffer.readBool();
  13913. pi.objectType = fgui.ObjectType.MovieClip;
  13914. pi.rawData = buffer.readBuffer();
  13915. break;
  13916. }
  13917. case fgui.PackageItemType.Font:
  13918. {
  13919. pi.rawData = buffer.readBuffer();
  13920. break;
  13921. }
  13922. case fgui.PackageItemType.Component:
  13923. {
  13924. var extension = buffer.readByte();
  13925. if (extension > 0)
  13926. pi.objectType = extension;
  13927. else
  13928. pi.objectType = fgui.ObjectType.Component;
  13929. pi.rawData = buffer.readBuffer();
  13930. fgui.UIObjectFactory.resolvePackageItemExtension(pi);
  13931. break;
  13932. }
  13933. case fgui.PackageItemType.Atlas:
  13934. case fgui.PackageItemType.Sound:
  13935. case fgui.PackageItemType.Misc:
  13936. {
  13937. pi.file = path + pi.file;
  13938. break;
  13939. }
  13940. case fgui.PackageItemType.Spine:
  13941. case fgui.PackageItemType.DragonBones:
  13942. {
  13943. pi.file = shortPath + pi.file;
  13944. pi.skeletonAnchor = new Laya.Point();
  13945. pi.skeletonAnchor.x = buffer.getFloat32();
  13946. pi.skeletonAnchor.y = buffer.getFloat32();
  13947. break;
  13948. }
  13949. }
  13950. if (ver2) {
  13951. str = buffer.readS(); //branch
  13952. if (str)
  13953. pi.name = str + "/" + pi.name;
  13954. var branchCnt = buffer.getUint8();
  13955. if (branchCnt > 0) {
  13956. if (branchIncluded)
  13957. pi.branches = buffer.readSArray(branchCnt);
  13958. else
  13959. this._itemsById[buffer.readS()] = pi;
  13960. }
  13961. var highResCnt = buffer.getUint8();
  13962. if (highResCnt > 0)
  13963. pi.highResolution = buffer.readSArray(highResCnt);
  13964. }
  13965. this._items.push(pi);
  13966. this._itemsById[pi.id] = pi;
  13967. if (pi.name != null)
  13968. this._itemsByName[pi.name] = pi;
  13969. buffer.pos = nextPos;
  13970. }
  13971. buffer.seek(indexTablePos, 2);
  13972. cnt = buffer.getUint16();
  13973. for (i = 0; i < cnt; i++) {
  13974. nextPos = buffer.getUint16();
  13975. nextPos += buffer.pos;
  13976. var itemId = buffer.readS();
  13977. pi = this._itemsById[buffer.readS()];
  13978. let sprite = { atlas: pi, rect: new Laya.Rectangle(), offset: new Laya.Point(), originalSize: new Laya.Point() };
  13979. sprite.atlas = pi;
  13980. sprite.rect.x = buffer.getInt32();
  13981. sprite.rect.y = buffer.getInt32();
  13982. sprite.rect.width = buffer.getInt32();
  13983. sprite.rect.height = buffer.getInt32();
  13984. sprite.rotated = buffer.readBool();
  13985. if (ver2 && buffer.readBool()) {
  13986. sprite.offset.x = buffer.getInt32();
  13987. sprite.offset.y = buffer.getInt32();
  13988. sprite.originalSize.x = buffer.getInt32();
  13989. sprite.originalSize.y = buffer.getInt32();
  13990. }
  13991. else {
  13992. sprite.originalSize.x = sprite.rect.width;
  13993. sprite.originalSize.y = sprite.rect.height;
  13994. }
  13995. this._sprites[itemId] = sprite;
  13996. buffer.pos = nextPos;
  13997. }
  13998. if (buffer.seek(indexTablePos, 3)) {
  13999. cnt = buffer.getUint16();
  14000. for (i = 0; i < cnt; i++) {
  14001. nextPos = buffer.getInt32();
  14002. nextPos += buffer.pos;
  14003. pi = this._itemsById[buffer.readS()];
  14004. if (pi && pi.type == fgui.PackageItemType.Image) {
  14005. pi.pixelHitTestData = new fgui.PixelHitTestData();
  14006. pi.pixelHitTestData.load(buffer);
  14007. }
  14008. buffer.pos = nextPos;
  14009. }
  14010. }
  14011. }
  14012. loadAllAssets() {
  14013. var cnt = this._items.length;
  14014. for (var i = 0; i < cnt; i++) {
  14015. var pi = this._items[i];
  14016. this.getItemAsset(pi);
  14017. }
  14018. }
  14019. unloadAssets() {
  14020. var cnt = this._items.length;
  14021. for (var i = 0; i < cnt; i++) {
  14022. var pi = this._items[i];
  14023. if (pi.type == fgui.PackageItemType.Atlas) {
  14024. if (pi.texture)
  14025. Laya.loader.clearTextureRes(pi.texture.url);
  14026. }
  14027. }
  14028. }
  14029. dispose() {
  14030. var cnt = this._items.length;
  14031. for (var i = 0; i < cnt; i++) {
  14032. var pi = this._items[i];
  14033. if (pi.type == fgui.PackageItemType.Atlas) {
  14034. if (pi.texture) {
  14035. pi.texture.destroy();
  14036. pi.texture = null;
  14037. }
  14038. }
  14039. else if (pi.type == fgui.PackageItemType.Sound) {
  14040. Laya.SoundManager.destroySound(pi.file);
  14041. }
  14042. else if (pi.templet)
  14043. pi.templet.destroy();
  14044. }
  14045. }
  14046. get id() {
  14047. return this._id;
  14048. }
  14049. get name() {
  14050. return this._name;
  14051. }
  14052. get customId() {
  14053. return this._customId;
  14054. }
  14055. set customId(value) {
  14056. if (this._customId)
  14057. delete UIPackage._instById[this._customId];
  14058. this._customId = value;
  14059. if (this._customId)
  14060. UIPackage._instById[this._customId] = this;
  14061. }
  14062. createObject(resName, userClass) {
  14063. var pi = this._itemsByName[resName];
  14064. if (pi)
  14065. return this.internalCreateObject(pi, userClass);
  14066. else
  14067. return null;
  14068. }
  14069. internalCreateObject(item, userClass) {
  14070. var g = fgui.UIObjectFactory.newObject(item, userClass);
  14071. if (g == null)
  14072. return null;
  14073. UIPackage._constructing++;
  14074. g.constructFromResource();
  14075. UIPackage._constructing--;
  14076. return g;
  14077. }
  14078. getItemById(itemId) {
  14079. return this._itemsById[itemId];
  14080. }
  14081. getItemByName(resName) {
  14082. return this._itemsByName[resName];
  14083. }
  14084. getItemAssetByName(resName) {
  14085. var pi = this._itemsByName[resName];
  14086. if (pi == null) {
  14087. throw "Resource not found -" + resName;
  14088. }
  14089. return this.getItemAsset(pi);
  14090. }
  14091. getItemAsset(item) {
  14092. switch (item.type) {
  14093. case fgui.PackageItemType.Image:
  14094. if (!item.decoded) {
  14095. item.decoded = true;
  14096. var sprite = this._sprites[item.id];
  14097. if (sprite) {
  14098. var atlasTexture = (this.getItemAsset(sprite.atlas));
  14099. if (atlasTexture) {
  14100. item.texture = Laya.Texture.create(atlasTexture, sprite.rect.x, sprite.rect.y, sprite.rect.width, sprite.rect.height, sprite.offset.x, sprite.offset.y, sprite.originalSize.x, sprite.originalSize.y);
  14101. }
  14102. else {
  14103. item.texture = null;
  14104. }
  14105. }
  14106. else
  14107. item.texture = null;
  14108. }
  14109. return item.texture;
  14110. case fgui.PackageItemType.Atlas:
  14111. if (!item.decoded) {
  14112. item.decoded = true;
  14113. item.texture = fgui.AssetProxy.inst.getRes(item.file);
  14114. //if(!fgui.UIConfig.textureLinearSampling)
  14115. //item.texture.isLinearSampling = false;
  14116. }
  14117. return item.texture;
  14118. case fgui.PackageItemType.Font:
  14119. if (!item.decoded) {
  14120. item.decoded = true;
  14121. this.loadFont(item);
  14122. }
  14123. return item.bitmapFont;
  14124. case fgui.PackageItemType.MovieClip:
  14125. if (!item.decoded) {
  14126. item.decoded = true;
  14127. this.loadMovieClip(item);
  14128. }
  14129. return item.frames;
  14130. case fgui.PackageItemType.Component:
  14131. return item.rawData;
  14132. case fgui.PackageItemType.Misc:
  14133. if (item.file)
  14134. return fgui.AssetProxy.inst.getRes(item.file);
  14135. else
  14136. return null;
  14137. default:
  14138. return null;
  14139. }
  14140. }
  14141. getItemAssetAsync(item, onComplete) {
  14142. if (item.decoded) {
  14143. onComplete(null, item);
  14144. return;
  14145. }
  14146. if (item.loading) {
  14147. item.loading.push(onComplete);
  14148. return;
  14149. }
  14150. switch (item.type) {
  14151. case fgui.PackageItemType.Spine:
  14152. case fgui.PackageItemType.DragonBones:
  14153. item.loading = [onComplete];
  14154. item.templet = new Laya.Templet();
  14155. item.templet.on(Laya.Event.COMPLETE, this, () => {
  14156. let arr = item.loading;
  14157. delete item.loading;
  14158. arr.forEach(e => e(null, item));
  14159. });
  14160. item.templet.on(Laya.Event.ERROR, this, () => {
  14161. let arr = item.loading;
  14162. delete item.loading;
  14163. delete item.templet;
  14164. arr.forEach(e => e('parse error', item));
  14165. });
  14166. let pos = item.file.lastIndexOf('.');
  14167. let str = item.file.substring(0, pos + 1).replace("_ske", "") + "sk";
  14168. item.templet.loadAni(str);
  14169. break;
  14170. default:
  14171. this.getItemAsset(item);
  14172. onComplete(null, item);
  14173. break;
  14174. }
  14175. }
  14176. loadMovieClip(item) {
  14177. var buffer = item.rawData;
  14178. buffer.seek(0, 0);
  14179. item.interval = buffer.getInt32();
  14180. item.swing = buffer.readBool();
  14181. item.repeatDelay = buffer.getInt32();
  14182. buffer.seek(0, 1);
  14183. var frameCount = buffer.getInt16();
  14184. item.frames = [];
  14185. var spriteId;
  14186. var sprite;
  14187. var fx;
  14188. var fy;
  14189. for (var i = 0; i < frameCount; i++) {
  14190. var nextPos = buffer.getInt16();
  14191. nextPos += buffer.pos;
  14192. fx = buffer.getInt32();
  14193. fy = buffer.getInt32();
  14194. buffer.getInt32(); //width
  14195. buffer.getInt32(); //height
  14196. let frame = { addDelay: buffer.getInt32() };
  14197. spriteId = buffer.readS();
  14198. if (spriteId != null && (sprite = this._sprites[spriteId]) != null) {
  14199. var atlasTexture = (this.getItemAsset(sprite.atlas));
  14200. frame.texture = Laya.Texture.create(atlasTexture, sprite.rect.x, sprite.rect.y, sprite.rect.width, sprite.rect.height, fx, fy, item.width, item.height);
  14201. }
  14202. item.frames[i] = frame;
  14203. buffer.pos = nextPos;
  14204. }
  14205. }
  14206. loadFont(item) {
  14207. item = item.getBranch();
  14208. var font = new fgui.BitmapFont();
  14209. item.bitmapFont = font;
  14210. var buffer = item.rawData;
  14211. buffer.seek(0, 0);
  14212. font.ttf = buffer.readBool();
  14213. font.tint = buffer.readBool();
  14214. font.resizable = buffer.readBool();
  14215. buffer.readBool(); //has channel
  14216. font.size = buffer.getInt32();
  14217. var xadvance = buffer.getInt32();
  14218. var lineHeight = buffer.getInt32();
  14219. var mainTexture = null;
  14220. var mainSprite = this._sprites[item.id];
  14221. if (mainSprite)
  14222. mainTexture = (this.getItemAsset(mainSprite.atlas));
  14223. buffer.seek(0, 1);
  14224. var bg = null;
  14225. var cnt = buffer.getInt32();
  14226. for (var i = 0; i < cnt; i++) {
  14227. var nextPos = buffer.getInt16();
  14228. nextPos += buffer.pos;
  14229. bg = {};
  14230. var ch = buffer.readChar();
  14231. font.glyphs[ch] = bg;
  14232. var img = buffer.readS();
  14233. var bx = buffer.getInt32();
  14234. var by = buffer.getInt32();
  14235. bg.x = buffer.getInt32();
  14236. bg.y = buffer.getInt32();
  14237. bg.width = buffer.getInt32();
  14238. bg.height = buffer.getInt32();
  14239. bg.advance = buffer.getInt32();
  14240. bg.channel = buffer.readByte();
  14241. if (bg.channel == 1)
  14242. bg.channel = 3;
  14243. else if (bg.channel == 2)
  14244. bg.channel = 2;
  14245. else if (bg.channel == 3)
  14246. bg.channel = 1;
  14247. if (font.ttf) {
  14248. bg.texture = Laya.Texture.create(mainTexture, bx + mainSprite.rect.x, by + mainSprite.rect.y, bg.width, bg.height);
  14249. bg.lineHeight = lineHeight;
  14250. }
  14251. else {
  14252. var charImg = this._itemsById[img];
  14253. if (charImg) {
  14254. charImg = charImg.getBranch();
  14255. bg.width = charImg.width;
  14256. bg.height = charImg.height;
  14257. charImg = charImg.getHighResolution();
  14258. this.getItemAsset(charImg);
  14259. bg.texture = charImg.texture;
  14260. }
  14261. if (bg.advance == 0) {
  14262. if (xadvance == 0)
  14263. bg.advance = bg.x + bg.width;
  14264. else
  14265. bg.advance = xadvance;
  14266. }
  14267. bg.lineHeight = bg.y < 0 ? bg.height : (bg.y + bg.height);
  14268. if (bg.lineHeight < font.size)
  14269. bg.lineHeight = font.size;
  14270. }
  14271. buffer.pos = nextPos;
  14272. }
  14273. }
  14274. }
  14275. UIPackage._constructing = 0;
  14276. UIPackage._instById = {};
  14277. UIPackage._instByName = {};
  14278. UIPackage._branch = "";
  14279. UIPackage._vars = {};
  14280. fgui.UIPackage = UIPackage;
  14281. })(fgui);
  14282. (function (fgui) {
  14283. class Window extends fgui.GComponent {
  14284. constructor() {
  14285. super();
  14286. this._requestingCmd = 0;
  14287. this._uiSources = [];
  14288. this.bringToFontOnClick = fgui.UIConfig.bringWindowToFrontOnClick;
  14289. this.displayObject.on(Laya.Event.DISPLAY, this, this.__onShown);
  14290. this.displayObject.on(Laya.Event.UNDISPLAY, this, this.__onHidden);
  14291. this.displayObject.on(Laya.Event.MOUSE_DOWN, this, this.__mouseDown);
  14292. }
  14293. addUISource(source) {
  14294. this._uiSources.push(source);
  14295. }
  14296. set contentPane(val) {
  14297. if (this._contentPane != val) {
  14298. if (this._contentPane)
  14299. this.removeChild(this._contentPane);
  14300. this._contentPane = val;
  14301. if (this._contentPane) {
  14302. this.addChild(this._contentPane);
  14303. this.setSize(this._contentPane.width, this._contentPane.height);
  14304. this._contentPane.addRelation(this, fgui.RelationType.Size);
  14305. this._frame = (this._contentPane.getChild("frame"));
  14306. if (this._frame) {
  14307. this.closeButton = this._frame.getChild("closeButton");
  14308. this.dragArea = this._frame.getChild("dragArea");
  14309. this.contentArea = this._frame.getChild("contentArea");
  14310. }
  14311. }
  14312. }
  14313. }
  14314. get contentPane() {
  14315. return this._contentPane;
  14316. }
  14317. get frame() {
  14318. return this._frame;
  14319. }
  14320. get closeButton() {
  14321. return this._closeButton;
  14322. }
  14323. set closeButton(value) {
  14324. if (this._closeButton)
  14325. this._closeButton.offClick(this, this.closeEventHandler);
  14326. this._closeButton = value;
  14327. if (this._closeButton)
  14328. this._closeButton.onClick(this, this.closeEventHandler);
  14329. }
  14330. get dragArea() {
  14331. return this._dragArea;
  14332. }
  14333. set dragArea(value) {
  14334. if (this._dragArea != value) {
  14335. if (this._dragArea) {
  14336. this._dragArea.draggable = false;
  14337. this._dragArea.off(fgui.Events.DRAG_START, this, this.__dragStart);
  14338. }
  14339. this._dragArea = value;
  14340. if (this._dragArea) {
  14341. if (this._dragArea instanceof fgui.GGraph)
  14342. this._dragArea.asGraph.drawRect(0, null, null);
  14343. this._dragArea.draggable = true;
  14344. this._dragArea.on(fgui.Events.DRAG_START, this, this.__dragStart);
  14345. }
  14346. }
  14347. }
  14348. get contentArea() {
  14349. return this._contentArea;
  14350. }
  14351. set contentArea(value) {
  14352. this._contentArea = value;
  14353. }
  14354. show() {
  14355. fgui.GRoot.inst.showWindow(this);
  14356. }
  14357. showOn(root) {
  14358. root.showWindow(this);
  14359. }
  14360. hide() {
  14361. if (this.isShowing)
  14362. this.doHideAnimation();
  14363. }
  14364. hideImmediately() {
  14365. var r = (this.parent instanceof fgui.GRoot) ? this.parent : null;
  14366. if (!r)
  14367. r = fgui.GRoot.inst;
  14368. r.hideWindowImmediately(this);
  14369. }
  14370. centerOn(r, restraint) {
  14371. this.setXY(Math.round((r.width - this.width) / 2), Math.round((r.height - this.height) / 2));
  14372. if (restraint) {
  14373. this.addRelation(r, fgui.RelationType.Center_Center);
  14374. this.addRelation(r, fgui.RelationType.Middle_Middle);
  14375. }
  14376. }
  14377. toggleStatus() {
  14378. if (this.isTop)
  14379. this.hide();
  14380. else
  14381. this.show();
  14382. }
  14383. get isShowing() {
  14384. return this.parent != null;
  14385. }
  14386. get isTop() {
  14387. return this.parent != null && this.parent.getChildIndex(this) == this.parent.numChildren - 1;
  14388. }
  14389. get modal() {
  14390. return this._modal;
  14391. }
  14392. set modal(val) {
  14393. this._modal = val;
  14394. }
  14395. bringToFront() {
  14396. this.root.bringToFront(this);
  14397. }
  14398. showModalWait(requestingCmd) {
  14399. if (requestingCmd != null)
  14400. this._requestingCmd = requestingCmd;
  14401. if (fgui.UIConfig.windowModalWaiting) {
  14402. if (!this._modalWaitPane)
  14403. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.windowModalWaiting);
  14404. this.layoutModalWaitPane();
  14405. this.addChild(this._modalWaitPane);
  14406. }
  14407. }
  14408. layoutModalWaitPane() {
  14409. if (this._contentArea) {
  14410. var pt = this._frame.localToGlobal();
  14411. pt = this.globalToLocal(pt.x, pt.y, pt);
  14412. this._modalWaitPane.setXY(pt.x + this._contentArea.x, pt.y + this._contentArea.y);
  14413. this._modalWaitPane.setSize(this._contentArea.width, this._contentArea.height);
  14414. }
  14415. else
  14416. this._modalWaitPane.setSize(this.width, this.height);
  14417. }
  14418. closeModalWait(requestingCmd) {
  14419. if (requestingCmd != null) {
  14420. if (this._requestingCmd != requestingCmd)
  14421. return false;
  14422. }
  14423. this._requestingCmd = 0;
  14424. if (this._modalWaitPane && this._modalWaitPane.parent != null)
  14425. this.removeChild(this._modalWaitPane);
  14426. return true;
  14427. }
  14428. get modalWaiting() {
  14429. return this._modalWaitPane && this._modalWaitPane.parent != null;
  14430. }
  14431. init() {
  14432. if (this._inited || this._loading)
  14433. return;
  14434. if (this._uiSources.length > 0) {
  14435. this._loading = false;
  14436. var cnt = this._uiSources.length;
  14437. for (var i = 0; i < cnt; i++) {
  14438. var lib = this._uiSources[i];
  14439. if (!lib.loaded) {
  14440. lib.load(this.__uiLoadComplete, this);
  14441. this._loading = true;
  14442. }
  14443. }
  14444. if (!this._loading)
  14445. this._init();
  14446. }
  14447. else
  14448. this._init();
  14449. }
  14450. onInit() {
  14451. }
  14452. onShown() {
  14453. }
  14454. onHide() {
  14455. }
  14456. doShowAnimation() {
  14457. this.onShown();
  14458. }
  14459. doHideAnimation() {
  14460. this.hideImmediately();
  14461. }
  14462. __uiLoadComplete() {
  14463. var cnt = this._uiSources.length;
  14464. for (var i = 0; i < cnt; i++) {
  14465. var lib = this._uiSources[i];
  14466. if (!lib.loaded)
  14467. return;
  14468. }
  14469. this._loading = false;
  14470. this._init();
  14471. }
  14472. _init() {
  14473. this._inited = true;
  14474. this.onInit();
  14475. if (this.isShowing)
  14476. this.doShowAnimation();
  14477. }
  14478. dispose() {
  14479. if (this.parent)
  14480. this.hideImmediately();
  14481. super.dispose();
  14482. }
  14483. closeEventHandler() {
  14484. this.hide();
  14485. }
  14486. __onShown() {
  14487. if (!this._inited)
  14488. this.init();
  14489. else
  14490. this.doShowAnimation();
  14491. }
  14492. __onHidden() {
  14493. this.closeModalWait();
  14494. this.onHide();
  14495. }
  14496. __mouseDown() {
  14497. if (this.isShowing && this.bringToFontOnClick)
  14498. this.bringToFront();
  14499. }
  14500. __dragStart(evt) {
  14501. fgui.GObject.cast(evt.currentTarget).stopDrag();
  14502. this.startDrag();
  14503. }
  14504. }
  14505. fgui.Window = Window;
  14506. })(fgui);
  14507. (function (fgui) {
  14508. class ControllerAction {
  14509. constructor() {
  14510. }
  14511. static createAction(type) {
  14512. switch (type) {
  14513. case 0:
  14514. return new fgui.PlayTransitionAction();
  14515. case 1:
  14516. return new fgui.ChangePageAction();
  14517. }
  14518. return null;
  14519. }
  14520. run(controller, prevPage, curPage) {
  14521. if ((this.fromPage == null || this.fromPage.length == 0 || this.fromPage.indexOf(prevPage) != -1)
  14522. && (this.toPage == null || this.toPage.length == 0 || this.toPage.indexOf(curPage) != -1))
  14523. this.enter(controller);
  14524. else
  14525. this.leave(controller);
  14526. }
  14527. enter(controller) {
  14528. }
  14529. leave(controller) {
  14530. }
  14531. setup(buffer) {
  14532. var cnt;
  14533. var i;
  14534. cnt = buffer.getInt16();
  14535. this.fromPage = [];
  14536. for (i = 0; i < cnt; i++)
  14537. this.fromPage[i] = buffer.readS();
  14538. cnt = buffer.getInt16();
  14539. this.toPage = [];
  14540. for (i = 0; i < cnt; i++)
  14541. this.toPage[i] = buffer.readS();
  14542. }
  14543. }
  14544. fgui.ControllerAction = ControllerAction;
  14545. })(fgui);
  14546. ///<reference path="ControllerAction.ts"/>
  14547. ///<reference path="ControllerAction.ts"/>
  14548. (function (fgui) {
  14549. class ChangePageAction extends fgui.ControllerAction {
  14550. constructor() {
  14551. super();
  14552. }
  14553. enter(controller) {
  14554. if (!this.controllerName)
  14555. return;
  14556. var gcom;
  14557. if (this.objectId)
  14558. gcom = controller.parent.getChildById(this.objectId);
  14559. else
  14560. gcom = controller.parent;
  14561. if (gcom) {
  14562. var cc = gcom.getController(this.controllerName);
  14563. if (cc && cc != controller && !cc.changing) {
  14564. if (this.targetPage == "~1") {
  14565. if (controller.selectedIndex < cc.pageCount)
  14566. cc.selectedIndex = controller.selectedIndex;
  14567. }
  14568. else if (this.targetPage == "~2")
  14569. cc.selectedPage = controller.selectedPage;
  14570. else
  14571. cc.selectedPageId = this.targetPage;
  14572. }
  14573. }
  14574. }
  14575. setup(buffer) {
  14576. super.setup(buffer);
  14577. this.objectId = buffer.readS();
  14578. this.controllerName = buffer.readS();
  14579. this.targetPage = buffer.readS();
  14580. }
  14581. }
  14582. fgui.ChangePageAction = ChangePageAction;
  14583. })(fgui);
  14584. (function (fgui) {
  14585. class PlayTransitionAction extends fgui.ControllerAction {
  14586. constructor() {
  14587. super();
  14588. }
  14589. enter(controller) {
  14590. var trans = controller.parent.getTransition(this.transitionName);
  14591. if (trans) {
  14592. if (this._currentTransition && this._currentTransition.playing)
  14593. trans.changePlayTimes(this.playTimes);
  14594. else
  14595. trans.play(null, this.playTimes, this.delay);
  14596. this._currentTransition = trans;
  14597. }
  14598. }
  14599. leave(controller) {
  14600. if (this.stopOnExit && this._currentTransition) {
  14601. this._currentTransition.stop();
  14602. this._currentTransition = null;
  14603. }
  14604. }
  14605. setup(buffer) {
  14606. super.setup(buffer);
  14607. this.transitionName = buffer.readS();
  14608. this.playTimes = buffer.getInt32();
  14609. this.delay = buffer.getFloat32();
  14610. this.stopOnExit = buffer.readBool();
  14611. }
  14612. }
  14613. fgui.PlayTransitionAction = PlayTransitionAction;
  14614. })(fgui);
  14615. (function (fgui) {
  14616. class BitmapFont {
  14617. constructor() {
  14618. this.size = 0;
  14619. this.glyphs = {};
  14620. }
  14621. }
  14622. fgui.BitmapFont = BitmapFont;
  14623. })(fgui);
  14624. (function (fgui) {
  14625. function fillImage(w, h, method, origin, clockwise, amount) {
  14626. if (amount <= 0)
  14627. return null;
  14628. else if (amount >= 0.9999)
  14629. return [0, 0, w, 0, w, h, 0, h];
  14630. var points;
  14631. switch (method) {
  14632. case fgui.FillMethod.Horizontal:
  14633. points = fillHorizontal(w, h, origin, amount);
  14634. break;
  14635. case fgui.FillMethod.Vertical:
  14636. points = fillVertical(w, h, origin, amount);
  14637. break;
  14638. case fgui.FillMethod.Radial90:
  14639. points = fillRadial90(w, h, origin, clockwise, amount);
  14640. break;
  14641. case fgui.FillMethod.Radial180:
  14642. points = fillRadial180(w, h, origin, clockwise, amount);
  14643. break;
  14644. case fgui.FillMethod.Radial360:
  14645. points = fillRadial360(w, h, origin, clockwise, amount);
  14646. break;
  14647. }
  14648. return points;
  14649. }
  14650. fgui.fillImage = fillImage;
  14651. function fillHorizontal(w, h, origin, amount) {
  14652. var w2 = w * amount;
  14653. if (origin == fgui.FillOrigin.Left || origin == fgui.FillOrigin.Top)
  14654. return [0, 0, w2, 0, w2, h, 0, h];
  14655. else
  14656. return [w, 0, w, h, w - w2, h, w - w2, 0];
  14657. }
  14658. function fillVertical(w, h, origin, amount) {
  14659. var h2 = h * amount;
  14660. if (origin == fgui.FillOrigin.Left || origin == fgui.FillOrigin.Top)
  14661. return [0, 0, 0, h2, w, h2, w, 0];
  14662. else
  14663. return [0, h, w, h, w, h - h2, 0, h - h2];
  14664. }
  14665. function fillRadial90(w, h, origin, clockwise, amount) {
  14666. if (clockwise && (origin == fgui.FillOrigin.TopRight || origin == fgui.FillOrigin.BottomLeft)
  14667. || !clockwise && (origin == fgui.FillOrigin.TopLeft || origin == fgui.FillOrigin.BottomRight)) {
  14668. amount = 1 - amount;
  14669. }
  14670. var v, v2, h2;
  14671. v = Math.tan(Math.PI / 2 * amount);
  14672. h2 = w * v;
  14673. v2 = (h2 - h) / h2;
  14674. var points;
  14675. switch (origin) {
  14676. case fgui.FillOrigin.TopLeft:
  14677. if (clockwise) {
  14678. if (h2 <= h)
  14679. points = [0, 0, w, h2, w, 0];
  14680. else
  14681. points = [0, 0, w * (1 - v2), h, w, h, w, 0];
  14682. }
  14683. else {
  14684. if (h2 <= h)
  14685. points = [0, 0, w, h2, w, h, 0, h];
  14686. else
  14687. points = [0, 0, w * (1 - v2), h, 0, h];
  14688. }
  14689. break;
  14690. case fgui.FillOrigin.TopRight:
  14691. if (clockwise) {
  14692. if (h2 <= h)
  14693. points = [w, 0, 0, h2, 0, h, w, h];
  14694. else
  14695. points = [w, 0, w * v2, h, w, h];
  14696. }
  14697. else {
  14698. if (h2 <= h)
  14699. points = [w, 0, 0, h2, 0, 0];
  14700. else
  14701. points = [w, 0, w * v2, h, 0, h, 0, 0];
  14702. }
  14703. break;
  14704. case fgui.FillOrigin.BottomLeft:
  14705. if (clockwise) {
  14706. if (h2 <= h)
  14707. points = [0, h, w, h - h2, w, 0, 0, 0];
  14708. else
  14709. points = [0, h, w * (1 - v2), 0, 0, 0];
  14710. }
  14711. else {
  14712. if (h2 <= h)
  14713. points = [0, h, w, h - h2, w, h];
  14714. else
  14715. points = [0, h, w * (1 - v2), 0, w, 0, w, h];
  14716. }
  14717. break;
  14718. case fgui.FillOrigin.BottomRight:
  14719. if (clockwise) {
  14720. if (h2 <= h)
  14721. points = [w, h, 0, h - h2, 0, h];
  14722. else
  14723. points = [w, h, w * v2, 0, 0, 0, 0, h];
  14724. }
  14725. else {
  14726. if (h2 <= h)
  14727. points = [w, h, 0, h - h2, 0, 0, w, 0];
  14728. else
  14729. points = [w, h, w * v2, 0, w, 0];
  14730. }
  14731. break;
  14732. }
  14733. return points;
  14734. }
  14735. function movePoints(points, offsetX, offsetY) {
  14736. var cnt = points.length;
  14737. for (var i = 0; i < cnt; i += 2) {
  14738. points[i] += offsetX;
  14739. points[i + 1] += offsetY;
  14740. }
  14741. }
  14742. function fillRadial180(w, h, origin, clockwise, amount) {
  14743. var points;
  14744. switch (origin) {
  14745. case fgui.FillOrigin.Top:
  14746. if (amount <= 0.5) {
  14747. amount = amount / 0.5;
  14748. points = fillRadial90(w / 2, h, clockwise ? fgui.FillOrigin.TopLeft : fgui.FillOrigin.TopRight, clockwise, amount);
  14749. if (clockwise)
  14750. movePoints(points, w / 2, 0);
  14751. }
  14752. else {
  14753. amount = (amount - 0.5) / 0.5;
  14754. points = fillRadial90(w / 2, h, clockwise ? fgui.FillOrigin.TopRight : fgui.FillOrigin.TopLeft, clockwise, amount);
  14755. if (clockwise)
  14756. points.push(w, h, w, 0);
  14757. else {
  14758. movePoints(points, w / 2, 0);
  14759. points.push(0, h, 0, 0);
  14760. }
  14761. }
  14762. break;
  14763. case fgui.FillOrigin.Bottom:
  14764. if (amount <= 0.5) {
  14765. amount = amount / 0.5;
  14766. points = fillRadial90(w / 2, h, clockwise ? fgui.FillOrigin.BottomRight : fgui.FillOrigin.BottomLeft, clockwise, amount);
  14767. if (!clockwise)
  14768. movePoints(points, w / 2, 0);
  14769. }
  14770. else {
  14771. amount = (amount - 0.5) / 0.5;
  14772. points = fillRadial90(w / 2, h, clockwise ? fgui.FillOrigin.BottomLeft : fgui.FillOrigin.BottomRight, clockwise, amount);
  14773. if (clockwise) {
  14774. movePoints(points, w / 2, 0);
  14775. points.push(0, 0, 0, h);
  14776. }
  14777. else
  14778. points.push(w, 0, w, h);
  14779. }
  14780. break;
  14781. case fgui.FillOrigin.Left:
  14782. if (amount <= 0.5) {
  14783. amount = amount / 0.5;
  14784. points = fillRadial90(w, h / 2, clockwise ? fgui.FillOrigin.BottomLeft : fgui.FillOrigin.TopLeft, clockwise, amount);
  14785. if (!clockwise)
  14786. movePoints(points, 0, h / 2);
  14787. }
  14788. else {
  14789. amount = (amount - 0.5) / 0.5;
  14790. points = fillRadial90(w, h / 2, clockwise ? fgui.FillOrigin.TopLeft : fgui.FillOrigin.BottomLeft, clockwise, amount);
  14791. if (clockwise) {
  14792. movePoints(points, 0, h / 2);
  14793. points.push(w, 0, 0, 0);
  14794. }
  14795. else
  14796. points.push(w, h, 0, h);
  14797. }
  14798. break;
  14799. case fgui.FillOrigin.Right:
  14800. if (amount <= 0.5) {
  14801. amount = amount / 0.5;
  14802. points = fillRadial90(w, h / 2, clockwise ? fgui.FillOrigin.TopRight : fgui.FillOrigin.BottomRight, clockwise, amount);
  14803. if (clockwise)
  14804. movePoints(points, 0, h / 2);
  14805. }
  14806. else {
  14807. amount = (amount - 0.5) / 0.5;
  14808. points = fillRadial90(w, h / 2, clockwise ? fgui.FillOrigin.BottomRight : fgui.FillOrigin.TopRight, clockwise, amount);
  14809. if (clockwise)
  14810. points.push(0, h, w, h);
  14811. else {
  14812. movePoints(points, 0, h / 2);
  14813. points.push(0, 0, w, 0);
  14814. }
  14815. }
  14816. break;
  14817. }
  14818. return points;
  14819. }
  14820. function fillRadial360(w, h, origin, clockwise, amount) {
  14821. var points;
  14822. switch (origin) {
  14823. case fgui.FillOrigin.Top:
  14824. if (amount <= 0.5) {
  14825. amount = amount / 0.5;
  14826. points = fillRadial180(w / 2, h, clockwise ? fgui.FillOrigin.Left : fgui.FillOrigin.Right, clockwise, amount);
  14827. if (clockwise)
  14828. movePoints(points, w / 2, 0);
  14829. }
  14830. else {
  14831. amount = (amount - 0.5) / 0.5;
  14832. points = fillRadial180(w / 2, h, clockwise ? fgui.FillOrigin.Right : fgui.FillOrigin.Left, clockwise, amount);
  14833. if (clockwise)
  14834. points.push(w, h, w, 0, w / 2, 0);
  14835. else {
  14836. movePoints(points, w / 2, 0);
  14837. points.push(0, h, 0, 0, w / 2, 0);
  14838. }
  14839. }
  14840. break;
  14841. case fgui.FillOrigin.Bottom:
  14842. if (amount <= 0.5) {
  14843. amount = amount / 0.5;
  14844. points = fillRadial180(w / 2, h, clockwise ? fgui.FillOrigin.Right : fgui.FillOrigin.Left, clockwise, amount);
  14845. if (!clockwise)
  14846. movePoints(points, w / 2, 0);
  14847. }
  14848. else {
  14849. amount = (amount - 0.5) / 0.5;
  14850. points = fillRadial180(w / 2, h, clockwise ? fgui.FillOrigin.Left : fgui.FillOrigin.Right, clockwise, amount);
  14851. if (clockwise) {
  14852. movePoints(points, w / 2, 0);
  14853. points.push(0, 0, 0, h, w / 2, h);
  14854. }
  14855. else
  14856. points.push(w, 0, w, h, w / 2, h);
  14857. }
  14858. break;
  14859. case fgui.FillOrigin.Left:
  14860. if (amount <= 0.5) {
  14861. amount = amount / 0.5;
  14862. points = fillRadial180(w, h / 2, clockwise ? fgui.FillOrigin.Bottom : fgui.FillOrigin.Top, clockwise, amount);
  14863. if (!clockwise)
  14864. movePoints(points, 0, h / 2);
  14865. }
  14866. else {
  14867. amount = (amount - 0.5) / 0.5;
  14868. points = fillRadial180(w, h / 2, clockwise ? fgui.FillOrigin.Top : fgui.FillOrigin.Bottom, clockwise, amount);
  14869. if (clockwise) {
  14870. movePoints(points, 0, h / 2);
  14871. points.push(w, 0, 0, 0, 0, h / 2);
  14872. }
  14873. else
  14874. points.push(w, h, 0, h, 0, h / 2);
  14875. }
  14876. break;
  14877. case fgui.FillOrigin.Right:
  14878. if (amount <= 0.5) {
  14879. amount = amount / 0.5;
  14880. points = fillRadial180(w, h / 2, clockwise ? fgui.FillOrigin.Top : fgui.FillOrigin.Bottom, clockwise, amount);
  14881. if (clockwise)
  14882. movePoints(points, 0, h / 2);
  14883. }
  14884. else {
  14885. amount = (amount - 0.5) / 0.5;
  14886. points = fillRadial180(w, h / 2, clockwise ? fgui.FillOrigin.Bottom : fgui.FillOrigin.Top, clockwise, amount);
  14887. if (clockwise)
  14888. points.push(0, h, w, h, w, h / 2);
  14889. else {
  14890. movePoints(points, 0, h / 2);
  14891. points.push(0, 0, w, 0, w, h / 2);
  14892. }
  14893. }
  14894. break;
  14895. }
  14896. return points;
  14897. }
  14898. })(fgui);
  14899. (function (fgui) {
  14900. class Image extends Laya.Sprite {
  14901. constructor() {
  14902. super();
  14903. this._tileGridIndice = 0;
  14904. this._needRebuild = 0;
  14905. this._fillMethod = 0;
  14906. this._fillOrigin = 0;
  14907. this._fillAmount = 0;
  14908. this.mouseEnabled = false;
  14909. this._color = "#FFFFFF";
  14910. }
  14911. set width(value) {
  14912. if (this["_width"] !== value) {
  14913. super.set_width(value);
  14914. this.markChanged(1);
  14915. }
  14916. }
  14917. set height(value) {
  14918. if (this["_height"] !== value) {
  14919. super.set_height(value);
  14920. this.markChanged(1);
  14921. }
  14922. }
  14923. get texture() {
  14924. return this._source;
  14925. }
  14926. set texture(value) {
  14927. if (this._source != value) {
  14928. this._source = value;
  14929. if (this["_width"] == 0) {
  14930. if (this._source)
  14931. this.size(this._source.width, this._source.height);
  14932. else
  14933. this.size(0, 0);
  14934. }
  14935. this.repaint();
  14936. this.markChanged(1);
  14937. }
  14938. }
  14939. get scale9Grid() {
  14940. return this._scale9Grid;
  14941. }
  14942. set scale9Grid(value) {
  14943. this._scale9Grid = value;
  14944. this._sizeGrid = null;
  14945. this.markChanged(1);
  14946. }
  14947. get scaleByTile() {
  14948. return this._scaleByTile;
  14949. }
  14950. set scaleByTile(value) {
  14951. if (this._scaleByTile != value) {
  14952. this._scaleByTile = value;
  14953. this.markChanged(1);
  14954. }
  14955. }
  14956. get tileGridIndice() {
  14957. return this._tileGridIndice;
  14958. }
  14959. set tileGridIndice(value) {
  14960. if (this._tileGridIndice != value) {
  14961. this._tileGridIndice = value;
  14962. this.markChanged(1);
  14963. }
  14964. }
  14965. get fillMethod() {
  14966. return this._fillMethod;
  14967. }
  14968. set fillMethod(value) {
  14969. if (this._fillMethod != value) {
  14970. this._fillMethod = value;
  14971. if (this._fillMethod != 0) {
  14972. if (!this._mask) {
  14973. this._mask = new Laya.Sprite();
  14974. this._mask.mouseEnabled = false;
  14975. }
  14976. this.mask = this._mask;
  14977. this.markChanged(2);
  14978. }
  14979. else if (this.mask) {
  14980. this._mask.graphics.clear();
  14981. this.mask = null;
  14982. }
  14983. }
  14984. }
  14985. get fillOrigin() {
  14986. return this._fillOrigin;
  14987. }
  14988. set fillOrigin(value) {
  14989. if (this._fillOrigin != value) {
  14990. this._fillOrigin = value;
  14991. if (this._fillMethod != 0)
  14992. this.markChanged(2);
  14993. }
  14994. }
  14995. get fillClockwise() {
  14996. return this._fillClockwise;
  14997. }
  14998. set fillClockwise(value) {
  14999. if (this._fillClockwise != value) {
  15000. this._fillClockwise = value;
  15001. if (this._fillMethod != 0)
  15002. this.markChanged(2);
  15003. }
  15004. }
  15005. get fillAmount() {
  15006. return this._fillAmount;
  15007. }
  15008. set fillAmount(value) {
  15009. if (this._fillAmount != value) {
  15010. this._fillAmount = value;
  15011. if (this._fillMethod != 0)
  15012. this.markChanged(2);
  15013. }
  15014. }
  15015. get color() {
  15016. return this._color;
  15017. }
  15018. set color(value) {
  15019. if (this._color != value) {
  15020. this._color = value;
  15021. fgui.ToolSet.setColorFilter(this, value);
  15022. }
  15023. }
  15024. markChanged(flag) {
  15025. if (!this._needRebuild) {
  15026. this._needRebuild = flag;
  15027. Laya.timer.callLater(this, this.rebuild);
  15028. }
  15029. else
  15030. this._needRebuild |= flag;
  15031. }
  15032. rebuild() {
  15033. if ((this._needRebuild & 1) != 0)
  15034. this.doDraw();
  15035. if ((this._needRebuild & 2) != 0 && this._fillMethod != 0)
  15036. this.doFill();
  15037. this._needRebuild = 0;
  15038. }
  15039. doDraw() {
  15040. var w = this["_width"];
  15041. var h = this["_height"];
  15042. var g = this.graphics;
  15043. var tex = this._source;
  15044. g.clear();
  15045. if (tex == null || w == 0 || h == 0) {
  15046. return;
  15047. }
  15048. if (this._scaleByTile) {
  15049. g.fillTexture(tex, 0, 0, w, h);
  15050. }
  15051. else if (this._scale9Grid) {
  15052. if (!this._sizeGrid) {
  15053. var tw = tex.width;
  15054. var th = tex.height;
  15055. var left = this._scale9Grid.x;
  15056. var right = Math.max(tw - this._scale9Grid.right, 0);
  15057. var top = this._scale9Grid.y;
  15058. var bottom = Math.max(th - this._scale9Grid.bottom, 0);
  15059. this._sizeGrid = [top, right, bottom, left, this._tileGridIndice];
  15060. }
  15061. g.draw9Grid(tex, 0, 0, w, h, this._sizeGrid);
  15062. }
  15063. else {
  15064. g.drawImage(tex, 0, 0, w, h);
  15065. }
  15066. }
  15067. doFill() {
  15068. var w = this["_width"];
  15069. var h = this["_height"];
  15070. var g = this._mask.graphics;
  15071. g.clear();
  15072. if (w == 0 || h == 0)
  15073. return;
  15074. var points = fgui.fillImage(w, h, this._fillMethod, this._fillOrigin, this._fillClockwise, this._fillAmount);
  15075. if (points == null) {
  15076. //不知道为什么,不这样操作一下空白的遮罩不能生效
  15077. this.mask = null;
  15078. this.mask = this._mask;
  15079. return;
  15080. }
  15081. g.drawPoly(0, 0, points, "#FFFFFF");
  15082. }
  15083. }
  15084. fgui.Image = Image;
  15085. })(fgui);
  15086. ///<reference path="./Image.ts"/>
  15087. ///<reference path="./Image.ts"/>
  15088. (function (fgui) {
  15089. class MovieClip extends fgui.Image {
  15090. constructor() {
  15091. super();
  15092. this.interval = 0;
  15093. this.repeatDelay = 0;
  15094. this.timeScale = 1;
  15095. this._playing = true;
  15096. this._frameCount = 0;
  15097. this._frame = 0;
  15098. this._start = 0;
  15099. this._end = 0;
  15100. this._times = 0;
  15101. this._endAt = 0;
  15102. this._status = 0; //0-none, 1-next loop, 2-ending, 3-ended
  15103. this._frameElapsed = 0; //当前帧延迟
  15104. this._repeatedCount = 0;
  15105. this.mouseEnabled = false;
  15106. this.setPlaySettings();
  15107. this.on(Laya.Event.DISPLAY, this, this.__addToStage);
  15108. this.on(Laya.Event.UNDISPLAY, this, this.__removeFromStage);
  15109. }
  15110. get frames() {
  15111. return this._frames;
  15112. }
  15113. set frames(value) {
  15114. this._frames = value;
  15115. this._scaleByTile = false;
  15116. this._scale9Grid = null;
  15117. if (this._frames) {
  15118. this._frameCount = this._frames.length;
  15119. if (this._end == -1 || this._end > this._frameCount - 1)
  15120. this._end = this._frameCount - 1;
  15121. if (this._endAt == -1 || this._endAt > this._frameCount - 1)
  15122. this._endAt = this._frameCount - 1;
  15123. if (this._frame < 0 || this._frame > this._frameCount - 1)
  15124. this._frame = this._frameCount - 1;
  15125. this._frameElapsed = 0;
  15126. this._repeatedCount = 0;
  15127. this._reversed = false;
  15128. }
  15129. else
  15130. this._frameCount = 0;
  15131. this.drawFrame();
  15132. this.checkTimer();
  15133. }
  15134. get frameCount() {
  15135. return this._frameCount;
  15136. }
  15137. get frame() {
  15138. return this._frame;
  15139. }
  15140. set frame(value) {
  15141. if (this._frame != value) {
  15142. if (this._frames && value >= this._frameCount)
  15143. value = this._frameCount - 1;
  15144. this._frame = value;
  15145. this._frameElapsed = 0;
  15146. this.drawFrame();
  15147. }
  15148. }
  15149. get playing() {
  15150. return this._playing;
  15151. }
  15152. set playing(value) {
  15153. if (this._playing != value) {
  15154. this._playing = value;
  15155. this.checkTimer();
  15156. }
  15157. }
  15158. //从start帧开始,播放到end帧(-1表示结尾),重复times次(0表示无限循环),循环结束后,停止在endAt帧(-1表示参数end)
  15159. rewind() {
  15160. this._frame = 0;
  15161. this._frameElapsed = 0;
  15162. this._reversed = false;
  15163. this._repeatedCount = 0;
  15164. this.drawFrame();
  15165. }
  15166. syncStatus(anotherMc) {
  15167. this._frame = anotherMc._frame;
  15168. this._frameElapsed = anotherMc._frameElapsed;
  15169. this._reversed = anotherMc._reversed;
  15170. this._repeatedCount = anotherMc._repeatedCount;
  15171. this.drawFrame();
  15172. }
  15173. advance(timeInMiniseconds) {
  15174. var beginFrame = this._frame;
  15175. var beginReversed = this._reversed;
  15176. var backupTime = timeInMiniseconds;
  15177. while (true) {
  15178. var tt = this.interval + this._frames[this._frame].addDelay;
  15179. if (this._frame == 0 && this._repeatedCount > 0)
  15180. tt += this.repeatDelay;
  15181. if (timeInMiniseconds < tt) {
  15182. this._frameElapsed = 0;
  15183. break;
  15184. }
  15185. timeInMiniseconds -= tt;
  15186. if (this.swing) {
  15187. if (this._reversed) {
  15188. this._frame--;
  15189. if (this._frame <= 0) {
  15190. this._frame = 0;
  15191. this._repeatedCount++;
  15192. this._reversed = !this._reversed;
  15193. }
  15194. }
  15195. else {
  15196. this._frame++;
  15197. if (this._frame > this._frameCount - 1) {
  15198. this._frame = Math.max(0, this._frameCount - 2);
  15199. this._repeatedCount++;
  15200. this._reversed = !this._reversed;
  15201. }
  15202. }
  15203. }
  15204. else {
  15205. this._frame++;
  15206. if (this._frame > this._frameCount - 1) {
  15207. this._frame = 0;
  15208. this._repeatedCount++;
  15209. }
  15210. }
  15211. if (this._frame == beginFrame && this._reversed == beginReversed) //走了一轮了
  15212. {
  15213. var roundTime = backupTime - timeInMiniseconds; //这就是一轮需要的时间
  15214. timeInMiniseconds -= Math.floor(timeInMiniseconds / roundTime) * roundTime; //跳过
  15215. }
  15216. }
  15217. this.drawFrame();
  15218. }
  15219. //从start帧开始,播放到end帧(-1表示结尾),重复times次(0表示无限循环),循环结束后,停止在endAt帧(-1表示参数end)
  15220. setPlaySettings(start, end, times, endAt, endHandler) {
  15221. if (start == undefined)
  15222. start = 0;
  15223. if (end == undefined)
  15224. end = -1;
  15225. if (times == undefined)
  15226. times = 0;
  15227. if (endAt == undefined)
  15228. endAt = -1;
  15229. this._start = start;
  15230. this._end = end;
  15231. if (this._end == -1 || this._end > this._frameCount - 1)
  15232. this._end = this._frameCount - 1;
  15233. this._times = times;
  15234. this._endAt = endAt;
  15235. if (this._endAt == -1)
  15236. this._endAt = this._end;
  15237. this._status = 0;
  15238. this._endHandler = endHandler;
  15239. this.frame = start;
  15240. }
  15241. update() {
  15242. if (!this._playing || this._frameCount == 0 || this._status == 3)
  15243. return;
  15244. var dt = Laya.timer.delta;
  15245. if (dt > 100)
  15246. dt = 100;
  15247. if (this.timeScale != 1)
  15248. dt *= this.timeScale;
  15249. this._frameElapsed += dt;
  15250. var tt = this.interval + this._frames[this._frame].addDelay;
  15251. if (this._frame == 0 && this._repeatedCount > 0)
  15252. tt += this.repeatDelay;
  15253. if (this._frameElapsed < tt)
  15254. return;
  15255. this._frameElapsed -= tt;
  15256. if (this._frameElapsed > this.interval)
  15257. this._frameElapsed = this.interval;
  15258. if (this.swing) {
  15259. if (this._reversed) {
  15260. this._frame--;
  15261. if (this._frame <= 0) {
  15262. this._frame = 0;
  15263. this._repeatedCount++;
  15264. this._reversed = !this._reversed;
  15265. }
  15266. }
  15267. else {
  15268. this._frame++;
  15269. if (this._frame > this._frameCount - 1) {
  15270. this._frame = Math.max(0, this._frameCount - 2);
  15271. this._repeatedCount++;
  15272. this._reversed = !this._reversed;
  15273. }
  15274. }
  15275. }
  15276. else {
  15277. this._frame++;
  15278. if (this._frame > this._frameCount - 1) {
  15279. this._frame = 0;
  15280. this._repeatedCount++;
  15281. }
  15282. }
  15283. if (this._status == 1) //new loop
  15284. {
  15285. this._frame = this._start;
  15286. this._frameElapsed = 0;
  15287. this._status = 0;
  15288. }
  15289. else if (this._status == 2) //ending
  15290. {
  15291. this._frame = this._endAt;
  15292. this._frameElapsed = 0;
  15293. this._status = 3; //ended
  15294. //play end
  15295. if (this._endHandler) {
  15296. var handler = this._endHandler;
  15297. this._endHandler = null;
  15298. handler.run();
  15299. }
  15300. }
  15301. else {
  15302. if (this._frame == this._end) {
  15303. if (this._times > 0) {
  15304. this._times--;
  15305. if (this._times == 0)
  15306. this._status = 2; //ending
  15307. else
  15308. this._status = 1; //new loop
  15309. }
  15310. else {
  15311. this._status = 1; //new loop
  15312. }
  15313. }
  15314. }
  15315. this.drawFrame();
  15316. }
  15317. drawFrame() {
  15318. if (this._frameCount > 0 && this._frame < this._frames.length) {
  15319. var frame = this._frames[this._frame];
  15320. this.texture = frame.texture;
  15321. }
  15322. else
  15323. this.texture = null;
  15324. this.rebuild();
  15325. }
  15326. checkTimer() {
  15327. if (this._playing && this._frameCount > 0 && this.stage != null)
  15328. Laya.timer.frameLoop(1, this, this.update);
  15329. else
  15330. Laya.timer.clear(this, this.update);
  15331. }
  15332. __addToStage() {
  15333. if (this._playing && this._frameCount > 0)
  15334. Laya.timer.frameLoop(1, this, this.update);
  15335. }
  15336. __removeFromStage() {
  15337. Laya.timer.clear(this, this.update);
  15338. }
  15339. }
  15340. fgui.MovieClip = MovieClip;
  15341. })(fgui);
  15342. (function (fgui) {
  15343. class GearBase {
  15344. constructor(owner) {
  15345. this._owner = owner;
  15346. }
  15347. static create(owner, index) {
  15348. if (!Classes)
  15349. Classes = [
  15350. fgui.GearDisplay, fgui.GearXY, fgui.GearSize, fgui.GearLook, fgui.GearColor,
  15351. fgui.GearAnimation, fgui.GearText, fgui.GearIcon, fgui.GearDisplay2, fgui.GearFontSize
  15352. ];
  15353. return new (Classes[index])(owner);
  15354. }
  15355. dispose() {
  15356. if (this._tweenConfig && this._tweenConfig._tweener) {
  15357. this._tweenConfig._tweener.kill();
  15358. this._tweenConfig._tweener = null;
  15359. }
  15360. }
  15361. get controller() {
  15362. return this._controller;
  15363. }
  15364. set controller(val) {
  15365. if (val != this._controller) {
  15366. this._controller = val;
  15367. if (this._controller)
  15368. this.init();
  15369. }
  15370. }
  15371. get tweenConfig() {
  15372. if (!this._tweenConfig)
  15373. this._tweenConfig = new GearTweenConfig();
  15374. return this._tweenConfig;
  15375. }
  15376. setup(buffer) {
  15377. this._controller = this._owner.parent.getControllerAt(buffer.getInt16());
  15378. this.init();
  15379. var i;
  15380. var page;
  15381. var cnt = buffer.getInt16();
  15382. if (this instanceof fgui.GearDisplay) {
  15383. this.pages = buffer.readSArray(cnt);
  15384. }
  15385. else if (this instanceof fgui.GearDisplay2) {
  15386. this.pages = buffer.readSArray(cnt);
  15387. }
  15388. else {
  15389. for (i = 0; i < cnt; i++) {
  15390. page = buffer.readS();
  15391. if (page == null)
  15392. continue;
  15393. this.addStatus(page, buffer);
  15394. }
  15395. if (buffer.readBool())
  15396. this.addStatus(null, buffer);
  15397. }
  15398. if (buffer.readBool()) {
  15399. this._tweenConfig = new GearTweenConfig();
  15400. this._tweenConfig.easeType = buffer.readByte();
  15401. this._tweenConfig.duration = buffer.getFloat32();
  15402. this._tweenConfig.delay = buffer.getFloat32();
  15403. }
  15404. if (buffer.version >= 2) {
  15405. if (this instanceof fgui.GearXY) {
  15406. if (buffer.readBool()) {
  15407. this.positionsInPercent = true;
  15408. for (i = 0; i < cnt; i++) {
  15409. page = buffer.readS();
  15410. if (page == null)
  15411. continue;
  15412. this.addExtStatus(page, buffer);
  15413. }
  15414. if (buffer.readBool())
  15415. this.addExtStatus(null, buffer);
  15416. }
  15417. }
  15418. else if (this instanceof fgui.GearDisplay2)
  15419. this.condition = buffer.readByte();
  15420. }
  15421. }
  15422. updateFromRelations(dx, dy) {
  15423. }
  15424. addStatus(pageId, buffer) {
  15425. }
  15426. init() {
  15427. }
  15428. apply() {
  15429. }
  15430. updateState() {
  15431. }
  15432. }
  15433. fgui.GearBase = GearBase;
  15434. var Classes;
  15435. class GearTweenConfig {
  15436. constructor() {
  15437. this.tween = true;
  15438. this.easeType = fgui.EaseType.QuadOut;
  15439. this.duration = 0.3;
  15440. this.delay = 0;
  15441. }
  15442. }
  15443. fgui.GearTweenConfig = GearTweenConfig;
  15444. })(fgui);
  15445. ///<reference path="GearBase.ts"/>
  15446. ///<reference path="GearBase.ts"/>
  15447. (function (fgui) {
  15448. class GearAnimation extends fgui.GearBase {
  15449. constructor(owner) {
  15450. super(owner);
  15451. }
  15452. init() {
  15453. this._default = {
  15454. playing: this._owner.getProp(fgui.ObjectPropID.Playing),
  15455. frame: this._owner.getProp(fgui.ObjectPropID.Frame)
  15456. };
  15457. this._storage = {};
  15458. }
  15459. addStatus(pageId, buffer) {
  15460. var gv;
  15461. if (pageId == null)
  15462. gv = this._default;
  15463. else
  15464. this._storage[pageId] = gv = {};
  15465. gv.playing = buffer.readBool();
  15466. gv.frame = buffer.getInt32();
  15467. }
  15468. apply() {
  15469. this._owner._gearLocked = true;
  15470. var gv = this._storage[this._controller.selectedPageId];
  15471. if (!gv)
  15472. gv = this._default;
  15473. this._owner.setProp(fgui.ObjectPropID.Playing, gv.playing);
  15474. this._owner.setProp(fgui.ObjectPropID.Frame, gv.frame);
  15475. this._owner._gearLocked = false;
  15476. }
  15477. updateState() {
  15478. var gv = this._storage[this._controller.selectedPageId];
  15479. if (!gv)
  15480. this._storage[this._controller.selectedPageId] = gv = {};
  15481. gv.playing = this._owner.getProp(fgui.ObjectPropID.Playing);
  15482. gv.frame = this._owner.getProp(fgui.ObjectPropID.Frame);
  15483. }
  15484. }
  15485. fgui.GearAnimation = GearAnimation;
  15486. })(fgui);
  15487. (function (fgui) {
  15488. class GearColor extends fgui.GearBase {
  15489. constructor(owner) {
  15490. super(owner);
  15491. }
  15492. init() {
  15493. this._default = {
  15494. color: this._owner.getProp(fgui.ObjectPropID.Color),
  15495. strokeColor: this._owner.getProp(fgui.ObjectPropID.OutlineColor)
  15496. };
  15497. this._storage = {};
  15498. }
  15499. addStatus(pageId, buffer) {
  15500. var gv;
  15501. if (pageId == null)
  15502. gv = this._default;
  15503. else
  15504. this._storage[pageId] = gv = {};
  15505. gv.color = buffer.readColorS();
  15506. gv.strokeColor = buffer.readColorS();
  15507. }
  15508. apply() {
  15509. this._owner._gearLocked = true;
  15510. var gv = this._storage[this._controller.selectedPageId];
  15511. if (!gv)
  15512. gv = this._default;
  15513. this._owner.setProp(fgui.ObjectPropID.Color, gv.color);
  15514. this._owner.setProp(fgui.ObjectPropID.OutlineColor, gv.strokeColor);
  15515. this._owner._gearLocked = false;
  15516. }
  15517. updateState() {
  15518. var gv = this._storage[this._controller.selectedPageId];
  15519. if (!gv)
  15520. this._storage[this._controller.selectedPageId] = gv = {};
  15521. gv.color = this._owner.getProp(fgui.ObjectPropID.Color);
  15522. gv.strokeColor = this._owner.getProp(fgui.ObjectPropID.OutlineColor);
  15523. }
  15524. }
  15525. fgui.GearColor = GearColor;
  15526. })(fgui);
  15527. (function (fgui) {
  15528. class GearDisplay extends fgui.GearBase {
  15529. constructor(owner) {
  15530. super(owner);
  15531. this._displayLockToken = 1;
  15532. this._visible = 0;
  15533. }
  15534. init() {
  15535. this.pages = null;
  15536. }
  15537. apply() {
  15538. this._displayLockToken++;
  15539. if (this._displayLockToken == 0)
  15540. this._displayLockToken = 1;
  15541. if (this.pages == null || this.pages.length == 0
  15542. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  15543. this._visible = 1;
  15544. else
  15545. this._visible = 0;
  15546. }
  15547. addLock() {
  15548. this._visible++;
  15549. return this._displayLockToken;
  15550. }
  15551. releaseLock(token) {
  15552. if (token == this._displayLockToken)
  15553. this._visible--;
  15554. }
  15555. get connected() {
  15556. return this._controller == null || this._visible > 0;
  15557. }
  15558. }
  15559. fgui.GearDisplay = GearDisplay;
  15560. })(fgui);
  15561. (function (fgui) {
  15562. class GearDisplay2 extends fgui.GearBase {
  15563. constructor(owner) {
  15564. super(owner);
  15565. this._visible = 0;
  15566. }
  15567. init() {
  15568. this.pages = null;
  15569. }
  15570. apply() {
  15571. if (this.pages == null || this.pages.length == 0
  15572. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  15573. this._visible = 1;
  15574. else
  15575. this._visible = 0;
  15576. }
  15577. evaluate(connected) {
  15578. var v = this._controller == null || this._visible > 0;
  15579. if (this.condition == 0)
  15580. v = v && connected;
  15581. else
  15582. v = v || connected;
  15583. return v;
  15584. }
  15585. }
  15586. fgui.GearDisplay2 = GearDisplay2;
  15587. })(fgui);
  15588. (function (fgui) {
  15589. class GearFontSize extends fgui.GearBase {
  15590. constructor(owner) {
  15591. super(owner);
  15592. this._default = 0;
  15593. }
  15594. init() {
  15595. this._default = this._owner.getProp(fgui.ObjectPropID.FontSize);
  15596. this._storage = {};
  15597. }
  15598. addStatus(pageId, buffer) {
  15599. if (pageId == null)
  15600. this._default = buffer.getInt32();
  15601. else
  15602. this._storage[pageId] = buffer.getInt32();
  15603. }
  15604. apply() {
  15605. this._owner._gearLocked = true;
  15606. var data = this._storage[this._controller.selectedPageId];
  15607. if (data != undefined)
  15608. this._owner.setProp(fgui.ObjectPropID.FontSize, data);
  15609. else
  15610. this._owner.setProp(fgui.ObjectPropID.FontSize, this._default);
  15611. this._owner._gearLocked = false;
  15612. }
  15613. updateState() {
  15614. this._storage[this._controller.selectedPageId] = this._owner.getProp(fgui.ObjectPropID.FontSize);
  15615. }
  15616. }
  15617. fgui.GearFontSize = GearFontSize;
  15618. })(fgui);
  15619. (function (fgui) {
  15620. class GearIcon extends fgui.GearBase {
  15621. constructor(owner) {
  15622. super(owner);
  15623. }
  15624. init() {
  15625. this._default = this._owner.icon;
  15626. this._storage = {};
  15627. }
  15628. addStatus(pageId, buffer) {
  15629. if (pageId == null)
  15630. this._default = buffer.readS();
  15631. else
  15632. this._storage[pageId] = buffer.readS();
  15633. }
  15634. apply() {
  15635. this._owner._gearLocked = true;
  15636. var data = this._storage[this._controller.selectedPageId];
  15637. if (data !== undefined)
  15638. this._owner.icon = data;
  15639. else
  15640. this._owner.icon = this._default;
  15641. this._owner._gearLocked = false;
  15642. }
  15643. updateState() {
  15644. this._storage[this._controller.selectedPageId] = this._owner.icon;
  15645. }
  15646. }
  15647. fgui.GearIcon = GearIcon;
  15648. })(fgui);
  15649. (function (fgui) {
  15650. class GearLook extends fgui.GearBase {
  15651. constructor(owner) {
  15652. super(owner);
  15653. }
  15654. init() {
  15655. this._default = {
  15656. alpha: this._owner.alpha,
  15657. rotation: this._owner.rotation,
  15658. grayed: this._owner.grayed,
  15659. touchable: this._owner.touchable
  15660. };
  15661. this._storage = {};
  15662. }
  15663. addStatus(pageId, buffer) {
  15664. var gv;
  15665. if (pageId == null)
  15666. gv = this._default;
  15667. else
  15668. this._storage[pageId] = gv = {};
  15669. gv.alpha = buffer.getFloat32();
  15670. gv.rotation = buffer.getFloat32();
  15671. gv.grayed = buffer.readBool();
  15672. gv.touchable = buffer.readBool();
  15673. }
  15674. apply() {
  15675. var gv = this._storage[this._controller.selectedPageId];
  15676. if (!gv)
  15677. gv = this._default;
  15678. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  15679. this._owner._gearLocked = true;
  15680. this._owner.grayed = gv.grayed;
  15681. this._owner.touchable = gv.touchable;
  15682. this._owner._gearLocked = false;
  15683. if (this._tweenConfig._tweener) {
  15684. if (this._tweenConfig._tweener.endValue.x != gv.alpha || this._tweenConfig._tweener.endValue.y != gv.rotation) {
  15685. this._tweenConfig._tweener.kill(true);
  15686. this._tweenConfig._tweener = null;
  15687. }
  15688. else
  15689. return;
  15690. }
  15691. var a = gv.alpha != this._owner.alpha;
  15692. var b = gv.rotation != this._owner.rotation;
  15693. if (a || b) {
  15694. if (this._owner.checkGearController(0, this._controller))
  15695. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  15696. this._tweenConfig._tweener = fgui.GTween.to2(this._owner.alpha, this._owner.rotation, gv.alpha, gv.rotation, this._tweenConfig.duration)
  15697. .setDelay(this._tweenConfig.delay)
  15698. .setEase(this._tweenConfig.easeType)
  15699. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  15700. .setTarget(this)
  15701. .onUpdate(this.__tweenUpdate, this)
  15702. .onComplete(this.__tweenComplete, this);
  15703. }
  15704. }
  15705. else {
  15706. this._owner._gearLocked = true;
  15707. this._owner.grayed = gv.grayed;
  15708. this._owner.touchable = gv.touchable;
  15709. this._owner.alpha = gv.alpha;
  15710. this._owner.rotation = gv.rotation;
  15711. this._owner._gearLocked = false;
  15712. }
  15713. }
  15714. __tweenUpdate(tweener) {
  15715. var flag = tweener.userData;
  15716. this._owner._gearLocked = true;
  15717. if ((flag & 1) != 0)
  15718. this._owner.alpha = tweener.value.x;
  15719. if ((flag & 2) != 0)
  15720. this._owner.rotation = tweener.value.y;
  15721. this._owner._gearLocked = false;
  15722. }
  15723. __tweenComplete() {
  15724. if (this._tweenConfig._displayLockToken != 0) {
  15725. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  15726. this._tweenConfig._displayLockToken = 0;
  15727. }
  15728. this._tweenConfig._tweener = null;
  15729. }
  15730. updateState() {
  15731. var gv = this._storage[this._controller.selectedPageId];
  15732. if (!gv)
  15733. this._storage[this._controller.selectedPageId] = gv = {};
  15734. gv.alpha = this._owner.alpha;
  15735. gv.rotation = this._owner.rotation;
  15736. gv.grayed = this._owner.grayed;
  15737. gv.touchable = this._owner.touchable;
  15738. }
  15739. }
  15740. fgui.GearLook = GearLook;
  15741. })(fgui);
  15742. (function (fgui) {
  15743. class GearSize extends fgui.GearBase {
  15744. constructor(owner) {
  15745. super(owner);
  15746. }
  15747. init() {
  15748. this._default = {
  15749. width: this._owner.width,
  15750. height: this._owner.height,
  15751. scaleX: this._owner.scaleX,
  15752. scaleY: this._owner.scaleY
  15753. };
  15754. this._storage = {};
  15755. }
  15756. addStatus(pageId, buffer) {
  15757. var gv;
  15758. if (pageId == null)
  15759. gv = this._default;
  15760. else
  15761. this._storage[pageId] = gv = {};
  15762. gv.width = buffer.getInt32();
  15763. gv.height = buffer.getInt32();
  15764. gv.scaleX = buffer.getFloat32();
  15765. gv.scaleY = buffer.getFloat32();
  15766. }
  15767. apply() {
  15768. var gv = this._storage[this._controller.selectedPageId];
  15769. if (!gv)
  15770. gv = this._default;
  15771. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  15772. if (this._tweenConfig._tweener) {
  15773. if (this._tweenConfig._tweener.endValue.x != gv.width || this._tweenConfig._tweener.endValue.y != gv.height
  15774. || this._tweenConfig._tweener.endValue.z != gv.scaleX || this._tweenConfig._tweener.endValue.w != gv.scaleY) {
  15775. this._tweenConfig._tweener.kill(true);
  15776. this._tweenConfig._tweener = null;
  15777. }
  15778. else
  15779. return;
  15780. }
  15781. var a = gv.width != this._owner.width || gv.height != this._owner.height;
  15782. var b = gv.scaleX != this._owner.scaleX || gv.scaleY != this._owner.scaleY;
  15783. if (a || b) {
  15784. if (this._owner.checkGearController(0, this._controller))
  15785. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  15786. 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)
  15787. .setDelay(this._tweenConfig.delay)
  15788. .setEase(this._tweenConfig.easeType)
  15789. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  15790. .setTarget(this)
  15791. .onUpdate(this.__tweenUpdate, this)
  15792. .onComplete(this.__tweenComplete, this);
  15793. }
  15794. }
  15795. else {
  15796. this._owner._gearLocked = true;
  15797. this._owner.setSize(gv.width, gv.height, this._owner.getGear(1).controller == this._controller);
  15798. this._owner.setScale(gv.scaleX, gv.scaleY);
  15799. this._owner._gearLocked = false;
  15800. }
  15801. }
  15802. __tweenUpdate(tweener) {
  15803. var flag = tweener.userData;
  15804. this._owner._gearLocked = true;
  15805. if ((flag & 1) != 0)
  15806. this._owner.setSize(tweener.value.x, tweener.value.y, this._owner.checkGearController(1, this._controller));
  15807. if ((flag & 2) != 0)
  15808. this._owner.setScale(tweener.value.z, tweener.value.w);
  15809. this._owner._gearLocked = false;
  15810. }
  15811. __tweenComplete() {
  15812. if (this._tweenConfig._displayLockToken != 0) {
  15813. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  15814. this._tweenConfig._displayLockToken = 0;
  15815. }
  15816. this._tweenConfig._tweener = null;
  15817. }
  15818. updateState() {
  15819. var gv = this._storage[this._controller.selectedPageId];
  15820. if (!gv)
  15821. this._storage[this._controller.selectedPageId] = gv = {};
  15822. gv.width = this._owner.width;
  15823. gv.height = this._owner.height;
  15824. gv.scaleX = this._owner.scaleX;
  15825. gv.scaleY = this._owner.scaleY;
  15826. }
  15827. updateFromRelations(dx, dy) {
  15828. if (this._controller == null || this._storage == null)
  15829. return;
  15830. for (var key in this._storage) {
  15831. var gv = this._storage[key];
  15832. gv.width += dx;
  15833. gv.height += dy;
  15834. }
  15835. this._default.width += dx;
  15836. this._default.height += dy;
  15837. this.updateState();
  15838. }
  15839. }
  15840. fgui.GearSize = GearSize;
  15841. })(fgui);
  15842. (function (fgui) {
  15843. class GearText extends fgui.GearBase {
  15844. constructor(owner) {
  15845. super(owner);
  15846. }
  15847. init() {
  15848. this._default = this._owner.text;
  15849. this._storage = {};
  15850. }
  15851. addStatus(pageId, buffer) {
  15852. if (pageId == null)
  15853. this._default = buffer.readS();
  15854. else
  15855. this._storage[pageId] = buffer.readS();
  15856. }
  15857. apply() {
  15858. this._owner._gearLocked = true;
  15859. var data = this._storage[this._controller.selectedPageId];
  15860. if (data !== undefined)
  15861. this._owner.text = data;
  15862. else
  15863. this._owner.text = this._default;
  15864. this._owner._gearLocked = false;
  15865. }
  15866. updateState() {
  15867. this._storage[this._controller.selectedPageId] = this._owner.text;
  15868. }
  15869. }
  15870. fgui.GearText = GearText;
  15871. })(fgui);
  15872. (function (fgui) {
  15873. class GearXY extends fgui.GearBase {
  15874. constructor(owner) {
  15875. super(owner);
  15876. }
  15877. init() {
  15878. this._default = {
  15879. x: this._owner.x,
  15880. y: this._owner.y,
  15881. px: this._owner.x / this._owner.parent.width,
  15882. py: this._owner.y / this._owner.parent.height
  15883. };
  15884. this._storage = {};
  15885. }
  15886. addStatus(pageId, buffer) {
  15887. var gv;
  15888. if (pageId == null)
  15889. gv = this._default;
  15890. else
  15891. this._storage[pageId] = gv = {};
  15892. gv.x = buffer.getInt32();
  15893. gv.y = buffer.getInt32();
  15894. }
  15895. addExtStatus(pageId, buffer) {
  15896. var gv;
  15897. if (pageId == null)
  15898. gv = this._default;
  15899. else
  15900. gv = this._storage[pageId];
  15901. gv.px = buffer.getFloat32();
  15902. gv.py = buffer.getFloat32();
  15903. }
  15904. apply() {
  15905. var gv = this._storage[this._controller.selectedPageId];
  15906. if (!gv)
  15907. gv = this._default;
  15908. var ex;
  15909. var ey;
  15910. if (this.positionsInPercent && this._owner.parent) {
  15911. ex = gv.px * this._owner.parent.width;
  15912. ey = gv.py * this._owner.parent.height;
  15913. }
  15914. else {
  15915. ex = gv.x;
  15916. ey = gv.y;
  15917. }
  15918. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  15919. if (this._tweenConfig._tweener) {
  15920. if (this._tweenConfig._tweener.endValue.x != ex || this._tweenConfig._tweener.endValue.y != ey) {
  15921. this._tweenConfig._tweener.kill(true);
  15922. this._tweenConfig._tweener = null;
  15923. }
  15924. else
  15925. return;
  15926. }
  15927. var ox = this._owner.x;
  15928. var oy = this._owner.y;
  15929. if (ox != ex || oy != ey) {
  15930. if (this._owner.checkGearController(0, this._controller))
  15931. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  15932. this._tweenConfig._tweener = fgui.GTween.to2(ox, oy, ex, ey, this._tweenConfig.duration)
  15933. .setDelay(this._tweenConfig.delay)
  15934. .setEase(this._tweenConfig.easeType)
  15935. .setTarget(this)
  15936. .onUpdate(this.__tweenUpdate, this)
  15937. .onComplete(this.__tweenComplete, this);
  15938. }
  15939. }
  15940. else {
  15941. this._owner._gearLocked = true;
  15942. this._owner.setXY(ex, ey);
  15943. this._owner._gearLocked = false;
  15944. }
  15945. }
  15946. __tweenUpdate(tweener) {
  15947. this._owner._gearLocked = true;
  15948. this._owner.setXY(tweener.value.x, tweener.value.y);
  15949. this._owner._gearLocked = false;
  15950. }
  15951. __tweenComplete() {
  15952. if (this._tweenConfig._displayLockToken != 0) {
  15953. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  15954. this._tweenConfig._displayLockToken = 0;
  15955. }
  15956. this._tweenConfig._tweener = null;
  15957. }
  15958. updateState() {
  15959. var gv = this._storage[this._controller.selectedPageId];
  15960. if (!gv)
  15961. this._storage[this._controller.selectedPageId] = gv = {};
  15962. gv.x = this._owner.x;
  15963. gv.y = this._owner.y;
  15964. gv.px = this._owner.x / this._owner.parent.width;
  15965. gv.py = this._owner.y / this._owner.parent.height;
  15966. }
  15967. updateFromRelations(dx, dy) {
  15968. if (this._controller == null || this._storage == null || this.positionsInPercent)
  15969. return;
  15970. for (var key in this._storage) {
  15971. var pt = this._storage[key];
  15972. pt.x += dx;
  15973. pt.y += dy;
  15974. }
  15975. this._default.x += dx;
  15976. this._default.y += dy;
  15977. this.updateState();
  15978. }
  15979. }
  15980. fgui.GearXY = GearXY;
  15981. })(fgui);
  15982. // Author: Daniele Giardini - http://www.demigiant.com
  15983. // Created: 2014/07/19 14:11
  15984. //
  15985. // License Copyright (c) Daniele Giardini.
  15986. // This work is subject to the terms at http://dotween.demigiant.com/license.php
  15987. //
  15988. // =============================================================
  15989. // Contains Daniele Giardini's C# port of the easing equations created by Robert Penner
  15990. // (all easing equations except for Flash, InFlash, OutFlash, InOutFlash,
  15991. // which use some parts of Robert Penner's equations but were created by Daniele Giardini)
  15992. // http://robertpenner.com/easing, see license below:
  15993. // =============================================================
  15994. //
  15995. // TERMS OF USE - EASING EQUATIONS
  15996. //
  15997. // Open source under the BSD License.
  15998. //
  15999. // Copyright ? 2001 Robert Penner
  16000. // All rights reserved.
  16001. //
  16002. // Redistribution and use in source and binary forms, with or without modification,
  16003. // are permitted provided that the following conditions are met:
  16004. //
  16005. // - Redistributions of source code must retain the above copyright notice,
  16006. // this list of conditions and the following disclaimer.
  16007. // - Redistributions in binary form must reproduce the above copyright notice,
  16008. // this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  16009. // - Neither the name of the author nor the names of contributors may be used to endorse
  16010. // or promote products derived from this software without specific prior written permission.
  16011. // - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16012. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16013. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16014. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16015. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  16016. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  16017. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  16018. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16019. // Author: Daniele Giardini - http://www.demigiant.com
  16020. // Created: 2014/07/19 14:11
  16021. //
  16022. // License Copyright (c) Daniele Giardini.
  16023. // This work is subject to the terms at http://dotween.demigiant.com/license.php
  16024. //
  16025. // =============================================================
  16026. // Contains Daniele Giardini's C# port of the easing equations created by Robert Penner
  16027. // (all easing equations except for Flash, InFlash, OutFlash, InOutFlash,
  16028. // which use some parts of Robert Penner's equations but were created by Daniele Giardini)
  16029. // http://robertpenner.com/easing, see license below:
  16030. // =============================================================
  16031. //
  16032. // TERMS OF USE - EASING EQUATIONS
  16033. //
  16034. // Open source under the BSD License.
  16035. //
  16036. // Copyright ? 2001 Robert Penner
  16037. // All rights reserved.
  16038. //
  16039. // Redistribution and use in source and binary forms, with or without modification,
  16040. // are permitted provided that the following conditions are met:
  16041. //
  16042. // - Redistributions of source code must retain the above copyright notice,
  16043. // this list of conditions and the following disclaimer.
  16044. // - Redistributions in binary form must reproduce the above copyright notice,
  16045. // this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  16046. // - Neither the name of the author nor the names of contributors may be used to endorse
  16047. // or promote products derived from this software without specific prior written permission.
  16048. // - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16049. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16050. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16051. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16052. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  16053. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  16054. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  16055. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16056. (function (fgui) {
  16057. const _PiOver2 = Math.PI * 0.5;
  16058. const _TwoPi = Math.PI * 2;
  16059. function evaluateEase(easeType, time, duration, overshootOrAmplitude, period) {
  16060. switch (easeType) {
  16061. case fgui.EaseType.Linear:
  16062. return time / duration;
  16063. case fgui.EaseType.SineIn:
  16064. return -Math.cos(time / duration * _PiOver2) + 1;
  16065. case fgui.EaseType.SineOut:
  16066. return Math.sin(time / duration * _PiOver2);
  16067. case fgui.EaseType.SineInOut:
  16068. return -0.5 * (Math.cos(Math.PI * time / duration) - 1);
  16069. case fgui.EaseType.QuadIn:
  16070. return (time /= duration) * time;
  16071. case fgui.EaseType.QuadOut:
  16072. return -(time /= duration) * (time - 2);
  16073. case fgui.EaseType.QuadInOut:
  16074. if ((time /= duration * 0.5) < 1)
  16075. return 0.5 * time * time;
  16076. return -0.5 * ((--time) * (time - 2) - 1);
  16077. case fgui.EaseType.CubicIn:
  16078. return (time /= duration) * time * time;
  16079. case fgui.EaseType.CubicOut:
  16080. return ((time = time / duration - 1) * time * time + 1);
  16081. case fgui.EaseType.CubicInOut:
  16082. if ((time /= duration * 0.5) < 1)
  16083. return 0.5 * time * time * time;
  16084. return 0.5 * ((time -= 2) * time * time + 2);
  16085. case fgui.EaseType.QuartIn:
  16086. return (time /= duration) * time * time * time;
  16087. case fgui.EaseType.QuartOut:
  16088. return -((time = time / duration - 1) * time * time * time - 1);
  16089. case fgui.EaseType.QuartInOut:
  16090. if ((time /= duration * 0.5) < 1)
  16091. return 0.5 * time * time * time * time;
  16092. return -0.5 * ((time -= 2) * time * time * time - 2);
  16093. case fgui.EaseType.QuintIn:
  16094. return (time /= duration) * time * time * time * time;
  16095. case fgui.EaseType.QuintOut:
  16096. return ((time = time / duration - 1) * time * time * time * time + 1);
  16097. case fgui.EaseType.QuintInOut:
  16098. if ((time /= duration * 0.5) < 1)
  16099. return 0.5 * time * time * time * time * time;
  16100. return 0.5 * ((time -= 2) * time * time * time * time + 2);
  16101. case fgui.EaseType.ExpoIn:
  16102. return (time == 0) ? 0 : Math.pow(2, 10 * (time / duration - 1));
  16103. case fgui.EaseType.ExpoOut:
  16104. if (time == duration)
  16105. return 1;
  16106. return (-Math.pow(2, -10 * time / duration) + 1);
  16107. case fgui.EaseType.ExpoInOut:
  16108. if (time == 0)
  16109. return 0;
  16110. if (time == duration)
  16111. return 1;
  16112. if ((time /= duration * 0.5) < 1)
  16113. return 0.5 * Math.pow(2, 10 * (time - 1));
  16114. return 0.5 * (-Math.pow(2, -10 * --time) + 2);
  16115. case fgui.EaseType.CircIn:
  16116. return -(Math.sqrt(1 - (time /= duration) * time) - 1);
  16117. case fgui.EaseType.CircOut:
  16118. return Math.sqrt(1 - (time = time / duration - 1) * time);
  16119. case fgui.EaseType.CircInOut:
  16120. if ((time /= duration * 0.5) < 1)
  16121. return -0.5 * (Math.sqrt(1 - time * time) - 1);
  16122. return 0.5 * (Math.sqrt(1 - (time -= 2) * time) + 1);
  16123. case fgui.EaseType.ElasticIn:
  16124. var s0;
  16125. if (time == 0)
  16126. return 0;
  16127. if ((time /= duration) == 1)
  16128. return 1;
  16129. if (period == 0)
  16130. period = duration * 0.3;
  16131. if (overshootOrAmplitude < 1) {
  16132. overshootOrAmplitude = 1;
  16133. s0 = period / 4;
  16134. }
  16135. else
  16136. s0 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  16137. return -(overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s0) * _TwoPi / period));
  16138. case fgui.EaseType.ElasticOut:
  16139. var s1;
  16140. if (time == 0)
  16141. return 0;
  16142. if ((time /= duration) == 1)
  16143. return 1;
  16144. if (period == 0)
  16145. period = duration * 0.3;
  16146. if (overshootOrAmplitude < 1) {
  16147. overshootOrAmplitude = 1;
  16148. s1 = period / 4;
  16149. }
  16150. else
  16151. s1 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  16152. return (overshootOrAmplitude * Math.pow(2, -10 * time) * Math.sin((time * duration - s1) * _TwoPi / period) + 1);
  16153. case fgui.EaseType.ElasticInOut:
  16154. var s;
  16155. if (time == 0)
  16156. return 0;
  16157. if ((time /= duration * 0.5) == 2)
  16158. return 1;
  16159. if (period == 0)
  16160. period = duration * (0.3 * 1.5);
  16161. if (overshootOrAmplitude < 1) {
  16162. overshootOrAmplitude = 1;
  16163. s = period / 4;
  16164. }
  16165. else
  16166. s = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  16167. if (time < 1)
  16168. return -0.5 * (overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period));
  16169. return overshootOrAmplitude * Math.pow(2, -10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period) * 0.5 + 1;
  16170. case fgui.EaseType.BackIn:
  16171. return (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude);
  16172. case fgui.EaseType.BackOut:
  16173. return ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);
  16174. case fgui.EaseType.BackInOut:
  16175. if ((time /= duration * 0.5) < 1)
  16176. return 0.5 * (time * time * (((overshootOrAmplitude *= (1.525)) + 1) * time - overshootOrAmplitude));
  16177. return 0.5 * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525)) + 1) * time + overshootOrAmplitude) + 2);
  16178. case fgui.EaseType.BounceIn:
  16179. return bounce_easeIn(time, duration);
  16180. case fgui.EaseType.BounceOut:
  16181. return bounce_easeOut(time, duration);
  16182. case fgui.EaseType.BounceInOut:
  16183. return bounce_easeInOut(time, duration);
  16184. default:
  16185. return -(time /= duration) * (time - 2);
  16186. }
  16187. }
  16188. fgui.evaluateEase = evaluateEase;
  16189. function bounce_easeIn(time, duration) {
  16190. return 1 - bounce_easeOut(duration - time, duration);
  16191. }
  16192. function bounce_easeOut(time, duration) {
  16193. if ((time /= duration) < (1 / 2.75)) {
  16194. return (7.5625 * time * time);
  16195. }
  16196. if (time < (2 / 2.75)) {
  16197. return (7.5625 * (time -= (1.5 / 2.75)) * time + 0.75);
  16198. }
  16199. if (time < (2.5 / 2.75)) {
  16200. return (7.5625 * (time -= (2.25 / 2.75)) * time + 0.9375);
  16201. }
  16202. return (7.5625 * (time -= (2.625 / 2.75)) * time + 0.984375);
  16203. }
  16204. function bounce_easeInOut(time, duration) {
  16205. if (time < duration * 0.5) {
  16206. return bounce_easeIn(time * 2, duration) * 0.5;
  16207. }
  16208. return bounce_easeOut(time * 2 - duration, duration) * 0.5 + 0.5;
  16209. }
  16210. })(fgui);
  16211. (function (fgui) {
  16212. class EaseType {
  16213. }
  16214. EaseType.Linear = 0;
  16215. EaseType.SineIn = 1;
  16216. EaseType.SineOut = 2;
  16217. EaseType.SineInOut = 3;
  16218. EaseType.QuadIn = 4;
  16219. EaseType.QuadOut = 5;
  16220. EaseType.QuadInOut = 6;
  16221. EaseType.CubicIn = 7;
  16222. EaseType.CubicOut = 8;
  16223. EaseType.CubicInOut = 9;
  16224. EaseType.QuartIn = 10;
  16225. EaseType.QuartOut = 11;
  16226. EaseType.QuartInOut = 12;
  16227. EaseType.QuintIn = 13;
  16228. EaseType.QuintOut = 14;
  16229. EaseType.QuintInOut = 15;
  16230. EaseType.ExpoIn = 16;
  16231. EaseType.ExpoOut = 17;
  16232. EaseType.ExpoInOut = 18;
  16233. EaseType.CircIn = 19;
  16234. EaseType.CircOut = 20;
  16235. EaseType.CircInOut = 21;
  16236. EaseType.ElasticIn = 22;
  16237. EaseType.ElasticOut = 23;
  16238. EaseType.ElasticInOut = 24;
  16239. EaseType.BackIn = 25;
  16240. EaseType.BackOut = 26;
  16241. EaseType.BackInOut = 27;
  16242. EaseType.BounceIn = 28;
  16243. EaseType.BounceOut = 29;
  16244. EaseType.BounceInOut = 30;
  16245. EaseType.Custom = 31;
  16246. fgui.EaseType = EaseType;
  16247. })(fgui);
  16248. (function (fgui) {
  16249. class GPath {
  16250. constructor() {
  16251. this._segments = new Array();
  16252. this._points = new Array();
  16253. }
  16254. get length() {
  16255. return this._fullLength;
  16256. }
  16257. create(pt1, pt2, pt3, pt4) {
  16258. var points;
  16259. if (Array.isArray(pt1))
  16260. points = pt1;
  16261. else {
  16262. points = new Array();
  16263. points.push(pt1);
  16264. points.push(pt2);
  16265. if (pt3)
  16266. points.push(pt3);
  16267. if (pt4)
  16268. points.push(pt4);
  16269. }
  16270. this._segments.length = 0;
  16271. this._points.length = 0;
  16272. this._fullLength = 0;
  16273. var cnt = points.length;
  16274. if (cnt == 0)
  16275. return;
  16276. var splinePoints = s_points;
  16277. splinePoints.length = 0;
  16278. var prev = points[0];
  16279. if (prev.curveType == fgui.CurveType.CRSpline)
  16280. splinePoints.push(new Laya.Point(prev.x, prev.y));
  16281. for (var i = 1; i < cnt; i++) {
  16282. var current = points[i];
  16283. if (prev.curveType != fgui.CurveType.CRSpline) {
  16284. var seg = {};
  16285. seg.type = prev.curveType;
  16286. seg.ptStart = this._points.length;
  16287. if (prev.curveType == fgui.CurveType.Straight) {
  16288. seg.ptCount = 2;
  16289. this._points.push(new Laya.Point(prev.x, prev.y));
  16290. this._points.push(new Laya.Point(current.x, current.y));
  16291. }
  16292. else if (prev.curveType == fgui.CurveType.Bezier) {
  16293. seg.ptCount = 3;
  16294. this._points.push(new Laya.Point(prev.x, prev.y));
  16295. this._points.push(new Laya.Point(current.x, current.y));
  16296. this._points.push(new Laya.Point(prev.control1_x, prev.control1_y));
  16297. }
  16298. else if (prev.curveType == fgui.CurveType.CubicBezier) {
  16299. seg.ptCount = 4;
  16300. this._points.push(new Laya.Point(prev.x, prev.y));
  16301. this._points.push(new Laya.Point(current.x, current.y));
  16302. this._points.push(new Laya.Point(prev.control1_x, prev.control1_y));
  16303. this._points.push(new Laya.Point(prev.control2_x, prev.control2_y));
  16304. }
  16305. seg.length = fgui.ToolSet.distance(prev.x, prev.y, current.x, current.y);
  16306. this._fullLength += seg.length;
  16307. this._segments.push(seg);
  16308. }
  16309. if (current.curveType != fgui.CurveType.CRSpline) {
  16310. if (splinePoints.length > 0) {
  16311. splinePoints.push(new Laya.Point(current.x, current.y));
  16312. this.createSplineSegment();
  16313. }
  16314. }
  16315. else
  16316. splinePoints.push(new Laya.Point(current.x, current.y));
  16317. prev = current;
  16318. }
  16319. if (splinePoints.length > 1)
  16320. this.createSplineSegment();
  16321. }
  16322. createSplineSegment() {
  16323. var splinePoints = s_points;
  16324. var cnt = splinePoints.length;
  16325. splinePoints.splice(0, 0, splinePoints[0]);
  16326. splinePoints.push(splinePoints[cnt]);
  16327. splinePoints.push(splinePoints[cnt]);
  16328. cnt += 3;
  16329. var seg = {};
  16330. seg.type = fgui.CurveType.CRSpline;
  16331. seg.ptStart = this._points.length;
  16332. seg.ptCount = cnt;
  16333. this._points = this._points.concat(splinePoints);
  16334. seg.length = 0;
  16335. for (var i = 1; i < cnt; i++) {
  16336. seg.length += fgui.ToolSet.distance(splinePoints[i - 1].x, splinePoints[i - 1].y, splinePoints[i].x, splinePoints[i].y);
  16337. }
  16338. this._fullLength += seg.length;
  16339. this._segments.push(seg);
  16340. splinePoints.length = 0;
  16341. }
  16342. clear() {
  16343. this._segments.length = 0;
  16344. this._points.length = 0;
  16345. }
  16346. getPointAt(t, result) {
  16347. if (!result)
  16348. result = new Laya.Point();
  16349. else
  16350. result.x = result.y = 0;
  16351. t = fgui.ToolSet.clamp01(t);
  16352. var cnt = this._segments.length;
  16353. if (cnt == 0) {
  16354. return result;
  16355. }
  16356. var seg;
  16357. if (t == 1) {
  16358. seg = this._segments[cnt - 1];
  16359. if (seg.type == fgui.CurveType.Straight) {
  16360. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  16361. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  16362. return result;
  16363. }
  16364. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  16365. return this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  16366. else
  16367. return this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  16368. }
  16369. var len = t * this._fullLength;
  16370. for (var i = 0; i < cnt; i++) {
  16371. seg = this._segments[i];
  16372. len -= seg.length;
  16373. if (len < 0) {
  16374. t = 1 + len / seg.length;
  16375. if (seg.type == fgui.CurveType.Straight) {
  16376. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  16377. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  16378. }
  16379. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  16380. result = this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  16381. else
  16382. result = this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  16383. break;
  16384. }
  16385. }
  16386. return result;
  16387. }
  16388. get segmentCount() {
  16389. return this._segments.length;
  16390. }
  16391. getAnchorsInSegment(segmentIndex, points) {
  16392. if (points == null)
  16393. points = new Array();
  16394. var seg = this._segments[segmentIndex];
  16395. for (var i = 0; i < seg.ptCount; i++)
  16396. points.push(new Laya.Point(this._points[seg.ptStart + i].x, this._points[seg.ptStart + i].y));
  16397. return points;
  16398. }
  16399. getPointsInSegment(segmentIndex, t0, t1, points, ts, pointDensity) {
  16400. if (points == null)
  16401. points = new Array();
  16402. if (!pointDensity || isNaN(pointDensity))
  16403. pointDensity = 0.1;
  16404. if (ts)
  16405. ts.push(t0);
  16406. var seg = this._segments[segmentIndex];
  16407. if (seg.type == fgui.CurveType.Straight) {
  16408. points.push(new Laya.Point(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)));
  16409. points.push(new Laya.Point(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)));
  16410. }
  16411. else {
  16412. var func;
  16413. if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  16414. func = this.onBezierCurve;
  16415. else
  16416. func = this.onCRSplineCurve;
  16417. points.push(func.call(this, seg.ptStart, seg.ptCount, t0, new Laya.Point()));
  16418. var SmoothAmount = Math.min(seg.length * pointDensity, 50);
  16419. for (var j = 0; j <= SmoothAmount; j++) {
  16420. var t = j / SmoothAmount;
  16421. if (t > t0 && t < t1) {
  16422. points.push(func.call(this, seg.ptStart, seg.ptCount, t, new Laya.Point()));
  16423. if (ts)
  16424. ts.push(t);
  16425. }
  16426. }
  16427. points.push(func.call(this, seg.ptStart, seg.ptCount, t1, new Laya.Point()));
  16428. }
  16429. if (ts)
  16430. ts.push(t1);
  16431. return points;
  16432. }
  16433. getAllPoints(points, ts, pointDensity) {
  16434. if (points == null)
  16435. points = new Array();
  16436. if (!pointDensity || isNaN(pointDensity))
  16437. pointDensity = 0.1;
  16438. var cnt = this._segments.length;
  16439. for (var i = 0; i < cnt; i++)
  16440. this.getPointsInSegment(i, 0, 1, points, ts, pointDensity);
  16441. return points;
  16442. }
  16443. onCRSplineCurve(ptStart, ptCount, t, result) {
  16444. var adjustedIndex = Math.floor(t * (ptCount - 4)) + ptStart; //Since the equation works with 4 points, we adjust the starting point depending on t to return a point on the specific segment
  16445. var p0x = this._points[adjustedIndex].x;
  16446. var p0y = this._points[adjustedIndex].y;
  16447. var p1x = this._points[adjustedIndex + 1].x;
  16448. var p1y = this._points[adjustedIndex + 1].y;
  16449. var p2x = this._points[adjustedIndex + 2].x;
  16450. var p2y = this._points[adjustedIndex + 2].y;
  16451. var p3x = this._points[adjustedIndex + 3].x;
  16452. var p3y = this._points[adjustedIndex + 3].y;
  16453. var adjustedT = (t == 1) ? 1 : fgui.ToolSet.repeat(t * (ptCount - 4), 1); // Then we adjust t to be that value on that new piece of segment... for t == 1f don't use repeat (that would return 0f);
  16454. var t0 = ((-adjustedT + 2) * adjustedT - 1) * adjustedT * 0.5;
  16455. var t1 = (((3 * adjustedT - 5) * adjustedT) * adjustedT + 2) * 0.5;
  16456. var t2 = ((-3 * adjustedT + 4) * adjustedT + 1) * adjustedT * 0.5;
  16457. var t3 = ((adjustedT - 1) * adjustedT * adjustedT) * 0.5;
  16458. result.x = p0x * t0 + p1x * t1 + p2x * t2 + p3x * t3;
  16459. result.y = p0y * t0 + p1y * t1 + p2y * t2 + p3y * t3;
  16460. return result;
  16461. }
  16462. onBezierCurve(ptStart, ptCount, t, result) {
  16463. var t2 = 1 - t;
  16464. var p0x = this._points[ptStart].x;
  16465. var p0y = this._points[ptStart].y;
  16466. var p1x = this._points[ptStart + 1].x;
  16467. var p1y = this._points[ptStart + 1].y;
  16468. var cp0x = this._points[ptStart + 2].x;
  16469. var cp0y = this._points[ptStart + 2].y;
  16470. if (ptCount == 4) {
  16471. var cp1x = this._points[ptStart + 3].x;
  16472. var cp1y = this._points[ptStart + 3].y;
  16473. result.x = t2 * t2 * t2 * p0x + 3 * t2 * t2 * t * cp0x + 3 * t2 * t * t * cp1x + t * t * t * p1x;
  16474. result.y = t2 * t2 * t2 * p0y + 3 * t2 * t2 * t * cp0y + 3 * t2 * t * t * cp1y + t * t * t * p1y;
  16475. }
  16476. else {
  16477. result.x = t2 * t2 * p0x + 2 * t2 * t * cp0x + t * t * p1x;
  16478. result.y = t2 * t2 * p0y + 2 * t2 * t * cp0y + t * t * p1y;
  16479. }
  16480. return result;
  16481. }
  16482. }
  16483. fgui.GPath = GPath;
  16484. var s_points = new Array();
  16485. })(fgui);
  16486. (function (fgui) {
  16487. let CurveType;
  16488. (function (CurveType) {
  16489. CurveType[CurveType["CRSpline"] = 0] = "CRSpline";
  16490. CurveType[CurveType["Bezier"] = 1] = "Bezier";
  16491. CurveType[CurveType["CubicBezier"] = 2] = "CubicBezier";
  16492. CurveType[CurveType["Straight"] = 3] = "Straight";
  16493. })(CurveType = fgui.CurveType || (fgui.CurveType = {}));
  16494. class GPathPoint {
  16495. constructor() {
  16496. this.x = 0;
  16497. this.y = 0;
  16498. this.control1_x = 0;
  16499. this.control1_y = 0;
  16500. this.control2_x = 0;
  16501. this.control2_y = 0;
  16502. this.curveType = 0;
  16503. }
  16504. static newPoint(x = 0, y = 0, curveType = 0) {
  16505. var pt = new GPathPoint();
  16506. pt.x = x;
  16507. pt.y = y;
  16508. pt.control1_x = 0;
  16509. pt.control1_y = 0;
  16510. pt.control2_x = 0;
  16511. pt.control2_y = 0;
  16512. pt.curveType = curveType;
  16513. return pt;
  16514. }
  16515. static newBezierPoint(x = 0, y = 0, control1_x = 0, control1_y = 0) {
  16516. var pt = new GPathPoint();
  16517. pt.x = x;
  16518. pt.y = y;
  16519. pt.control1_x = control1_x;
  16520. pt.control1_y = control1_y;
  16521. pt.control2_x = 0;
  16522. pt.control2_y = 0;
  16523. pt.curveType = CurveType.Bezier;
  16524. return pt;
  16525. }
  16526. static newCubicBezierPoint(x = 0, y = 0, control1_x = 0, control1_y = 0, control2_x = 0, control2_y = 0) {
  16527. var pt = new GPathPoint();
  16528. pt.x = x;
  16529. pt.y = y;
  16530. pt.control1_x = control1_x;
  16531. pt.control1_y = control1_y;
  16532. pt.control2_x = control2_x;
  16533. pt.control2_y = control2_y;
  16534. pt.curveType = CurveType.CubicBezier;
  16535. return pt;
  16536. }
  16537. clone() {
  16538. var ret = new GPathPoint();
  16539. ret.x = this.x;
  16540. ret.y = this.y;
  16541. ret.control1_x = this.control1_x;
  16542. ret.control1_y = this.control1_y;
  16543. ret.control2_x = this.control2_x;
  16544. ret.control2_y = this.control2_y;
  16545. ret.curveType = this.curveType;
  16546. return ret;
  16547. }
  16548. }
  16549. fgui.GPathPoint = GPathPoint;
  16550. })(fgui);
  16551. (function (fgui) {
  16552. class GTween {
  16553. static to(start, end, duration) {
  16554. return fgui.TweenManager.createTween()._to(start, end, duration);
  16555. }
  16556. static to2(start, start2, end, end2, duration) {
  16557. return fgui.TweenManager.createTween()._to2(start, start2, end, end2, duration);
  16558. }
  16559. static to3(start, start2, start3, end, end2, end3, duration) {
  16560. return fgui.TweenManager.createTween()._to3(start, start2, start3, end, end2, end3, duration);
  16561. }
  16562. static to4(start, start2, start3, start4, end, end2, end3, end4, duration) {
  16563. return fgui.TweenManager.createTween()._to4(start, start2, start3, start4, end, end2, end3, end4, duration);
  16564. }
  16565. static toColor(start, end, duration) {
  16566. return fgui.TweenManager.createTween()._toColor(start, end, duration);
  16567. }
  16568. static delayedCall(delay) {
  16569. return fgui.TweenManager.createTween().setDelay(delay);
  16570. }
  16571. static shake(startX, startY, amplitude, duration) {
  16572. return fgui.TweenManager.createTween()._shake(startX, startY, amplitude, duration);
  16573. }
  16574. static isTweening(target, propType) {
  16575. return fgui.TweenManager.isTweening(target, propType);
  16576. }
  16577. static kill(target, complete, propType) {
  16578. fgui.TweenManager.killTweens(target, complete, propType);
  16579. }
  16580. static getTween(target, propType) {
  16581. return fgui.TweenManager.getTween(target, propType);
  16582. }
  16583. }
  16584. GTween.catchCallbackExceptions = true;
  16585. fgui.GTween = GTween;
  16586. })(fgui);
  16587. (function (fgui) {
  16588. class GTweener {
  16589. constructor() {
  16590. this._startValue = new fgui.TweenValue();
  16591. this._endValue = new fgui.TweenValue();
  16592. this._value = new fgui.TweenValue();
  16593. this._deltaValue = new fgui.TweenValue();
  16594. this._reset();
  16595. }
  16596. setDelay(value) {
  16597. this._delay = value;
  16598. return this;
  16599. }
  16600. get delay() {
  16601. return this._delay;
  16602. }
  16603. setDuration(value) {
  16604. this._duration = value;
  16605. return this;
  16606. }
  16607. get duration() {
  16608. return this._duration;
  16609. }
  16610. setBreakpoint(value) {
  16611. this._breakpoint = value;
  16612. return this;
  16613. }
  16614. setEase(value) {
  16615. this._easeType = value;
  16616. return this;
  16617. }
  16618. setEasePeriod(value) {
  16619. this._easePeriod = value;
  16620. return this;
  16621. }
  16622. setEaseOvershootOrAmplitude(value) {
  16623. this._easeOvershootOrAmplitude = value;
  16624. return this;
  16625. }
  16626. setRepeat(repeat, yoyo = false) {
  16627. this._repeat = repeat;
  16628. this._yoyo = yoyo;
  16629. return this;
  16630. }
  16631. get repeat() {
  16632. return this._repeat;
  16633. }
  16634. setTimeScale(value) {
  16635. this._timeScale = value;
  16636. return this;
  16637. }
  16638. setSnapping(value) {
  16639. this._snapping = value;
  16640. return this;
  16641. }
  16642. setTarget(value, propType) {
  16643. this._target = value;
  16644. this._propType = propType;
  16645. return this;
  16646. }
  16647. get target() {
  16648. return this._target;
  16649. }
  16650. setPath(value) {
  16651. this._path = value;
  16652. return this;
  16653. }
  16654. setUserData(value) {
  16655. this._userData = value;
  16656. return this;
  16657. }
  16658. get userData() {
  16659. return this._userData;
  16660. }
  16661. onUpdate(callback, caller) {
  16662. this._onUpdate = callback;
  16663. this._onUpdateCaller = caller;
  16664. return this;
  16665. }
  16666. onStart(callback, caller) {
  16667. this._onStart = callback;
  16668. this._onStartCaller = caller;
  16669. return this;
  16670. }
  16671. onComplete(callback, caller) {
  16672. this._onComplete = callback;
  16673. this._onCompleteCaller = caller;
  16674. return this;
  16675. }
  16676. get startValue() {
  16677. return this._startValue;
  16678. }
  16679. get endValue() {
  16680. return this._endValue;
  16681. }
  16682. get value() {
  16683. return this._value;
  16684. }
  16685. get deltaValue() {
  16686. return this._deltaValue;
  16687. }
  16688. get normalizedTime() {
  16689. return this._normalizedTime;
  16690. }
  16691. get completed() {
  16692. return this._ended != 0;
  16693. }
  16694. get allCompleted() {
  16695. return this._ended == 1;
  16696. }
  16697. setPaused(paused) {
  16698. this._paused = paused;
  16699. return this;
  16700. }
  16701. /**
  16702. * seek position of the tween, in seconds.
  16703. */
  16704. seek(time) {
  16705. if (this._killed)
  16706. return;
  16707. this._elapsedTime = time;
  16708. if (this._elapsedTime < this._delay) {
  16709. if (this._started)
  16710. this._elapsedTime = this._delay;
  16711. else
  16712. return;
  16713. }
  16714. this.update();
  16715. }
  16716. kill(complete) {
  16717. if (this._killed)
  16718. return;
  16719. if (complete) {
  16720. if (this._ended == 0) {
  16721. if (this._breakpoint >= 0)
  16722. this._elapsedTime = this._delay + this._breakpoint;
  16723. else if (this._repeat >= 0)
  16724. this._elapsedTime = this._delay + this._duration * (this._repeat + 1);
  16725. else
  16726. this._elapsedTime = this._delay + this._duration * 2;
  16727. this.update();
  16728. }
  16729. this.callCompleteCallback();
  16730. }
  16731. this._killed = true;
  16732. }
  16733. _to(start, end, duration) {
  16734. this._valueSize = 1;
  16735. this._startValue.x = start;
  16736. this._endValue.x = end;
  16737. this._value.x = start;
  16738. this._duration = duration;
  16739. return this;
  16740. }
  16741. _to2(start, start2, end, end2, duration) {
  16742. this._valueSize = 2;
  16743. this._startValue.x = start;
  16744. this._endValue.x = end;
  16745. this._startValue.y = start2;
  16746. this._endValue.y = end2;
  16747. this._value.x = start;
  16748. this._value.y = start2;
  16749. this._duration = duration;
  16750. return this;
  16751. }
  16752. _to3(start, start2, start3, end, end2, end3, duration) {
  16753. this._valueSize = 3;
  16754. this._startValue.x = start;
  16755. this._endValue.x = end;
  16756. this._startValue.y = start2;
  16757. this._endValue.y = end2;
  16758. this._startValue.z = start3;
  16759. this._endValue.z = end3;
  16760. this._value.x = start;
  16761. this._value.y = start2;
  16762. this._value.z = start3;
  16763. this._duration = duration;
  16764. return this;
  16765. }
  16766. _to4(start, start2, start3, start4, end, end2, end3, end4, duration) {
  16767. this._valueSize = 4;
  16768. this._startValue.x = start;
  16769. this._endValue.x = end;
  16770. this._startValue.y = start2;
  16771. this._endValue.y = end2;
  16772. this._startValue.z = start3;
  16773. this._endValue.z = end3;
  16774. this._startValue.w = start4;
  16775. this._endValue.w = end4;
  16776. this._value.x = start;
  16777. this._value.y = start2;
  16778. this._value.z = start3;
  16779. this._value.w = start4;
  16780. this._duration = duration;
  16781. return this;
  16782. }
  16783. _toColor(start, end, duration) {
  16784. this._valueSize = 4;
  16785. this._startValue.color = start;
  16786. this._endValue.color = end;
  16787. this._value.color = start;
  16788. this._duration = duration;
  16789. return this;
  16790. }
  16791. _shake(startX, startY, amplitude, duration) {
  16792. this._valueSize = 5;
  16793. this._startValue.x = startX;
  16794. this._startValue.y = startY;
  16795. this._startValue.w = amplitude;
  16796. this._duration = duration;
  16797. return this;
  16798. }
  16799. _init() {
  16800. this._delay = 0;
  16801. this._duration = 0;
  16802. this._breakpoint = -1;
  16803. this._easeType = fgui.EaseType.QuadOut;
  16804. this._timeScale = 1;
  16805. this._easePeriod = 0;
  16806. this._easeOvershootOrAmplitude = 1.70158;
  16807. this._snapping = false;
  16808. this._repeat = 0;
  16809. this._yoyo = false;
  16810. this._valueSize = 0;
  16811. this._started = false;
  16812. this._paused = false;
  16813. this._killed = false;
  16814. this._elapsedTime = 0;
  16815. this._normalizedTime = 0;
  16816. this._ended = 0;
  16817. }
  16818. _reset() {
  16819. this._target = null;
  16820. this._propType = null;
  16821. this._userData = null;
  16822. this._path = null;
  16823. this._onStart = this._onUpdate = this._onComplete = null;
  16824. this._onStartCaller = this._onUpdateCaller = this._onCompleteCaller = null;
  16825. }
  16826. _update(dt) {
  16827. if (this._timeScale != 1)
  16828. dt *= this._timeScale;
  16829. if (dt == 0)
  16830. return;
  16831. if (this._ended != 0) //Maybe completed by seek
  16832. {
  16833. this.callCompleteCallback();
  16834. this._killed = true;
  16835. return;
  16836. }
  16837. this._elapsedTime += dt;
  16838. this.update();
  16839. if (this._ended != 0) {
  16840. if (!this._killed) {
  16841. this.callCompleteCallback();
  16842. this._killed = true;
  16843. }
  16844. }
  16845. }
  16846. update() {
  16847. this._ended = 0;
  16848. if (this._valueSize == 0) //DelayedCall
  16849. {
  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 && this._propType) {
  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 Laya.Point();
  16990. })(fgui);
  16991. (function (fgui) {
  16992. class TweenManager {
  16993. static createTween() {
  16994. if (!_inited) {
  16995. Laya.timer.frameLoop(1, null, TweenManager.update);
  16996. _inited = true;
  16997. }
  16998. var tweener;
  16999. var cnt = _tweenerPool.length;
  17000. if (cnt > 0) {
  17001. tweener = _tweenerPool.pop();
  17002. }
  17003. else
  17004. tweener = new fgui.GTweener();
  17005. tweener._init();
  17006. _activeTweens[_totalActiveTweens++] = tweener;
  17007. return tweener;
  17008. }
  17009. static isTweening(target, propType) {
  17010. if (target == null)
  17011. return false;
  17012. var anyType = !propType;
  17013. for (var i = 0; i < _totalActiveTweens; i++) {
  17014. var tweener = _activeTweens[i];
  17015. if (tweener && tweener.target == target && !tweener._killed
  17016. && (anyType || tweener._propType == propType))
  17017. return true;
  17018. }
  17019. return false;
  17020. }
  17021. static killTweens(target, completed, propType) {
  17022. if (target == null)
  17023. return false;
  17024. var flag = false;
  17025. var cnt = _totalActiveTweens;
  17026. var anyType = !propType;
  17027. for (var i = 0; i < cnt; i++) {
  17028. var tweener = _activeTweens[i];
  17029. if (tweener && tweener.target == target && !tweener._killed
  17030. && (anyType || tweener._propType == propType)) {
  17031. tweener.kill(completed);
  17032. flag = true;
  17033. }
  17034. }
  17035. return flag;
  17036. }
  17037. static getTween(target, propType) {
  17038. if (target == null)
  17039. return null;
  17040. var cnt = _totalActiveTweens;
  17041. var anyType = !propType;
  17042. for (var i = 0; i < cnt; i++) {
  17043. var tweener = _activeTweens[i];
  17044. if (tweener && tweener.target == target && !tweener._killed
  17045. && (anyType || tweener._propType == propType)) {
  17046. return tweener;
  17047. }
  17048. }
  17049. return null;
  17050. }
  17051. static update() {
  17052. var dt = Laya.timer.delta / 1000;
  17053. var cnt = _totalActiveTweens;
  17054. var freePosStart = -1;
  17055. for (var i = 0; i < cnt; i++) {
  17056. var tweener = _activeTweens[i];
  17057. if (tweener == null) {
  17058. if (freePosStart == -1)
  17059. freePosStart = i;
  17060. }
  17061. else if (tweener._killed) {
  17062. tweener._reset();
  17063. _tweenerPool.push(tweener);
  17064. _activeTweens[i] = null;
  17065. if (freePosStart == -1)
  17066. freePosStart = i;
  17067. }
  17068. else {
  17069. if ((tweener._target instanceof fgui.GObject) && tweener._target.isDisposed)
  17070. tweener._killed = true;
  17071. else if (!tweener._paused)
  17072. tweener._update(dt);
  17073. if (freePosStart != -1) {
  17074. _activeTweens[freePosStart] = tweener;
  17075. _activeTweens[i] = null;
  17076. freePosStart++;
  17077. }
  17078. }
  17079. }
  17080. if (freePosStart >= 0) {
  17081. if (_totalActiveTweens != cnt) //new tweens added
  17082. {
  17083. var j = cnt;
  17084. cnt = _totalActiveTweens - cnt;
  17085. for (i = 0; i < cnt; i++)
  17086. _activeTweens[freePosStart++] = _activeTweens[j++];
  17087. }
  17088. _totalActiveTweens = freePosStart;
  17089. }
  17090. }
  17091. }
  17092. fgui.TweenManager = TweenManager;
  17093. var _activeTweens = [];
  17094. var _tweenerPool = [];
  17095. var _totalActiveTweens = 0;
  17096. var _inited = false;
  17097. })(fgui);
  17098. (function (fgui) {
  17099. class TweenValue {
  17100. constructor() {
  17101. this.x = this.y = this.z = this.w = 0;
  17102. }
  17103. get color() {
  17104. return (this.w << 24) + (this.x << 16) + (this.y << 8) + this.z;
  17105. }
  17106. set color(value) {
  17107. this.x = (value & 0xFF0000) >> 16;
  17108. this.y = (value & 0x00FF00) >> 8;
  17109. this.z = (value & 0x0000FF);
  17110. this.w = (value & 0xFF000000) >> 24;
  17111. }
  17112. getField(index) {
  17113. switch (index) {
  17114. case 0:
  17115. return this.x;
  17116. case 1:
  17117. return this.y;
  17118. case 2:
  17119. return this.z;
  17120. case 3:
  17121. return this.w;
  17122. default:
  17123. throw new Error("Index out of bounds: " + index);
  17124. }
  17125. }
  17126. setField(index, value) {
  17127. switch (index) {
  17128. case 0:
  17129. this.x = value;
  17130. break;
  17131. case 1:
  17132. this.y = value;
  17133. break;
  17134. case 2:
  17135. this.z = value;
  17136. break;
  17137. case 3:
  17138. this.w = value;
  17139. break;
  17140. default:
  17141. throw new Error("Index out of bounds: " + index);
  17142. }
  17143. }
  17144. setZero() {
  17145. this.x = this.y = this.z = this.w = 0;
  17146. }
  17147. }
  17148. fgui.TweenValue = TweenValue;
  17149. })(fgui);
  17150. (function (fgui) {
  17151. class ByteBuffer extends Laya.Byte {
  17152. constructor(data, offset, length) {
  17153. offset = offset || 0;
  17154. if (length == null || length == -1)
  17155. length = data.byteLength - offset;
  17156. if (offset == 0 && length == data.byteLength)
  17157. super(data);
  17158. else {
  17159. super();
  17160. this._u8d_ = new Uint8Array(data, offset, length);
  17161. this._d_ = new DataView(this._u8d_.buffer, offset, length);
  17162. this._length = length;
  17163. }
  17164. this.endian = Laya.Byte.BIG_ENDIAN;
  17165. }
  17166. skip(count) {
  17167. this.pos += count;
  17168. }
  17169. readBool() {
  17170. return this.getUint8() == 1;
  17171. }
  17172. readS() {
  17173. var index = this.getUint16();
  17174. if (index == 65534) //null
  17175. return null;
  17176. else if (index == 65533)
  17177. return "";
  17178. else
  17179. return this.stringTable[index];
  17180. }
  17181. readSArray(cnt) {
  17182. var ret = new Array(cnt);
  17183. for (var i = 0; i < cnt; i++)
  17184. ret[i] = this.readS();
  17185. return ret;
  17186. }
  17187. writeS(value) {
  17188. var index = this.getUint16();
  17189. if (index != 65534 && index != 65533)
  17190. this.stringTable[index] = value;
  17191. }
  17192. readColor(hasAlpha) {
  17193. var r = this.getUint8();
  17194. var g = this.getUint8();
  17195. var b = this.getUint8();
  17196. var a = this.getUint8();
  17197. return (hasAlpha ? (a << 24) : 0) + (r << 16) + (g << 8) + b;
  17198. }
  17199. readColorS(hasAlpha) {
  17200. var r = this.getUint8();
  17201. var g = this.getUint8();
  17202. var b = this.getUint8();
  17203. var a = this.getUint8();
  17204. if (hasAlpha && a != 255)
  17205. return "rgba(" + r + "," + g + "," + b + "," + (a / 255) + ")";
  17206. else {
  17207. var sr = r.toString(16);
  17208. var sg = g.toString(16);
  17209. var sb = b.toString(16);
  17210. if (sr.length == 1)
  17211. sr = "0" + sr;
  17212. if (sg.length == 1)
  17213. sg = "0" + sg;
  17214. if (sb.length == 1)
  17215. sb = "0" + sb;
  17216. return "#" + sr + sg + sb;
  17217. }
  17218. }
  17219. readChar() {
  17220. var i = this.getUint16();
  17221. return String.fromCharCode(i);
  17222. }
  17223. readBuffer() {
  17224. var count = this.getUint32();
  17225. var ba = new ByteBuffer(this.buffer, this._pos_, count);
  17226. this.pos += count;
  17227. ba.stringTable = this.stringTable;
  17228. ba.version = this.version;
  17229. return ba;
  17230. }
  17231. seek(indexTablePos, blockIndex) {
  17232. var tmp = this._pos_;
  17233. this.pos = indexTablePos;
  17234. var segCount = this.getUint8();
  17235. if (blockIndex < segCount) {
  17236. var useShort = this.getUint8() == 1;
  17237. var newPos;
  17238. if (useShort) {
  17239. this.pos += 2 * blockIndex;
  17240. newPos = this.getUint16();
  17241. }
  17242. else {
  17243. this.pos += 4 * blockIndex;
  17244. newPos = this.getUint32();
  17245. }
  17246. if (newPos > 0) {
  17247. this.pos = indexTablePos + newPos;
  17248. return true;
  17249. }
  17250. else {
  17251. this.pos = tmp;
  17252. return false;
  17253. }
  17254. }
  17255. else {
  17256. this.pos = tmp;
  17257. return false;
  17258. }
  17259. }
  17260. }
  17261. fgui.ByteBuffer = ByteBuffer;
  17262. })(fgui);
  17263. (function (fgui) {
  17264. let _func = Laya.HitArea["_isHitGraphic"];
  17265. class ChildHitArea extends Laya.HitArea {
  17266. constructor(child, reversed) {
  17267. super();
  17268. this._child = child;
  17269. this._reversed = reversed;
  17270. if (this._reversed)
  17271. this.unHit = child.hitArea.hit;
  17272. else
  17273. this.hit = child.hitArea.hit;
  17274. }
  17275. contains(x, y) {
  17276. var tPos;
  17277. tPos = Laya.Point.TEMP;
  17278. tPos.setTo(0, 0);
  17279. tPos = this._child.toParentPoint(tPos);
  17280. if (this._reversed)
  17281. return !_func(x - tPos.x, y - tPos.y, this.unHit);
  17282. else
  17283. return _func(x - tPos.x, y - tPos.y, this.hit);
  17284. }
  17285. }
  17286. fgui.ChildHitArea = ChildHitArea;
  17287. })(fgui);
  17288. (function (fgui) {
  17289. class ColorMatrix {
  17290. constructor(p_brightness, p_contrast, p_saturation, p_hue) {
  17291. this.matrix = new Array(LENGTH);
  17292. this.reset();
  17293. if (p_brightness !== undefined || p_contrast !== undefined || p_saturation !== undefined || p_hue !== undefined)
  17294. this.adjustColor(p_brightness, p_contrast, p_saturation, p_hue);
  17295. }
  17296. reset() {
  17297. for (var i = 0; i < LENGTH; i++) {
  17298. this.matrix[i] = IDENTITY_MATRIX[i];
  17299. }
  17300. }
  17301. invert() {
  17302. this.multiplyMatrix([-1, 0, 0, 0, 255,
  17303. 0, -1, 0, 0, 255,
  17304. 0, 0, -1, 0, 255,
  17305. 0, 0, 0, 1, 0]);
  17306. }
  17307. adjustColor(p_brightness, p_contrast, p_saturation, p_hue) {
  17308. this.adjustHue(p_hue || 0);
  17309. this.adjustContrast(p_contrast || 0);
  17310. this.adjustBrightness(p_brightness || 0);
  17311. this.adjustSaturation(p_saturation || 0);
  17312. }
  17313. adjustBrightness(p_val) {
  17314. p_val = this.cleanValue(p_val, 1) * 255;
  17315. this.multiplyMatrix([
  17316. 1, 0, 0, 0, p_val,
  17317. 0, 1, 0, 0, p_val,
  17318. 0, 0, 1, 0, p_val,
  17319. 0, 0, 0, 1, 0
  17320. ]);
  17321. }
  17322. adjustContrast(p_val) {
  17323. p_val = this.cleanValue(p_val, 1);
  17324. var s = p_val + 1;
  17325. var o = 128 * (1 - s);
  17326. this.multiplyMatrix([
  17327. s, 0, 0, 0, o,
  17328. 0, s, 0, 0, o,
  17329. 0, 0, s, 0, o,
  17330. 0, 0, 0, 1, 0
  17331. ]);
  17332. }
  17333. adjustSaturation(p_val) {
  17334. p_val = this.cleanValue(p_val, 1);
  17335. p_val += 1;
  17336. var invSat = 1 - p_val;
  17337. var invLumR = invSat * LUMA_R;
  17338. var invLumG = invSat * LUMA_G;
  17339. var invLumB = invSat * LUMA_B;
  17340. this.multiplyMatrix([
  17341. (invLumR + p_val), invLumG, invLumB, 0, 0,
  17342. invLumR, (invLumG + p_val), invLumB, 0, 0,
  17343. invLumR, invLumG, (invLumB + p_val), 0, 0,
  17344. 0, 0, 0, 1, 0
  17345. ]);
  17346. }
  17347. adjustHue(p_val) {
  17348. p_val = this.cleanValue(p_val, 1);
  17349. p_val *= Math.PI;
  17350. var cos = Math.cos(p_val);
  17351. var sin = Math.sin(p_val);
  17352. this.multiplyMatrix([
  17353. ((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,
  17354. ((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,
  17355. ((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,
  17356. 0, 0, 0, 1, 0
  17357. ]);
  17358. }
  17359. concat(p_matrix) {
  17360. if (p_matrix.length != LENGTH) {
  17361. return;
  17362. }
  17363. this.multiplyMatrix(p_matrix);
  17364. }
  17365. clone() {
  17366. var result = new ColorMatrix();
  17367. result.copyMatrix(this.matrix);
  17368. return result;
  17369. }
  17370. copyMatrix(p_matrix) {
  17371. var l = LENGTH;
  17372. for (var i = 0; i < l; i++) {
  17373. this.matrix[i] = p_matrix[i];
  17374. }
  17375. }
  17376. multiplyMatrix(p_matrix) {
  17377. var col = [];
  17378. var i = 0;
  17379. for (var y = 0; y < 4; ++y) {
  17380. for (var x = 0; x < 5; ++x) {
  17381. col[i + x] = p_matrix[i] * this.matrix[x] +
  17382. p_matrix[i + 1] * this.matrix[x + 5] +
  17383. p_matrix[i + 2] * this.matrix[x + 10] +
  17384. p_matrix[i + 3] * this.matrix[x + 15] +
  17385. (x == 4 ? p_matrix[i + 4] : 0);
  17386. }
  17387. i += 5;
  17388. }
  17389. this.copyMatrix(col);
  17390. }
  17391. cleanValue(p_val, p_limit) {
  17392. return Math.min(p_limit, Math.max(-p_limit, p_val));
  17393. }
  17394. }
  17395. fgui.ColorMatrix = ColorMatrix;
  17396. // identity matrix constant:
  17397. const IDENTITY_MATRIX = [
  17398. 1, 0, 0, 0, 0,
  17399. 0, 1, 0, 0, 0,
  17400. 0, 0, 1, 0, 0,
  17401. 0, 0, 0, 1, 0
  17402. ];
  17403. const LENGTH = IDENTITY_MATRIX.length;
  17404. const LUMA_R = 0.299;
  17405. const LUMA_G = 0.587;
  17406. const LUMA_B = 0.114;
  17407. })(fgui);
  17408. (function (fgui) {
  17409. class PixelHitTest extends Laya.HitArea {
  17410. constructor(data, offsetX, offsetY) {
  17411. super();
  17412. this._data = data;
  17413. this.offsetX = offsetX;
  17414. this.offsetY = offsetY;
  17415. this.scaleX = 1;
  17416. this.scaleY = 1;
  17417. }
  17418. contains(x, y) {
  17419. x = Math.floor((x / this.scaleX - this.offsetX) * this._data.scale);
  17420. y = Math.floor((y / this.scaleY - this.offsetY) * this._data.scale);
  17421. if (x < 0 || y < 0 || x >= this._data.pixelWidth)
  17422. return false;
  17423. var pos = y * this._data.pixelWidth + x;
  17424. var pos2 = Math.floor(pos / 8);
  17425. var pos3 = pos % 8;
  17426. if (pos2 >= 0 && pos2 < this._data.pixels.length)
  17427. return ((this._data.pixels[pos2] >> pos3) & 0x1) == 1;
  17428. else
  17429. return false;
  17430. }
  17431. }
  17432. fgui.PixelHitTest = PixelHitTest;
  17433. class PixelHitTestData {
  17434. constructor() {
  17435. }
  17436. load(ba) {
  17437. ba.getInt32();
  17438. this.pixelWidth = ba.getInt32();
  17439. this.scale = 1 / ba.readByte();
  17440. var len = ba.getInt32();
  17441. this.pixels = [];
  17442. for (var i = 0; i < len; i++) {
  17443. var j = ba.readByte();
  17444. if (j < 0)
  17445. j += 256;
  17446. this.pixels[i] = j;
  17447. }
  17448. }
  17449. }
  17450. fgui.PixelHitTestData = PixelHitTestData;
  17451. })(fgui);
  17452. (function (fgui) {
  17453. class UBBParser {
  17454. constructor() {
  17455. this._readPos = 0;
  17456. this.defaultImgWidth = 0;
  17457. this.defaultImgHeight = 0;
  17458. this._handlers = {};
  17459. this._handlers["url"] = this.onTag_URL;
  17460. this._handlers["img"] = this.onTag_IMG;
  17461. this._handlers["b"] = this.onTag_B;
  17462. this._handlers["i"] = this.onTag_I;
  17463. this._handlers["u"] = this.onTag_U;
  17464. this._handlers["sup"] = this.onTag_Simple;
  17465. this._handlers["sub"] = this.onTag_Simple;
  17466. this._handlers["color"] = this.onTag_COLOR;
  17467. this._handlers["font"] = this.onTag_FONT;
  17468. this._handlers["size"] = this.onTag_SIZE;
  17469. }
  17470. onTag_URL(tagName, end, attr) {
  17471. if (!end) {
  17472. if (attr != null)
  17473. return "<a href=\"" + attr + "\" target=\"_blank\">";
  17474. else {
  17475. var href = this.getTagText();
  17476. return "<a href=\"" + href + "\" target=\"_blank\">";
  17477. }
  17478. }
  17479. else
  17480. return "</a>";
  17481. }
  17482. onTag_IMG(tagName, end, attr) {
  17483. if (!end) {
  17484. var src = this.getTagText(true);
  17485. if (!src)
  17486. return null;
  17487. if (this.defaultImgWidth)
  17488. return "<img src=\"" + src + "\" width=\"" + this.defaultImgWidth + "\" height=\"" + this.defaultImgHeight + "\"/>";
  17489. else
  17490. return "<img src=\"" + src + "\"/>";
  17491. }
  17492. else
  17493. return null;
  17494. }
  17495. onTag_B(tagName, end, attr) {
  17496. return end ? ("</span>") : ("<span style='font-weight:bold'>");
  17497. }
  17498. onTag_I(tagName, end, attr) {
  17499. return end ? ("</span>") : ("<span style='font-style:italic'>");
  17500. }
  17501. onTag_U(tagName, end, attr) {
  17502. return end ? ("</span>") : ("<span style='text-decoration:underline'>");
  17503. }
  17504. onTag_Simple(tagName, end, attr) {
  17505. return end ? ("</" + tagName + ">") : ("<" + tagName + ">");
  17506. }
  17507. onTag_COLOR(tagName, end, attr) {
  17508. if (!end) {
  17509. this.lastColor = attr;
  17510. return "<span style=\"color:" + attr + "\">";
  17511. }
  17512. else
  17513. return "</span>";
  17514. }
  17515. onTag_FONT(tagName, end, attr) {
  17516. if (!end)
  17517. return "<span style=\"font-family:" + attr + "\">";
  17518. else
  17519. return "</span>";
  17520. }
  17521. onTag_SIZE(tagName, end, attr) {
  17522. if (!end) {
  17523. this.lastSize = attr;
  17524. return "<span style=\"font-size:" + attr + "\">";
  17525. }
  17526. else
  17527. return "</span>";
  17528. }
  17529. getTagText(remove) {
  17530. var pos1 = this._readPos;
  17531. var pos2;
  17532. var result = "";
  17533. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  17534. if (this._text.charCodeAt(pos2 - 1) == 92) //\
  17535. {
  17536. result += this._text.substring(pos1, pos2 - 1);
  17537. result += "[";
  17538. pos1 = pos2 + 1;
  17539. }
  17540. else {
  17541. result += this._text.substring(pos1, pos2);
  17542. break;
  17543. }
  17544. }
  17545. if (pos2 == -1)
  17546. return null;
  17547. if (remove)
  17548. this._readPos = pos2;
  17549. return result;
  17550. }
  17551. parse(text, remove) {
  17552. this._text = text;
  17553. this.lastColor = null;
  17554. this.lastSize = null;
  17555. var pos1 = 0, pos2, pos3;
  17556. var end;
  17557. var tag, attr;
  17558. var repl;
  17559. var func;
  17560. var result = "";
  17561. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  17562. if (pos2 > 0 && this._text.charCodeAt(pos2 - 1) == 92) //\
  17563. {
  17564. result += this._text.substring(pos1, pos2 - 1);
  17565. result += "[";
  17566. pos1 = pos2 + 1;
  17567. continue;
  17568. }
  17569. result += this._text.substring(pos1, pos2);
  17570. pos1 = pos2;
  17571. pos2 = this._text.indexOf("]", pos1);
  17572. if (pos2 == -1)
  17573. break;
  17574. end = this._text.charAt(pos1 + 1) == '/';
  17575. tag = this._text.substring(end ? pos1 + 2 : pos1 + 1, pos2);
  17576. this._readPos = pos2 + 1;
  17577. attr = null;
  17578. repl = null;
  17579. pos3 = tag.indexOf("=");
  17580. if (pos3 != -1) {
  17581. attr = tag.substring(pos3 + 1);
  17582. tag = tag.substring(0, pos3);
  17583. }
  17584. tag = tag.toLowerCase();
  17585. func = this._handlers[tag];
  17586. if (func != null) {
  17587. if (!remove) {
  17588. repl = func.call(this, tag, end, attr);
  17589. if (repl != null)
  17590. result += repl;
  17591. }
  17592. }
  17593. else
  17594. result += this._text.substring(pos1, this._readPos);
  17595. pos1 = this._readPos;
  17596. }
  17597. if (pos1 < this._text.length)
  17598. result += this._text.substr(pos1);
  17599. this._text = null;
  17600. return result;
  17601. }
  17602. }
  17603. UBBParser.inst = new UBBParser();
  17604. fgui.UBBParser = UBBParser;
  17605. })(fgui);
  17606. ///<reference path="UBBParser.ts"/>
  17607. ///<reference path="UBBParser.ts"/>
  17608. (function (fgui) {
  17609. class ToolSet {
  17610. static startsWith(source, str, ignoreCase) {
  17611. if (!source)
  17612. return false;
  17613. else if (source.length < str.length)
  17614. return false;
  17615. else {
  17616. source = source.substring(0, str.length);
  17617. if (!ignoreCase)
  17618. return source == str;
  17619. else
  17620. return source.toLowerCase() == str.toLowerCase();
  17621. }
  17622. }
  17623. static endsWith(source, str, ignoreCase) {
  17624. if (!source)
  17625. return false;
  17626. else if (source.length < str.length)
  17627. return false;
  17628. else {
  17629. source = source.substring(source.length - str.length);
  17630. if (!ignoreCase)
  17631. return source == str;
  17632. else
  17633. return source.toLowerCase() == str.toLowerCase();
  17634. }
  17635. }
  17636. static trimRight(targetString) {
  17637. var tempChar = "";
  17638. for (var i = targetString.length - 1; i >= 0; i--) {
  17639. tempChar = targetString.charAt(i);
  17640. if (tempChar != " " && tempChar != "\n" && tempChar != "\r") {
  17641. break;
  17642. }
  17643. }
  17644. return targetString.substring(0, i + 1);
  17645. }
  17646. static convertToHtmlColor(argb, hasAlpha) {
  17647. var alpha;
  17648. if (hasAlpha)
  17649. alpha = (argb >> 24 & 0xFF).toString(16);
  17650. else
  17651. alpha = "";
  17652. var red = (argb >> 16 & 0xFF).toString(16);
  17653. var green = (argb >> 8 & 0xFF).toString(16);
  17654. var blue = (argb & 0xFF).toString(16);
  17655. if (alpha.length == 1)
  17656. alpha = "0" + alpha;
  17657. if (red.length == 1)
  17658. red = "0" + red;
  17659. if (green.length == 1)
  17660. green = "0" + green;
  17661. if (blue.length == 1)
  17662. blue = "0" + blue;
  17663. return "#" + alpha + red + green + blue;
  17664. }
  17665. static convertFromHtmlColor(str, hasAlpha) {
  17666. if (str.length < 1)
  17667. return 0;
  17668. if (str.charAt(0) == "#")
  17669. str = str.substr(1);
  17670. if (str.length == 8)
  17671. return (parseInt(str.substr(0, 2), 16) << 24) + parseInt(str.substr(2), 16);
  17672. else if (hasAlpha)
  17673. return 0xFF000000 + parseInt(str, 16);
  17674. else
  17675. return parseInt(str, 16);
  17676. }
  17677. static displayObjectToGObject(obj) {
  17678. while (obj && !(obj instanceof Laya.Stage)) {
  17679. if (obj["$owner"])
  17680. return obj["$owner"];
  17681. obj = obj.parent;
  17682. }
  17683. return null;
  17684. }
  17685. static encodeHTML(str) {
  17686. if (!str)
  17687. return "";
  17688. else
  17689. return str.replace(/&/g, "&amp;").replace(/</g, "&lt;")
  17690. .replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/"/g, "&quot;");
  17691. }
  17692. static clamp(value, min, max) {
  17693. if (value < min)
  17694. value = min;
  17695. else if (value > max)
  17696. value = max;
  17697. return value;
  17698. }
  17699. static clamp01(value) {
  17700. if (isNaN(value))
  17701. value = 0;
  17702. else if (value > 1)
  17703. value = 1;
  17704. else if (value < 0)
  17705. value = 0;
  17706. return value;
  17707. }
  17708. static lerp(start, end, percent) {
  17709. return (start + percent * (end - start));
  17710. }
  17711. static repeat(t, length) {
  17712. return t - Math.floor(t / length) * length;
  17713. }
  17714. static distance(x1, y1, x2, y2) {
  17715. return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  17716. }
  17717. static setColorFilter(obj, color) {
  17718. var filter = obj.$_colorFilter_; //cached instance
  17719. var filters = obj.filters;
  17720. var toApplyColor;
  17721. var toApplyGray;
  17722. var tp = typeof (color);
  17723. if (tp == "boolean") //gray
  17724. {
  17725. toApplyColor = filter ? filter.$_color_ : null;
  17726. toApplyGray = color;
  17727. }
  17728. else {
  17729. if (tp == "string") {
  17730. var arr = Laya.ColorUtils.create(color).arrColor;
  17731. if (arr[0] == 1 && arr[1] == 1 && arr[2] == 1)
  17732. color = null;
  17733. else {
  17734. color = [arr[0], 0, 0, 0, 0,
  17735. 0, arr[1], 0, 0, 0,
  17736. 0, 0, arr[2], 0, 0,
  17737. 0, 0, 0, 1, 0];
  17738. }
  17739. }
  17740. toApplyColor = color;
  17741. toApplyGray = filter ? filter.$_grayed_ : false;
  17742. }
  17743. if ((!toApplyColor && toApplyColor != 0) && !toApplyGray) {
  17744. if (filters && filter) {
  17745. let i = filters.indexOf(filter);
  17746. if (i != -1) {
  17747. filters.splice(i, 1);
  17748. if (filters.length > 0)
  17749. obj.filters = filters;
  17750. else
  17751. obj.filters = null;
  17752. }
  17753. }
  17754. return;
  17755. }
  17756. if (!filter) {
  17757. filter = new Laya.ColorFilter();
  17758. obj.$_colorFilter_ = filter;
  17759. }
  17760. if (!filters)
  17761. filters = [filter];
  17762. else {
  17763. let i = filters.indexOf(filter);
  17764. if (i == -1)
  17765. filters.push(filter);
  17766. }
  17767. obj.filters = filters;
  17768. filter.$_color_ = toApplyColor;
  17769. filter.$_grayed_ = toApplyGray;
  17770. filter.reset();
  17771. if (toApplyGray)
  17772. filter.gray();
  17773. else if (toApplyColor.length == 20)
  17774. filter.setByMatrix(toApplyColor);
  17775. else
  17776. filter.setByMatrix(getColorMatrix(toApplyColor[0], toApplyColor[1], toApplyColor[2], toApplyColor[3]));
  17777. }
  17778. }
  17779. fgui.ToolSet = ToolSet;
  17780. let helper = new fgui.ColorMatrix();
  17781. function getColorMatrix(p_brightness, p_contrast, p_saturation, p_hue, result) {
  17782. result = result || new Array(fgui.ColorMatrix.length);
  17783. helper.reset();
  17784. helper.adjustColor(p_brightness, p_contrast, p_saturation, p_hue);
  17785. helper.matrix.forEach((e, i) => result[i] = e);
  17786. return result;
  17787. }
  17788. })(fgui);