laya.ui.js 195 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153
  1. (function (exports, Laya) {
  2. 'use strict';
  3. class UIConfig {
  4. }
  5. UIConfig.touchScrollEnable = true;
  6. UIConfig.mouseWheelEnable = true;
  7. UIConfig.showButtons = true;
  8. UIConfig.popupBgColor = "#000000";
  9. UIConfig.popupBgAlpha = 0.5;
  10. UIConfig.closeDialogOnSide = true;
  11. window.UIConfig = UIConfig;
  12. class Styles {
  13. }
  14. Styles.defaultSizeGrid = [4, 4, 4, 4, 0];
  15. Styles.labelColor = "#000000";
  16. Styles.labelPadding = [2, 2, 2, 2];
  17. Styles.inputLabelPadding = [1, 1, 1, 3];
  18. Styles.buttonStateNum = 3;
  19. Styles.buttonLabelColors = ["#32556b", "#32cc6b", "#ff0000", "#C0C0C0"];
  20. Styles.comboBoxItemColors = ["#5e95b6", "#ffffff", "#000000", "#8fa4b1", "#ffffff"];
  21. Styles.scrollBarMinNum = 15;
  22. Styles.scrollBarDelayTime = 500;
  23. class AutoBitmap extends Laya.Graphics {
  24. constructor() {
  25. super(...arguments);
  26. this.autoCacheCmd = true;
  27. this._width = 0;
  28. this._height = 0;
  29. this.uv = null;
  30. }
  31. destroy() {
  32. super.destroy();
  33. this._source = null;
  34. this._sizeGrid = null;
  35. this._offset = null;
  36. }
  37. get sizeGrid() {
  38. return this._sizeGrid;
  39. }
  40. set sizeGrid(value) {
  41. this._sizeGrid = value.map((v) => { return +v; });
  42. this._setChanged();
  43. }
  44. get width() {
  45. if (this._width)
  46. return this._width;
  47. if (this._source)
  48. return this._source.sourceWidth;
  49. return 0;
  50. }
  51. set width(value) {
  52. if (this._width != value) {
  53. this._width = value;
  54. this._setChanged();
  55. }
  56. }
  57. get height() {
  58. if (this._height)
  59. return this._height;
  60. if (this._source)
  61. return this._source.sourceHeight;
  62. return 0;
  63. }
  64. set height(value) {
  65. if (this._height != value) {
  66. this._height = value;
  67. this._setChanged();
  68. }
  69. }
  70. get source() {
  71. return this._source;
  72. }
  73. set source(value) {
  74. if (value) {
  75. this._source = value;
  76. this._setChanged();
  77. }
  78. else {
  79. this._source = null;
  80. if (this._drawGridCmd) {
  81. if (this._one) {
  82. if (this._one == this._drawGridCmd) {
  83. this.clear();
  84. }
  85. }
  86. let cmds = this.cmds;
  87. if (cmds && cmds.length > 0) {
  88. if (cmds[0] == this._drawGridCmd) {
  89. cmds.splice(0, 1);
  90. }
  91. }
  92. }
  93. }
  94. }
  95. _setChanged() {
  96. if (!this._isChanged) {
  97. this._isChanged = true;
  98. Laya.ILaya.timer.callLater(this, this.changeSource);
  99. }
  100. }
  101. _createDrawTexture(texture, x = 0, y = 0, width = 0, height = 0, matrix = null, alpha = 1, color = null, blendMode = null, uv) {
  102. if (!texture || alpha < 0.01)
  103. return null;
  104. if (!texture.getIsReady())
  105. return null;
  106. if (!width)
  107. width = texture.sourceWidth;
  108. if (!height)
  109. height = texture.sourceHeight;
  110. if (texture.getIsReady()) {
  111. var wRate = width / texture.sourceWidth;
  112. var hRate = height / texture.sourceHeight;
  113. width = texture.width * wRate;
  114. height = texture.height * hRate;
  115. if (width <= 0 || height <= 0)
  116. return null;
  117. x += texture.offsetX * wRate;
  118. y += texture.offsetY * hRate;
  119. }
  120. if (this._sp) {
  121. this._sp._renderType |= Laya.SpriteConst.GRAPHICS;
  122. this._sp._setRenderType(this._sp._renderType);
  123. }
  124. return Laya.DrawTextureCmd.create.call(this, texture, x, y, width, height, matrix, alpha, color, blendMode, uv);
  125. }
  126. changeSource() {
  127. this._isChanged = false;
  128. var source = this._source;
  129. if (!source || !source.bitmap)
  130. return;
  131. var width = this.width;
  132. var height = this.height;
  133. var sizeGrid = this._sizeGrid;
  134. var sw = source.sourceWidth;
  135. var sh = source.sourceHeight;
  136. if (!sizeGrid || (sw === width && sh === height)) {
  137. let cmd = this._createDrawTexture(source, this._offset ? this._offset[0] : 0, this._offset ? this._offset[1] : 0, width, height, null, 1, null, null, this.uv);
  138. cmd && this._setDrawGridCmd(cmd);
  139. }
  140. else {
  141. let cmd = Laya.Draw9GridTexture.create(source, 0, 0, width, height, sizeGrid);
  142. this._setDrawGridCmd(cmd);
  143. }
  144. this._repaint();
  145. }
  146. drawBitmap(repeat, tex, x, y, width = 0, height = 0) {
  147. if (width < 0.1 || height < 0.1)
  148. return;
  149. if (repeat && (tex.width != width || tex.height != height))
  150. this.fillTexture(tex, x, y, width, height);
  151. else
  152. this.drawImage(tex, x, y, width, height);
  153. }
  154. static getTexture(tex, x, y, width, height) {
  155. if (width <= 0)
  156. width = 1;
  157. if (height <= 0)
  158. height = 1;
  159. tex.$_GID || (tex.$_GID = Laya.Utils.getGID());
  160. var texture;
  161. if (!texture || !texture._getSource()) {
  162. texture = Laya.Texture.createFromTexture(tex, x, y, width, height);
  163. }
  164. return texture;
  165. }
  166. _setDrawGridCmd(newcmd) {
  167. var source = this._source;
  168. if (!source || !source.bitmap) {
  169. return;
  170. }
  171. let cmds = this.cmds;
  172. if (!this._one && (!cmds || cmds.length <= 0)) {
  173. this._saveToCmd(null, newcmd);
  174. }
  175. else {
  176. let lastOne = this._one;
  177. if (lastOne) {
  178. if (lastOne == this._drawGridCmd) {
  179. this._one = newcmd;
  180. }
  181. else {
  182. this.clear();
  183. this._saveToCmd(null, newcmd);
  184. this._saveToCmd(null, lastOne);
  185. }
  186. }
  187. else {
  188. cmds.splice(0, 0, newcmd);
  189. }
  190. }
  191. this._drawGridCmd = newcmd;
  192. }
  193. }
  194. Laya.ClassUtils.regClass("laya.ui.AutoBitmap", AutoBitmap);
  195. Laya.ClassUtils.regClass("Laya.AutoBitmap", AutoBitmap);
  196. class Widget extends Laya.Component {
  197. constructor() {
  198. super(...arguments);
  199. this._top = NaN;
  200. this._bottom = NaN;
  201. this._left = NaN;
  202. this._right = NaN;
  203. this._centerX = NaN;
  204. this._centerY = NaN;
  205. }
  206. onReset() {
  207. this._top = this._bottom = this._left = this._right = this._centerX = this._centerY = NaN;
  208. }
  209. _onEnable() {
  210. if (this.owner.parent)
  211. this._onAdded();
  212. else
  213. this.owner.once(Laya.Event.ADDED, this, this._onAdded);
  214. }
  215. _onDisable() {
  216. this.owner.off(Laya.Event.ADDED, this, this._onAdded);
  217. if (this.owner.parent)
  218. this.owner.parent.off(Laya.Event.RESIZE, this, this._onParentResize);
  219. }
  220. _onAdded() {
  221. if (this.owner.parent)
  222. this.owner.parent.on(Laya.Event.RESIZE, this, this._onParentResize);
  223. this.resetLayoutX();
  224. this.resetLayoutY();
  225. }
  226. _onParentResize() {
  227. var flagX = this.resetLayoutX();
  228. var flagY = this.resetLayoutY();
  229. if (flagX || flagY)
  230. this.owner.event(Laya.Event.RESIZE);
  231. }
  232. resetLayoutX() {
  233. var owner = this.owner;
  234. if (!owner)
  235. return false;
  236. var parent = owner.parent;
  237. if (parent) {
  238. if (!isNaN(this.centerX)) {
  239. owner.x = Math.round((parent.width - owner.displayWidth) * 0.5 + this.centerX + owner.pivotX * owner.scaleX);
  240. }
  241. else if (!isNaN(this.left)) {
  242. owner.x = Math.round(this.left + owner.pivotX * owner.scaleX);
  243. if (!isNaN(this.right)) {
  244. var temp = (parent._width - this.left - this.right) / (owner.scaleX || 0.01);
  245. if (temp != owner.width) {
  246. owner.width = temp;
  247. return true;
  248. }
  249. }
  250. }
  251. else if (!isNaN(this.right)) {
  252. owner.x = Math.round(parent.width - owner.displayWidth - this.right + owner.pivotX * owner.scaleX);
  253. }
  254. }
  255. return false;
  256. }
  257. resetLayoutY() {
  258. var owner = this.owner;
  259. if (!owner)
  260. return false;
  261. var parent = owner.parent;
  262. if (parent) {
  263. if (!isNaN(this.centerY)) {
  264. owner.y = Math.round((parent.height - owner.displayHeight) * 0.5 + this.centerY + owner.pivotY * owner.scaleY);
  265. }
  266. else if (!isNaN(this.top)) {
  267. owner.y = Math.round(this.top + owner.pivotY * owner.scaleY);
  268. if (!isNaN(this.bottom)) {
  269. var temp = (parent._height - this.top - this.bottom) / (owner.scaleY || 0.01);
  270. if (temp != owner.height) {
  271. owner.height = temp;
  272. return true;
  273. }
  274. }
  275. }
  276. else if (!isNaN(this.bottom)) {
  277. owner.y = Math.round(parent.height - owner.displayHeight - this.bottom + owner.pivotY * owner.scaleY);
  278. }
  279. }
  280. return false;
  281. }
  282. resetLayout() {
  283. if (this.owner) {
  284. this.resetLayoutX();
  285. this.resetLayoutY();
  286. }
  287. }
  288. get top() {
  289. return this._top;
  290. }
  291. set top(value) {
  292. if (this._top != value) {
  293. this._top = value;
  294. this.resetLayoutY();
  295. }
  296. }
  297. get bottom() {
  298. return this._bottom;
  299. }
  300. set bottom(value) {
  301. if (this._bottom != value) {
  302. this._bottom = value;
  303. this.resetLayoutY();
  304. }
  305. }
  306. get left() {
  307. return this._left;
  308. }
  309. set left(value) {
  310. if (this._left != value) {
  311. this._left = value;
  312. this.resetLayoutX();
  313. }
  314. }
  315. get right() {
  316. return this._right;
  317. }
  318. set right(value) {
  319. if (this._right != value) {
  320. this._right = value;
  321. this.resetLayoutX();
  322. }
  323. }
  324. get centerX() {
  325. return this._centerX;
  326. }
  327. set centerX(value) {
  328. if (this._centerX != value) {
  329. this._centerX = value;
  330. this.resetLayoutX();
  331. }
  332. }
  333. get centerY() {
  334. return this._centerY;
  335. }
  336. set centerY(value) {
  337. if (this._centerY != value) {
  338. this._centerY = value;
  339. this.resetLayoutY();
  340. }
  341. }
  342. }
  343. Widget.EMPTY = null;
  344. Laya.ILaya.regClass(Widget);
  345. Widget.EMPTY = new Widget();
  346. Laya.ClassUtils.regClass("laya.ui.Widget", Widget);
  347. Laya.ClassUtils.regClass("Laya.Widget", Widget);
  348. class UIEvent extends Laya.Event {
  349. }
  350. UIEvent.SHOW_TIP = "showtip";
  351. UIEvent.HIDE_TIP = "hidetip";
  352. Laya.ILaya.regClass(UIEvent);
  353. Laya.ClassUtils.regClass("laya.ui.UIEvent", UIEvent);
  354. Laya.ClassUtils.regClass("Laya.UIEvent", UIEvent);
  355. class UIUtils {
  356. static fillArray(arr, str, type = null) {
  357. var temp = arr.concat();
  358. if (str) {
  359. var a = str.split(",");
  360. for (var i = 0, n = Math.min(temp.length, a.length); i < n; i++) {
  361. var value = a[i];
  362. temp[i] = (value == "true" ? true : (value == "false" ? false : value));
  363. if (type != null)
  364. temp[i] = type(value);
  365. }
  366. }
  367. return temp;
  368. }
  369. static toColor(color) {
  370. return Laya.Utils.toHexColor(color);
  371. }
  372. static gray(traget, isGray = true) {
  373. if (isGray) {
  374. UIUtils.addFilter(traget, UIUtils.grayFilter);
  375. }
  376. else {
  377. UIUtils.clearFilter(traget, Laya.ColorFilter);
  378. }
  379. }
  380. static addFilter(target, filter) {
  381. var filters = target.filters || [];
  382. filters.push(filter);
  383. target.filters = filters;
  384. }
  385. static clearFilter(target, filterType) {
  386. var filters = target.filters;
  387. if (filters != null && filters.length > 0) {
  388. for (var i = filters.length - 1; i > -1; i--) {
  389. var filter = filters[i];
  390. if (filter instanceof filterType)
  391. filters.splice(i, 1);
  392. }
  393. target.filters = filters;
  394. }
  395. }
  396. static _getReplaceStr(word) {
  397. return UIUtils.escapeSequence[word];
  398. }
  399. static adptString(str) {
  400. return str.replace(/\\(\w)/g, UIUtils._getReplaceStr);
  401. }
  402. static getBindFun(value) {
  403. if (!UIUtils._funMap) {
  404. UIUtils._funMap = new Laya.WeakObject();
  405. }
  406. var fun = UIUtils._funMap.get(value);
  407. if (fun == null) {
  408. var temp = "\"" + value + "\"";
  409. temp = temp.replace(/^"\${|}"$/g, "").replace(/\${/g, "\"+").replace(/}/g, "+\"");
  410. var str = "(function(data){if(data==null)return;with(data){try{\nreturn " + temp + "\n}catch(e){}}})";
  411. fun = window.Laya._runScript(str);
  412. UIUtils._funMap.set(value, fun);
  413. }
  414. return fun;
  415. }
  416. }
  417. UIUtils.grayFilter = new Laya.ColorFilter([0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0, 0, 0, 1, 0]);
  418. UIUtils.escapeSequence = { "\\n": "\n", "\\t": "\t" };
  419. UIUtils._funMap = null;
  420. Laya.ClassUtils.regClass("laya.ui.UIUtils", UIUtils);
  421. Laya.ClassUtils.regClass("Laya.UIUtils", UIUtils);
  422. class UIComponent extends Laya.Sprite {
  423. constructor(createChildren = true) {
  424. super();
  425. this._anchorX = NaN;
  426. this._anchorY = NaN;
  427. this._widget = Widget.EMPTY;
  428. if (createChildren) {
  429. this.preinitialize();
  430. this.createChildren();
  431. this.initialize();
  432. }
  433. }
  434. destroy(destroyChild = true) {
  435. super.destroy(destroyChild);
  436. this._dataSource = null;
  437. this._tag = null;
  438. this._toolTip = null;
  439. }
  440. preinitialize() {
  441. }
  442. createChildren() {
  443. }
  444. initialize() {
  445. }
  446. get width() {
  447. return this.get_width();
  448. }
  449. get_width() {
  450. if (this._width)
  451. return this._width;
  452. return this.measureWidth();
  453. }
  454. measureWidth() {
  455. var max = 0;
  456. this.commitMeasure();
  457. for (var i = this.numChildren - 1; i > -1; i--) {
  458. var comp = this.getChildAt(i);
  459. if (comp._visible) {
  460. max = Math.max(comp._x + comp.width * comp.scaleX, max);
  461. }
  462. }
  463. return max;
  464. }
  465. commitMeasure() {
  466. }
  467. get height() {
  468. return this.get_height();
  469. }
  470. get_height() {
  471. if (this._height)
  472. return this._height;
  473. return this.measureHeight();
  474. }
  475. measureHeight() {
  476. var max = 0;
  477. this.commitMeasure();
  478. for (var i = this.numChildren - 1; i > -1; i--) {
  479. var comp = this.getChildAt(i);
  480. if (comp._visible) {
  481. max = Math.max(comp._y + comp.height * comp.scaleY, max);
  482. }
  483. }
  484. return max;
  485. }
  486. get dataSource() {
  487. return this.get_dataSource();
  488. }
  489. get_dataSource() {
  490. return this._dataSource;
  491. }
  492. set dataSource(value) {
  493. this.set_dataSource(value);
  494. }
  495. set_dataSource(value) {
  496. this._dataSource = value;
  497. for (var prop in this._dataSource) {
  498. if (prop in this && !(typeof (this[prop]) == 'function')) {
  499. this[prop] = this._dataSource[prop];
  500. }
  501. }
  502. }
  503. get top() {
  504. return this.get_top();
  505. }
  506. get_top() {
  507. return this._widget.top;
  508. }
  509. set top(value) {
  510. this.set_top(value);
  511. }
  512. set_top(value) {
  513. if (value != this._widget.top) {
  514. this._getWidget().top = value;
  515. }
  516. }
  517. get bottom() {
  518. return this.get_bottom();
  519. }
  520. get_bottom() {
  521. return this._widget.bottom;
  522. }
  523. set bottom(value) {
  524. this.set_bottom(value);
  525. }
  526. set_bottom(value) {
  527. if (value != this._widget.bottom) {
  528. this._getWidget().bottom = value;
  529. }
  530. }
  531. get left() {
  532. return this._widget.left;
  533. }
  534. set left(value) {
  535. if (value != this._widget.left) {
  536. this._getWidget().left = value;
  537. }
  538. }
  539. get right() {
  540. return this._widget.right;
  541. }
  542. set right(value) {
  543. if (value != this._widget.right) {
  544. this._getWidget().right = value;
  545. }
  546. }
  547. get centerX() {
  548. return this._widget.centerX;
  549. }
  550. set centerX(value) {
  551. if (value != this._widget.centerX) {
  552. this._getWidget().centerX = value;
  553. }
  554. }
  555. get centerY() {
  556. return this._widget.centerY;
  557. }
  558. set centerY(value) {
  559. if (value != this._widget.centerY) {
  560. this._getWidget().centerY = value;
  561. }
  562. }
  563. _sizeChanged() {
  564. if (!isNaN(this._anchorX))
  565. this.pivotX = this.anchorX * this.width;
  566. if (!isNaN(this._anchorY))
  567. this.pivotY = this.anchorY * this.height;
  568. this.event(Laya.Event.RESIZE);
  569. if (this._widget !== Widget.EMPTY)
  570. this._widget.resetLayout();
  571. }
  572. get tag() {
  573. return this._tag;
  574. }
  575. set tag(value) {
  576. this._tag = value;
  577. }
  578. get toolTip() {
  579. return this._toolTip;
  580. }
  581. set toolTip(value) {
  582. if (this._toolTip != value) {
  583. this._toolTip = value;
  584. if (value != null) {
  585. this.on(Laya.Event.MOUSE_OVER, this, this.onMouseOver);
  586. this.on(Laya.Event.MOUSE_OUT, this, this.onMouseOut);
  587. }
  588. else {
  589. this.off(Laya.Event.MOUSE_OVER, this, this.onMouseOver);
  590. this.off(Laya.Event.MOUSE_OUT, this, this.onMouseOut);
  591. }
  592. }
  593. }
  594. onMouseOver(e) {
  595. Laya.ILaya.stage.event(UIEvent.SHOW_TIP, this._toolTip);
  596. }
  597. onMouseOut(e) {
  598. Laya.ILaya.stage.event(UIEvent.HIDE_TIP, this._toolTip);
  599. }
  600. get gray() {
  601. return this._gray;
  602. }
  603. set gray(value) {
  604. if (value !== this._gray) {
  605. this._gray = value;
  606. UIUtils.gray(this, value);
  607. }
  608. }
  609. get disabled() {
  610. return this._disabled;
  611. }
  612. set disabled(value) {
  613. if (value !== this._disabled) {
  614. this.gray = this._disabled = value;
  615. this.mouseEnabled = !value;
  616. }
  617. }
  618. _getWidget() {
  619. this._widget === Widget.EMPTY && (this._widget = this.addComponent(Widget));
  620. return this._widget;
  621. }
  622. set scaleX(value) {
  623. this.set_scaleX(value);
  624. }
  625. set_scaleX(value) {
  626. if (super.get_scaleX() == value)
  627. return;
  628. super.set_scaleX(value);
  629. this.callLater(this._sizeChanged);
  630. }
  631. get scaleX() {
  632. return super.scaleX;
  633. }
  634. set scaleY(value) {
  635. this.set_scaleY(value);
  636. }
  637. set_scaleY(value) {
  638. if (super.get_scaleY() == value)
  639. return;
  640. super.set_scaleY(value);
  641. this.callLater(this._sizeChanged);
  642. }
  643. get scaleY() {
  644. return super.scaleY;
  645. }
  646. onCompResize() {
  647. this._sizeChanged();
  648. }
  649. set width(value) {
  650. this.set_width(value);
  651. }
  652. set_width(value) {
  653. if (super.get_width() == value)
  654. return;
  655. super.set_width(value);
  656. this.callLater(this._sizeChanged);
  657. }
  658. set height(value) {
  659. this.set_height(value);
  660. }
  661. set_height(value) {
  662. if (super.get_height() == value)
  663. return;
  664. super.set_height(value);
  665. this.callLater(this._sizeChanged);
  666. }
  667. get anchorX() {
  668. return this.get_anchorX();
  669. }
  670. get_anchorX() {
  671. return this._anchorX;
  672. }
  673. set anchorX(value) {
  674. this.set_anchorX(value);
  675. }
  676. set_anchorX(value) {
  677. if (this._anchorX != value) {
  678. this._anchorX = value;
  679. this.callLater(this._sizeChanged);
  680. }
  681. }
  682. get anchorY() {
  683. return this.get_anchorY();
  684. }
  685. get_anchorY() {
  686. return this._anchorY;
  687. }
  688. set anchorY(value) {
  689. this.set_anchorY(value);
  690. }
  691. set_anchorY(value) {
  692. if (this._anchorY != value) {
  693. this._anchorY = value;
  694. this.callLater(this._sizeChanged);
  695. }
  696. }
  697. _childChanged(child = null) {
  698. this.callLater(this._sizeChanged);
  699. super._childChanged(child);
  700. }
  701. }
  702. Laya.ILaya.regClass(UIComponent);
  703. Laya.ClassUtils.regClass("laya.ui.UIComponent", UIComponent);
  704. Laya.ClassUtils.regClass("Laya.UIComponent", UIComponent);
  705. class Image extends UIComponent {
  706. constructor(skin = null) {
  707. super();
  708. this.skin = skin;
  709. }
  710. destroy(destroyChild = true) {
  711. super.destroy(destroyChild);
  712. this._bitmap && this._bitmap.destroy();
  713. this._bitmap = null;
  714. }
  715. dispose() {
  716. this.destroy(true);
  717. Laya.ILaya.loader.clearRes(this._skin);
  718. }
  719. createChildren() {
  720. this.graphics = this._bitmap = new AutoBitmap();
  721. this._bitmap.autoCacheCmd = false;
  722. }
  723. get skin() {
  724. return this._skin;
  725. }
  726. set skin(value) {
  727. if (this._skin != value) {
  728. this._skin = value;
  729. if (value) {
  730. var source = Laya.Loader.getRes(value);
  731. if (source) {
  732. this.source = source;
  733. this.onCompResize();
  734. }
  735. else
  736. Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this.setSource, [this._skin]), null, Laya.Loader.IMAGE, 1, true, this._group);
  737. }
  738. else {
  739. this.source = null;
  740. }
  741. }
  742. }
  743. get source() {
  744. return this._bitmap.source;
  745. }
  746. set source(value) {
  747. if (!this._bitmap)
  748. return;
  749. this._bitmap.source = value;
  750. this.event(Laya.Event.LOADED);
  751. this.repaint();
  752. }
  753. get group() {
  754. return this._group;
  755. }
  756. set group(value) {
  757. if (value && this._skin)
  758. Laya.Loader.setGroup(this._skin, value);
  759. this._group = value;
  760. }
  761. setSource(url, img = null) {
  762. if (url === this._skin && img) {
  763. this.source = img;
  764. this.onCompResize();
  765. }
  766. }
  767. measureWidth() {
  768. return this._bitmap.width;
  769. }
  770. measureHeight() {
  771. return this._bitmap.height;
  772. }
  773. set width(value) {
  774. super.width = value;
  775. this._bitmap.width = value == 0 ? 0.0000001 : value;
  776. }
  777. get width() {
  778. return super.width;
  779. }
  780. set height(value) {
  781. super.height = value;
  782. this._bitmap.height = value == 0 ? 0.0000001 : value;
  783. }
  784. get height() {
  785. return super.height;
  786. }
  787. get sizeGrid() {
  788. if (this._bitmap.sizeGrid)
  789. return this._bitmap.sizeGrid.join(",");
  790. return null;
  791. }
  792. set sizeGrid(value) {
  793. this._bitmap.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
  794. }
  795. set dataSource(value) {
  796. this._dataSource = value;
  797. if (typeof (value) == 'string')
  798. this.skin = value;
  799. else
  800. super.dataSource = value;
  801. }
  802. get dataSource() {
  803. return super.dataSource;
  804. }
  805. }
  806. Laya.ILaya.regClass(Image);
  807. Laya.ClassUtils.regClass("laya.ui.Image", Image);
  808. Laya.ClassUtils.regClass("Laya.Image", Image);
  809. class AdvImage extends Image {
  810. constructor(skin = null) {
  811. super();
  812. this.advsListArr = [];
  813. this.resUrl = "https://unioncdn.layabox.com/config/iconlist.json";
  814. this._http = new Laya.Browser.window.XMLHttpRequest();
  815. this._data = [];
  816. this._resquestTime = 360000;
  817. this._playIndex = 0;
  818. this._lunboTime = 5000;
  819. this.skin = skin;
  820. this.setLoadUrl();
  821. this.init();
  822. this.size(120, 120);
  823. }
  824. setLoadUrl() {
  825. }
  826. init() {
  827. if (this.isSupportJump()) {
  828. if (Laya.Browser.onMiniGame || Laya.Browser.onBDMiniGame) {
  829. Laya.ILaya.timer.loop(this._resquestTime, this, this.onGetAdvsListData);
  830. }
  831. this.onGetAdvsListData();
  832. this.initEvent();
  833. }
  834. else
  835. this.visible = false;
  836. }
  837. initEvent() {
  838. this.on(Laya.Event.CLICK, this, this.onAdvsImgClick);
  839. }
  840. onAdvsImgClick() {
  841. var currentJumpUrl = this.getCurrentAppidObj();
  842. if (currentJumpUrl)
  843. this.jumptoGame();
  844. }
  845. revertAdvsData() {
  846. if (this.advsListArr[this._playIndex]) {
  847. this.visible = true;
  848. this.skin = this.advsListArr[this._playIndex];
  849. }
  850. }
  851. isSupportJump() {
  852. if (Laya.Browser.onMiniGame) {
  853. var isSupperJump = window.wx.navigateToMiniProgram instanceof Function;
  854. return isSupperJump;
  855. }
  856. else if (Laya.Browser.onBDMiniGame)
  857. return true;
  858. return false;
  859. }
  860. jumptoGame() {
  861. var advsObj = this.advsListArr[this._playIndex];
  862. var desGameId = parseInt(advsObj.gameid);
  863. var extendInfo = advsObj.extendInfo;
  864. var path = advsObj.path;
  865. if (Laya.Browser.onMiniGame) {
  866. if (this.isSupportJump()) {
  867. window.wx.navigateToMiniProgram({
  868. appId: this._appid,
  869. path: "",
  870. extraData: "",
  871. envVersion: "release",
  872. success: function success() {
  873. console.log("-------------跳转成功--------------");
  874. },
  875. fail: function fail() {
  876. console.log("-------------跳转失败--------------");
  877. },
  878. complete: function complete() {
  879. console.log("-------------跳转接口调用成功--------------");
  880. this.updateAdvsInfo();
  881. }.bind(this)
  882. });
  883. }
  884. }
  885. else if (Laya.Browser.onBDMiniGame) ;
  886. else {
  887. this.visible = false;
  888. }
  889. }
  890. updateAdvsInfo() {
  891. this.visible = false;
  892. this.onLunbo();
  893. Laya.ILaya.timer.loop(this._lunboTime, this, this.onLunbo);
  894. }
  895. onLunbo() {
  896. if (this._playIndex >= this.advsListArr.length - 1)
  897. this._playIndex = 0;
  898. else
  899. this._playIndex += 1;
  900. this.visible = true;
  901. this.revertAdvsData();
  902. }
  903. getCurrentAppidObj() {
  904. return this.advsListArr[this._playIndex];
  905. }
  906. onGetAdvsListData() {
  907. var _this = this;
  908. var random = AdvImage.randRange(10000, 1000000);
  909. var url = this.resUrl + "?" + random;
  910. this._http.open("get", url, true);
  911. this._http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  912. this._http.responseType = "text";
  913. this._http.onerror = function (e) {
  914. _this._onError(e);
  915. };
  916. this._http.onload = function (e) {
  917. _this._onLoad(e);
  918. };
  919. this._http.send(null);
  920. }
  921. static randRange(minNum, maxNum) {
  922. return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
  923. }
  924. _onError(e) {
  925. this.error("Request failed Status:" + this._http.status + " text:" + this._http.statusText);
  926. }
  927. _onLoad(e) {
  928. var http = this._http;
  929. var status = http.status !== undefined ? http.status : 200;
  930. if (status === 200 || status === 204 || status === 0) {
  931. this.complete();
  932. }
  933. else {
  934. this.error("[" + http.status + "]" + http.statusText + ":" + http.responseURL);
  935. }
  936. }
  937. error(message) {
  938. this.event(Laya.Event.ERROR, message);
  939. }
  940. complete() {
  941. try {
  942. this._data = this._http.response || this._http.responseText;
  943. this._data = JSON.parse(this._data);
  944. this.advsListArr = this._data.list;
  945. this._appid = this._data.appid;
  946. this.updateAdvsInfo();
  947. this.revertAdvsData();
  948. }
  949. catch (e) {
  950. this.error(e.message);
  951. }
  952. }
  953. getAdvsQArr(data) {
  954. var tempArr = [];
  955. var gameAdvsObj = Laya.LocalStorage.getJSON("gameObj");
  956. for (var key in data) {
  957. var tempObj = data[key];
  958. if (gameAdvsObj && gameAdvsObj[tempObj.gameid] && !tempObj.isQiangZhi)
  959. continue;
  960. tempArr.push(tempObj);
  961. }
  962. return tempArr;
  963. }
  964. clear() {
  965. var http = this._http;
  966. http.onerror = http.onabort = http.onprogress = http.onload = null;
  967. }
  968. destroy(destroyChild = true) {
  969. Laya.ILaya.timer.clear(this, this.onLunbo);
  970. super.destroy(true);
  971. this.clear();
  972. Laya.ILaya.timer.clear(this, this.onGetAdvsListData);
  973. }
  974. }
  975. Laya.ClassUtils.regClass("laya.ui.AdvImage", AdvImage);
  976. Laya.ClassUtils.regClass("Laya.AdvImage", AdvImage);
  977. class Box extends UIComponent {
  978. set dataSource(value) {
  979. this._dataSource = value;
  980. for (var name in value) {
  981. var comp = this.getChildByName(name);
  982. if (comp)
  983. comp.dataSource = value[name];
  984. else if (name in this && !(this[name] instanceof Function))
  985. this[name] = value[name];
  986. }
  987. }
  988. get dataSource() {
  989. return super.dataSource;
  990. }
  991. get bgColor() {
  992. return this._bgColor;
  993. }
  994. set bgColor(value) {
  995. this._bgColor = value;
  996. if (value) {
  997. this._onResize(null);
  998. this.on(Laya.Event.RESIZE, this, this._onResize);
  999. }
  1000. else {
  1001. this.graphics.clear();
  1002. this.off(Laya.Event.RESIZE, this, this._onResize);
  1003. }
  1004. }
  1005. _onResize(e) {
  1006. this.graphics.clear();
  1007. this.graphics.drawRect(0, 0, this.width, this.height, this._bgColor);
  1008. }
  1009. }
  1010. Laya.ILaya.regClass(Box);
  1011. Laya.ClassUtils.regClass("laya.ui.Box", Box);
  1012. Laya.ClassUtils.regClass("Laya.Box", Box);
  1013. class Button extends UIComponent {
  1014. constructor(skin = null, label = "") {
  1015. super();
  1016. this._labelColors = Styles.buttonLabelColors;
  1017. this._state = 0;
  1018. this._autoSize = true;
  1019. this._stateNum = Styles.buttonStateNum;
  1020. this._stateChanged = false;
  1021. this.skin = skin;
  1022. this.label = label;
  1023. }
  1024. destroy(destroyChild = true) {
  1025. super.destroy(destroyChild);
  1026. this._bitmap && this._bitmap.destroy();
  1027. this._text && this._text.destroy(destroyChild);
  1028. this._bitmap = null;
  1029. this._text = null;
  1030. this._clickHandler = null;
  1031. this._labelColors = this._sources = this._strokeColors = null;
  1032. }
  1033. createChildren() {
  1034. this.graphics = this._bitmap = new AutoBitmap();
  1035. }
  1036. createText() {
  1037. if (!this._text) {
  1038. this._text = new Laya.Text();
  1039. this._text.overflow = Laya.Text.HIDDEN;
  1040. this._text.align = "center";
  1041. this._text.valign = "middle";
  1042. this._text.width = this._width;
  1043. this._text.height = this._height;
  1044. }
  1045. }
  1046. initialize() {
  1047. if (this._mouseState !== 1) {
  1048. this.mouseEnabled = true;
  1049. this._setBit(Laya.Const.HAS_MOUSE, true);
  1050. }
  1051. this._createListener(Laya.Event.MOUSE_OVER, this, this.onMouse, null, false, false);
  1052. this._createListener(Laya.Event.MOUSE_OUT, this, this.onMouse, null, false, false);
  1053. this._createListener(Laya.Event.MOUSE_DOWN, this, this.onMouse, null, false, false);
  1054. this._createListener(Laya.Event.MOUSE_UP, this, this.onMouse, null, false, false);
  1055. this._createListener(Laya.Event.CLICK, this, this.onMouse, null, false, false);
  1056. }
  1057. onMouse(e) {
  1058. if (this.toggle === false && this._selected)
  1059. return;
  1060. if (e.type === Laya.Event.CLICK) {
  1061. this.toggle && (this.selected = !this._selected);
  1062. this._clickHandler && this._clickHandler.run();
  1063. return;
  1064. }
  1065. !this._selected && (this.state = Button.stateMap[e.type]);
  1066. }
  1067. get skin() {
  1068. return this._skin;
  1069. }
  1070. set skin(value) {
  1071. if (this._skin != value) {
  1072. this._skin = value;
  1073. if (value) {
  1074. if (!Laya.Loader.getRes(value)) {
  1075. Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
  1076. }
  1077. else {
  1078. this._skinLoaded();
  1079. }
  1080. }
  1081. else {
  1082. this._skinLoaded();
  1083. }
  1084. }
  1085. }
  1086. _skinLoaded() {
  1087. this.callLater(this.changeClips);
  1088. this._setStateChanged();
  1089. this._sizeChanged();
  1090. this.event(Laya.Event.LOADED);
  1091. }
  1092. get stateNum() {
  1093. return this._stateNum;
  1094. }
  1095. set stateNum(value) {
  1096. if (typeof value == 'string') {
  1097. value = parseInt(value);
  1098. }
  1099. if (this._stateNum != value) {
  1100. this._stateNum = value < 1 ? 1 : value > 3 ? 3 : value;
  1101. this.callLater(this.changeClips);
  1102. }
  1103. }
  1104. changeClips() {
  1105. var img = Laya.Loader.getRes(this._skin);
  1106. if (!img) {
  1107. console.log("lose skin", this._skin);
  1108. return;
  1109. }
  1110. var width = img.sourceWidth;
  1111. var height = img.sourceHeight / this._stateNum;
  1112. img.$_GID || (img.$_GID = Laya.Utils.getGID());
  1113. var key = img.$_GID + "-" + this._stateNum;
  1114. var clips = Laya.WeakObject.I.get(key);
  1115. if (!Laya.Utils.isOkTextureList(clips)) {
  1116. clips = null;
  1117. }
  1118. if (clips)
  1119. this._sources = clips;
  1120. else {
  1121. this._sources = [];
  1122. if (this._stateNum === 1) {
  1123. this._sources.push(img);
  1124. }
  1125. else {
  1126. for (var i = 0; i < this._stateNum; i++) {
  1127. this._sources.push(Laya.Texture.createFromTexture(img, 0, height * i, width, height));
  1128. }
  1129. }
  1130. Laya.WeakObject.I.set(key, this._sources);
  1131. }
  1132. if (this._autoSize) {
  1133. this._bitmap.width = this._width || width;
  1134. this._bitmap.height = this._height || height;
  1135. if (this._text) {
  1136. this._text.width = this._bitmap.width;
  1137. this._text.height = this._bitmap.height;
  1138. }
  1139. }
  1140. else {
  1141. this._text && (this._text.x = width);
  1142. }
  1143. }
  1144. measureWidth() {
  1145. this.runCallLater(this.changeClips);
  1146. if (this._autoSize)
  1147. return this._bitmap.width;
  1148. this.runCallLater(this.changeState);
  1149. return this._bitmap.width + (this._text ? this._text.width : 0);
  1150. }
  1151. measureHeight() {
  1152. this.runCallLater(this.changeClips);
  1153. return this._text ? Math.max(this._bitmap.height, this._text.height) : this._bitmap.height;
  1154. }
  1155. get label() {
  1156. return this._text ? this._text.text : null;
  1157. }
  1158. set label(value) {
  1159. if (!this._text && !value)
  1160. return;
  1161. this.createText();
  1162. if (this._text.text != value) {
  1163. value && !this._text.parent && this.addChild(this._text);
  1164. this._text.text = (value + "").replace(/\\n/g, "\n");
  1165. this._setStateChanged();
  1166. }
  1167. }
  1168. get selected() {
  1169. return this._selected;
  1170. }
  1171. set selected(value) {
  1172. if (this._selected != value) {
  1173. this._selected = value;
  1174. this.state = this._selected ? 2 : 0;
  1175. this.event(Laya.Event.CHANGE);
  1176. }
  1177. }
  1178. get state() {
  1179. return this._state;
  1180. }
  1181. set state(value) {
  1182. if (this._state != value) {
  1183. this._state = value;
  1184. this._setStateChanged();
  1185. }
  1186. }
  1187. changeState() {
  1188. this._stateChanged = false;
  1189. this.runCallLater(this.changeClips);
  1190. var index = this._state < this._stateNum ? this._state : this._stateNum - 1;
  1191. this._sources && (this._bitmap.source = this._sources[index]);
  1192. if (this.label) {
  1193. this._text.color = this._labelColors[index];
  1194. if (this._strokeColors)
  1195. this._text.strokeColor = this._strokeColors[index];
  1196. }
  1197. }
  1198. get labelColors() {
  1199. return this._labelColors.join(",");
  1200. }
  1201. set labelColors(value) {
  1202. this._labelColors = UIUtils.fillArray(Styles.buttonLabelColors, value, String);
  1203. this._setStateChanged();
  1204. }
  1205. get strokeColors() {
  1206. return this._strokeColors ? this._strokeColors.join(",") : "";
  1207. }
  1208. set strokeColors(value) {
  1209. this._strokeColors = UIUtils.fillArray(Styles.buttonLabelColors, value, String);
  1210. this._setStateChanged();
  1211. }
  1212. get labelPadding() {
  1213. this.createText();
  1214. return this._text.padding.join(",");
  1215. }
  1216. set labelPadding(value) {
  1217. this.createText();
  1218. this._text.padding = UIUtils.fillArray(Styles.labelPadding, value, Number);
  1219. }
  1220. get labelSize() {
  1221. this.createText();
  1222. return this._text.fontSize;
  1223. }
  1224. set labelSize(value) {
  1225. this.createText();
  1226. this._text.fontSize = value;
  1227. }
  1228. get labelStroke() {
  1229. this.createText();
  1230. return this._text.stroke;
  1231. }
  1232. set labelStroke(value) {
  1233. this.createText();
  1234. this._text.stroke = value;
  1235. }
  1236. get labelStrokeColor() {
  1237. this.createText();
  1238. return this._text.strokeColor;
  1239. }
  1240. set labelStrokeColor(value) {
  1241. this.createText();
  1242. this._text.strokeColor = value;
  1243. }
  1244. get labelBold() {
  1245. this.createText();
  1246. return this._text.bold;
  1247. }
  1248. set labelBold(value) {
  1249. this.createText();
  1250. this._text.bold = value;
  1251. }
  1252. get labelFont() {
  1253. this.createText();
  1254. return this._text.font;
  1255. }
  1256. set labelFont(value) {
  1257. this.createText();
  1258. this._text.font = value;
  1259. }
  1260. get labelAlign() {
  1261. this.createText();
  1262. return this._text.align;
  1263. }
  1264. set labelAlign(value) {
  1265. this.createText();
  1266. this._text.align = value;
  1267. }
  1268. get clickHandler() {
  1269. return this._clickHandler;
  1270. }
  1271. set clickHandler(value) {
  1272. this._clickHandler = value;
  1273. }
  1274. get text() {
  1275. this.createText();
  1276. return this._text;
  1277. }
  1278. get sizeGrid() {
  1279. if (this._bitmap.sizeGrid)
  1280. return this._bitmap.sizeGrid.join(",");
  1281. return null;
  1282. }
  1283. set sizeGrid(value) {
  1284. this._bitmap.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
  1285. }
  1286. set width(value) {
  1287. super.set_width(value);
  1288. if (this._autoSize) {
  1289. this._bitmap.width = value;
  1290. this._text && (this._text.width = value);
  1291. }
  1292. }
  1293. get width() {
  1294. return super.get_width();
  1295. }
  1296. set height(value) {
  1297. super.set_height(value);
  1298. if (this._autoSize) {
  1299. this._bitmap.height = value;
  1300. this._text && (this._text.height = value);
  1301. }
  1302. }
  1303. get height() {
  1304. return super.get_height();
  1305. }
  1306. set dataSource(value) {
  1307. this._dataSource = value;
  1308. if (typeof (value) == 'number' || typeof (value) == 'string')
  1309. this.label = value + "";
  1310. else
  1311. super.set_dataSource(value);
  1312. }
  1313. get dataSource() {
  1314. return super.get_dataSource();
  1315. }
  1316. get iconOffset() {
  1317. return this._bitmap._offset ? this._bitmap._offset.join(",") : null;
  1318. }
  1319. set iconOffset(value) {
  1320. if (value)
  1321. this._bitmap._offset = UIUtils.fillArray([1, 1], value, Number);
  1322. else
  1323. this._bitmap._offset = [];
  1324. }
  1325. _setStateChanged() {
  1326. if (!this._stateChanged) {
  1327. this._stateChanged = true;
  1328. this.callLater(this.changeState);
  1329. }
  1330. }
  1331. }
  1332. Button.stateMap = { "mouseup": 0, "mouseover": 1, "mousedown": 2, "mouseout": 0 };
  1333. Laya.ILaya.regClass(Button);
  1334. Laya.ClassUtils.regClass("laya.ui.Button", Button);
  1335. Laya.ClassUtils.regClass("Laya.Button", Button);
  1336. class CheckBox extends Button {
  1337. constructor(skin = null, label = "") {
  1338. super(skin, label);
  1339. this.toggle = true;
  1340. this._autoSize = false;
  1341. }
  1342. preinitialize() {
  1343. super.preinitialize();
  1344. this.toggle = true;
  1345. this._autoSize = false;
  1346. }
  1347. initialize() {
  1348. super.initialize();
  1349. this.createText();
  1350. this._text.align = "left";
  1351. this._text.valign = "top";
  1352. this._text.width = 0;
  1353. }
  1354. set dataSource(value) {
  1355. this._dataSource = value;
  1356. if (value instanceof Boolean)
  1357. this.selected = value;
  1358. else if (typeof (value) == 'string')
  1359. this.selected = value === "true";
  1360. else
  1361. super.dataSource = value;
  1362. }
  1363. get dataSource() {
  1364. return super.dataSource;
  1365. }
  1366. }
  1367. Laya.ILaya.regClass(CheckBox);
  1368. Laya.ClassUtils.regClass("laya.ui.CheckBox", CheckBox);
  1369. Laya.ClassUtils.regClass("Laya.CheckBox", CheckBox);
  1370. class Clip extends UIComponent {
  1371. constructor(url = null, clipX = 1, clipY = 1) {
  1372. super();
  1373. this._clipX = 1;
  1374. this._clipY = 1;
  1375. this._clipWidth = 0;
  1376. this._clipHeight = 0;
  1377. this._interval = 50;
  1378. this._index = 0;
  1379. this._toIndex = -1;
  1380. this._clipX = clipX;
  1381. this._clipY = clipY;
  1382. this.skin = url;
  1383. }
  1384. destroy(destroyChild = true) {
  1385. super.destroy(true);
  1386. this._bitmap && this._bitmap.destroy();
  1387. this._bitmap = null;
  1388. this._sources = null;
  1389. }
  1390. dispose() {
  1391. this.destroy(true);
  1392. Laya.ILaya.loader.clearRes(this._skin);
  1393. }
  1394. createChildren() {
  1395. this.graphics = this._bitmap = new AutoBitmap();
  1396. }
  1397. _onDisplay(e) {
  1398. if (this._isPlaying) {
  1399. if (this._getBit(Laya.Const.DISPLAYED_INSTAGE))
  1400. this.play();
  1401. else
  1402. this.stop();
  1403. }
  1404. else if (this._autoPlay) {
  1405. this.play();
  1406. }
  1407. }
  1408. get skin() {
  1409. return this._skin;
  1410. }
  1411. set skin(value) {
  1412. if (this._skin != value) {
  1413. this._skin = value;
  1414. if (value) {
  1415. if (!Laya.Loader.getRes(value)) {
  1416. Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
  1417. }
  1418. else {
  1419. this._skinLoaded();
  1420. }
  1421. }
  1422. else {
  1423. this._bitmap.source = null;
  1424. }
  1425. }
  1426. }
  1427. _skinLoaded() {
  1428. this._setClipChanged();
  1429. this._sizeChanged();
  1430. this.event(Laya.Event.LOADED);
  1431. }
  1432. get clipX() {
  1433. return this._clipX;
  1434. }
  1435. set clipX(value) {
  1436. this._clipX = value || 1;
  1437. this._setClipChanged();
  1438. }
  1439. get clipY() {
  1440. return this._clipY;
  1441. }
  1442. set clipY(value) {
  1443. this._clipY = value || 1;
  1444. this._setClipChanged();
  1445. }
  1446. get clipWidth() {
  1447. return this._clipWidth;
  1448. }
  1449. set clipWidth(value) {
  1450. this._clipWidth = value;
  1451. this._setClipChanged();
  1452. }
  1453. get clipHeight() {
  1454. return this._clipHeight;
  1455. }
  1456. set clipHeight(value) {
  1457. this._clipHeight = value;
  1458. this._setClipChanged();
  1459. }
  1460. changeClip() {
  1461. this._clipChanged = false;
  1462. if (!this._skin)
  1463. return;
  1464. var img = Laya.Loader.getRes(this._skin);
  1465. if (img) {
  1466. this.loadComplete(this._skin, img);
  1467. }
  1468. else {
  1469. Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this.loadComplete, [this._skin]));
  1470. }
  1471. }
  1472. loadComplete(url, img) {
  1473. if (url === this._skin && img) {
  1474. var w = this._clipWidth || Math.ceil(img.sourceWidth / this._clipX);
  1475. var h = this._clipHeight || Math.ceil(img.sourceHeight / this._clipY);
  1476. var key = this._skin + w + h;
  1477. var clips = Laya.WeakObject.I.get(key);
  1478. if (!Laya.Utils.isOkTextureList(clips)) {
  1479. clips = null;
  1480. }
  1481. if (clips)
  1482. this._sources = clips;
  1483. else {
  1484. this._sources = [];
  1485. for (var i = 0; i < this._clipY; i++) {
  1486. for (var j = 0; j < this._clipX; j++) {
  1487. this._sources.push(Laya.Texture.createFromTexture(img, w * j, h * i, w, h));
  1488. }
  1489. }
  1490. Laya.WeakObject.I.set(key, this._sources);
  1491. }
  1492. this.index = this._index;
  1493. this.event(Laya.Event.LOADED);
  1494. this.onCompResize();
  1495. }
  1496. }
  1497. get sources() {
  1498. return this._sources;
  1499. }
  1500. set sources(value) {
  1501. this._sources = value;
  1502. this.index = this._index;
  1503. this.event(Laya.Event.LOADED);
  1504. }
  1505. get group() {
  1506. return this._group;
  1507. }
  1508. set group(value) {
  1509. if (value && this._skin)
  1510. Laya.Loader.setGroup(this._skin, value);
  1511. this._group = value;
  1512. }
  1513. set width(value) {
  1514. super.width = value;
  1515. this._bitmap.width = value;
  1516. }
  1517. get width() {
  1518. return super.width;
  1519. }
  1520. set height(value) {
  1521. super.height = value;
  1522. this._bitmap.height = value;
  1523. }
  1524. get height() {
  1525. return super.height;
  1526. }
  1527. measureWidth() {
  1528. this.runCallLater(this.changeClip);
  1529. return this._bitmap.width;
  1530. }
  1531. measureHeight() {
  1532. this.runCallLater(this.changeClip);
  1533. return this._bitmap.height;
  1534. }
  1535. get sizeGrid() {
  1536. if (this._bitmap.sizeGrid)
  1537. return this._bitmap.sizeGrid.join(",");
  1538. return null;
  1539. }
  1540. set sizeGrid(value) {
  1541. this._bitmap.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
  1542. }
  1543. get index() {
  1544. return this._index;
  1545. }
  1546. set index(value) {
  1547. this._index = value;
  1548. this._bitmap && this._sources && (this._bitmap.source = this._sources[value]);
  1549. this.event(Laya.Event.CHANGE);
  1550. }
  1551. get total() {
  1552. this.runCallLater(this.changeClip);
  1553. return this._sources ? this._sources.length : 0;
  1554. }
  1555. get autoPlay() {
  1556. return this._autoPlay;
  1557. }
  1558. set autoPlay(value) {
  1559. if (this._autoPlay != value) {
  1560. this._autoPlay = value;
  1561. value ? this.play() : this.stop();
  1562. }
  1563. }
  1564. get interval() {
  1565. return this._interval;
  1566. }
  1567. set interval(value) {
  1568. if (this._interval != value) {
  1569. this._interval = value;
  1570. if (this._isPlaying)
  1571. this.play();
  1572. }
  1573. }
  1574. get isPlaying() {
  1575. return this._isPlaying;
  1576. }
  1577. set isPlaying(value) {
  1578. this._isPlaying = value;
  1579. }
  1580. play(from = 0, to = -1) {
  1581. this._isPlaying = true;
  1582. this.index = from;
  1583. this._toIndex = to;
  1584. this._index++;
  1585. Laya.ILaya.timer.loop(this.interval, this, this._loop);
  1586. this.on(Laya.Event.DISPLAY, this, this._onDisplay);
  1587. this.on(Laya.Event.UNDISPLAY, this, this._onDisplay);
  1588. }
  1589. _loop() {
  1590. if (this._visible && this._sources) {
  1591. this._index++;
  1592. if (this._toIndex > -1 && this._index >= this._toIndex)
  1593. this.stop();
  1594. else if (this._index >= this._sources.length)
  1595. this._index = 0;
  1596. this.index = this._index;
  1597. }
  1598. }
  1599. stop() {
  1600. this._isPlaying = false;
  1601. Laya.ILaya.timer.clear(this, this._loop);
  1602. this.event(Laya.Event.COMPLETE);
  1603. }
  1604. set dataSource(value) {
  1605. this._dataSource = value;
  1606. if (typeof (value) == 'number' || typeof (value) == 'string')
  1607. this.index = parseInt(value);
  1608. else
  1609. super.dataSource = value;
  1610. }
  1611. get dataSource() {
  1612. return super.dataSource;
  1613. }
  1614. get bitmap() {
  1615. return this._bitmap;
  1616. }
  1617. _setClipChanged() {
  1618. if (!this._clipChanged) {
  1619. this._clipChanged = true;
  1620. this.callLater(this.changeClip);
  1621. }
  1622. }
  1623. }
  1624. Laya.ILaya.regClass(Clip);
  1625. Laya.ClassUtils.regClass("laya.ui.Clip", Clip);
  1626. Laya.ClassUtils.regClass("Laya.Clip", Clip);
  1627. class ColorPicker extends UIComponent {
  1628. constructor(createChildren = true) {
  1629. super(false);
  1630. this._gridSize = 11;
  1631. this._bgColor = "#ffffff";
  1632. this._borderColor = "#000000";
  1633. this._inputColor = "#000000";
  1634. this._inputBgColor = "#efefef";
  1635. this._colors = [];
  1636. this._selectedColor = "#000000";
  1637. if (createChildren) {
  1638. this.preinitialize();
  1639. this.createChildren();
  1640. this.initialize();
  1641. }
  1642. }
  1643. destroy(destroyChild = true) {
  1644. Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this.removeColorBox);
  1645. super.destroy(destroyChild);
  1646. this._colorPanel && this._colorPanel.destroy(destroyChild);
  1647. this._colorButton && this._colorButton.destroy(destroyChild);
  1648. this._colorPanel = null;
  1649. this._colorTiles = null;
  1650. this._colorBlock = null;
  1651. this._colorInput = null;
  1652. this._colorButton = null;
  1653. this._colors = null;
  1654. this.changeHandler = null;
  1655. }
  1656. createChildren() {
  1657. this.addChild(this._colorButton = new Button());
  1658. this._colorPanel = new Box();
  1659. this._colorPanel.size(230, 166);
  1660. this._colorPanel.addChild(this._colorTiles = new Laya.Sprite());
  1661. this._colorPanel.addChild(this._colorBlock = new Laya.Sprite());
  1662. this._colorPanel.addChild(this._colorInput = new Laya.Input());
  1663. }
  1664. initialize() {
  1665. this._colorButton.on(Laya.Event.CLICK, this, this.onColorButtonClick);
  1666. this._colorBlock.pos(5, 5);
  1667. this._colorInput.pos(60, 5);
  1668. this._colorInput.size(60, 20);
  1669. this._colorInput.on(Laya.Event.CHANGE, this, this.onColorInputChange);
  1670. this._colorInput.on(Laya.Event.KEY_DOWN, this, this.onColorFieldKeyDown);
  1671. this._colorTiles.pos(5, 30);
  1672. this._colorTiles.on(Laya.Event.MOUSE_MOVE, this, this.onColorTilesMouseMove);
  1673. this._colorTiles.on(Laya.Event.CLICK, this, this.onColorTilesClick);
  1674. this._colorTiles.size(20 * this._gridSize, 12 * this._gridSize);
  1675. this._colorPanel.on(Laya.Event.MOUSE_DOWN, this, this.onPanelMouseDown);
  1676. this.bgColor = this._bgColor;
  1677. }
  1678. onPanelMouseDown(e) {
  1679. e.stopPropagation();
  1680. }
  1681. changePanel() {
  1682. this._panelChanged = false;
  1683. var g = this._colorPanel.graphics;
  1684. g.clear(true);
  1685. g.drawRect(0, 0, 230, 166, this._bgColor, this._borderColor);
  1686. this.drawBlock(this._selectedColor);
  1687. this._colorInput.borderColor = this._borderColor;
  1688. this._colorInput.bgColor = this._inputBgColor;
  1689. this._colorInput.color = this._inputColor;
  1690. g = this._colorTiles.graphics;
  1691. g.clear(true);
  1692. var mainColors = [0x000000, 0x333333, 0x666666, 0x999999, 0xCCCCCC, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF];
  1693. for (var i = 0; i < 12; i++) {
  1694. for (var j = 0; j < 20; j++) {
  1695. var color;
  1696. if (j === 0)
  1697. color = mainColors[i];
  1698. else if (j === 1)
  1699. color = 0x000000;
  1700. else
  1701. color = (((i * 3 + j / 6) % 3 << 0) + ((i / 6) << 0) * 3) * 0x33 << 16 | j % 6 * 0x33 << 8 | (i << 0) % 6 * 0x33;
  1702. var strColor = UIUtils.toColor(color);
  1703. this._colors.push(strColor);
  1704. var x = j * this._gridSize;
  1705. var y = i * this._gridSize;
  1706. g.drawRect(x, y, this._gridSize, this._gridSize, strColor, "#000000");
  1707. }
  1708. }
  1709. }
  1710. onColorButtonClick(e) {
  1711. if (this._colorPanel.parent)
  1712. this.close();
  1713. else
  1714. this.open();
  1715. }
  1716. open() {
  1717. let stage = Laya.ILaya.stage;
  1718. var p = this.localToGlobal(new Laya.Point());
  1719. var px = p.x + this._colorPanel.width <= stage.width ? p.x : stage.width - this._colorPanel.width;
  1720. var py = p.y + this._colorButton.height;
  1721. py = py + this._colorPanel.height <= stage.height ? py : p.y - this._colorPanel.height;
  1722. this._colorPanel.pos(px, py);
  1723. this._colorPanel.zOrder = 1001;
  1724. stage.addChild(this._colorPanel);
  1725. stage.on(Laya.Event.MOUSE_DOWN, this, this.removeColorBox);
  1726. }
  1727. close() {
  1728. Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this.removeColorBox);
  1729. this._colorPanel.removeSelf();
  1730. }
  1731. removeColorBox(e = null) {
  1732. this.close();
  1733. }
  1734. onColorFieldKeyDown(e) {
  1735. if (e.keyCode == 13) {
  1736. if (this._colorInput.text)
  1737. this.selectedColor = this._colorInput.text;
  1738. else
  1739. this.selectedColor = null;
  1740. this.close();
  1741. e.stopPropagation();
  1742. }
  1743. }
  1744. onColorInputChange(e = null) {
  1745. if (this._colorInput.text)
  1746. this.drawBlock(this._colorInput.text);
  1747. else
  1748. this.drawBlock("#FFFFFF");
  1749. }
  1750. onColorTilesClick(e) {
  1751. this.selectedColor = this.getColorByMouse();
  1752. this.close();
  1753. }
  1754. onColorTilesMouseMove(e) {
  1755. this._colorInput.focus = false;
  1756. var color = this.getColorByMouse();
  1757. this._colorInput.text = color;
  1758. this.drawBlock(color);
  1759. }
  1760. getColorByMouse() {
  1761. var point = this._colorTiles.getMousePoint();
  1762. var x = Math.floor(point.x / this._gridSize);
  1763. var y = Math.floor(point.y / this._gridSize);
  1764. return this._colors[y * 20 + x];
  1765. }
  1766. drawBlock(color) {
  1767. var g = this._colorBlock.graphics;
  1768. g.clear(true);
  1769. var showColor = color ? color : "#ffffff";
  1770. g.drawRect(0, 0, 50, 20, showColor, this._borderColor);
  1771. color || g.drawLine(0, 0, 50, 20, "#ff0000");
  1772. }
  1773. get selectedColor() {
  1774. return this._selectedColor;
  1775. }
  1776. set selectedColor(value) {
  1777. if (this._selectedColor != value) {
  1778. this._selectedColor = this._colorInput.text = value;
  1779. this.drawBlock(value);
  1780. this.changeColor();
  1781. this.changeHandler && this.changeHandler.runWith(this._selectedColor);
  1782. this.event(Laya.Event.CHANGE, Laya.Event.EMPTY.setTo(Laya.Event.CHANGE, this, this));
  1783. }
  1784. }
  1785. get skin() {
  1786. return this._colorButton.skin;
  1787. }
  1788. set skin(value) {
  1789. this._colorButton.once(Laya.Event.LOADED, this, this.changeColor);
  1790. this._colorButton.skin = value;
  1791. }
  1792. changeColor() {
  1793. var g = this.graphics;
  1794. g.clear(true);
  1795. var showColor = this._selectedColor || "#000000";
  1796. g.drawRect(0, 0, this._colorButton.width, this._colorButton.height, showColor);
  1797. }
  1798. get bgColor() {
  1799. return this._bgColor;
  1800. }
  1801. set bgColor(value) {
  1802. this._bgColor = value;
  1803. this._setPanelChanged();
  1804. }
  1805. get borderColor() {
  1806. return this._borderColor;
  1807. }
  1808. set borderColor(value) {
  1809. this._borderColor = value;
  1810. this._setPanelChanged();
  1811. }
  1812. get inputColor() {
  1813. return this._inputColor;
  1814. }
  1815. set inputColor(value) {
  1816. this._inputColor = value;
  1817. this._setPanelChanged();
  1818. }
  1819. get inputBgColor() {
  1820. return this._inputBgColor;
  1821. }
  1822. set inputBgColor(value) {
  1823. this._inputBgColor = value;
  1824. this._setPanelChanged();
  1825. }
  1826. _setPanelChanged() {
  1827. if (!this._panelChanged) {
  1828. this._panelChanged = true;
  1829. this.callLater(this.changePanel);
  1830. }
  1831. }
  1832. }
  1833. Laya.ILaya.regClass(ColorPicker);
  1834. Laya.ClassUtils.regClass("laya.ui.ColorPicker", ColorPicker);
  1835. Laya.ClassUtils.regClass("Laya.ColorPicker", ColorPicker);
  1836. class Label extends UIComponent {
  1837. constructor(text = "") {
  1838. super();
  1839. this.text = text;
  1840. }
  1841. destroy(destroyChild = true) {
  1842. super.destroy(destroyChild);
  1843. this._tf = null;
  1844. }
  1845. createChildren() {
  1846. this.addChild(this._tf = new Laya.Text());
  1847. }
  1848. get text() {
  1849. return this._tf.text;
  1850. }
  1851. set text(value) {
  1852. if (this._tf.text != value) {
  1853. if (value)
  1854. value = UIUtils.adptString(value + "");
  1855. this._tf.text = value;
  1856. this.event(Laya.Event.CHANGE);
  1857. if (!this._width || !this._height)
  1858. this.onCompResize();
  1859. }
  1860. }
  1861. changeText(text) {
  1862. this._tf.changeText(text);
  1863. }
  1864. get wordWrap() {
  1865. return this._tf.wordWrap;
  1866. }
  1867. set wordWrap(value) {
  1868. this._tf.wordWrap = value;
  1869. }
  1870. get color() {
  1871. return this._tf.color;
  1872. }
  1873. set color(value) {
  1874. this._tf.color = value;
  1875. }
  1876. get font() {
  1877. return this._tf.font;
  1878. }
  1879. set font(value) {
  1880. this._tf.font = value;
  1881. }
  1882. get align() {
  1883. return this._tf.align;
  1884. }
  1885. set align(value) {
  1886. this._tf.align = value;
  1887. }
  1888. get valign() {
  1889. return this._tf.valign;
  1890. }
  1891. set valign(value) {
  1892. this._tf.valign = value;
  1893. }
  1894. get bold() {
  1895. return this._tf.bold;
  1896. }
  1897. set bold(value) {
  1898. this._tf.bold = value;
  1899. }
  1900. get italic() {
  1901. return this._tf.italic;
  1902. }
  1903. set italic(value) {
  1904. this._tf.italic = value;
  1905. }
  1906. get leading() {
  1907. return this._tf.leading;
  1908. }
  1909. set leading(value) {
  1910. this._tf.leading = value;
  1911. }
  1912. get fontSize() {
  1913. return this._tf.fontSize;
  1914. }
  1915. set fontSize(value) {
  1916. this._tf.fontSize = value;
  1917. }
  1918. get padding() {
  1919. return this._tf.padding.join(",");
  1920. }
  1921. set padding(value) {
  1922. this._tf.padding = UIUtils.fillArray(Styles.labelPadding, value, Number);
  1923. }
  1924. get bgColor() {
  1925. return this._tf.bgColor;
  1926. }
  1927. set bgColor(value) {
  1928. this._tf.bgColor = value;
  1929. }
  1930. get borderColor() {
  1931. return this._tf.borderColor;
  1932. }
  1933. set borderColor(value) {
  1934. this._tf.borderColor = value;
  1935. }
  1936. get stroke() {
  1937. return this._tf.stroke;
  1938. }
  1939. set stroke(value) {
  1940. this._tf.stroke = value;
  1941. }
  1942. get strokeColor() {
  1943. return this._tf.strokeColor;
  1944. }
  1945. set strokeColor(value) {
  1946. this._tf.strokeColor = value;
  1947. }
  1948. get textField() {
  1949. return this._tf;
  1950. }
  1951. measureWidth() {
  1952. return this._tf.width;
  1953. }
  1954. measureHeight() {
  1955. return this._tf.height;
  1956. }
  1957. get width() {
  1958. if (this._width || this._tf.text)
  1959. return super.width;
  1960. return 0;
  1961. }
  1962. set width(value) {
  1963. super.width = value;
  1964. this._tf.width = value;
  1965. }
  1966. get height() {
  1967. if (this._height || this._tf.text)
  1968. return super.height;
  1969. return 0;
  1970. }
  1971. set height(value) {
  1972. super.height = value;
  1973. this._tf.height = value;
  1974. }
  1975. set dataSource(value) {
  1976. this._dataSource = value;
  1977. if (typeof (value) == 'number' || typeof (value) == 'string')
  1978. this.text = value + "";
  1979. else
  1980. super.dataSource = value;
  1981. }
  1982. get dataSource() {
  1983. return super.dataSource;
  1984. }
  1985. get overflow() {
  1986. return this._tf.overflow;
  1987. }
  1988. set overflow(value) {
  1989. this._tf.overflow = value;
  1990. }
  1991. get underline() {
  1992. return this._tf.underline;
  1993. }
  1994. set underline(value) {
  1995. this._tf.underline = value;
  1996. }
  1997. get underlineColor() {
  1998. return this._tf.underlineColor;
  1999. }
  2000. set underlineColor(value) {
  2001. this._tf.underlineColor = value;
  2002. }
  2003. }
  2004. Laya.ILaya.regClass(Label);
  2005. Laya.ClassUtils.regClass("laya.ui.Label", Label);
  2006. Laya.ClassUtils.regClass("Laya.Label", Label);
  2007. class Slider extends UIComponent {
  2008. constructor(skin = null) {
  2009. super();
  2010. this.isVertical = true;
  2011. this.showLabel = true;
  2012. this._max = 100;
  2013. this._min = 0;
  2014. this._tick = 1;
  2015. this._value = 0;
  2016. if (!Slider.label) {
  2017. Slider.label = new Label();
  2018. }
  2019. this.skin = skin;
  2020. }
  2021. destroy(destroyChild = true) {
  2022. super.destroy(destroyChild);
  2023. this._bg && this._bg.destroy(destroyChild);
  2024. this._bar && this._bar.destroy(destroyChild);
  2025. this._progress && this._progress.destroy(destroyChild);
  2026. this._bg = null;
  2027. this._bar = null;
  2028. this._progress = null;
  2029. this.changeHandler = null;
  2030. }
  2031. createChildren() {
  2032. this.addChild(this._bg = new Image());
  2033. this.addChild(this._bar = new Button());
  2034. }
  2035. initialize() {
  2036. this._bar.on(Laya.Event.MOUSE_DOWN, this, this.onBarMouseDown);
  2037. this._bg.sizeGrid = this._bar.sizeGrid = "4,4,4,4,0";
  2038. if (this._progress)
  2039. this._progress.sizeGrid = this._bar.sizeGrid;
  2040. this.allowClickBack = true;
  2041. }
  2042. onBarMouseDown(e) {
  2043. var Laya$1 = Laya.ILaya;
  2044. this._globalSacle || (this._globalSacle = new Laya.Point());
  2045. this._globalSacle.setTo(this.globalScaleX || 0.01, this.globalScaleY || 0.01);
  2046. this._maxMove = this.isVertical ? (this.height - this._bar.height) : (this.width - this._bar.width);
  2047. this._tx = Laya$1.stage.mouseX;
  2048. this._ty = Laya$1.stage.mouseY;
  2049. Laya$1.stage.on(Laya.Event.MOUSE_MOVE, this, this.mouseMove);
  2050. Laya$1.stage.once(Laya.Event.MOUSE_UP, this, this.mouseUp);
  2051. Laya$1.stage.once(Laya.Event.MOUSE_OUT, this, this.mouseUp);
  2052. this.showValueText();
  2053. }
  2054. showValueText() {
  2055. if (this.showLabel) {
  2056. var label = Slider.label;
  2057. this.addChild(label);
  2058. label.textField.changeText(this._value + "");
  2059. if (this.isVertical) {
  2060. label.x = this._bar._x + 20;
  2061. label.y = (this._bar.height - label.height) * 0.5 + this._bar._y;
  2062. }
  2063. else {
  2064. label.y = this._bar._y - 20;
  2065. label.x = (this._bar.width - label.width) * 0.5 + this._bar._x;
  2066. }
  2067. }
  2068. }
  2069. hideValueText() {
  2070. Slider.label && Slider.label.removeSelf();
  2071. }
  2072. mouseUp(e) {
  2073. let stage = Laya.ILaya.stage;
  2074. stage.off(Laya.Event.MOUSE_MOVE, this, this.mouseMove);
  2075. stage.off(Laya.Event.MOUSE_UP, this, this.mouseUp);
  2076. stage.off(Laya.Event.MOUSE_OUT, this, this.mouseUp);
  2077. this.sendChangeEvent(Laya.Event.CHANGED);
  2078. this.hideValueText();
  2079. }
  2080. mouseMove(e) {
  2081. let stage = Laya.ILaya.stage;
  2082. var oldValue = this._value;
  2083. if (this.isVertical) {
  2084. this._bar.y += (stage.mouseY - this._ty) / this._globalSacle.y;
  2085. if (this._bar._y > this._maxMove)
  2086. this._bar.y = this._maxMove;
  2087. else if (this._bar._y < 0)
  2088. this._bar.y = 0;
  2089. this._value = this._bar._y / this._maxMove * (this._max - this._min) + this._min;
  2090. if (this._progress)
  2091. this._progress.height = this._bar._y + 0.5 * this._bar.height;
  2092. }
  2093. else {
  2094. this._bar.x += (stage.mouseX - this._tx) / this._globalSacle.x;
  2095. if (this._bar._x > this._maxMove)
  2096. this._bar.x = this._maxMove;
  2097. else if (this._bar._x < 0)
  2098. this._bar.x = 0;
  2099. this._value = this._bar._x / this._maxMove * (this._max - this._min) + this._min;
  2100. if (this._progress)
  2101. this._progress.width = this._bar._x + 0.5 * this._bar.width;
  2102. }
  2103. this._tx = stage.mouseX;
  2104. this._ty = stage.mouseY;
  2105. if (this._tick != 0) {
  2106. var pow = Math.pow(10, (this._tick + "").length - 1);
  2107. this._value = Math.round(Math.round(this._value / this._tick) * this._tick * pow) / pow;
  2108. }
  2109. if (this._value != oldValue) {
  2110. this.sendChangeEvent();
  2111. }
  2112. this.showValueText();
  2113. }
  2114. sendChangeEvent(type = Laya.Event.CHANGE) {
  2115. this.event(type);
  2116. this.changeHandler && this.changeHandler.runWith(this._value);
  2117. }
  2118. get skin() {
  2119. return this._skin;
  2120. }
  2121. set skin(value) {
  2122. if (this._skin != value) {
  2123. this._skin = value;
  2124. if (this._skin && !Laya.Loader.getRes(this._skin)) {
  2125. Laya.ILaya.loader.load([this._skin, this._skin.replace(".png", "$bar.png")], Laya.Handler.create(this, this._skinLoaded));
  2126. }
  2127. else {
  2128. this._skinLoaded();
  2129. }
  2130. }
  2131. }
  2132. _skinLoaded() {
  2133. this._bg.skin = this._skin;
  2134. this._bar.skin = this._skin.replace(".png", "$bar.png");
  2135. var progressSkin = this._skin.replace(".png", "$progress.png");
  2136. if (Laya.Loader.getRes(progressSkin)) {
  2137. if (!this._progress) {
  2138. this.addChild(this._progress = new Image());
  2139. this._progress.sizeGrid = this._bar.sizeGrid;
  2140. this.setChildIndex(this._progress, 1);
  2141. }
  2142. this._progress.skin = progressSkin;
  2143. }
  2144. this.setBarPoint();
  2145. this.callLater(this.changeValue);
  2146. this._sizeChanged();
  2147. this.event(Laya.Event.LOADED);
  2148. }
  2149. setBarPoint() {
  2150. if (this.isVertical)
  2151. this._bar.x = Math.round((this._bg.width - this._bar.width) * 0.5);
  2152. else
  2153. this._bar.y = Math.round((this._bg.height - this._bar.height) * 0.5);
  2154. }
  2155. measureWidth() {
  2156. return Math.max(this._bg.width, this._bar.width);
  2157. }
  2158. measureHeight() {
  2159. return Math.max(this._bg.height, this._bar.height);
  2160. }
  2161. _sizeChanged() {
  2162. super._sizeChanged();
  2163. if (this.isVertical)
  2164. this._bg.height = this.height;
  2165. else
  2166. this._bg.width = this.width;
  2167. this.setBarPoint();
  2168. this.changeValue();
  2169. }
  2170. get sizeGrid() {
  2171. return this._bg.sizeGrid;
  2172. }
  2173. set sizeGrid(value) {
  2174. this._bg.sizeGrid = value;
  2175. this._bar.sizeGrid = value;
  2176. if (this._progress)
  2177. this._progress.sizeGrid = this._bar.sizeGrid;
  2178. }
  2179. setSlider(min, max, value) {
  2180. this._value = -1;
  2181. this._min = min;
  2182. this._max = max > min ? max : min;
  2183. this.value = value < min ? min : value > max ? max : value;
  2184. }
  2185. get tick() {
  2186. return this._tick;
  2187. }
  2188. set tick(value) {
  2189. if (this._tick != value) {
  2190. this._tick = value;
  2191. this.callLater(this.changeValue);
  2192. }
  2193. }
  2194. changeValue() {
  2195. if (this.tick != 0) {
  2196. var pow = Math.pow(10, (this._tick + "").length - 1);
  2197. this._value = Math.round(Math.round(this._value / this._tick) * this._tick * pow) / pow;
  2198. }
  2199. this._value = this._value > this._max ? this._max : this._value < this._min ? this._min : this._value;
  2200. var num = this._max - this._min;
  2201. if (num === 0)
  2202. num = 1;
  2203. if (this.isVertical) {
  2204. this._bar.y = (this._value - this._min) / num * (this.height - this._bar.height);
  2205. if (this._progress)
  2206. this._progress.height = this._bar._y + 0.5 * this._bar.height;
  2207. }
  2208. else {
  2209. this._bar.x = (this._value - this._min) / num * (this.width - this._bar.width);
  2210. if (this._progress)
  2211. this._progress.width = this._bar._x + 0.5 * this._bar.width;
  2212. }
  2213. }
  2214. get max() {
  2215. return this._max;
  2216. }
  2217. set max(value) {
  2218. if (this._max != value) {
  2219. this._max = value;
  2220. this.callLater(this.changeValue);
  2221. }
  2222. }
  2223. get min() {
  2224. return this._min;
  2225. }
  2226. set min(value) {
  2227. if (this._min != value) {
  2228. this._min = value;
  2229. this.callLater(this.changeValue);
  2230. }
  2231. }
  2232. get value() {
  2233. return this._value;
  2234. }
  2235. set value(num) {
  2236. if (this._value != num) {
  2237. var oldValue = this._value;
  2238. this._value = num;
  2239. this.changeValue();
  2240. if (this._value != oldValue) {
  2241. this.sendChangeEvent();
  2242. }
  2243. }
  2244. }
  2245. get allowClickBack() {
  2246. return this._allowClickBack;
  2247. }
  2248. set allowClickBack(value) {
  2249. if (this._allowClickBack != value) {
  2250. this._allowClickBack = value;
  2251. if (value)
  2252. this._bg.on(Laya.Event.MOUSE_DOWN, this, this.onBgMouseDown);
  2253. else
  2254. this._bg.off(Laya.Event.MOUSE_DOWN, this, this.onBgMouseDown);
  2255. }
  2256. }
  2257. onBgMouseDown(e) {
  2258. var point = this._bg.getMousePoint();
  2259. if (this.isVertical)
  2260. this.value = point.y / (this.height - this._bar.height) * (this._max - this._min) + this._min;
  2261. else
  2262. this.value = point.x / (this.width - this._bar.width) * (this._max - this._min) + this._min;
  2263. }
  2264. set dataSource(value) {
  2265. this._dataSource = value;
  2266. if (typeof (value) == 'number' || typeof (value) == 'string')
  2267. this.value = Number(value);
  2268. else
  2269. super.dataSource = value;
  2270. }
  2271. get dataSource() {
  2272. return super.dataSource;
  2273. }
  2274. get bar() {
  2275. return this._bar;
  2276. }
  2277. }
  2278. Slider.label = null;
  2279. Laya.ILaya.regClass(Slider);
  2280. Laya.ClassUtils.regClass("laya.ui.Slider", Slider);
  2281. Laya.ClassUtils.regClass("Laya.Slider", Slider);
  2282. class ScrollBar extends UIComponent {
  2283. constructor(skin = null) {
  2284. super();
  2285. this.rollRatio = 0.97;
  2286. this.scaleBar = true;
  2287. this.autoHide = false;
  2288. this.elasticDistance = 0;
  2289. this.elasticBackTime = 500;
  2290. this._showButtons = UIConfig.showButtons;
  2291. this._scrollSize = 1;
  2292. this._thumbPercent = 1;
  2293. this._lastOffset = 0;
  2294. this._checkElastic = false;
  2295. this._isElastic = false;
  2296. this._hide = false;
  2297. this._clickOnly = true;
  2298. this._touchScrollEnable = UIConfig.touchScrollEnable;
  2299. this._mouseWheelEnable = UIConfig.mouseWheelEnable;
  2300. this.skin = skin;
  2301. this.max = 1;
  2302. }
  2303. destroy(destroyChild = true) {
  2304. this.stopScroll();
  2305. this.target = null;
  2306. super.destroy(destroyChild);
  2307. this.upButton && this.upButton.destroy(destroyChild);
  2308. this.downButton && this.downButton.destroy(destroyChild);
  2309. this.slider && this.slider.destroy(destroyChild);
  2310. this.upButton = this.downButton = null;
  2311. this.slider = null;
  2312. this.changeHandler = null;
  2313. this._offsets = null;
  2314. }
  2315. createChildren() {
  2316. this.addChild(this.slider = new Slider());
  2317. this.addChild(this.upButton = new Button());
  2318. this.addChild(this.downButton = new Button());
  2319. }
  2320. initialize() {
  2321. this.slider.showLabel = false;
  2322. this.slider.tick = 0;
  2323. this.slider.on(Laya.Event.CHANGE, this, this.onSliderChange);
  2324. this.slider.setSlider(0, 0, 0);
  2325. this.upButton.on(Laya.Event.MOUSE_DOWN, this, this.onButtonMouseDown);
  2326. this.downButton.on(Laya.Event.MOUSE_DOWN, this, this.onButtonMouseDown);
  2327. }
  2328. onSliderChange() {
  2329. if (this._value != this.slider.value)
  2330. this.value = this.slider.value;
  2331. }
  2332. onButtonMouseDown(e) {
  2333. var isUp = e.currentTarget === this.upButton;
  2334. this.slide(isUp);
  2335. Laya.ILaya.timer.once(Styles.scrollBarDelayTime, this, this.startLoop, [isUp]);
  2336. Laya.ILaya.stage.once(Laya.Event.MOUSE_UP, this, this.onStageMouseUp);
  2337. }
  2338. startLoop(isUp) {
  2339. Laya.ILaya.timer.frameLoop(1, this, this.slide, [isUp]);
  2340. }
  2341. slide(isUp) {
  2342. if (isUp)
  2343. this.value -= this._scrollSize;
  2344. else
  2345. this.value += this._scrollSize;
  2346. }
  2347. onStageMouseUp(e) {
  2348. Laya.ILaya.timer.clear(this, this.startLoop);
  2349. Laya.ILaya.timer.clear(this, this.slide);
  2350. }
  2351. get skin() {
  2352. return this._skin;
  2353. }
  2354. set skin(value) {
  2355. if (value == " ")
  2356. return;
  2357. if (this._skin != value) {
  2358. this._skin = value;
  2359. if (this._skin && !Laya.Loader.getRes(this._skin)) {
  2360. Laya.ILaya.loader.load([this._skin, this._skin.replace(".png", "$up.png"), this._skin.replace(".png", "$down.png"), this._skin.replace(".png", "$bar.png")], Laya.Handler.create(this, this._skinLoaded));
  2361. }
  2362. else {
  2363. this._skinLoaded();
  2364. }
  2365. }
  2366. }
  2367. _skinLoaded() {
  2368. this.slider.skin = this._skin;
  2369. this.callLater(this.changeScrollBar);
  2370. this._sizeChanged();
  2371. this.event(Laya.Event.LOADED);
  2372. }
  2373. changeScrollBar() {
  2374. this.upButton.visible = this._showButtons;
  2375. this.downButton.visible = this._showButtons;
  2376. if (this._showButtons) {
  2377. this.upButton.skin = this._skin.replace(".png", "$up.png");
  2378. this.downButton.skin = this._skin.replace(".png", "$down.png");
  2379. }
  2380. if (this.slider.isVertical)
  2381. this.slider.y = this._showButtons ? this.upButton.height : 0;
  2382. else
  2383. this.slider.x = this._showButtons ? this.upButton.width : 0;
  2384. this.resetPositions();
  2385. this.repaint();
  2386. }
  2387. _sizeChanged() {
  2388. super._sizeChanged();
  2389. this.repaint();
  2390. this.resetPositions();
  2391. this.event(Laya.Event.CHANGE);
  2392. this.changeHandler && this.changeHandler.runWith(this.value);
  2393. }
  2394. resetPositions() {
  2395. if (this.slider.isVertical)
  2396. this.slider.height = this.height - (this._showButtons ? (this.upButton.height + this.downButton.height) : 0);
  2397. else
  2398. this.slider.width = this.width - (this._showButtons ? (this.upButton.width + this.downButton.width) : 0);
  2399. this.resetButtonPosition();
  2400. }
  2401. resetButtonPosition() {
  2402. if (this.slider.isVertical)
  2403. this.downButton.y = this.slider._y + this.slider.height;
  2404. else
  2405. this.downButton.x = this.slider._x + this.slider.width;
  2406. }
  2407. measureWidth() {
  2408. if (this.slider.isVertical)
  2409. return this.slider.width;
  2410. return 100;
  2411. }
  2412. measureHeight() {
  2413. if (this.slider.isVertical)
  2414. return 100;
  2415. return this.slider.height;
  2416. }
  2417. setScroll(min, max, value) {
  2418. this.runCallLater(this._sizeChanged);
  2419. this.slider.setSlider(min, max, value);
  2420. this.slider.bar.visible = max > 0;
  2421. if (!this._hide && this.autoHide)
  2422. this.visible = false;
  2423. }
  2424. get max() {
  2425. return this.slider.max;
  2426. }
  2427. set max(value) {
  2428. this.slider.max = value;
  2429. }
  2430. get min() {
  2431. return this.slider.min;
  2432. }
  2433. set min(value) {
  2434. this.slider.min = value;
  2435. }
  2436. get value() {
  2437. return this._value;
  2438. }
  2439. set value(v) {
  2440. if (v !== this._value) {
  2441. this._value = v;
  2442. if (!this._isElastic) {
  2443. if (this.slider["_value"] != v) {
  2444. this.slider["_value"] = v;
  2445. this.slider.changeValue();
  2446. }
  2447. this._value = this.slider["_value"];
  2448. }
  2449. this.event(Laya.Event.CHANGE);
  2450. this.changeHandler && this.changeHandler.runWith(this._value);
  2451. }
  2452. }
  2453. get isVertical() {
  2454. return this.slider.isVertical;
  2455. }
  2456. set isVertical(value) {
  2457. this.slider.isVertical = value;
  2458. }
  2459. get sizeGrid() {
  2460. return this.slider.sizeGrid;
  2461. }
  2462. set sizeGrid(value) {
  2463. this.slider.sizeGrid = value;
  2464. }
  2465. get scrollSize() {
  2466. return this._scrollSize;
  2467. }
  2468. set scrollSize(value) {
  2469. this._scrollSize = value;
  2470. }
  2471. set dataSource(value) {
  2472. this._dataSource = value;
  2473. if (typeof (value) == 'number' || typeof (value) == 'string')
  2474. this.value = Number(value);
  2475. else
  2476. super.dataSource = value;
  2477. }
  2478. get dataSource() {
  2479. return super.dataSource;
  2480. }
  2481. get thumbPercent() {
  2482. return this._thumbPercent;
  2483. }
  2484. set thumbPercent(value) {
  2485. this.runCallLater(this.changeScrollBar);
  2486. this.runCallLater(this._sizeChanged);
  2487. value = value >= 1 ? 0.99 : value;
  2488. this._thumbPercent = value;
  2489. if (this.scaleBar) {
  2490. if (this.slider.isVertical)
  2491. this.slider.bar.height = Math.max(this.slider.height * value, Styles.scrollBarMinNum);
  2492. else
  2493. this.slider.bar.width = Math.max(this.slider.width * value, Styles.scrollBarMinNum);
  2494. }
  2495. }
  2496. get target() {
  2497. return this._target;
  2498. }
  2499. set target(value) {
  2500. if (this._target) {
  2501. this._target.off(Laya.Event.MOUSE_WHEEL, this, this.onTargetMouseWheel);
  2502. this._target.off(Laya.Event.MOUSE_DOWN, this, this.onTargetMouseDown);
  2503. }
  2504. this._target = value;
  2505. if (value) {
  2506. this._mouseWheelEnable && this._target.on(Laya.Event.MOUSE_WHEEL, this, this.onTargetMouseWheel);
  2507. this._touchScrollEnable && this._target.on(Laya.Event.MOUSE_DOWN, this, this.onTargetMouseDown);
  2508. }
  2509. }
  2510. get hide() {
  2511. return this._hide;
  2512. }
  2513. set hide(value) {
  2514. this._hide = value;
  2515. this.visible = !value;
  2516. }
  2517. get showButtons() {
  2518. return this._showButtons;
  2519. }
  2520. set showButtons(value) {
  2521. this._showButtons = value;
  2522. this.callLater(this.changeScrollBar);
  2523. }
  2524. get touchScrollEnable() {
  2525. return this._touchScrollEnable;
  2526. }
  2527. set touchScrollEnable(value) {
  2528. this._touchScrollEnable = value;
  2529. this.target = this._target;
  2530. }
  2531. get mouseWheelEnable() {
  2532. return this._mouseWheelEnable;
  2533. }
  2534. set mouseWheelEnable(value) {
  2535. this._mouseWheelEnable = value;
  2536. this.target = this._target;
  2537. }
  2538. onTargetMouseWheel(e) {
  2539. this.value -= e.delta * this._scrollSize;
  2540. this.target = this._target;
  2541. }
  2542. onTargetMouseDown(e) {
  2543. if ((this.isLockedFun) && !this.isLockedFun(e))
  2544. return;
  2545. this.event(Laya.Event.END);
  2546. this._clickOnly = true;
  2547. this._lastOffset = 0;
  2548. this._checkElastic = false;
  2549. this._lastPoint || (this._lastPoint = new Laya.Point());
  2550. this._lastPoint.setTo(Laya.ILaya.stage.mouseX, Laya.ILaya.stage.mouseY);
  2551. Laya.ILaya.timer.clear(this, this.tweenMove);
  2552. Laya.Tween.clearTween(this);
  2553. Laya.ILaya.stage.once(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
  2554. Laya.ILaya.stage.once(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
  2555. Laya.ILaya.timer.frameLoop(1, this, this.loop);
  2556. }
  2557. startDragForce() {
  2558. this._clickOnly = true;
  2559. this._lastOffset = 0;
  2560. this._checkElastic = false;
  2561. this._lastPoint || (this._lastPoint = new Laya.Point());
  2562. this._lastPoint.setTo(Laya.ILaya.stage.mouseX, Laya.ILaya.stage.mouseY);
  2563. Laya.ILaya.timer.clear(this, this.tweenMove);
  2564. Laya.Tween.clearTween(this);
  2565. Laya.ILaya.stage.once(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
  2566. Laya.ILaya.stage.once(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
  2567. Laya.ILaya.timer.frameLoop(1, this, this.loop);
  2568. }
  2569. cancelDragOp() {
  2570. Laya.ILaya.stage.off(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
  2571. Laya.ILaya.stage.off(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
  2572. Laya.ILaya.timer.clear(this, this.tweenMove);
  2573. Laya.ILaya.timer.clear(this, this.loop);
  2574. this._target.mouseEnabled = true;
  2575. }
  2576. checkTriggers(isTweenMove = false) {
  2577. if (this.value >= 0 && this.value - this._lastOffset <= 0) {
  2578. if ((this.triggerDownDragLimit) && this.triggerDownDragLimit(isTweenMove)) {
  2579. this.cancelDragOp();
  2580. this.value = 0;
  2581. return true;
  2582. }
  2583. }
  2584. if (this.value <= this.max && (this.value - this._lastOffset >= this.max)) {
  2585. if ((this.triggerUpDragLimit) && this.triggerUpDragLimit(isTweenMove)) {
  2586. this.cancelDragOp();
  2587. this.value = this.max;
  2588. return true;
  2589. }
  2590. }
  2591. return false;
  2592. }
  2593. get lastOffset() {
  2594. return this._lastOffset;
  2595. }
  2596. startTweenMoveForce(lastOffset) {
  2597. this._lastOffset = lastOffset;
  2598. Laya.ILaya.timer.frameLoop(1, this, this.tweenMove, [200]);
  2599. }
  2600. loop() {
  2601. var mouseY = Laya.ILaya.stage.mouseY;
  2602. var mouseX = Laya.ILaya.stage.mouseX;
  2603. this._lastOffset = this.isVertical ? (mouseY - this._lastPoint.y) : (mouseX - this._lastPoint.x);
  2604. if (this._clickOnly) {
  2605. if (Math.abs(this._lastOffset * (this.isVertical ? Laya.ILaya.stage._canvasTransform.getScaleY() : Laya.ILaya.stage._canvasTransform.getScaleX())) > 1) {
  2606. this._clickOnly = false;
  2607. if (this.checkTriggers())
  2608. return;
  2609. this._offsets || (this._offsets = []);
  2610. this._offsets.length = 0;
  2611. this._target.mouseEnabled = false;
  2612. if (!this.hide && this.autoHide) {
  2613. this.alpha = 1;
  2614. this.visible = true;
  2615. }
  2616. this.event(Laya.Event.START);
  2617. }
  2618. else
  2619. return;
  2620. }
  2621. else {
  2622. if (this.checkTriggers())
  2623. return;
  2624. }
  2625. this._offsets.push(this._lastOffset);
  2626. this._lastPoint.x = mouseX;
  2627. this._lastPoint.y = mouseY;
  2628. if (this._lastOffset === 0)
  2629. return;
  2630. if (!this._checkElastic) {
  2631. if (this.elasticDistance > 0) {
  2632. if (!this._checkElastic && this._lastOffset != 0) {
  2633. if ((this._lastOffset > 0 && this._value <= this.min) || (this._lastOffset < 0 && this._value >= this.max)) {
  2634. this._isElastic = true;
  2635. this._checkElastic = true;
  2636. }
  2637. else {
  2638. this._isElastic = false;
  2639. }
  2640. }
  2641. }
  2642. else {
  2643. this._checkElastic = true;
  2644. }
  2645. }
  2646. if (this._isElastic) {
  2647. if (this._value <= this.min) {
  2648. if (this._lastOffset > 0) {
  2649. this.value -= this._lastOffset * Math.max(0, (1 - ((this.min - this._value) / this.elasticDistance)));
  2650. }
  2651. else {
  2652. this.value -= this._lastOffset * 0.5;
  2653. if (this._value >= this.min)
  2654. this._checkElastic = false;
  2655. }
  2656. }
  2657. else if (this._value >= this.max) {
  2658. if (this._lastOffset < 0) {
  2659. this.value -= this._lastOffset * Math.max(0, (1 - ((this._value - this.max) / this.elasticDistance)));
  2660. }
  2661. else {
  2662. this.value -= this._lastOffset * 0.5;
  2663. if (this._value <= this.max)
  2664. this._checkElastic = false;
  2665. }
  2666. }
  2667. }
  2668. else {
  2669. this.value -= this._lastOffset;
  2670. }
  2671. }
  2672. onStageMouseUp2(e) {
  2673. Laya.ILaya.stage.off(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
  2674. Laya.ILaya.stage.off(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
  2675. Laya.ILaya.timer.clear(this, this.loop);
  2676. if (this._clickOnly) {
  2677. if (this._value >= this.min && this._value <= this.max)
  2678. return;
  2679. }
  2680. this._target.mouseEnabled = true;
  2681. if (this._isElastic) {
  2682. if (this._value < this.min) {
  2683. Laya.Tween.to(this, { value: this.min }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
  2684. }
  2685. else if (this._value > this.max) {
  2686. Laya.Tween.to(this, { value: this.max }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
  2687. }
  2688. }
  2689. else {
  2690. if (!this._offsets)
  2691. return;
  2692. if (this._offsets.length < 1) {
  2693. this._offsets[0] = this.isVertical ? Laya.ILaya.stage.mouseY - this._lastPoint.y : Laya.ILaya.stage.mouseX - this._lastPoint.x;
  2694. }
  2695. var offset = 0;
  2696. var n = Math.min(this._offsets.length, 3);
  2697. for (var i = 0; i < n; i++) {
  2698. offset += this._offsets[this._offsets.length - 1 - i];
  2699. }
  2700. this._lastOffset = offset / n;
  2701. offset = Math.abs(this._lastOffset);
  2702. if (offset < 2) {
  2703. this.event(Laya.Event.END);
  2704. return;
  2705. }
  2706. if (offset > 250)
  2707. this._lastOffset = this._lastOffset > 0 ? 250 : -250;
  2708. var dis = Math.round(Math.abs(this.elasticDistance * (this._lastOffset / 150)));
  2709. Laya.ILaya.timer.frameLoop(1, this, this.tweenMove, [dis]);
  2710. }
  2711. }
  2712. elasticOver() {
  2713. this._isElastic = false;
  2714. if (!this.hide && this.autoHide) {
  2715. Laya.Tween.to(this, { alpha: 0 }, 500);
  2716. }
  2717. this.event(Laya.Event.END);
  2718. }
  2719. tweenMove(maxDistance) {
  2720. this._lastOffset *= this.rollRatio;
  2721. if (this.checkTriggers(true)) {
  2722. return;
  2723. }
  2724. var tarSpeed;
  2725. if (maxDistance > 0) {
  2726. if (this._lastOffset > 0 && this.value <= this.min) {
  2727. this._isElastic = true;
  2728. tarSpeed = -(this.min - maxDistance - this.value) * 0.5;
  2729. if (this._lastOffset > tarSpeed)
  2730. this._lastOffset = tarSpeed;
  2731. }
  2732. else if (this._lastOffset < 0 && this.value >= this.max) {
  2733. this._isElastic = true;
  2734. tarSpeed = -(this.max + maxDistance - this.value) * 0.5;
  2735. if (this._lastOffset < tarSpeed)
  2736. this._lastOffset = tarSpeed;
  2737. }
  2738. }
  2739. this.value -= this._lastOffset;
  2740. if (Math.abs(this._lastOffset) < 0.1) {
  2741. Laya.ILaya.timer.clear(this, this.tweenMove);
  2742. if (this._isElastic) {
  2743. if (this._value < this.min) {
  2744. Laya.Tween.to(this, { value: this.min }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
  2745. }
  2746. else if (this._value > this.max) {
  2747. Laya.Tween.to(this, { value: this.max }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
  2748. }
  2749. else {
  2750. this.elasticOver();
  2751. }
  2752. return;
  2753. }
  2754. this.event(Laya.Event.END);
  2755. if (!this.hide && this.autoHide) {
  2756. Laya.Tween.to(this, { alpha: 0 }, 500);
  2757. }
  2758. }
  2759. }
  2760. stopScroll() {
  2761. this.onStageMouseUp2(null);
  2762. Laya.ILaya.timer.clear(this, this.tweenMove);
  2763. Laya.Tween.clearTween(this);
  2764. }
  2765. get tick() {
  2766. return this.slider.tick;
  2767. }
  2768. set tick(value) {
  2769. this.slider.tick = value;
  2770. }
  2771. }
  2772. Laya.ILaya.regClass(ScrollBar);
  2773. Laya.ClassUtils.regClass("laya.ui.ScrollBar", ScrollBar);
  2774. Laya.ClassUtils.regClass("Laya.ScrollBar", ScrollBar);
  2775. class VScrollBar extends ScrollBar {
  2776. }
  2777. Laya.ILaya.regClass(VScrollBar);
  2778. Laya.ClassUtils.regClass("laya.ui.VScrollBar", VScrollBar);
  2779. Laya.ClassUtils.regClass("Laya.VScrollBar", VScrollBar);
  2780. class HScrollBar extends ScrollBar {
  2781. initialize() {
  2782. super.initialize();
  2783. this.slider.isVertical = false;
  2784. }
  2785. }
  2786. Laya.ILaya.regClass(HScrollBar);
  2787. Laya.ClassUtils.regClass("laya.ui.HScrollBar", HScrollBar);
  2788. Laya.ClassUtils.regClass("Laya.HScrollBar", HScrollBar);
  2789. class List extends Box {
  2790. constructor() {
  2791. super(...arguments);
  2792. this.selectEnable = false;
  2793. this.totalPage = 0;
  2794. this._$componentType = "List";
  2795. this._repeatX = 0;
  2796. this._repeatY = 0;
  2797. this._repeatX2 = 0;
  2798. this._repeatY2 = 0;
  2799. this._spaceX = 0;
  2800. this._spaceY = 0;
  2801. this._cells = [];
  2802. this._startIndex = 0;
  2803. this._selectedIndex = -1;
  2804. this._page = 0;
  2805. this._isVertical = true;
  2806. this._cellSize = 20;
  2807. this._cellOffset = 0;
  2808. this._createdLine = 0;
  2809. this._offset = new Laya.Point();
  2810. this._usedCache = null;
  2811. this._elasticEnabled = false;
  2812. this._preLen = 0;
  2813. }
  2814. destroy(destroyChild = true) {
  2815. this._content && this._content.destroy(destroyChild);
  2816. this._scrollBar && this._scrollBar.destroy(destroyChild);
  2817. super.destroy(destroyChild);
  2818. this._content = null;
  2819. this._scrollBar = null;
  2820. this._itemRender = null;
  2821. this._cells = null;
  2822. this._array = null;
  2823. this.selectHandler = this.renderHandler = this.mouseHandler = null;
  2824. }
  2825. createChildren() {
  2826. this.addChild(this._content = new Box());
  2827. }
  2828. set cacheAs(value) {
  2829. super.cacheAs = value;
  2830. if (this._scrollBar) {
  2831. this._usedCache = null;
  2832. if (value !== "none")
  2833. this._scrollBar.on(Laya.Event.START, this, this.onScrollStart);
  2834. else
  2835. this._scrollBar.off(Laya.Event.START, this, this.onScrollStart);
  2836. }
  2837. }
  2838. get cacheAs() {
  2839. return super.cacheAs;
  2840. }
  2841. onScrollStart() {
  2842. this._usedCache || (this._usedCache = super.cacheAs);
  2843. super.cacheAs = "none";
  2844. this._scrollBar.once(Laya.Event.END, this, this.onScrollEnd);
  2845. }
  2846. onScrollEnd() {
  2847. super.cacheAs = this._usedCache || 'none';
  2848. }
  2849. get content() {
  2850. return this._content;
  2851. }
  2852. get vScrollBarSkin() {
  2853. return this._scrollBar ? this._scrollBar.skin : null;
  2854. }
  2855. set vScrollBarSkin(value) {
  2856. this._removePreScrollBar();
  2857. var scrollBar = new VScrollBar();
  2858. scrollBar.name = "scrollBar";
  2859. scrollBar.right = 0;
  2860. scrollBar.skin = value;
  2861. scrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
  2862. this.scrollBar = scrollBar;
  2863. this.addChild(scrollBar);
  2864. this._setCellChanged();
  2865. }
  2866. _removePreScrollBar() {
  2867. var preNode = this.removeChildByName("scrollBar");
  2868. if (preNode)
  2869. preNode.destroy(true);
  2870. }
  2871. get hScrollBarSkin() {
  2872. return this._scrollBar ? this._scrollBar.skin : null;
  2873. }
  2874. set hScrollBarSkin(value) {
  2875. this._removePreScrollBar();
  2876. var scrollBar = new HScrollBar();
  2877. scrollBar.name = "scrollBar";
  2878. scrollBar.bottom = 0;
  2879. scrollBar.skin = value;
  2880. scrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
  2881. this.scrollBar = scrollBar;
  2882. this.addChild(scrollBar);
  2883. this._setCellChanged();
  2884. }
  2885. get scrollBar() {
  2886. return this._scrollBar;
  2887. }
  2888. set scrollBar(value) {
  2889. if (this._scrollBar != value) {
  2890. this._scrollBar = value;
  2891. if (value) {
  2892. this._isVertical = this._scrollBar.isVertical;
  2893. this.addChild(this._scrollBar);
  2894. this._scrollBar.on(Laya.Event.CHANGE, this, this.onScrollBarChange);
  2895. }
  2896. }
  2897. }
  2898. get itemRender() {
  2899. return this._itemRender;
  2900. }
  2901. set itemRender(value) {
  2902. if (this._itemRender != value) {
  2903. this._itemRender = value;
  2904. for (var i = this._cells.length - 1; i > -1; i--) {
  2905. this._cells[i].destroy();
  2906. }
  2907. this._cells.length = 0;
  2908. this._setCellChanged();
  2909. }
  2910. }
  2911. set width(value) {
  2912. if (value != this._width) {
  2913. super.width = value;
  2914. this._setCellChanged();
  2915. }
  2916. }
  2917. get width() {
  2918. return super.width;
  2919. }
  2920. set height(value) {
  2921. if (value != this._height) {
  2922. super.height = value;
  2923. this._setCellChanged();
  2924. }
  2925. }
  2926. get height() {
  2927. return super.height;
  2928. }
  2929. get repeatX() {
  2930. return this._repeatX > 0 ? this._repeatX : this._repeatX2 > 0 ? this._repeatX2 : 1;
  2931. }
  2932. set repeatX(value) {
  2933. this._repeatX = value;
  2934. this._setCellChanged();
  2935. }
  2936. get repeatY() {
  2937. return this._repeatY > 0 ? this._repeatY : this._repeatY2 > 0 ? this._repeatY2 : 1;
  2938. }
  2939. set repeatY(value) {
  2940. this._repeatY = value;
  2941. this._setCellChanged();
  2942. }
  2943. get spaceX() {
  2944. return this._spaceX;
  2945. }
  2946. set spaceX(value) {
  2947. this._spaceX = value;
  2948. this._setCellChanged();
  2949. }
  2950. get spaceY() {
  2951. return this._spaceY;
  2952. }
  2953. set spaceY(value) {
  2954. this._spaceY = value;
  2955. this._setCellChanged();
  2956. }
  2957. changeCells() {
  2958. this._cellChanged = false;
  2959. if (this._itemRender) {
  2960. this.scrollBar = this.getChildByName("scrollBar");
  2961. var cell = this._getOneCell();
  2962. var cellWidth = (cell.width + this._spaceX) || 1;
  2963. var cellHeight = (cell.height + this._spaceY) || 1;
  2964. if (this._width > 0)
  2965. this._repeatX2 = this._isVertical ? Math.round(this._width / cellWidth) : Math.ceil(this._width / cellWidth);
  2966. if (this._height > 0)
  2967. this._repeatY2 = this._isVertical ? Math.ceil(this._height / cellHeight) : Math.round(this._height / cellHeight);
  2968. var listWidth = this._width ? this._width : (cellWidth * this.repeatX - this._spaceX);
  2969. var listHeight = this._height ? this._height : (cellHeight * this.repeatY - this._spaceY);
  2970. this._cellSize = this._isVertical ? cellHeight : cellWidth;
  2971. this._cellOffset = this._isVertical ? (cellHeight * Math.max(this._repeatY2, this._repeatY) - listHeight - this._spaceY) : (cellWidth * Math.max(this._repeatX2, this._repeatX) - listWidth - this._spaceX);
  2972. if (this._isVertical && this.vScrollBarSkin)
  2973. this._scrollBar.height = listHeight;
  2974. else if (!this._isVertical && this.hScrollBarSkin)
  2975. this._scrollBar.width = listWidth;
  2976. this.setContentSize(listWidth, listHeight);
  2977. var numX = this._isVertical ? this.repeatX : this.repeatY;
  2978. var numY = (this._isVertical ? this.repeatY : this.repeatX) + (this._scrollBar ? 1 : 0);
  2979. this._createItems(0, numX, numY);
  2980. this._createdLine = numY;
  2981. if (this._array) {
  2982. this.array = this._array;
  2983. this.runCallLater(this.renderItems);
  2984. }
  2985. }
  2986. }
  2987. _getOneCell() {
  2988. if (this._cells.length === 0) {
  2989. var item = this.createItem();
  2990. this._offset.setTo(item._x, item._y);
  2991. if (this.cacheContent)
  2992. return item;
  2993. this._cells.push(item);
  2994. }
  2995. return this._cells[0];
  2996. }
  2997. _createItems(startY, numX, numY) {
  2998. var box = this._content;
  2999. var cell = this._getOneCell();
  3000. var cellWidth = cell.width + this._spaceX;
  3001. var cellHeight = cell.height + this._spaceY;
  3002. if (this.cacheContent) {
  3003. var cacheBox = new Box();
  3004. cacheBox.cacheAs = "normal";
  3005. cacheBox.pos((this._isVertical ? 0 : startY) * cellWidth, (this._isVertical ? startY : 0) * cellHeight);
  3006. this._content.addChild(cacheBox);
  3007. box = cacheBox;
  3008. }
  3009. else {
  3010. var arr = [];
  3011. for (var i = this._cells.length - 1; i > -1; i--) {
  3012. var item = this._cells[i];
  3013. item.removeSelf();
  3014. arr.push(item);
  3015. }
  3016. this._cells.length = 0;
  3017. }
  3018. for (var k = startY; k < numY; k++) {
  3019. for (var l = 0; l < numX; l++) {
  3020. if (arr && arr.length) {
  3021. cell = arr.pop();
  3022. }
  3023. else {
  3024. cell = this.createItem();
  3025. }
  3026. cell.x = (this._isVertical ? l : k) * cellWidth - box._x;
  3027. cell.y = (this._isVertical ? k : l) * cellHeight - box._y;
  3028. cell.name = "item" + (k * numX + l);
  3029. box.addChild(cell);
  3030. this.addCell(cell);
  3031. }
  3032. }
  3033. }
  3034. createItem() {
  3035. var arr = [];
  3036. if (typeof (this._itemRender) == "function") {
  3037. var box = new this._itemRender();
  3038. }
  3039. else {
  3040. box = Laya.SceneUtils.createComp(this._itemRender, null, null, arr);
  3041. }
  3042. if (arr.length == 0 && box["_watchMap"]) {
  3043. var watchMap = box["_watchMap"];
  3044. for (var name in watchMap) {
  3045. var a = watchMap[name];
  3046. for (var i = 0; i < a.length; i++) {
  3047. var watcher = a[i];
  3048. arr.push(watcher.comp, watcher.prop, watcher.value);
  3049. }
  3050. }
  3051. }
  3052. if (arr.length)
  3053. box["_$bindData"] = arr;
  3054. return box;
  3055. }
  3056. addCell(cell) {
  3057. cell.on(Laya.Event.CLICK, this, this.onCellMouse);
  3058. cell.on(Laya.Event.RIGHT_CLICK, this, this.onCellMouse);
  3059. cell.on(Laya.Event.MOUSE_OVER, this, this.onCellMouse);
  3060. cell.on(Laya.Event.MOUSE_OUT, this, this.onCellMouse);
  3061. cell.on(Laya.Event.MOUSE_DOWN, this, this.onCellMouse);
  3062. cell.on(Laya.Event.MOUSE_UP, this, this.onCellMouse);
  3063. this._cells.push(cell);
  3064. }
  3065. _afterInited() {
  3066. this.initItems();
  3067. }
  3068. initItems() {
  3069. if (!this._itemRender && this.getChildByName("item0") != null) {
  3070. this.repeatX = 1;
  3071. var count;
  3072. count = 0;
  3073. for (var i = 0; i < 10000; i++) {
  3074. var cell = this.getChildByName("item" + i);
  3075. if (cell) {
  3076. this.addCell(cell);
  3077. count++;
  3078. continue;
  3079. }
  3080. break;
  3081. }
  3082. this.repeatY = count;
  3083. }
  3084. }
  3085. setContentSize(width, height) {
  3086. this._content.width = width;
  3087. this._content.height = height;
  3088. if (this._scrollBar || this._offset.x != 0 || this._offset.y != 0) {
  3089. this._content._style.scrollRect || (this._content.scrollRect = Laya.Rectangle.create());
  3090. this._content._style.scrollRect.setTo(-this._offset.x, -this._offset.y, width, height);
  3091. this._content.scrollRect = this._content.scrollRect;
  3092. }
  3093. this.event(Laya.Event.RESIZE);
  3094. }
  3095. onCellMouse(e) {
  3096. if (e.type === Laya.Event.MOUSE_DOWN)
  3097. this._isMoved = false;
  3098. var cell = e.currentTarget;
  3099. var index = this._startIndex + this._cells.indexOf(cell);
  3100. if (index < 0)
  3101. return;
  3102. if (e.type === Laya.Event.CLICK || e.type === Laya.Event.RIGHT_CLICK) {
  3103. if (this.selectEnable && !this._isMoved)
  3104. this.selectedIndex = index;
  3105. else
  3106. this.changeCellState(cell, true, 0);
  3107. }
  3108. else if ((e.type === Laya.Event.MOUSE_OVER || e.type === Laya.Event.MOUSE_OUT) && this._selectedIndex !== index) {
  3109. this.changeCellState(cell, e.type === Laya.Event.MOUSE_OVER, 0);
  3110. }
  3111. this.mouseHandler && this.mouseHandler.runWith([e, index]);
  3112. }
  3113. changeCellState(cell, visible, index) {
  3114. var selectBox = cell.getChildByName("selectBox");
  3115. if (selectBox) {
  3116. this.selectEnable = true;
  3117. selectBox.visible = visible;
  3118. selectBox.index = index;
  3119. }
  3120. }
  3121. _sizeChanged() {
  3122. super._sizeChanged();
  3123. this.setContentSize(this.width, this.height);
  3124. if (this._scrollBar)
  3125. this.callLater(this.onScrollBarChange);
  3126. }
  3127. onScrollBarChange(e = null) {
  3128. this.runCallLater(this.changeCells);
  3129. var scrollValue = this._scrollBar.value;
  3130. var lineX = (this._isVertical ? this.repeatX : this.repeatY);
  3131. var lineY = (this._isVertical ? this.repeatY : this.repeatX);
  3132. var scrollLine = Math.floor(scrollValue / this._cellSize);
  3133. if (!this.cacheContent) {
  3134. var index = scrollLine * lineX;
  3135. var num = 0;
  3136. let down = true;
  3137. var toIndex = 0;
  3138. if (index > this._startIndex) {
  3139. num = index - this._startIndex;
  3140. toIndex = this._startIndex + lineX * (lineY + 1);
  3141. this._isMoved = true;
  3142. }
  3143. else if (index < this._startIndex) {
  3144. num = this._startIndex - index;
  3145. down = false;
  3146. toIndex = this._startIndex - 1;
  3147. this._isMoved = true;
  3148. }
  3149. for (var i = 0; i < num; i++) {
  3150. if (down) {
  3151. var cell = this._cells.shift();
  3152. this._cells[this._cells.length] = cell;
  3153. var cellIndex = toIndex + i;
  3154. }
  3155. else {
  3156. cell = this._cells.pop();
  3157. this._cells.unshift(cell);
  3158. cellIndex = toIndex - i;
  3159. }
  3160. var pos = Math.floor(cellIndex / lineX) * this._cellSize;
  3161. this._isVertical ? cell.y = pos : cell.x = pos;
  3162. this.renderItem(cell, cellIndex);
  3163. }
  3164. this._startIndex = index;
  3165. this.changeSelectStatus();
  3166. }
  3167. else {
  3168. num = (lineY + 1);
  3169. if (this._createdLine - scrollLine < num) {
  3170. this._createItems(this._createdLine, lineX, this._createdLine + num);
  3171. this.renderItems(this._createdLine * lineX, 0);
  3172. this._createdLine += num;
  3173. }
  3174. }
  3175. var r = this._content._style.scrollRect;
  3176. if (this._isVertical) {
  3177. r.y = scrollValue - this._offset.y;
  3178. r.x = -this._offset.x;
  3179. }
  3180. else {
  3181. r.y = -this._offset.y;
  3182. r.x = scrollValue - this._offset.x;
  3183. }
  3184. this._content.scrollRect = r;
  3185. }
  3186. posCell(cell, cellIndex) {
  3187. if (!this._scrollBar)
  3188. return;
  3189. var lineX = (this._isVertical ? this.repeatX : this.repeatY);
  3190. var pos = Math.floor(cellIndex / lineX) * this._cellSize;
  3191. this._isVertical ? cell._y = pos : cell.x = pos;
  3192. }
  3193. get selectedIndex() {
  3194. return this._selectedIndex;
  3195. }
  3196. set selectedIndex(value) {
  3197. if (this._selectedIndex != value) {
  3198. this._selectedIndex = value;
  3199. this.changeSelectStatus();
  3200. this.event(Laya.Event.CHANGE);
  3201. this.selectHandler && this.selectHandler.runWith(value);
  3202. this.startIndex = this._startIndex;
  3203. }
  3204. }
  3205. changeSelectStatus() {
  3206. for (var i = 0, n = this._cells.length; i < n; i++) {
  3207. this.changeCellState(this._cells[i], this._selectedIndex === this._startIndex + i, 1);
  3208. }
  3209. }
  3210. get selectedItem() {
  3211. if (!this._array)
  3212. return null;
  3213. return this._selectedIndex != -1 ? this._array[this._selectedIndex] : null;
  3214. }
  3215. set selectedItem(value) {
  3216. this._array && (this.selectedIndex = this._array.indexOf(value));
  3217. }
  3218. get selection() {
  3219. return this.getCell(this._selectedIndex);
  3220. }
  3221. set selection(value) {
  3222. this.selectedIndex = this._startIndex + this._cells.indexOf(value);
  3223. }
  3224. get startIndex() {
  3225. return this._startIndex;
  3226. }
  3227. set startIndex(value) {
  3228. this._startIndex = value > 0 ? value : 0;
  3229. this.callLater(this.renderItems);
  3230. }
  3231. renderItems(from = 0, to = 0) {
  3232. for (var i = from, n = to || this._cells.length; i < n; i++) {
  3233. this.renderItem(this._cells[i], this._startIndex + i);
  3234. }
  3235. this.changeSelectStatus();
  3236. }
  3237. renderItem(cell, index) {
  3238. if (this._array && index >= 0 && index < this._array.length) {
  3239. cell.visible = true;
  3240. if (cell["_$bindData"]) {
  3241. cell["_dataSource"] = this._array[index];
  3242. this._bindData(cell, this._array[index]);
  3243. }
  3244. else
  3245. cell.dataSource = this._array[index];
  3246. if (!this.cacheContent) {
  3247. this.posCell(cell, index);
  3248. }
  3249. if (this.hasListener(Laya.Event.RENDER))
  3250. this.event(Laya.Event.RENDER, [cell, index]);
  3251. if (this.renderHandler)
  3252. this.renderHandler.runWith([cell, index]);
  3253. }
  3254. else {
  3255. cell.visible = false;
  3256. cell.dataSource = null;
  3257. }
  3258. }
  3259. _bindData(cell, data) {
  3260. var arr = cell._$bindData;
  3261. for (var i = 0, n = arr.length; i < n; i++) {
  3262. var ele = arr[i++];
  3263. var prop = arr[i++];
  3264. var value = arr[i];
  3265. var fun = UIUtils.getBindFun(value);
  3266. ele[prop] = fun.call(this, data);
  3267. }
  3268. }
  3269. get array() {
  3270. return this._array;
  3271. }
  3272. set array(value) {
  3273. this.runCallLater(this.changeCells);
  3274. this._array = value || [];
  3275. this._preLen = this._array.length;
  3276. var length = this._array.length;
  3277. this.totalPage = Math.ceil(length / (this.repeatX * this.repeatY));
  3278. this._selectedIndex = this._selectedIndex < length ? this._selectedIndex : length - 1;
  3279. this.startIndex = this._startIndex;
  3280. if (this._scrollBar) {
  3281. this._scrollBar.stopScroll();
  3282. var numX = this._isVertical ? this.repeatX : this.repeatY;
  3283. var numY = this._isVertical ? this.repeatY : this.repeatX;
  3284. var lineCount = Math.ceil(length / numX);
  3285. var total = this._cellOffset > 0 ? this.totalPage + 1 : this.totalPage;
  3286. if (total > 1 && lineCount >= numY) {
  3287. this._scrollBar.scrollSize = this._cellSize;
  3288. this._scrollBar.thumbPercent = numY / lineCount;
  3289. this._scrollBar.setScroll(0, (lineCount - numY) * this._cellSize + this._cellOffset, this._scrollBar.value);
  3290. this._scrollBar.target = this._content;
  3291. }
  3292. else {
  3293. this._scrollBar.setScroll(0, 0, 0);
  3294. this._scrollBar.target = this._content;
  3295. }
  3296. }
  3297. }
  3298. updateArray(array) {
  3299. this._array = array;
  3300. if (this._array) {
  3301. let freshStart = this._preLen - this._startIndex;
  3302. if (freshStart >= 0)
  3303. this.renderItems(freshStart);
  3304. this._preLen = this._array.length;
  3305. }
  3306. if (this._scrollBar) {
  3307. var length = array.length;
  3308. var numX = this._isVertical ? this.repeatX : this.repeatY;
  3309. var numY = this._isVertical ? this.repeatY : this.repeatX;
  3310. var lineCount = Math.ceil(length / numX);
  3311. if (lineCount >= numY) {
  3312. this._scrollBar.thumbPercent = numY / lineCount;
  3313. this._scrollBar.slider["_max"] = (lineCount - numY) * this._cellSize + this._cellOffset;
  3314. }
  3315. }
  3316. }
  3317. get page() {
  3318. return this._page;
  3319. }
  3320. set page(value) {
  3321. this._page = value;
  3322. if (this._array) {
  3323. this._page = value > 0 ? value : 0;
  3324. this._page = this._page < this.totalPage ? this._page : this.totalPage - 1;
  3325. this.startIndex = this._page * this.repeatX * this.repeatY;
  3326. }
  3327. }
  3328. get length() {
  3329. return this._array ? this._array.length : 0;
  3330. }
  3331. set dataSource(value) {
  3332. this._dataSource = value;
  3333. if (typeof (value) == 'number' || typeof (value) == 'string')
  3334. this.selectedIndex = parseInt(value);
  3335. else if (value instanceof Array)
  3336. this.array = value;
  3337. else
  3338. super.dataSource = value;
  3339. }
  3340. get dataSource() {
  3341. return super.dataSource;
  3342. }
  3343. get cells() {
  3344. this.runCallLater(this.changeCells);
  3345. return this._cells;
  3346. }
  3347. get elasticEnabled() {
  3348. return this._elasticEnabled;
  3349. }
  3350. set elasticEnabled(value) {
  3351. this._elasticEnabled = value;
  3352. if (this._scrollBar) {
  3353. this._scrollBar.elasticDistance = value ? 200 : 0;
  3354. }
  3355. }
  3356. refresh() {
  3357. this.array = this._array;
  3358. }
  3359. getItem(index) {
  3360. if (!this._array)
  3361. return null;
  3362. if (index > -1 && index < this._array.length) {
  3363. return this._array[index];
  3364. }
  3365. return null;
  3366. }
  3367. changeItem(index, source) {
  3368. if (index > -1 && this._array && index < this._array.length) {
  3369. this._array[index] = source;
  3370. if (index >= this._startIndex && index < this._startIndex + this._cells.length) {
  3371. this.renderItem(this.getCell(index), index);
  3372. }
  3373. }
  3374. }
  3375. setItem(index, source) {
  3376. this.changeItem(index, source);
  3377. }
  3378. addItem(source) {
  3379. if (!this.array) {
  3380. this.array = [source];
  3381. }
  3382. else {
  3383. this._array.push(source);
  3384. }
  3385. this.array = this._array;
  3386. }
  3387. addItemAt(souce, index) {
  3388. this._array.splice(index, 0, souce);
  3389. this.array = this._array;
  3390. }
  3391. deleteItem(index) {
  3392. if (this._array) {
  3393. this._array.splice(index, 1);
  3394. this.array = this._array;
  3395. }
  3396. }
  3397. getCell(index) {
  3398. this.runCallLater(this.changeCells);
  3399. if (index > -1 && this._cells) {
  3400. return this._cells[(index - this._startIndex) % this._cells.length];
  3401. }
  3402. return null;
  3403. }
  3404. scrollTo(index) {
  3405. if (this._scrollBar) {
  3406. var numX = this._isVertical ? this.repeatX : this.repeatY;
  3407. this._scrollBar.value = Math.floor(index / numX) * this._cellSize;
  3408. }
  3409. else {
  3410. this.startIndex = index;
  3411. }
  3412. }
  3413. tweenTo(index, time = 200, complete = null) {
  3414. if (this._scrollBar) {
  3415. this._scrollBar.stopScroll();
  3416. var numX = this._isVertical ? this.repeatX : this.repeatY;
  3417. Laya.Tween.to(this._scrollBar, { value: Math.floor(index / numX) * this._cellSize }, time, null, complete, 0, true);
  3418. }
  3419. else {
  3420. this.startIndex = index;
  3421. if (complete)
  3422. complete.run();
  3423. }
  3424. }
  3425. _setCellChanged() {
  3426. if (!this._cellChanged) {
  3427. this._cellChanged = true;
  3428. this.callLater(this.changeCells);
  3429. }
  3430. }
  3431. commitMeasure() {
  3432. this.runCallLater(this.changeCells);
  3433. }
  3434. }
  3435. Laya.ILaya.regClass(List);
  3436. Laya.ClassUtils.regClass("laya.ui.List", List);
  3437. Laya.ClassUtils.regClass("Laya.List", List);
  3438. class ComboBox extends UIComponent {
  3439. constructor(skin = null, labels = null) {
  3440. super();
  3441. this._visibleNum = 6;
  3442. this._itemColors = Styles.comboBoxItemColors;
  3443. this._itemSize = 12;
  3444. this._labels = [];
  3445. this._selectedIndex = -1;
  3446. this.itemRender = null;
  3447. this.skin = skin;
  3448. this.labels = labels;
  3449. }
  3450. destroy(destroyChild = true) {
  3451. super.destroy(destroyChild);
  3452. this._button && this._button.destroy(destroyChild);
  3453. this._list && this._list.destroy(destroyChild);
  3454. this._button = null;
  3455. this._list = null;
  3456. this._itemColors = null;
  3457. this._labels = null;
  3458. this._selectHandler = null;
  3459. }
  3460. createChildren() {
  3461. this.addChild(this._button = new Button());
  3462. this._button.text.align = "left";
  3463. this._button.labelPadding = "0,0,0,5";
  3464. this._button.on(Laya.Event.MOUSE_DOWN, this, this.onButtonMouseDown);
  3465. }
  3466. _createList() {
  3467. this._list = new List();
  3468. if (this._scrollBarSkin)
  3469. this._list.vScrollBarSkin = this._scrollBarSkin;
  3470. this._setListEvent(this._list);
  3471. }
  3472. _setListEvent(list) {
  3473. this._list.selectEnable = true;
  3474. this._list.on(Laya.Event.MOUSE_DOWN, this, this.onListDown);
  3475. this._list.mouseHandler = Laya.Handler.create(this, this.onlistItemMouse, null, false);
  3476. if (this._list.scrollBar)
  3477. this._list.scrollBar.on(Laya.Event.MOUSE_DOWN, this, this.onScrollBarDown);
  3478. }
  3479. onListDown(e) {
  3480. e.stopPropagation();
  3481. }
  3482. onScrollBarDown(e) {
  3483. e.stopPropagation();
  3484. }
  3485. onButtonMouseDown(e) {
  3486. this.callLater(this.switchTo, [!this._isOpen]);
  3487. }
  3488. get skin() {
  3489. return this._button.skin;
  3490. }
  3491. set skin(value) {
  3492. if (this._button.skin != value) {
  3493. this._button.skin = value;
  3494. this._listChanged = true;
  3495. }
  3496. }
  3497. measureWidth() {
  3498. return this._button.width;
  3499. }
  3500. measureHeight() {
  3501. return this._button.height;
  3502. }
  3503. changeList() {
  3504. this._listChanged = false;
  3505. var labelWidth = this.width - 2;
  3506. var labelColor = this._itemColors[2];
  3507. this._itemHeight = this._itemSize + 6;
  3508. this._list.itemRender = this.itemRender || { type: "Box", child: [{ type: "Label", props: { name: "label", x: 1, padding: "3,3,3,3", width: labelWidth, height: this._itemHeight, fontSize: this._itemSize, color: labelColor } }] };
  3509. this._list.repeatY = this._visibleNum;
  3510. this._list.refresh();
  3511. }
  3512. onlistItemMouse(e, index) {
  3513. var type = e.type;
  3514. if (type === Laya.Event.MOUSE_OVER || type === Laya.Event.MOUSE_OUT) {
  3515. if (this._isCustomList)
  3516. return;
  3517. var box = this._list.getCell(index);
  3518. if (!box)
  3519. return;
  3520. var label = box.getChildByName("label");
  3521. if (label) {
  3522. if (type === Laya.Event.ROLL_OVER) {
  3523. label.bgColor = this._itemColors[0];
  3524. label.color = this._itemColors[1];
  3525. }
  3526. else {
  3527. label.bgColor = null;
  3528. label.color = this._itemColors[2];
  3529. }
  3530. }
  3531. }
  3532. else if (type === Laya.Event.CLICK) {
  3533. this.selectedIndex = index;
  3534. this.isOpen = false;
  3535. }
  3536. }
  3537. switchTo(value) {
  3538. this.isOpen = value;
  3539. }
  3540. changeOpen() {
  3541. this.isOpen = !this._isOpen;
  3542. }
  3543. set width(value) {
  3544. super.width = value;
  3545. this._button.width = this._width;
  3546. this._itemChanged = true;
  3547. this._listChanged = true;
  3548. }
  3549. get width() {
  3550. return super.width;
  3551. }
  3552. set height(value) {
  3553. super.height = value;
  3554. this._button.height = this._height;
  3555. }
  3556. get height() {
  3557. return super.height;
  3558. }
  3559. get labels() {
  3560. return this._labels.join(",");
  3561. }
  3562. set labels(value) {
  3563. if (this._labels.length > 0)
  3564. this.selectedIndex = -1;
  3565. if (value)
  3566. this._labels = value.split(",");
  3567. else
  3568. this._labels.length = 0;
  3569. this._itemChanged = true;
  3570. }
  3571. changeItem() {
  3572. this._itemChanged = false;
  3573. this._listHeight = this._labels.length > 0 ? Math.min(this._visibleNum, this._labels.length) * this._itemHeight : this._itemHeight;
  3574. if (!this._isCustomList) {
  3575. var g = this._list.graphics;
  3576. g.clear(true);
  3577. g.drawRect(0, 0, this.width - 1, this._listHeight, this._itemColors[4], this._itemColors[3]);
  3578. }
  3579. var a = this._list.array || [];
  3580. a.length = 0;
  3581. for (var i = 0, n = this._labels.length; i < n; i++) {
  3582. a.push({ label: this._labels[i] });
  3583. }
  3584. this._list.height = this._listHeight;
  3585. this._list.array = a;
  3586. }
  3587. get selectedIndex() {
  3588. return this._selectedIndex;
  3589. }
  3590. set selectedIndex(value) {
  3591. if (this._selectedIndex != value) {
  3592. this._selectedIndex = value;
  3593. if (this._labels.length > 0)
  3594. this.changeSelected();
  3595. else
  3596. this.callLater(this.changeSelected);
  3597. this.event(Laya.Event.CHANGE, [Laya.Event.EMPTY.setTo(Laya.Event.CHANGE, this, this)]);
  3598. this._selectHandler && this._selectHandler.runWith(this._selectedIndex);
  3599. }
  3600. }
  3601. changeSelected() {
  3602. this._button.label = this.selectedLabel;
  3603. }
  3604. get selectHandler() {
  3605. return this._selectHandler;
  3606. }
  3607. set selectHandler(value) {
  3608. this._selectHandler = value;
  3609. }
  3610. get selectedLabel() {
  3611. return this._selectedIndex > -1 && this._selectedIndex < this._labels.length ? this._labels[this._selectedIndex] : null;
  3612. }
  3613. set selectedLabel(value) {
  3614. this.selectedIndex = this._labels.indexOf(value);
  3615. }
  3616. get visibleNum() {
  3617. return this._visibleNum;
  3618. }
  3619. set visibleNum(value) {
  3620. this._visibleNum = value;
  3621. this._listChanged = true;
  3622. }
  3623. get itemColors() {
  3624. return String(this._itemColors);
  3625. }
  3626. set itemColors(value) {
  3627. this._itemColors = UIUtils.fillArray(this._itemColors, value, String);
  3628. this._listChanged = true;
  3629. }
  3630. get itemSize() {
  3631. return this._itemSize;
  3632. }
  3633. set itemSize(value) {
  3634. this._itemSize = value;
  3635. this._listChanged = true;
  3636. }
  3637. get isOpen() {
  3638. return this._isOpen;
  3639. }
  3640. set isOpen(value) {
  3641. if (this._isOpen != value) {
  3642. this._isOpen = value;
  3643. this._button.selected = this._isOpen;
  3644. if (this._isOpen) {
  3645. this._list || this._createList();
  3646. this._listChanged && !this._isCustomList && this.changeList();
  3647. this._itemChanged && this.changeItem();
  3648. var p = this.localToGlobal(Laya.Point.TEMP.setTo(0, 0));
  3649. var py = p.y + this._button.height;
  3650. py = py + this._listHeight <= Laya.ILaya.stage.height ? py : p.y - this._listHeight;
  3651. this._list.pos(p.x, py);
  3652. this._list.zOrder = 1001;
  3653. Laya.ILaya.stage.addChild(this._list);
  3654. Laya.ILaya.stage.once(Laya.Event.MOUSE_DOWN, this, this.removeList);
  3655. Laya.ILaya.stage.on(Laya.Event.MOUSE_WHEEL, this, this._onStageMouseWheel);
  3656. this._list.selectedIndex = this._selectedIndex;
  3657. }
  3658. else {
  3659. this._list && this._list.removeSelf();
  3660. }
  3661. }
  3662. }
  3663. _onStageMouseWheel(e) {
  3664. if (!this._list || this._list.contains(e.target))
  3665. return;
  3666. this.removeList(null);
  3667. }
  3668. removeList(e) {
  3669. Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this.removeList);
  3670. Laya.ILaya.stage.off(Laya.Event.MOUSE_WHEEL, this, this._onStageMouseWheel);
  3671. this.isOpen = false;
  3672. }
  3673. get scrollBarSkin() {
  3674. return this._scrollBarSkin;
  3675. }
  3676. set scrollBarSkin(value) {
  3677. this._scrollBarSkin = value;
  3678. }
  3679. get sizeGrid() {
  3680. return this._button.sizeGrid;
  3681. }
  3682. set sizeGrid(value) {
  3683. this._button.sizeGrid = value;
  3684. }
  3685. get scrollBar() {
  3686. return this.list.scrollBar;
  3687. }
  3688. get button() {
  3689. return this._button;
  3690. }
  3691. get list() {
  3692. this._list || this._createList();
  3693. return this._list;
  3694. }
  3695. set list(value) {
  3696. if (value) {
  3697. value.removeSelf();
  3698. this._isCustomList = true;
  3699. this._list = value;
  3700. this._setListEvent(value);
  3701. this._itemHeight = value.getCell(0).height + value.spaceY;
  3702. }
  3703. }
  3704. set dataSource(value) {
  3705. this._dataSource = value;
  3706. if (typeof (value) == 'number' || typeof (value) == 'string')
  3707. this.selectedIndex = parseInt(value);
  3708. else if (value instanceof Array)
  3709. this.labels = value.join(",");
  3710. else
  3711. super.dataSource = value;
  3712. }
  3713. get dataSource() {
  3714. return super.dataSource;
  3715. }
  3716. get labelColors() {
  3717. return this._button.labelColors;
  3718. }
  3719. set labelColors(value) {
  3720. if (this._button.labelColors != value) {
  3721. this._button.labelColors = value;
  3722. }
  3723. }
  3724. get labelPadding() {
  3725. return this._button.text.padding.join(",");
  3726. }
  3727. set labelPadding(value) {
  3728. this._button.text.padding = UIUtils.fillArray(Styles.labelPadding, value, Number);
  3729. }
  3730. get labelSize() {
  3731. return this._button.text.fontSize;
  3732. }
  3733. set labelSize(value) {
  3734. this._button.text.fontSize = value;
  3735. }
  3736. get labelBold() {
  3737. return this._button.text.bold;
  3738. }
  3739. set labelBold(value) {
  3740. this._button.text.bold = value;
  3741. }
  3742. get labelFont() {
  3743. return this._button.text.font;
  3744. }
  3745. set labelFont(value) {
  3746. this._button.text.font = value;
  3747. }
  3748. get stateNum() {
  3749. return this._button.stateNum;
  3750. }
  3751. set stateNum(value) {
  3752. this._button.stateNum = value;
  3753. }
  3754. }
  3755. Laya.ILaya.regClass(ComboBox);
  3756. Laya.ClassUtils.regClass("laya.ui.ComboBox", ComboBox);
  3757. Laya.ClassUtils.regClass("Laya.ComboBox", ComboBox);
  3758. class ProgressBar extends UIComponent {
  3759. constructor(skin = null) {
  3760. super();
  3761. this._value = 0.5;
  3762. this.skin = skin;
  3763. }
  3764. destroy(destroyChild = true) {
  3765. super.destroy(destroyChild);
  3766. this._bg && this._bg.destroy(destroyChild);
  3767. this._bar && this._bar.destroy(destroyChild);
  3768. this._bg = this._bar = null;
  3769. this.changeHandler = null;
  3770. }
  3771. createChildren() {
  3772. this.addChild(this._bg = new Image());
  3773. this.addChild(this._bar = new Image());
  3774. this._bar._bitmap.autoCacheCmd = false;
  3775. }
  3776. get skin() {
  3777. return this._skin;
  3778. }
  3779. set skin(value) {
  3780. if (this._skin != value) {
  3781. this._skin = value;
  3782. if (this._skin && !Laya.Loader.getRes(this._skin)) {
  3783. Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
  3784. }
  3785. else {
  3786. this._skinLoaded();
  3787. }
  3788. }
  3789. }
  3790. _skinLoaded() {
  3791. this._bg.skin = this._skin;
  3792. this._bar.skin = this._skin.replace(".png", "$bar.png");
  3793. this.callLater(this.changeValue);
  3794. this._sizeChanged();
  3795. this.event(Laya.Event.LOADED);
  3796. }
  3797. measureWidth() {
  3798. return this._bg.width;
  3799. }
  3800. measureHeight() {
  3801. return this._bg.height;
  3802. }
  3803. get value() {
  3804. return this._value;
  3805. }
  3806. set value(num) {
  3807. if (this._value != num) {
  3808. num = num > 1 ? 1 : num < 0 ? 0 : num;
  3809. this._value = num;
  3810. this.callLater(this.changeValue);
  3811. this.event(Laya.Event.CHANGE);
  3812. this.changeHandler && this.changeHandler.runWith(num);
  3813. }
  3814. }
  3815. changeValue() {
  3816. if (this.sizeGrid) {
  3817. var grid = this.sizeGrid.split(",");
  3818. var left = Number(grid[3]);
  3819. var right = Number(grid[1]);
  3820. var max = this.width - left - right;
  3821. var sw = max * this._value;
  3822. this._bar.width = left + right + sw;
  3823. this._bar.visible = this._bar.width > left + right;
  3824. }
  3825. else {
  3826. this._bar.width = this.width * this._value;
  3827. }
  3828. }
  3829. get bar() {
  3830. return this._bar;
  3831. }
  3832. get bg() {
  3833. return this._bg;
  3834. }
  3835. get sizeGrid() {
  3836. return this._bg.sizeGrid;
  3837. }
  3838. set sizeGrid(value) {
  3839. this._bg.sizeGrid = this._bar.sizeGrid = value;
  3840. }
  3841. set width(value) {
  3842. super.width = value;
  3843. this._bg.width = this._width;
  3844. this.callLater(this.changeValue);
  3845. }
  3846. get width() {
  3847. return super.width;
  3848. }
  3849. set height(value) {
  3850. super.height = value;
  3851. this._bg.height = this._height;
  3852. this._bar.height = this._height;
  3853. }
  3854. get height() {
  3855. return super.height;
  3856. }
  3857. set dataSource(value) {
  3858. this._dataSource = value;
  3859. if (typeof (value) == 'number' || typeof (value) == 'string')
  3860. this.value = Number(value);
  3861. else
  3862. super.dataSource = value;
  3863. }
  3864. get dataSource() {
  3865. return super.dataSource;
  3866. }
  3867. }
  3868. Laya.ILaya.regClass(ProgressBar);
  3869. Laya.ClassUtils.regClass("laya.ui.ProgressBar", ProgressBar);
  3870. Laya.ClassUtils.regClass("Laya.ProgressBar", ProgressBar);
  3871. class Radio extends Button {
  3872. constructor(skin = null, label = "") {
  3873. super(skin, label);
  3874. this.toggle = false;
  3875. this._autoSize = false;
  3876. }
  3877. destroy(destroyChild = true) {
  3878. super.destroy(destroyChild);
  3879. this._value = null;
  3880. }
  3881. preinitialize() {
  3882. super.preinitialize();
  3883. this.toggle = false;
  3884. this._autoSize = false;
  3885. }
  3886. initialize() {
  3887. super.initialize();
  3888. this.createText();
  3889. this._text.align = "left";
  3890. this._text.valign = "top";
  3891. this._text.width = 0;
  3892. this.on(Laya.Event.CLICK, this, this.onClick);
  3893. }
  3894. onClick(e) {
  3895. this.selected = true;
  3896. }
  3897. get value() {
  3898. return this._value != null ? this._value : this.label;
  3899. }
  3900. set value(obj) {
  3901. this._value = obj;
  3902. }
  3903. }
  3904. Laya.ILaya.regClass(Radio);
  3905. Laya.ClassUtils.regClass("laya.ui.Radio", Radio);
  3906. Laya.ClassUtils.regClass("Laya.Radio", Radio);
  3907. class UIGroup extends Box {
  3908. constructor(labels = null, skin = null) {
  3909. super();
  3910. this._selectedIndex = -1;
  3911. this._direction = "horizontal";
  3912. this._space = 0;
  3913. this.skin = skin;
  3914. this.labels = labels;
  3915. }
  3916. preinitialize() {
  3917. this.mouseEnabled = true;
  3918. }
  3919. destroy(destroyChild = true) {
  3920. super.destroy(destroyChild);
  3921. this._items && (this._items.length = 0);
  3922. this._items = null;
  3923. this.selectHandler = null;
  3924. }
  3925. addItem(item, autoLayOut = true) {
  3926. var display = item;
  3927. var index = this._items.length;
  3928. display.name = "item" + index;
  3929. this.addChild(display);
  3930. this.initItems();
  3931. if (autoLayOut && index > 0) {
  3932. var preItem = this._items[index - 1];
  3933. if (this._direction == "horizontal") {
  3934. display.x = preItem._x + preItem.width + this._space;
  3935. }
  3936. else {
  3937. display.y = preItem._y + preItem.height + this._space;
  3938. }
  3939. }
  3940. else {
  3941. if (autoLayOut) {
  3942. display.x = 0;
  3943. display.y = 0;
  3944. }
  3945. }
  3946. return index;
  3947. }
  3948. delItem(item, autoLayOut = true) {
  3949. var index = this._items.indexOf(item);
  3950. if (index != -1) {
  3951. var display = item;
  3952. this.removeChild(display);
  3953. for (var i = index + 1, n = this._items.length; i < n; i++) {
  3954. var child = this._items[i];
  3955. child.name = "item" + (i - 1);
  3956. if (autoLayOut) {
  3957. if (this._direction == "horizontal") {
  3958. child.x -= display.width + this._space;
  3959. }
  3960. else {
  3961. child.y -= display.height + this._space;
  3962. }
  3963. }
  3964. }
  3965. this.initItems();
  3966. if (this._selectedIndex > -1) {
  3967. var newIndex;
  3968. newIndex = this._selectedIndex < this._items.length ? this._selectedIndex : (this._selectedIndex - 1);
  3969. this._selectedIndex = -1;
  3970. this.selectedIndex = newIndex;
  3971. }
  3972. }
  3973. }
  3974. _afterInited() {
  3975. this.initItems();
  3976. }
  3977. initItems() {
  3978. this._items || (this._items = []);
  3979. this._items.length = 0;
  3980. for (var i = 0; i < 10000; i++) {
  3981. var item = this.getChildByName("item" + i);
  3982. if (item == null)
  3983. break;
  3984. this._items.push(item);
  3985. item.selected = (i === this._selectedIndex);
  3986. item.clickHandler = Laya.Handler.create(this, this.itemClick, [i], false);
  3987. }
  3988. }
  3989. itemClick(index) {
  3990. this.selectedIndex = index;
  3991. }
  3992. get selectedIndex() {
  3993. return this._selectedIndex;
  3994. }
  3995. set selectedIndex(value) {
  3996. if (this._selectedIndex != value) {
  3997. this.setSelect(this._selectedIndex, false);
  3998. this._selectedIndex = value;
  3999. this.setSelect(value, true);
  4000. this.event(Laya.Event.CHANGE);
  4001. this.selectHandler && this.selectHandler.runWith(this._selectedIndex);
  4002. }
  4003. }
  4004. setSelect(index, selected) {
  4005. if (this._items && index > -1 && index < this._items.length)
  4006. this._items[index].selected = selected;
  4007. }
  4008. get skin() {
  4009. return this._skin;
  4010. }
  4011. set skin(value) {
  4012. if (this._skin != value) {
  4013. this._skin = value;
  4014. if (this._skin && !Laya.Loader.getRes(this._skin)) {
  4015. Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
  4016. }
  4017. else {
  4018. this._skinLoaded();
  4019. }
  4020. }
  4021. }
  4022. _skinLoaded() {
  4023. this._setLabelChanged();
  4024. this.event(Laya.Event.LOADED);
  4025. }
  4026. get labels() {
  4027. return this._labels;
  4028. }
  4029. set labels(value) {
  4030. if (this._labels != value) {
  4031. this._labels = value;
  4032. this.removeChildren();
  4033. this._setLabelChanged();
  4034. if (this._labels) {
  4035. var a = this._labels.split(",");
  4036. for (var i = 0, n = a.length; i < n; i++) {
  4037. var item = this.createItem(this._skin, a[i]);
  4038. item.name = "item" + i;
  4039. this.addChild(item);
  4040. }
  4041. }
  4042. this.initItems();
  4043. }
  4044. }
  4045. createItem(skin, label) {
  4046. return null;
  4047. }
  4048. get labelColors() {
  4049. return this._labelColors;
  4050. }
  4051. set labelColors(value) {
  4052. if (this._labelColors != value) {
  4053. this._labelColors = value;
  4054. this._setLabelChanged();
  4055. }
  4056. }
  4057. get labelStroke() {
  4058. return this._labelStroke;
  4059. }
  4060. set labelStroke(value) {
  4061. if (this._labelStroke != value) {
  4062. this._labelStroke = value;
  4063. this._setLabelChanged();
  4064. }
  4065. }
  4066. get labelStrokeColor() {
  4067. return this._labelStrokeColor;
  4068. }
  4069. set labelStrokeColor(value) {
  4070. if (this._labelStrokeColor != value) {
  4071. this._labelStrokeColor = value;
  4072. this._setLabelChanged();
  4073. }
  4074. }
  4075. get strokeColors() {
  4076. return this._strokeColors;
  4077. }
  4078. set strokeColors(value) {
  4079. if (this._strokeColors != value) {
  4080. this._strokeColors = value;
  4081. this._setLabelChanged();
  4082. }
  4083. }
  4084. get labelSize() {
  4085. return this._labelSize;
  4086. }
  4087. set labelSize(value) {
  4088. if (this._labelSize != value) {
  4089. this._labelSize = value;
  4090. this._setLabelChanged();
  4091. }
  4092. }
  4093. get stateNum() {
  4094. return this._stateNum;
  4095. }
  4096. set stateNum(value) {
  4097. if (this._stateNum != value) {
  4098. this._stateNum = value;
  4099. this._setLabelChanged();
  4100. }
  4101. }
  4102. get labelBold() {
  4103. return this._labelBold;
  4104. }
  4105. set labelBold(value) {
  4106. if (this._labelBold != value) {
  4107. this._labelBold = value;
  4108. this._setLabelChanged();
  4109. }
  4110. }
  4111. get labelFont() {
  4112. return this._labelFont;
  4113. }
  4114. set labelFont(value) {
  4115. if (this._labelFont != value) {
  4116. this._labelFont = value;
  4117. this._setLabelChanged();
  4118. }
  4119. }
  4120. get labelPadding() {
  4121. return this._labelPadding;
  4122. }
  4123. set labelPadding(value) {
  4124. if (this._labelPadding != value) {
  4125. this._labelPadding = value;
  4126. this._setLabelChanged();
  4127. }
  4128. }
  4129. get direction() {
  4130. return this._direction;
  4131. }
  4132. set direction(value) {
  4133. this._direction = value;
  4134. this._setLabelChanged();
  4135. }
  4136. get space() {
  4137. return this._space;
  4138. }
  4139. set space(value) {
  4140. this._space = value;
  4141. this._setLabelChanged();
  4142. }
  4143. changeLabels() {
  4144. this._labelChanged = false;
  4145. if (this._items) {
  4146. var left = 0;
  4147. for (var i = 0, n = this._items.length; i < n; i++) {
  4148. var btn = this._items[i];
  4149. this._skin && (btn.skin = this._skin);
  4150. this._labelColors && (btn.labelColors = this._labelColors);
  4151. this._labelSize && (btn.labelSize = this._labelSize);
  4152. this._labelStroke && (btn.labelStroke = this._labelStroke);
  4153. this._labelStrokeColor && (btn.labelStrokeColor = this._labelStrokeColor);
  4154. this._strokeColors && (btn.strokeColors = this._strokeColors);
  4155. this._labelBold && (btn.labelBold = this._labelBold);
  4156. this._labelPadding && (btn.labelPadding = this._labelPadding);
  4157. this._labelAlign && (btn.labelAlign = this._labelAlign);
  4158. this._stateNum && (btn.stateNum = this._stateNum);
  4159. this._labelFont && (btn.labelFont = this._labelFont);
  4160. if (this._direction === "horizontal") {
  4161. btn.y = 0;
  4162. btn.x = left;
  4163. left += btn.width + this._space;
  4164. }
  4165. else {
  4166. btn.x = 0;
  4167. btn.y = left;
  4168. left += btn.height + this._space;
  4169. }
  4170. }
  4171. }
  4172. this._sizeChanged();
  4173. }
  4174. commitMeasure() {
  4175. this.runCallLater(this.changeLabels);
  4176. }
  4177. get items() {
  4178. return this._items;
  4179. }
  4180. get selection() {
  4181. return this._selectedIndex > -1 && this._selectedIndex < this._items.length ? this._items[this._selectedIndex] : null;
  4182. }
  4183. set selection(value) {
  4184. this.selectedIndex = this._items.indexOf(value);
  4185. }
  4186. set dataSource(value) {
  4187. this._dataSource = value;
  4188. if (typeof (value) == 'number' || typeof (value) == 'string')
  4189. this.selectedIndex = parseInt(value);
  4190. else if (value instanceof Array)
  4191. this.labels = value.join(",");
  4192. else
  4193. super.dataSource = value;
  4194. }
  4195. get dataSource() {
  4196. return super.dataSource;
  4197. }
  4198. _setLabelChanged() {
  4199. if (!this._labelChanged) {
  4200. this._labelChanged = true;
  4201. this.callLater(this.changeLabels);
  4202. }
  4203. }
  4204. }
  4205. Laya.ILaya.regClass(UIGroup);
  4206. Laya.ClassUtils.regClass("laya.ui.UIGroup", UIGroup);
  4207. Laya.ClassUtils.regClass("Laya.UIGroup", UIGroup);
  4208. class RadioGroup extends UIGroup {
  4209. createItem(skin, label) {
  4210. return new Radio(skin, label);
  4211. }
  4212. }
  4213. Laya.ILaya.regClass(RadioGroup);
  4214. Laya.ClassUtils.regClass("laya.ui.RadioGroup", RadioGroup);
  4215. Laya.ClassUtils.regClass("Laya.RadioGroup", RadioGroup);
  4216. class Tab extends UIGroup {
  4217. createItem(skin, label) {
  4218. return new Button(skin, label);
  4219. }
  4220. }
  4221. Laya.ILaya.regClass(Tab);
  4222. Laya.ClassUtils.regClass("laya.ui.Tab", Tab);
  4223. Laya.ClassUtils.regClass("Laya.Tab", Tab);
  4224. class ViewStack extends Box {
  4225. constructor() {
  4226. super(...arguments);
  4227. this._setIndexHandler = Laya.Handler.create(this, this.setIndex, null, false);
  4228. }
  4229. setItems(views) {
  4230. this.removeChildren();
  4231. var index = 0;
  4232. for (var i = 0, n = views.length; i < n; i++) {
  4233. var item = views[i];
  4234. if (item) {
  4235. item.name = "item" + index;
  4236. this.addChild(item);
  4237. index++;
  4238. }
  4239. }
  4240. this.initItems();
  4241. }
  4242. addItem(view) {
  4243. view.name = "item" + this._items.length;
  4244. this.addChild(view);
  4245. this.initItems();
  4246. }
  4247. _afterInited() {
  4248. this.initItems();
  4249. }
  4250. initItems() {
  4251. this._items = [];
  4252. for (var i = 0; i < 10000; i++) {
  4253. var item = this.getChildByName("item" + i);
  4254. if (item == null) {
  4255. break;
  4256. }
  4257. this._items.push(item);
  4258. item.visible = (i == this._selectedIndex);
  4259. }
  4260. }
  4261. get selectedIndex() {
  4262. return this._selectedIndex;
  4263. }
  4264. set selectedIndex(value) {
  4265. if (this._selectedIndex != value) {
  4266. this.setSelect(this._selectedIndex, false);
  4267. this._selectedIndex = value;
  4268. this.setSelect(this._selectedIndex, true);
  4269. }
  4270. }
  4271. setSelect(index, selected) {
  4272. if (this._items && index > -1 && index < this._items.length) {
  4273. this._items[index].visible = selected;
  4274. }
  4275. }
  4276. get selection() {
  4277. return this._selectedIndex > -1 && this._selectedIndex < this._items.length ? this._items[this._selectedIndex] : null;
  4278. }
  4279. set selection(value) {
  4280. this.selectedIndex = this._items.indexOf(value);
  4281. }
  4282. get setIndexHandler() {
  4283. return this._setIndexHandler;
  4284. }
  4285. set setIndexHandler(value) {
  4286. this._setIndexHandler = value;
  4287. }
  4288. setIndex(index) {
  4289. this.selectedIndex = index;
  4290. }
  4291. get items() {
  4292. return this._items;
  4293. }
  4294. set dataSource(value) {
  4295. this._dataSource = value;
  4296. if (typeof (value) == 'number' || typeof (value) == 'string') {
  4297. this.selectedIndex = parseInt(value);
  4298. }
  4299. else {
  4300. for (var prop in this._dataSource) {
  4301. if (prop in this) {
  4302. this[prop] = this._dataSource[prop];
  4303. }
  4304. }
  4305. }
  4306. }
  4307. get dataSource() {
  4308. return super.dataSource;
  4309. }
  4310. }
  4311. Laya.ILaya.regClass(ViewStack);
  4312. Laya.ClassUtils.regClass("laya.ui.ViewStack", ViewStack);
  4313. Laya.ClassUtils.regClass("Laya.ViewStack", ViewStack);
  4314. class TextInput extends Label {
  4315. constructor(text = "") {
  4316. super();
  4317. this.text = text;
  4318. this.skin = this.skin;
  4319. }
  4320. preinitialize() {
  4321. this.mouseEnabled = true;
  4322. }
  4323. destroy(destroyChild = true) {
  4324. super.destroy(destroyChild);
  4325. this._bg && this._bg.destroy();
  4326. this._bg = null;
  4327. }
  4328. createChildren() {
  4329. this.addChild(this._tf = new Laya.Input());
  4330. this._tf.padding = Styles.inputLabelPadding;
  4331. this._tf.on(Laya.Event.INPUT, this, this._onInput);
  4332. this._tf.on(Laya.Event.ENTER, this, this._onEnter);
  4333. this._tf.on(Laya.Event.BLUR, this, this._onBlur);
  4334. this._tf.on(Laya.Event.FOCUS, this, this._onFocus);
  4335. }
  4336. _onFocus() {
  4337. this.event(Laya.Event.FOCUS, this);
  4338. }
  4339. _onBlur() {
  4340. this.event(Laya.Event.BLUR, this);
  4341. }
  4342. _onInput() {
  4343. this.event(Laya.Event.INPUT, this);
  4344. }
  4345. _onEnter() {
  4346. this.event(Laya.Event.ENTER, this);
  4347. }
  4348. initialize() {
  4349. this.width = 128;
  4350. this.height = 22;
  4351. }
  4352. get bg() {
  4353. return this._bg;
  4354. }
  4355. set bg(value) {
  4356. this.graphics = this._bg = value;
  4357. }
  4358. get skin() {
  4359. return this._skin;
  4360. }
  4361. set skin(value) {
  4362. if (this._skin != value) {
  4363. this._skin = value;
  4364. if (this._skin && !Laya.Loader.getRes(this._skin)) {
  4365. Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
  4366. }
  4367. else {
  4368. this._skinLoaded();
  4369. }
  4370. }
  4371. }
  4372. _skinLoaded() {
  4373. this._bg || (this.graphics = this._bg = new AutoBitmap());
  4374. this._bg.source = Laya.Loader.getRes(this._skin);
  4375. this._width && (this._bg.width = this._width);
  4376. this._height && (this._bg.height = this._height);
  4377. this._sizeChanged();
  4378. this.event(Laya.Event.LOADED);
  4379. }
  4380. get sizeGrid() {
  4381. return this._bg && this._bg.sizeGrid ? this._bg.sizeGrid.join(",") : null;
  4382. }
  4383. set sizeGrid(value) {
  4384. this._bg || (this.graphics = this._bg = new AutoBitmap());
  4385. this._bg.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
  4386. }
  4387. set text(value) {
  4388. if (this._tf.text != value) {
  4389. value = value + "";
  4390. this._tf.text = value;
  4391. this.event(Laya.Event.CHANGE);
  4392. }
  4393. }
  4394. get text() {
  4395. return super.text;
  4396. }
  4397. set width(value) {
  4398. super.width = value;
  4399. this._bg && (this._bg.width = value);
  4400. }
  4401. get width() {
  4402. return super.width;
  4403. }
  4404. set height(value) {
  4405. super.height = value;
  4406. this._bg && (this._bg.height = value);
  4407. }
  4408. get height() {
  4409. return super.height;
  4410. }
  4411. get multiline() {
  4412. return this._tf.multiline;
  4413. }
  4414. set multiline(value) {
  4415. this._tf.multiline = value;
  4416. }
  4417. set editable(value) {
  4418. this._tf.editable = value;
  4419. }
  4420. get editable() {
  4421. return this._tf.editable;
  4422. }
  4423. select() {
  4424. this._tf.select();
  4425. }
  4426. get restrict() {
  4427. return this._tf.restrict;
  4428. }
  4429. set restrict(pattern) {
  4430. this._tf.restrict = pattern;
  4431. }
  4432. get prompt() {
  4433. return this._tf.prompt;
  4434. }
  4435. set prompt(value) {
  4436. this._tf.prompt = value;
  4437. }
  4438. get promptColor() {
  4439. return this._tf.promptColor;
  4440. }
  4441. set promptColor(value) {
  4442. this._tf.promptColor = value;
  4443. }
  4444. get maxChars() {
  4445. return this._tf.maxChars;
  4446. }
  4447. set maxChars(value) {
  4448. this._tf.maxChars = value;
  4449. }
  4450. get focus() {
  4451. return this._tf.focus;
  4452. }
  4453. set focus(value) {
  4454. this._tf.focus = value;
  4455. }
  4456. get type() {
  4457. return this._tf.type;
  4458. }
  4459. set type(value) {
  4460. this._tf.type = value;
  4461. }
  4462. setSelection(startIndex, endIndex) {
  4463. this._tf.setSelection(startIndex, endIndex);
  4464. }
  4465. }
  4466. Laya.ILaya.regClass(TextInput);
  4467. Laya.ClassUtils.regClass("laya.ui.TextInput", TextInput);
  4468. Laya.ClassUtils.regClass("Laya.TextInput", TextInput);
  4469. class TextArea extends TextInput {
  4470. constructor(text = "") {
  4471. super(text);
  4472. this.on(Laya.Event.CHANGE, this, this._onTextChange);
  4473. }
  4474. _onTextChange() {
  4475. this.callLater(this.changeScroll);
  4476. }
  4477. destroy(destroyChild = true) {
  4478. this._vScrollBar && this._vScrollBar.destroy();
  4479. this._hScrollBar && this._hScrollBar.destroy();
  4480. this._vScrollBar = null;
  4481. this._hScrollBar = null;
  4482. super.destroy(destroyChild);
  4483. }
  4484. initialize() {
  4485. this.width = 180;
  4486. this.height = 150;
  4487. this._tf.wordWrap = true;
  4488. this.multiline = true;
  4489. }
  4490. set width(value) {
  4491. super.width = value;
  4492. this.callLater(this.changeScroll);
  4493. }
  4494. get width() {
  4495. return super.width;
  4496. }
  4497. set height(value) {
  4498. super.height = value;
  4499. this.callLater(this.changeScroll);
  4500. }
  4501. get height() {
  4502. return super.height;
  4503. }
  4504. get vScrollBarSkin() {
  4505. return this._vScrollBar ? this._vScrollBar.skin : null;
  4506. }
  4507. set vScrollBarSkin(value) {
  4508. if (this._vScrollBar == null) {
  4509. this.addChild(this._vScrollBar = new VScrollBar());
  4510. this._vScrollBar.on(Laya.Event.CHANGE, this, this.onVBarChanged);
  4511. this._vScrollBar.target = this._tf;
  4512. this.callLater(this.changeScroll);
  4513. }
  4514. this._vScrollBar.skin = value;
  4515. }
  4516. get hScrollBarSkin() {
  4517. return this._hScrollBar ? this._hScrollBar.skin : null;
  4518. }
  4519. set hScrollBarSkin(value) {
  4520. if (this._hScrollBar == null) {
  4521. this.addChild(this._hScrollBar = new HScrollBar());
  4522. this._hScrollBar.on(Laya.Event.CHANGE, this, this.onHBarChanged);
  4523. this._hScrollBar.mouseWheelEnable = false;
  4524. this._hScrollBar.target = this._tf;
  4525. this.callLater(this.changeScroll);
  4526. }
  4527. this._hScrollBar.skin = value;
  4528. }
  4529. onVBarChanged(e) {
  4530. if (this._tf.scrollY != this._vScrollBar.value) {
  4531. this._tf.scrollY = this._vScrollBar.value;
  4532. }
  4533. }
  4534. onHBarChanged(e) {
  4535. if (this._tf.scrollX != this._hScrollBar.value) {
  4536. this._tf.scrollX = this._hScrollBar.value;
  4537. }
  4538. }
  4539. get vScrollBar() {
  4540. return this._vScrollBar;
  4541. }
  4542. get hScrollBar() {
  4543. return this._hScrollBar;
  4544. }
  4545. get maxScrollY() {
  4546. return this._tf.maxScrollY;
  4547. }
  4548. get scrollY() {
  4549. return this._tf.scrollY;
  4550. }
  4551. get maxScrollX() {
  4552. return this._tf.maxScrollX;
  4553. }
  4554. get scrollX() {
  4555. return this._tf.scrollX;
  4556. }
  4557. changeScroll() {
  4558. var vShow = this._vScrollBar && this._tf.maxScrollY > 0;
  4559. var hShow = this._hScrollBar && this._tf.maxScrollX > 0;
  4560. var showWidth = vShow ? this._width - this._vScrollBar.width : this._width;
  4561. var showHeight = hShow ? this._height - this._hScrollBar.height : this._height;
  4562. var padding = this._tf.padding || Styles.labelPadding;
  4563. this._tf.width = showWidth;
  4564. this._tf.height = showHeight;
  4565. if (this._vScrollBar) {
  4566. this._vScrollBar.x = this._width - this._vScrollBar.width - padding[2];
  4567. this._vScrollBar.y = padding[1];
  4568. this._vScrollBar.height = this._height - (hShow ? this._hScrollBar.height : 0) - padding[1] - padding[3];
  4569. this._vScrollBar.scrollSize = 1;
  4570. this._vScrollBar.thumbPercent = showHeight / Math.max(this._tf.textHeight, showHeight);
  4571. this._vScrollBar.setScroll(1, this._tf.maxScrollY, this._tf.scrollY);
  4572. this._vScrollBar.visible = vShow;
  4573. }
  4574. if (this._hScrollBar) {
  4575. this._hScrollBar.x = padding[0];
  4576. this._hScrollBar.y = this._height - this._hScrollBar.height - padding[3];
  4577. this._hScrollBar.width = this._width - (vShow ? this._vScrollBar.width : 0) - padding[0] - padding[2];
  4578. this._hScrollBar.scrollSize = Math.max(showWidth * 0.033, 1);
  4579. this._hScrollBar.thumbPercent = showWidth / Math.max(this._tf.textWidth, showWidth);
  4580. this._hScrollBar.setScroll(0, this.maxScrollX, this.scrollX);
  4581. this._hScrollBar.visible = hShow;
  4582. }
  4583. }
  4584. scrollTo(y) {
  4585. this.commitMeasure();
  4586. this._tf.scrollY = y;
  4587. }
  4588. }
  4589. Laya.ILaya.regClass(TextArea);
  4590. Laya.ClassUtils.regClass("laya.ui.TextArea", TextArea);
  4591. Laya.ClassUtils.regClass("Laya.TextArea", TextArea);
  4592. class ScaleBox extends Box {
  4593. constructor() {
  4594. super(...arguments);
  4595. this._oldW = 0;
  4596. this._oldH = 0;
  4597. }
  4598. onEnable() {
  4599. Laya.ILaya.stage.on("resize", this, this.onResize);
  4600. this.onResize();
  4601. }
  4602. onDisable() {
  4603. Laya.ILaya.stage.off("resize", this, this.onResize);
  4604. }
  4605. onResize() {
  4606. let stage = Laya.ILaya.stage;
  4607. if (this.width > 0 && this.height > 0) {
  4608. var scale = Math.min(stage.width / this._oldW, stage.height / this._oldH);
  4609. super.width = stage.width;
  4610. super.height = stage.height;
  4611. this.scale(scale, scale);
  4612. }
  4613. }
  4614. set width(value) {
  4615. super.width = value;
  4616. this._oldW = value;
  4617. }
  4618. get width() {
  4619. return super.width;
  4620. }
  4621. set height(value) {
  4622. super.height = value;
  4623. this._oldH = value;
  4624. }
  4625. get height() {
  4626. return super.height;
  4627. }
  4628. }
  4629. Laya.ILaya.regClass(ScaleBox);
  4630. Laya.ClassUtils.regClass("laya.ui.ScaleBox", ScaleBox);
  4631. Laya.ClassUtils.regClass("Laya.ScaleBox", ScaleBox);
  4632. class HSlider extends Slider {
  4633. constructor(skin = null) {
  4634. super(skin);
  4635. this.isVertical = false;
  4636. }
  4637. }
  4638. Laya.ILaya.regClass(HSlider);
  4639. Laya.ClassUtils.regClass("laya.ui.HSlider", HSlider);
  4640. Laya.ClassUtils.regClass("Laya.HSlider", HSlider);
  4641. class Panel extends Box {
  4642. constructor() {
  4643. super();
  4644. this._usedCache = null;
  4645. this._elasticEnabled = false;
  4646. this.width = this.height = 100;
  4647. }
  4648. destroy(destroyChild = true) {
  4649. super.destroy(destroyChild);
  4650. this._content && this._content.destroy(destroyChild);
  4651. this._vScrollBar && this._vScrollBar.destroy(destroyChild);
  4652. this._hScrollBar && this._hScrollBar.destroy(destroyChild);
  4653. this._vScrollBar = null;
  4654. this._hScrollBar = null;
  4655. this._content = null;
  4656. }
  4657. destroyChildren() {
  4658. this._content.destroyChildren();
  4659. }
  4660. createChildren() {
  4661. super.addChild(this._content = new Box());
  4662. }
  4663. addChild(child) {
  4664. child.on(Laya.Event.RESIZE, this, this.onResize);
  4665. this._setScrollChanged();
  4666. return this._content.addChild(child);
  4667. }
  4668. onResize() {
  4669. this._setScrollChanged();
  4670. }
  4671. addChildAt(child, index) {
  4672. child.on(Laya.Event.RESIZE, this, this.onResize);
  4673. this._setScrollChanged();
  4674. return this._content.addChildAt(child, index);
  4675. }
  4676. removeChild(child) {
  4677. child.off(Laya.Event.RESIZE, this, this.onResize);
  4678. this._setScrollChanged();
  4679. return this._content.removeChild(child);
  4680. }
  4681. removeChildAt(index) {
  4682. this.getChildAt(index).off(Laya.Event.RESIZE, this, this.onResize);
  4683. this._setScrollChanged();
  4684. return this._content.removeChildAt(index);
  4685. }
  4686. removeChildren(beginIndex = 0, endIndex = 0x7fffffff) {
  4687. this._content.removeChildren(beginIndex, endIndex);
  4688. this._setScrollChanged();
  4689. return this;
  4690. }
  4691. getChildAt(index) {
  4692. return this._content.getChildAt(index);
  4693. }
  4694. getChildByName(name) {
  4695. return this._content.getChildByName(name);
  4696. }
  4697. getChildIndex(child) {
  4698. return this._content.getChildIndex(child);
  4699. }
  4700. get numChildren() {
  4701. return this._content.numChildren;
  4702. }
  4703. changeScroll() {
  4704. this._scrollChanged = false;
  4705. var contentW = this.contentWidth || 1;
  4706. var contentH = this.contentHeight || 1;
  4707. var vscroll = this._vScrollBar;
  4708. var hscroll = this._hScrollBar;
  4709. var vShow = vscroll && contentH > this._height;
  4710. var hShow = hscroll && contentW > this._width;
  4711. var showWidth = vShow ? this._width - vscroll.width : this._width;
  4712. var showHeight = hShow ? this._height - hscroll.height : this._height;
  4713. if (vscroll) {
  4714. vscroll.x = this._width - vscroll.width;
  4715. vscroll.y = 0;
  4716. vscroll.height = this._height - (hShow ? hscroll.height : 0);
  4717. vscroll.scrollSize = Math.max(this._height * 0.033, 1);
  4718. vscroll.thumbPercent = showHeight / contentH;
  4719. vscroll.setScroll(0, contentH - showHeight, vscroll.value);
  4720. }
  4721. if (hscroll) {
  4722. hscroll.x = 0;
  4723. hscroll.y = this._height - hscroll.height;
  4724. hscroll.width = this._width - (vShow ? vscroll.width : 0);
  4725. hscroll.scrollSize = Math.max(this._width * 0.033, 1);
  4726. hscroll.thumbPercent = showWidth / contentW;
  4727. hscroll.setScroll(0, contentW - showWidth, hscroll.value);
  4728. }
  4729. }
  4730. _sizeChanged() {
  4731. super._sizeChanged();
  4732. this.setContentSize(this._width, this._height);
  4733. }
  4734. get contentWidth() {
  4735. var max = 0;
  4736. for (var i = this._content.numChildren - 1; i > -1; i--) {
  4737. var comp = this._content.getChildAt(i);
  4738. max = Math.max(comp._x + comp.width * comp.scaleX - comp.pivotX, max);
  4739. }
  4740. return max;
  4741. }
  4742. get contentHeight() {
  4743. var max = 0;
  4744. for (var i = this._content.numChildren - 1; i > -1; i--) {
  4745. var comp = this._content.getChildAt(i);
  4746. max = Math.max(comp._y + comp.height * comp.scaleY - comp.pivotY, max);
  4747. }
  4748. return max;
  4749. }
  4750. setContentSize(width, height) {
  4751. var content = this._content;
  4752. content.width = width;
  4753. content.height = height;
  4754. content._style.scrollRect || (content.scrollRect = Laya.Rectangle.create());
  4755. content._style.scrollRect.setTo(0, 0, width, height);
  4756. content.scrollRect = content.scrollRect;
  4757. }
  4758. set width(value) {
  4759. super.width = value;
  4760. this._setScrollChanged();
  4761. }
  4762. get width() {
  4763. return super.width;
  4764. }
  4765. set height(value) {
  4766. super.height = value;
  4767. this._setScrollChanged();
  4768. }
  4769. get height() {
  4770. return super.height;
  4771. }
  4772. get vScrollBarSkin() {
  4773. return this._vScrollBar ? this._vScrollBar.skin : null;
  4774. }
  4775. set vScrollBarSkin(value) {
  4776. if (this._vScrollBar == null) {
  4777. super.addChild(this._vScrollBar = new VScrollBar());
  4778. this._vScrollBar.on(Laya.Event.CHANGE, this, this.onScrollBarChange, [this._vScrollBar]);
  4779. this._vScrollBar.target = this._content;
  4780. this._vScrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
  4781. this._setScrollChanged();
  4782. }
  4783. this._vScrollBar.skin = value;
  4784. }
  4785. get hScrollBarSkin() {
  4786. return this._hScrollBar ? this._hScrollBar.skin : null;
  4787. }
  4788. set hScrollBarSkin(value) {
  4789. if (this._hScrollBar == null) {
  4790. super.addChild(this._hScrollBar = new HScrollBar());
  4791. this._hScrollBar.on(Laya.Event.CHANGE, this, this.onScrollBarChange, [this._hScrollBar]);
  4792. this._hScrollBar.target = this._content;
  4793. this._hScrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
  4794. this._setScrollChanged();
  4795. }
  4796. this._hScrollBar.skin = value;
  4797. }
  4798. get vScrollBar() {
  4799. return this._vScrollBar;
  4800. }
  4801. get hScrollBar() {
  4802. return this._hScrollBar;
  4803. }
  4804. get content() {
  4805. return this._content;
  4806. }
  4807. onScrollBarChange(scrollBar) {
  4808. var rect = this._content._style.scrollRect;
  4809. if (rect) {
  4810. var start = Math.round(scrollBar.value);
  4811. scrollBar.isVertical ? rect.y = start : rect.x = start;
  4812. this._content.scrollRect = rect;
  4813. }
  4814. }
  4815. scrollTo(x = 0, y = 0) {
  4816. if (this.vScrollBar)
  4817. this.vScrollBar.value = y;
  4818. if (this.hScrollBar)
  4819. this.hScrollBar.value = x;
  4820. }
  4821. refresh() {
  4822. this.changeScroll();
  4823. }
  4824. set cacheAs(value) {
  4825. super.cacheAs = value;
  4826. this._usedCache = null;
  4827. if (value !== "none") {
  4828. this._hScrollBar && this._hScrollBar.on(Laya.Event.START, this, this.onScrollStart);
  4829. this._vScrollBar && this._vScrollBar.on(Laya.Event.START, this, this.onScrollStart);
  4830. }
  4831. else {
  4832. this._hScrollBar && this._hScrollBar.off(Laya.Event.START, this, this.onScrollStart);
  4833. this._vScrollBar && this._vScrollBar.off(Laya.Event.START, this, this.onScrollStart);
  4834. }
  4835. }
  4836. get cacheAs() {
  4837. return super.cacheAs;
  4838. }
  4839. get elasticEnabled() {
  4840. return this._elasticEnabled;
  4841. }
  4842. set elasticEnabled(value) {
  4843. this._elasticEnabled = value;
  4844. if (this._vScrollBar) {
  4845. this._vScrollBar.elasticDistance = value ? 200 : 0;
  4846. }
  4847. if (this._hScrollBar) {
  4848. this._hScrollBar.elasticDistance = value ? 200 : 0;
  4849. }
  4850. }
  4851. onScrollStart() {
  4852. this._usedCache || (this._usedCache = super.cacheAs);
  4853. super.cacheAs = "none";
  4854. this._hScrollBar && this._hScrollBar.once(Laya.Event.END, this, this.onScrollEnd);
  4855. this._vScrollBar && this._vScrollBar.once(Laya.Event.END, this, this.onScrollEnd);
  4856. }
  4857. onScrollEnd() {
  4858. super.cacheAs = this._usedCache;
  4859. }
  4860. _setScrollChanged() {
  4861. if (!this._scrollChanged) {
  4862. this._scrollChanged = true;
  4863. this.callLater(this.changeScroll);
  4864. }
  4865. }
  4866. }
  4867. Laya.ILaya.regClass(Panel);
  4868. Laya.ClassUtils.regClass("laya.ui.Panel", Panel);
  4869. Laya.ClassUtils.regClass("Laya.Panel", Panel);
  4870. class VSlider extends Slider {
  4871. }
  4872. Laya.ILaya.regClass(VSlider);
  4873. Laya.ClassUtils.regClass("laya.ui.VSlider", VSlider);
  4874. Laya.ClassUtils.regClass("Laya.VSlider", VSlider);
  4875. class Tree extends Box {
  4876. constructor() {
  4877. super();
  4878. this._spaceLeft = 10;
  4879. this._spaceBottom = 0;
  4880. this._keepStatus = true;
  4881. this.width = this.height = 200;
  4882. }
  4883. destroy(destroyChild = true) {
  4884. super.destroy(destroyChild);
  4885. this._list && this._list.destroy(destroyChild);
  4886. this._list = null;
  4887. this._source = null;
  4888. this._renderHandler = null;
  4889. }
  4890. createChildren() {
  4891. this.addChild(this._list = new List());
  4892. this._list.renderHandler = Laya.Handler.create(this, this.renderItem, null, false);
  4893. this._list.repeatX = 1;
  4894. this._list.on(Laya.Event.CHANGE, this, this.onListChange);
  4895. }
  4896. onListChange(e = null) {
  4897. this.event(Laya.Event.CHANGE);
  4898. }
  4899. get keepStatus() {
  4900. return this._keepStatus;
  4901. }
  4902. set keepStatus(value) {
  4903. this._keepStatus = value;
  4904. }
  4905. get array() {
  4906. return this._list.array;
  4907. }
  4908. set array(value) {
  4909. if (this._keepStatus && this._list.array && value) {
  4910. this.parseOpenStatus(this._list.array, value);
  4911. }
  4912. this._source = value;
  4913. this._list.array = this.getArray();
  4914. }
  4915. get source() {
  4916. return this._source;
  4917. }
  4918. get list() {
  4919. return this._list;
  4920. }
  4921. get itemRender() {
  4922. return this._list.itemRender;
  4923. }
  4924. set itemRender(value) {
  4925. this._list.itemRender = value;
  4926. }
  4927. get scrollBarSkin() {
  4928. return this._list.vScrollBarSkin;
  4929. }
  4930. set scrollBarSkin(value) {
  4931. this._list.vScrollBarSkin = value;
  4932. }
  4933. get scrollBar() {
  4934. return this._list.scrollBar;
  4935. }
  4936. get mouseHandler() {
  4937. return this._list.mouseHandler;
  4938. }
  4939. set mouseHandler(value) {
  4940. this._list.mouseHandler = value;
  4941. }
  4942. get renderHandler() {
  4943. return this._renderHandler;
  4944. }
  4945. set renderHandler(value) {
  4946. this._renderHandler = value;
  4947. }
  4948. get spaceLeft() {
  4949. return this._spaceLeft;
  4950. }
  4951. set spaceLeft(value) {
  4952. this._spaceLeft = value;
  4953. }
  4954. get spaceBottom() {
  4955. return this._list.spaceY;
  4956. }
  4957. set spaceBottom(value) {
  4958. this._list.spaceY = value;
  4959. }
  4960. get selectedIndex() {
  4961. return this._list.selectedIndex;
  4962. }
  4963. set selectedIndex(value) {
  4964. this._list.selectedIndex = value;
  4965. }
  4966. get selectedItem() {
  4967. return this._list.selectedItem;
  4968. }
  4969. set selectedItem(value) {
  4970. this._list.selectedItem = value;
  4971. }
  4972. set width(value) {
  4973. super.width = value;
  4974. this._list.width = value;
  4975. }
  4976. get width() {
  4977. return super.width;
  4978. }
  4979. set height(value) {
  4980. super.height = value;
  4981. this._list.height = value;
  4982. }
  4983. get height() {
  4984. return super.height;
  4985. }
  4986. getArray() {
  4987. var arr = [];
  4988. for (let key in this._source) {
  4989. let item = this._source[key];
  4990. if (this.getParentOpenStatus(item)) {
  4991. item.x = this._spaceLeft * this.getDepth(item);
  4992. arr.push(item);
  4993. }
  4994. }
  4995. return arr;
  4996. }
  4997. getDepth(item, num = 0) {
  4998. if (item.nodeParent == null)
  4999. return num;
  5000. else
  5001. return this.getDepth(item.nodeParent, num + 1);
  5002. }
  5003. getParentOpenStatus(item) {
  5004. var parent = item.nodeParent;
  5005. if (parent == null) {
  5006. return true;
  5007. }
  5008. else {
  5009. if (parent.isOpen) {
  5010. if (parent.nodeParent != null)
  5011. return this.getParentOpenStatus(parent);
  5012. else
  5013. return true;
  5014. }
  5015. else {
  5016. return false;
  5017. }
  5018. }
  5019. }
  5020. renderItem(cell, index) {
  5021. var item = cell.dataSource;
  5022. if (item) {
  5023. cell.left = item.x;
  5024. var arrow = cell.getChildByName("arrow");
  5025. if (arrow) {
  5026. if (item.hasChild) {
  5027. arrow.visible = true;
  5028. arrow.index = item.isOpen ? 1 : 0;
  5029. arrow.tag = index;
  5030. arrow.off(Laya.Event.CLICK, this, this.onArrowClick);
  5031. arrow.on(Laya.Event.CLICK, this, this.onArrowClick);
  5032. }
  5033. else {
  5034. arrow.visible = false;
  5035. }
  5036. }
  5037. var folder = cell.getChildByName("folder");
  5038. if (folder) {
  5039. if (folder.clipY == 2) {
  5040. folder.index = item.isDirectory ? 0 : 1;
  5041. }
  5042. else {
  5043. folder.index = item.isDirectory ? item.isOpen ? 1 : 0 : 2;
  5044. }
  5045. }
  5046. this._renderHandler && this._renderHandler.runWith([cell, index]);
  5047. }
  5048. }
  5049. onArrowClick(e) {
  5050. var arrow = e.currentTarget;
  5051. var index = arrow.tag;
  5052. this._list.array[index].isOpen = !this._list.array[index].isOpen;
  5053. this.event(Laya.Event.OPEN);
  5054. this._list.array = this.getArray();
  5055. }
  5056. setItemState(index, isOpen) {
  5057. if (!this._list.array[index])
  5058. return;
  5059. this._list.array[index].isOpen = isOpen;
  5060. this._list.array = this.getArray();
  5061. }
  5062. fresh() {
  5063. this._list.array = this.getArray();
  5064. this.repaint();
  5065. }
  5066. set dataSource(value) {
  5067. this._dataSource = value;
  5068. super.dataSource = value;
  5069. }
  5070. get dataSource() {
  5071. return super.dataSource;
  5072. }
  5073. set xml(value) {
  5074. var arr = [];
  5075. this.parseXml(value.childNodes[0], arr, null, true);
  5076. this.array = arr;
  5077. }
  5078. parseXml(xml, source, nodeParent, isRoot) {
  5079. var obj;
  5080. var list = xml.childNodes;
  5081. var childCount = list.length;
  5082. if (!isRoot) {
  5083. obj = {};
  5084. var list2 = xml.attributes;
  5085. for (let key in list2) {
  5086. var attrs = list2[key];
  5087. var prop = attrs.nodeName;
  5088. var value = attrs.nodeValue;
  5089. obj[prop] = value == "true" ? true : value == "false" ? false : value;
  5090. }
  5091. obj.nodeParent = nodeParent;
  5092. if (childCount > 0)
  5093. obj.isDirectory = true;
  5094. obj.hasChild = childCount > 0;
  5095. source.push(obj);
  5096. }
  5097. for (var i = 0; i < childCount; i++) {
  5098. var node = list[i];
  5099. this.parseXml(node, source, obj, false);
  5100. }
  5101. }
  5102. parseOpenStatus(oldSource, newSource) {
  5103. for (var i = 0, n = newSource.length; i < n; i++) {
  5104. var newItem = newSource[i];
  5105. if (newItem.isDirectory) {
  5106. for (var j = 0, m = oldSource.length; j < m; j++) {
  5107. var oldItem = oldSource[j];
  5108. if (oldItem.isDirectory && this.isSameParent(oldItem, newItem) && newItem.label == oldItem.label) {
  5109. newItem.isOpen = oldItem.isOpen;
  5110. break;
  5111. }
  5112. }
  5113. }
  5114. }
  5115. }
  5116. isSameParent(item1, item2) {
  5117. if (item1.nodeParent == null && item2.nodeParent == null)
  5118. return true;
  5119. else if (item1.nodeParent == null || item2.nodeParent == null)
  5120. return false;
  5121. else {
  5122. if (item1.nodeParent.label == item2.nodeParent.label)
  5123. return this.isSameParent(item1.nodeParent, item2.nodeParent);
  5124. else
  5125. return false;
  5126. }
  5127. }
  5128. get selectedPath() {
  5129. if (this._list.selectedItem) {
  5130. return this._list.selectedItem.path;
  5131. }
  5132. return null;
  5133. }
  5134. filter(key) {
  5135. if (Boolean(key)) {
  5136. var result = [];
  5137. this.getFilterSource(this._source, result, key);
  5138. this._list.array = result;
  5139. }
  5140. else {
  5141. this._list.array = this.getArray();
  5142. }
  5143. }
  5144. getFilterSource(array, result, key) {
  5145. key = key.toLocaleLowerCase();
  5146. for (let item of array) {
  5147. if (!item.isDirectory && String(item.label).toLowerCase().indexOf(key) > -1) {
  5148. item.x = 0;
  5149. result.push(item);
  5150. }
  5151. if (item.child && item.child.length > 0) {
  5152. this.getFilterSource(item.child, result, key);
  5153. }
  5154. }
  5155. }
  5156. }
  5157. Laya.ILaya.regClass(Tree);
  5158. Laya.ClassUtils.regClass("laya.ui.Tree", Tree);
  5159. Laya.ClassUtils.regClass("Laya.Tree", Tree);
  5160. class LayoutBox extends Box {
  5161. constructor() {
  5162. super(...arguments);
  5163. this._space = 0;
  5164. this._align = "none";
  5165. this._itemChanged = false;
  5166. }
  5167. addChild(child) {
  5168. child.on(Laya.Event.RESIZE, this, this.onResize);
  5169. this._setItemChanged();
  5170. return super.addChild(child);
  5171. }
  5172. onResize(e) {
  5173. this._setItemChanged();
  5174. }
  5175. addChildAt(child, index) {
  5176. child.on(Laya.Event.RESIZE, this, this.onResize);
  5177. this._setItemChanged();
  5178. return super.addChildAt(child, index);
  5179. }
  5180. removeChildAt(index) {
  5181. this.getChildAt(index).off(Laya.Event.RESIZE, this, this.onResize);
  5182. this._setItemChanged();
  5183. return super.removeChildAt(index);
  5184. }
  5185. refresh() {
  5186. this._setItemChanged();
  5187. }
  5188. changeItems() {
  5189. this._itemChanged = false;
  5190. }
  5191. get space() {
  5192. return this._space;
  5193. }
  5194. set space(value) {
  5195. this._space = value;
  5196. this._setItemChanged();
  5197. }
  5198. get align() {
  5199. return this._align;
  5200. }
  5201. set align(value) {
  5202. this._align = value;
  5203. this._setItemChanged();
  5204. }
  5205. sortItem(items) {
  5206. if (items)
  5207. items.sort(function (a, b) { return a.y - b.y; });
  5208. }
  5209. _setItemChanged() {
  5210. if (!this._itemChanged) {
  5211. this._itemChanged = true;
  5212. this.callLater(this.changeItems);
  5213. }
  5214. }
  5215. }
  5216. Laya.ILaya.regClass(LayoutBox);
  5217. Laya.ClassUtils.regClass("laya.ui.LayoutBox", LayoutBox);
  5218. Laya.ClassUtils.regClass("Laya.LayoutBox", LayoutBox);
  5219. class HBox extends LayoutBox {
  5220. sortItem(items) {
  5221. if (items)
  5222. items.sort(function (a, b) { return a.x - b.x; });
  5223. }
  5224. set height(value) {
  5225. if (this._height != value) {
  5226. super.height = value;
  5227. this.callLater(this.changeItems);
  5228. }
  5229. }
  5230. get height() {
  5231. return super.height;
  5232. }
  5233. changeItems() {
  5234. this._itemChanged = false;
  5235. var items = [];
  5236. var maxHeight = 0;
  5237. for (var i = 0, n = this.numChildren; i < n; i++) {
  5238. var item = this.getChildAt(i);
  5239. if (item) {
  5240. items.push(item);
  5241. maxHeight = this._height ? this._height : Math.max(maxHeight, item.height * item.scaleY);
  5242. }
  5243. }
  5244. this.sortItem(items);
  5245. var left = 0;
  5246. for (i = 0, n = items.length; i < n; i++) {
  5247. item = items[i];
  5248. item.x = left;
  5249. left += item.width * item.scaleX + this._space;
  5250. if (this._align == HBox.TOP) {
  5251. item.y = 0;
  5252. }
  5253. else if (this._align == HBox.MIDDLE) {
  5254. item.y = (maxHeight - item.height * item.scaleY) * 0.5;
  5255. }
  5256. else if (this._align == HBox.BOTTOM) {
  5257. item.y = maxHeight - item.height * item.scaleY;
  5258. }
  5259. }
  5260. this._sizeChanged();
  5261. }
  5262. }
  5263. HBox.NONE = "none";
  5264. HBox.TOP = "top";
  5265. HBox.MIDDLE = "middle";
  5266. HBox.BOTTOM = "bottom";
  5267. Laya.ILaya.regClass(HBox);
  5268. Laya.ClassUtils.regClass("laya.ui.HBox", HBox);
  5269. Laya.ClassUtils.regClass("Laya.HBox", HBox);
  5270. class VBox extends LayoutBox {
  5271. set width(value) {
  5272. if (this._width != value) {
  5273. super.width = value;
  5274. this.callLater(this.changeItems);
  5275. }
  5276. }
  5277. get width() {
  5278. return super.width;
  5279. }
  5280. changeItems() {
  5281. this._itemChanged = false;
  5282. var items = [];
  5283. var maxWidth = 0;
  5284. for (var i = 0, n = this.numChildren; i < n; i++) {
  5285. var item = this.getChildAt(i);
  5286. if (item) {
  5287. items.push(item);
  5288. maxWidth = this._width ? this._width : Math.max(maxWidth, item.width * item.scaleX);
  5289. }
  5290. }
  5291. this.sortItem(items);
  5292. var top = 0;
  5293. for (i = 0, n = items.length; i < n; i++) {
  5294. item = items[i];
  5295. item.y = top;
  5296. top += item.height * item.scaleY + this._space;
  5297. if (this._align == VBox.LEFT) {
  5298. item.x = 0;
  5299. }
  5300. else if (this._align == VBox.CENTER) {
  5301. item.x = (maxWidth - item.width * item.scaleX) * 0.5;
  5302. }
  5303. else if (this._align == VBox.RIGHT) {
  5304. item.x = maxWidth - item.width * item.scaleX;
  5305. }
  5306. }
  5307. this._sizeChanged();
  5308. }
  5309. }
  5310. VBox.NONE = "none";
  5311. VBox.LEFT = "left";
  5312. VBox.CENTER = "center";
  5313. VBox.RIGHT = "right";
  5314. Laya.ILaya.regClass(VBox);
  5315. Laya.ClassUtils.regClass("laya.ui.VBox", VBox);
  5316. Laya.ClassUtils.regClass("Laya.VBox", VBox);
  5317. class FontClip extends Clip {
  5318. constructor(skin = null, sheet = null) {
  5319. super();
  5320. this._valueArr = '';
  5321. this._indexMap = null;
  5322. this._sheet = null;
  5323. this._direction = "horizontal";
  5324. this._spaceX = 0;
  5325. this._spaceY = 0;
  5326. this._align = "left";
  5327. this._wordsW = 0;
  5328. this._wordsH = 0;
  5329. if (skin)
  5330. this.skin = skin;
  5331. if (sheet)
  5332. this.sheet = sheet;
  5333. }
  5334. createChildren() {
  5335. this._bitmap = new AutoBitmap();
  5336. this.on(Laya.Event.LOADED, this, this._onClipLoaded);
  5337. }
  5338. _onClipLoaded() {
  5339. this.callLater(this.changeValue);
  5340. }
  5341. get sheet() {
  5342. return this._sheet;
  5343. }
  5344. set sheet(value) {
  5345. value += "";
  5346. this._sheet = value;
  5347. var arr = value.split(" ");
  5348. this._clipX = String(arr[0]).length;
  5349. this.clipY = arr.length;
  5350. this._indexMap = {};
  5351. for (var i = 0; i < this._clipY; i++) {
  5352. var line = arr[i].split("");
  5353. for (var j = 0, n = line.length; j < n; j++) {
  5354. this._indexMap[line[j]] = i * this._clipX + j;
  5355. }
  5356. }
  5357. }
  5358. get value() {
  5359. if (!this._valueArr)
  5360. return "";
  5361. return this._valueArr;
  5362. }
  5363. set value(value) {
  5364. value += "";
  5365. this._valueArr = value;
  5366. this.callLater(this.changeValue);
  5367. }
  5368. get direction() {
  5369. return this._direction;
  5370. }
  5371. set direction(value) {
  5372. this._direction = value;
  5373. this.callLater(this.changeValue);
  5374. }
  5375. get spaceX() {
  5376. return this._spaceX;
  5377. }
  5378. set spaceX(value) {
  5379. this._spaceX = value;
  5380. if (this._direction === "horizontal")
  5381. this.callLater(this.changeValue);
  5382. }
  5383. get spaceY() {
  5384. return this._spaceY;
  5385. }
  5386. set spaceY(value) {
  5387. this._spaceY = value;
  5388. if (!(this._direction === "horizontal"))
  5389. this.callLater(this.changeValue);
  5390. }
  5391. set align(v) {
  5392. this._align = v;
  5393. this.callLater(this.changeValue);
  5394. }
  5395. get align() {
  5396. return this._align;
  5397. }
  5398. changeValue() {
  5399. if (!this._sources)
  5400. return;
  5401. if (!this._valueArr)
  5402. return;
  5403. this.graphics.clear(true);
  5404. var texture;
  5405. texture = this._sources[0];
  5406. if (!texture)
  5407. return;
  5408. var isHorizontal = (this._direction === "horizontal");
  5409. if (isHorizontal) {
  5410. this._wordsW = this._valueArr.length * (texture.sourceWidth + this.spaceX);
  5411. this._wordsH = texture.sourceHeight;
  5412. }
  5413. else {
  5414. this._wordsW = texture.sourceWidth;
  5415. this._wordsH = (texture.sourceHeight + this.spaceY) * this._valueArr.length;
  5416. }
  5417. var dX = 0;
  5418. if (this._width) {
  5419. switch (this._align) {
  5420. case "center":
  5421. dX = 0.5 * (this._width - this._wordsW);
  5422. break;
  5423. case "right":
  5424. dX = this._width - this._wordsW;
  5425. break;
  5426. default:
  5427. dX = 0;
  5428. }
  5429. }
  5430. for (var i = 0, sz = this._valueArr.length; i < sz; i++) {
  5431. var index = this._indexMap[this._valueArr.charAt(i)];
  5432. if (!this.sources[index])
  5433. continue;
  5434. texture = this.sources[index];
  5435. if (isHorizontal)
  5436. this.graphics.drawImage(texture, dX + i * (texture.sourceWidth + this.spaceX), 0, texture.sourceWidth, texture.sourceHeight);
  5437. else
  5438. this.graphics.drawImage(texture, 0 + dX, i * (texture.sourceHeight + this.spaceY), texture.sourceWidth, texture.sourceHeight);
  5439. }
  5440. if (!this._width) {
  5441. this._widget.resetLayoutX();
  5442. this.callLater(this._sizeChanged);
  5443. }
  5444. if (!this._height) {
  5445. this._widget.resetLayoutY();
  5446. this.callLater(this._sizeChanged);
  5447. }
  5448. }
  5449. set width(value) {
  5450. super.width = value;
  5451. this.callLater(this.changeValue);
  5452. }
  5453. get width() {
  5454. return super.width;
  5455. }
  5456. set height(value) {
  5457. super.height = value;
  5458. this.callLater(this.changeValue);
  5459. }
  5460. get height() {
  5461. return super.height;
  5462. }
  5463. measureWidth() {
  5464. return this._wordsW;
  5465. }
  5466. measureHeight() {
  5467. return this._wordsH;
  5468. }
  5469. destroy(destroyChild = true) {
  5470. this._valueArr = null;
  5471. this._indexMap = null;
  5472. this.graphics.clear(true);
  5473. this.removeSelf();
  5474. this.off(Laya.Event.LOADED, this, this._onClipLoaded);
  5475. super.destroy(destroyChild);
  5476. }
  5477. }
  5478. Laya.ILaya.regClass(FontClip);
  5479. Laya.ClassUtils.regClass("laya.ui.FontClip", FontClip);
  5480. Laya.ClassUtils.regClass("Laya.FontClip", FontClip);
  5481. class View extends Laya.Scene {
  5482. constructor() {
  5483. super(false);
  5484. this._watchMap = {};
  5485. this._anchorX = NaN;
  5486. this._anchorY = NaN;
  5487. this._widget = Widget.EMPTY;
  5488. this.createChildren();
  5489. }
  5490. static __init__() {
  5491. Laya.ILaya.ClassUtils.regShortClassName([ViewStack, Button, TextArea, ColorPicker, Box, ScaleBox, CheckBox, Clip, ComboBox, UIComponent,
  5492. HScrollBar, HSlider, Image, Label, List, Panel, ProgressBar, Radio, RadioGroup, ScrollBar, Slider, Tab, TextInput, View,
  5493. VScrollBar, VSlider, Tree, HBox, VBox, Laya.Animation, Laya.Text, FontClip]);
  5494. }
  5495. static regComponent(key, compClass) {
  5496. Laya.ILaya.ClassUtils.regClass(key, compClass);
  5497. }
  5498. static regViewRuntime(key, compClass) {
  5499. Laya.ILaya.ClassUtils.regClass(key, compClass);
  5500. }
  5501. static regUI(url, json) {
  5502. Laya.ILaya.loader.cacheRes(url, json);
  5503. }
  5504. destroy(destroyChild = true) {
  5505. this._watchMap = null;
  5506. super.destroy(destroyChild);
  5507. }
  5508. changeData(key) {
  5509. var arr = this._watchMap[key];
  5510. if (!arr)
  5511. return;
  5512. for (var i = 0, n = arr.length; i < n; i++) {
  5513. var watcher = arr[i];
  5514. watcher.exe(this);
  5515. }
  5516. }
  5517. get top() {
  5518. return this._widget.top;
  5519. }
  5520. set top(value) {
  5521. if (value != this._widget.top) {
  5522. this._getWidget().top = value;
  5523. }
  5524. }
  5525. get bottom() {
  5526. return this._widget.bottom;
  5527. }
  5528. set bottom(value) {
  5529. if (value != this._widget.bottom) {
  5530. this._getWidget().bottom = value;
  5531. }
  5532. }
  5533. get left() {
  5534. return this._widget.left;
  5535. }
  5536. set left(value) {
  5537. if (value != this._widget.left) {
  5538. this._getWidget().left = value;
  5539. }
  5540. }
  5541. get right() {
  5542. return this._widget.right;
  5543. }
  5544. set right(value) {
  5545. if (value != this._widget.right) {
  5546. this._getWidget().right = value;
  5547. }
  5548. }
  5549. get centerX() {
  5550. return this._widget.centerX;
  5551. }
  5552. set centerX(value) {
  5553. if (value != this._widget.centerX) {
  5554. this._getWidget().centerX = value;
  5555. }
  5556. }
  5557. get centerY() {
  5558. return this._widget.centerY;
  5559. }
  5560. set centerY(value) {
  5561. if (value != this._widget.centerY) {
  5562. this._getWidget().centerY = value;
  5563. }
  5564. }
  5565. get anchorX() {
  5566. return this._anchorX;
  5567. }
  5568. set anchorX(value) {
  5569. if (this._anchorX != value) {
  5570. this._anchorX = value;
  5571. this.callLater(this._sizeChanged);
  5572. }
  5573. }
  5574. get anchorY() {
  5575. return this._anchorY;
  5576. }
  5577. set anchorY(value) {
  5578. if (this._anchorY != value) {
  5579. this._anchorY = value;
  5580. this.callLater(this._sizeChanged);
  5581. }
  5582. }
  5583. _sizeChanged() {
  5584. if (!isNaN(this._anchorX))
  5585. this.pivotX = this.anchorX * this.width;
  5586. if (!isNaN(this._anchorY))
  5587. this.pivotY = this.anchorY * this.height;
  5588. this.event(Laya.Event.RESIZE);
  5589. }
  5590. _getWidget() {
  5591. this._widget === Widget.EMPTY && (this._widget = this.addComponent(Widget));
  5592. return this._widget;
  5593. }
  5594. loadUI(path) {
  5595. var uiView = View.uiMap[path];
  5596. View.uiMap && this.createView(uiView);
  5597. }
  5598. get dataSource() {
  5599. return this._dataSource;
  5600. }
  5601. set dataSource(value) {
  5602. this._dataSource = value;
  5603. for (var name in value) {
  5604. var comp = this.getChildByName(name);
  5605. if (comp instanceof UIComponent)
  5606. comp.dataSource = value[name];
  5607. else if (name in this && !(this[name] instanceof Function))
  5608. this[name] = value[name];
  5609. }
  5610. }
  5611. }
  5612. View.uiMap = {};
  5613. Laya.ILaya.regClass(View);
  5614. Laya.ClassUtils.regClass("laya.ui.View", View);
  5615. Laya.ClassUtils.regClass("Laya.View", View);
  5616. class IUI {
  5617. }
  5618. class DialogManager extends Laya.Sprite {
  5619. constructor() {
  5620. super();
  5621. this.maskLayer = new Laya.Sprite();
  5622. this.popupEffect = (dialog) => {
  5623. dialog.scale(1, 1);
  5624. dialog._effectTween = Laya.Tween.from(dialog, { x: Laya.ILaya.stage.width / 2, y: Laya.ILaya.stage.height / 2, scaleX: 0, scaleY: 0 }, 300, Laya.Ease.backOut, Laya.Handler.create(this, this.doOpen, [dialog]), 0, false, false);
  5625. };
  5626. this.closeEffect = (dialog) => {
  5627. dialog._effectTween = Laya.Tween.to(dialog, { x: Laya.ILaya.stage.width / 2, y: Laya.ILaya.stage.height / 2, scaleX: 0, scaleY: 0 }, 300, Laya.Ease.strongOut, Laya.Handler.create(this, this.doClose, [dialog]), 0, false, false);
  5628. };
  5629. this.popupEffectHandler = new Laya.Handler(this, this.popupEffect);
  5630. this.closeEffectHandler = new Laya.Handler(this, this.closeEffect);
  5631. this.mouseEnabled = this.maskLayer.mouseEnabled = true;
  5632. this.zOrder = 1000;
  5633. Laya.ILaya.stage.addChild(this);
  5634. Laya.ILaya.stage.on(Laya.Event.RESIZE, this, this._onResize);
  5635. if (UIConfig.closeDialogOnSide)
  5636. this.maskLayer.on("click", this, this._closeOnSide);
  5637. this._onResize(null);
  5638. }
  5639. _closeOnSide() {
  5640. var dialog = this.getChildAt(this.numChildren - 1);
  5641. if (dialog instanceof IUI.Dialog)
  5642. dialog.close();
  5643. }
  5644. setLockView(value) {
  5645. if (!this.lockLayer) {
  5646. this.lockLayer = new Box();
  5647. this.lockLayer.mouseEnabled = true;
  5648. this.lockLayer.size(Laya.ILaya.stage.width, Laya.ILaya.stage.height);
  5649. }
  5650. this.lockLayer.removeChildren();
  5651. if (value) {
  5652. value.centerX = value.centerY = 0;
  5653. this.lockLayer.addChild(value);
  5654. }
  5655. }
  5656. _onResize(e = null) {
  5657. var width = this.maskLayer.width = Laya.ILaya.stage.width;
  5658. var height = this.maskLayer.height = Laya.ILaya.stage.height;
  5659. if (this.lockLayer)
  5660. this.lockLayer.size(width, height);
  5661. this.maskLayer.graphics.clear(true);
  5662. this.maskLayer.graphics.drawRect(0, 0, width, height, UIConfig.popupBgColor);
  5663. this.maskLayer.alpha = UIConfig.popupBgAlpha;
  5664. for (var i = this.numChildren - 1; i > -1; i--) {
  5665. var item = this.getChildAt(i);
  5666. if (item.isPopupCenter)
  5667. this._centerDialog(item);
  5668. }
  5669. }
  5670. _centerDialog(dialog) {
  5671. dialog.x = Math.round(((Laya.ILaya.stage.width - dialog.width) >> 1) + dialog.pivotX);
  5672. dialog.y = Math.round(((Laya.ILaya.stage.height - dialog.height) >> 1) + dialog.pivotY);
  5673. }
  5674. open(dialog, closeOther = false, showEffect = false) {
  5675. if (closeOther)
  5676. this._closeAll();
  5677. this._clearDialogEffect(dialog);
  5678. if (dialog.isPopupCenter)
  5679. this._centerDialog(dialog);
  5680. this.addChild(dialog);
  5681. if (dialog.isModal || this._getBit(Laya.Const.HAS_ZORDER))
  5682. Laya.ILaya.timer.callLater(this, this._checkMask);
  5683. if (showEffect && dialog.popupEffect != null)
  5684. dialog.popupEffect.runWith(dialog);
  5685. else
  5686. this.doOpen(dialog);
  5687. this.event(Laya.Event.OPEN);
  5688. }
  5689. _clearDialogEffect(dialog) {
  5690. if (dialog._effectTween) {
  5691. Laya.Tween.clear(dialog._effectTween);
  5692. dialog._effectTween = null;
  5693. }
  5694. }
  5695. doOpen(dialog) {
  5696. dialog.onOpened(dialog._param);
  5697. }
  5698. lock(value) {
  5699. if (this.lockLayer) {
  5700. if (value)
  5701. this.addChild(this.lockLayer);
  5702. else
  5703. this.lockLayer.removeSelf();
  5704. }
  5705. }
  5706. close(dialog) {
  5707. this._clearDialogEffect(dialog);
  5708. if (dialog.isShowEffect && dialog.closeEffect != null)
  5709. dialog.closeEffect.runWith([dialog]);
  5710. else
  5711. this.doClose(dialog);
  5712. this.event(Laya.Event.CLOSE);
  5713. }
  5714. doClose(dialog) {
  5715. dialog.removeSelf();
  5716. dialog.isModal && this._checkMask();
  5717. dialog.closeHandler && dialog.closeHandler.runWith(dialog.closeType);
  5718. dialog.onClosed(dialog.closeType);
  5719. if (dialog.autoDestroyAtClosed)
  5720. dialog.destroy();
  5721. }
  5722. closeAll() {
  5723. this._closeAll();
  5724. this.event(Laya.Event.CLOSE);
  5725. }
  5726. _closeAll() {
  5727. for (var i = this.numChildren - 1; i > -1; i--) {
  5728. var item = this.getChildAt(i);
  5729. if (item && item.close != null) {
  5730. this.doClose(item);
  5731. }
  5732. }
  5733. }
  5734. getDialogsByGroup(group) {
  5735. var arr = [];
  5736. for (var i = this.numChildren - 1; i > -1; i--) {
  5737. var item = this.getChildAt(i);
  5738. if (item && item.group === group) {
  5739. arr.push(item);
  5740. }
  5741. }
  5742. return arr;
  5743. }
  5744. closeByGroup(group) {
  5745. var arr = [];
  5746. for (var i = this.numChildren - 1; i > -1; i--) {
  5747. var item = this.getChildAt(i);
  5748. if (item && item.group === group) {
  5749. item.close();
  5750. arr.push(item);
  5751. }
  5752. }
  5753. return arr;
  5754. }
  5755. _checkMask() {
  5756. this.maskLayer.removeSelf();
  5757. for (var i = this.numChildren - 1; i > -1; i--) {
  5758. var dialog = this.getChildAt(i);
  5759. if (dialog && dialog.isModal) {
  5760. this.addChildAt(this.maskLayer, i);
  5761. return;
  5762. }
  5763. }
  5764. }
  5765. }
  5766. Laya.ClassUtils.regClass("laya.ui.DialogManager", DialogManager);
  5767. Laya.ClassUtils.regClass("Laya.DialogManager", DialogManager);
  5768. class Dialog extends View {
  5769. constructor() {
  5770. super();
  5771. this.isShowEffect = true;
  5772. this.isPopupCenter = true;
  5773. this.popupEffect = Dialog.manager.popupEffectHandler;
  5774. this.closeEffect = Dialog.manager.closeEffectHandler;
  5775. this._dealDragArea();
  5776. this.on(Laya.Event.CLICK, this, this._onClick);
  5777. }
  5778. static get manager() {
  5779. return Dialog._manager = Dialog._manager || new DialogManager();
  5780. }
  5781. static set manager(value) {
  5782. Dialog._manager = value;
  5783. }
  5784. _dealDragArea() {
  5785. var dragTarget = this.getChildByName("drag");
  5786. if (dragTarget) {
  5787. this.dragArea = dragTarget._x + "," + dragTarget._y + "," + dragTarget.width + "," + dragTarget.height;
  5788. dragTarget.removeSelf();
  5789. }
  5790. }
  5791. get dragArea() {
  5792. if (this._dragArea)
  5793. return this._dragArea.toString();
  5794. return null;
  5795. }
  5796. set dragArea(value) {
  5797. if (value) {
  5798. var a = UIUtils.fillArray([0, 0, 0, 0], value, Number);
  5799. this._dragArea = new Laya.Rectangle(a[0], a[1], a[2], a[3]);
  5800. this.on(Laya.Event.MOUSE_DOWN, this, this._onMouseDown);
  5801. }
  5802. else {
  5803. this._dragArea = null;
  5804. this.off(Laya.Event.MOUSE_DOWN, this, this._onMouseDown);
  5805. }
  5806. }
  5807. _onMouseDown(e) {
  5808. var point = this.getMousePoint();
  5809. if (this._dragArea.contains(point.x, point.y))
  5810. this.startDrag();
  5811. else
  5812. this.stopDrag();
  5813. }
  5814. _onClick(e) {
  5815. var btn = e.target;
  5816. if (btn) {
  5817. switch (btn.name) {
  5818. case Dialog.CLOSE:
  5819. case Dialog.CANCEL:
  5820. case Dialog.SURE:
  5821. case Dialog.NO:
  5822. case Dialog.OK:
  5823. case Dialog.YES:
  5824. this.close(btn.name);
  5825. return;
  5826. }
  5827. }
  5828. }
  5829. open(closeOther = true, param = null) {
  5830. this._dealDragArea();
  5831. this._param = param;
  5832. Dialog.manager.open(this, closeOther, this.isShowEffect);
  5833. Dialog.manager.lock(false);
  5834. }
  5835. close(type = null) {
  5836. this.closeType = type;
  5837. Dialog.manager.close(this);
  5838. }
  5839. destroy(destroyChild = true) {
  5840. this.closeHandler = null;
  5841. this.popupEffect = null;
  5842. this.closeEffect = null;
  5843. this._dragArea = null;
  5844. super.destroy(destroyChild);
  5845. }
  5846. show(closeOther = false, showEffect = true) {
  5847. this._open(false, closeOther, showEffect);
  5848. }
  5849. popup(closeOther = false, showEffect = true) {
  5850. this._open(true, closeOther, showEffect);
  5851. }
  5852. _open(modal, closeOther, showEffect) {
  5853. this.isModal = modal;
  5854. this.isShowEffect = showEffect;
  5855. Dialog.manager.lock(true);
  5856. this.open(closeOther);
  5857. }
  5858. get isPopup() {
  5859. return this.parent != null;
  5860. }
  5861. set zOrder(value) {
  5862. super.zOrder = value;
  5863. Dialog.manager._checkMask();
  5864. }
  5865. get zOrder() {
  5866. return super.zOrder;
  5867. }
  5868. static setLockView(view) {
  5869. Dialog.manager.setLockView(view);
  5870. }
  5871. static lock(value) {
  5872. Dialog.manager.lock(value);
  5873. }
  5874. static closeAll() {
  5875. Dialog.manager.closeAll();
  5876. }
  5877. static getDialogsByGroup(group) {
  5878. return Dialog.manager.getDialogsByGroup(group);
  5879. }
  5880. static closeByGroup(group) {
  5881. return Dialog.manager.closeByGroup(group);
  5882. }
  5883. }
  5884. Dialog.CLOSE = "close";
  5885. Dialog.CANCEL = "cancel";
  5886. Dialog.SURE = "sure";
  5887. Dialog.NO = "no";
  5888. Dialog.YES = "yes";
  5889. Dialog.OK = "ok";
  5890. IUI.Dialog = Dialog;
  5891. Laya.ILaya.regClass(Dialog);
  5892. Laya.ClassUtils.regClass("laya.ui.Dialog", Dialog);
  5893. Laya.ClassUtils.regClass("Laya.Dialog", Dialog);
  5894. class TipManager extends UIComponent {
  5895. constructor() {
  5896. super();
  5897. this._tipBox = new UIComponent();
  5898. this._tipBox.addChild(this._tipText = new Laya.Text());
  5899. this._tipText.x = this._tipText.y = 5;
  5900. this._tipText.color = TipManager.tipTextColor;
  5901. this._defaultTipHandler = this._showDefaultTip;
  5902. Laya.ILaya.stage.on(UIEvent.SHOW_TIP, this, this._onStageShowTip);
  5903. Laya.ILaya.stage.on(UIEvent.HIDE_TIP, this, this._onStageHideTip);
  5904. this.zOrder = 1100;
  5905. }
  5906. _onStageHideTip(e) {
  5907. Laya.ILaya.timer.clear(this, this._showTip);
  5908. this.closeAll();
  5909. this.removeSelf();
  5910. }
  5911. _onStageShowTip(data) {
  5912. Laya.ILaya.timer.once(TipManager.tipDelay, this, this._showTip, [data], true);
  5913. }
  5914. _showTip(tip) {
  5915. if (typeof (tip) == 'string') {
  5916. var text = String(tip);
  5917. if (Boolean(text)) {
  5918. this._defaultTipHandler(text);
  5919. }
  5920. }
  5921. else if (tip instanceof Laya.Handler) {
  5922. tip.run();
  5923. }
  5924. else if (tip instanceof Function) {
  5925. tip.apply();
  5926. }
  5927. {
  5928. Laya.ILaya.stage.on(Laya.Event.MOUSE_MOVE, this, this._onStageMouseMove);
  5929. Laya.ILaya.stage.on(Laya.Event.MOUSE_DOWN, this, this._onStageMouseDown);
  5930. }
  5931. this._onStageMouseMove(null);
  5932. }
  5933. _onStageMouseDown(e) {
  5934. this.closeAll();
  5935. }
  5936. _onStageMouseMove(e) {
  5937. this._showToStage(this, TipManager.offsetX, TipManager.offsetY);
  5938. }
  5939. _showToStage(dis, offX = 0, offY = 0) {
  5940. var rec = dis.getBounds();
  5941. dis.x = Laya.ILaya.stage.mouseX + offX;
  5942. dis.y = Laya.ILaya.stage.mouseY + offY;
  5943. if (dis._x + rec.width > Laya.ILaya.stage.width) {
  5944. dis.x -= rec.width + offX;
  5945. }
  5946. if (dis._y + rec.height > Laya.ILaya.stage.height) {
  5947. dis.y -= rec.height + offY;
  5948. }
  5949. }
  5950. closeAll() {
  5951. Laya.ILaya.timer.clear(this, this._showTip);
  5952. Laya.ILaya.stage.off(Laya.Event.MOUSE_MOVE, this, this._onStageMouseMove);
  5953. Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this._onStageMouseDown);
  5954. this.removeChildren();
  5955. }
  5956. showDislayTip(tip) {
  5957. this.addChild(tip);
  5958. this._showToStage(this);
  5959. Laya.ILaya.stage.addChild(this);
  5960. }
  5961. _showDefaultTip(text) {
  5962. this._tipText.text = text;
  5963. var g = this._tipBox.graphics;
  5964. g.clear(true);
  5965. g.drawRect(0, 0, this._tipText.width + 10, this._tipText.height + 10, TipManager.tipBackColor);
  5966. this.addChild(this._tipBox);
  5967. this._showToStage(this);
  5968. Laya.ILaya.stage.addChild(this);
  5969. }
  5970. get defaultTipHandler() {
  5971. return this._defaultTipHandler;
  5972. }
  5973. set defaultTipHandler(value) {
  5974. this._defaultTipHandler = value;
  5975. }
  5976. }
  5977. TipManager.offsetX = 10;
  5978. TipManager.offsetY = 15;
  5979. TipManager.tipTextColor = "#ffffff";
  5980. TipManager.tipBackColor = "#111111";
  5981. TipManager.tipDelay = 200;
  5982. Laya.ILaya.regClass(TipManager);
  5983. Laya.ClassUtils.regClass("laya.ui.TipManager", TipManager);
  5984. Laya.ClassUtils.regClass("Laya.TipManager", TipManager);
  5985. class UILib {
  5986. static __init__() {
  5987. }
  5988. }
  5989. class WXOpenDataViewer extends UIComponent {
  5990. constructor() {
  5991. super();
  5992. this._width = this._height = 200;
  5993. var tex = new Laya.Texture();
  5994. tex.bitmap = new Laya.Texture2D();
  5995. this.texture = tex;
  5996. }
  5997. onEnable() {
  5998. this.postMsg({ type: "display", rate: Laya.Laya.stage.frameRate });
  5999. if (window.wx && window.sharedCanvas)
  6000. Laya.Laya.timer.frameLoop(1, this, this._onLoop);
  6001. }
  6002. onDisable() {
  6003. this.postMsg({ type: "undisplay" });
  6004. Laya.Laya.timer.clear(this, this._onLoop);
  6005. }
  6006. _onLoop() {
  6007. let _canvas = window.sharedCanvas;
  6008. this.texture.sourceWidth = _canvas.width;
  6009. this.texture.sourceHeight = _canvas.height;
  6010. this.texture.bitmap.loadImageSource(_canvas);
  6011. }
  6012. set width(value) {
  6013. super.width = value;
  6014. if (window.sharedCanvas)
  6015. window.sharedCanvas.width = value;
  6016. this.callLater(this._postMsg);
  6017. }
  6018. get width() {
  6019. return super.width;
  6020. }
  6021. set height(value) {
  6022. super.height = value;
  6023. if (window.sharedCanvas)
  6024. window.sharedCanvas.height = value;
  6025. this.callLater(this._postMsg);
  6026. }
  6027. get height() {
  6028. return super.height;
  6029. }
  6030. set x(value) {
  6031. super.x = value;
  6032. this.callLater(this._postMsg);
  6033. }
  6034. get x() {
  6035. return super.x;
  6036. }
  6037. set y(value) {
  6038. super.y = value;
  6039. this.callLater(this._postMsg);
  6040. }
  6041. get y() {
  6042. return super.y;
  6043. }
  6044. _postMsg() {
  6045. var mat = new Laya.Matrix();
  6046. mat.translate(this.x, this.y);
  6047. var stage = Laya.Laya.stage;
  6048. mat.scale(stage._canvasTransform.getScaleX() * this.globalScaleX * stage.transform.getScaleX(), stage._canvasTransform.getScaleY() * this.globalScaleY * stage.transform.getScaleY());
  6049. this.postMsg({ type: "changeMatrix", a: mat.a, b: mat.b, c: mat.c, d: mat.d, tx: mat.tx, ty: mat.ty, w: this.width, h: this.height });
  6050. }
  6051. postMsg(msg) {
  6052. if (window.wx && window.wx.getOpenDataContext) {
  6053. var openDataContext = window.wx.getOpenDataContext();
  6054. openDataContext.postMessage(msg);
  6055. }
  6056. }
  6057. }
  6058. Laya.ILaya.regClass(WXOpenDataViewer);
  6059. Laya.ClassUtils.regClass("laya.ui.WXOpenDataViewer", WXOpenDataViewer);
  6060. Laya.ClassUtils.regClass("Laya.WXOpenDataViewer", WXOpenDataViewer);
  6061. exports.AdvImage = AdvImage;
  6062. exports.AutoBitmap = AutoBitmap;
  6063. exports.Box = Box;
  6064. exports.Button = Button;
  6065. exports.CheckBox = CheckBox;
  6066. exports.Clip = Clip;
  6067. exports.ColorPicker = ColorPicker;
  6068. exports.ComboBox = ComboBox;
  6069. exports.Dialog = Dialog;
  6070. exports.DialogManager = DialogManager;
  6071. exports.FontClip = FontClip;
  6072. exports.HBox = HBox;
  6073. exports.HScrollBar = HScrollBar;
  6074. exports.HSlider = HSlider;
  6075. exports.IUI = IUI;
  6076. exports.Image = Image;
  6077. exports.Label = Label;
  6078. exports.LayoutBox = LayoutBox;
  6079. exports.List = List;
  6080. exports.Panel = Panel;
  6081. exports.ProgressBar = ProgressBar;
  6082. exports.Radio = Radio;
  6083. exports.RadioGroup = RadioGroup;
  6084. exports.ScaleBox = ScaleBox;
  6085. exports.ScrollBar = ScrollBar;
  6086. exports.Slider = Slider;
  6087. exports.Styles = Styles;
  6088. exports.Tab = Tab;
  6089. exports.TextArea = TextArea;
  6090. exports.TextInput = TextInput;
  6091. exports.TipManager = TipManager;
  6092. exports.Tree = Tree;
  6093. exports.UIComponent = UIComponent;
  6094. exports.UIConfig = UIConfig;
  6095. exports.UIEvent = UIEvent;
  6096. exports.UIGroup = UIGroup;
  6097. exports.UILib = UILib;
  6098. exports.UIUtils = UIUtils;
  6099. exports.VBox = VBox;
  6100. exports.VScrollBar = VScrollBar;
  6101. exports.VSlider = VSlider;
  6102. exports.View = View;
  6103. exports.ViewStack = ViewStack;
  6104. exports.WXOpenDataViewer = WXOpenDataViewer;
  6105. exports.Widget = Widget;
  6106. }(window.Laya = window.Laya || {}, Laya));