123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153 |
- (function (exports, Laya) {
- 'use strict';
- class UIConfig {
- }
- UIConfig.touchScrollEnable = true;
- UIConfig.mouseWheelEnable = true;
- UIConfig.showButtons = true;
- UIConfig.popupBgColor = "#000000";
- UIConfig.popupBgAlpha = 0.5;
- UIConfig.closeDialogOnSide = true;
- window.UIConfig = UIConfig;
- class Styles {
- }
- Styles.defaultSizeGrid = [4, 4, 4, 4, 0];
- Styles.labelColor = "#000000";
- Styles.labelPadding = [2, 2, 2, 2];
- Styles.inputLabelPadding = [1, 1, 1, 3];
- Styles.buttonStateNum = 3;
- Styles.buttonLabelColors = ["#32556b", "#32cc6b", "#ff0000", "#C0C0C0"];
- Styles.comboBoxItemColors = ["#5e95b6", "#ffffff", "#000000", "#8fa4b1", "#ffffff"];
- Styles.scrollBarMinNum = 15;
- Styles.scrollBarDelayTime = 500;
- class AutoBitmap extends Laya.Graphics {
- constructor() {
- super(...arguments);
- this.autoCacheCmd = true;
- this._width = 0;
- this._height = 0;
- this.uv = null;
- }
- destroy() {
- super.destroy();
- this._source = null;
- this._sizeGrid = null;
- this._offset = null;
- }
- get sizeGrid() {
- return this._sizeGrid;
- }
- set sizeGrid(value) {
- this._sizeGrid = value.map((v) => { return +v; });
- this._setChanged();
- }
- get width() {
- if (this._width)
- return this._width;
- if (this._source)
- return this._source.sourceWidth;
- return 0;
- }
- set width(value) {
- if (this._width != value) {
- this._width = value;
- this._setChanged();
- }
- }
- get height() {
- if (this._height)
- return this._height;
- if (this._source)
- return this._source.sourceHeight;
- return 0;
- }
- set height(value) {
- if (this._height != value) {
- this._height = value;
- this._setChanged();
- }
- }
- get source() {
- return this._source;
- }
- set source(value) {
- if (value) {
- this._source = value;
- this._setChanged();
- }
- else {
- this._source = null;
- if (this._drawGridCmd) {
- if (this._one) {
- if (this._one == this._drawGridCmd) {
- this.clear();
- }
- }
- let cmds = this.cmds;
- if (cmds && cmds.length > 0) {
- if (cmds[0] == this._drawGridCmd) {
- cmds.splice(0, 1);
- }
- }
- }
- }
- }
- _setChanged() {
- if (!this._isChanged) {
- this._isChanged = true;
- Laya.ILaya.timer.callLater(this, this.changeSource);
- }
- }
- _createDrawTexture(texture, x = 0, y = 0, width = 0, height = 0, matrix = null, alpha = 1, color = null, blendMode = null, uv) {
- if (!texture || alpha < 0.01)
- return null;
- if (!texture.getIsReady())
- return null;
- if (!width)
- width = texture.sourceWidth;
- if (!height)
- height = texture.sourceHeight;
- if (texture.getIsReady()) {
- var wRate = width / texture.sourceWidth;
- var hRate = height / texture.sourceHeight;
- width = texture.width * wRate;
- height = texture.height * hRate;
- if (width <= 0 || height <= 0)
- return null;
- x += texture.offsetX * wRate;
- y += texture.offsetY * hRate;
- }
- if (this._sp) {
- this._sp._renderType |= Laya.SpriteConst.GRAPHICS;
- this._sp._setRenderType(this._sp._renderType);
- }
- return Laya.DrawTextureCmd.create.call(this, texture, x, y, width, height, matrix, alpha, color, blendMode, uv);
- }
- changeSource() {
- this._isChanged = false;
- var source = this._source;
- if (!source || !source.bitmap)
- return;
- var width = this.width;
- var height = this.height;
- var sizeGrid = this._sizeGrid;
- var sw = source.sourceWidth;
- var sh = source.sourceHeight;
- if (!sizeGrid || (sw === width && sh === height)) {
- 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);
- cmd && this._setDrawGridCmd(cmd);
- }
- else {
- let cmd = Laya.Draw9GridTexture.create(source, 0, 0, width, height, sizeGrid);
- this._setDrawGridCmd(cmd);
- }
- this._repaint();
- }
- drawBitmap(repeat, tex, x, y, width = 0, height = 0) {
- if (width < 0.1 || height < 0.1)
- return;
- if (repeat && (tex.width != width || tex.height != height))
- this.fillTexture(tex, x, y, width, height);
- else
- this.drawImage(tex, x, y, width, height);
- }
- static getTexture(tex, x, y, width, height) {
- if (width <= 0)
- width = 1;
- if (height <= 0)
- height = 1;
- tex.$_GID || (tex.$_GID = Laya.Utils.getGID());
- var texture;
- if (!texture || !texture._getSource()) {
- texture = Laya.Texture.createFromTexture(tex, x, y, width, height);
- }
- return texture;
- }
- _setDrawGridCmd(newcmd) {
- var source = this._source;
- if (!source || !source.bitmap) {
- return;
- }
- let cmds = this.cmds;
- if (!this._one && (!cmds || cmds.length <= 0)) {
- this._saveToCmd(null, newcmd);
- }
- else {
- let lastOne = this._one;
- if (lastOne) {
- if (lastOne == this._drawGridCmd) {
- this._one = newcmd;
- }
- else {
- this.clear();
- this._saveToCmd(null, newcmd);
- this._saveToCmd(null, lastOne);
- }
- }
- else {
- cmds.splice(0, 0, newcmd);
- }
- }
- this._drawGridCmd = newcmd;
- }
- }
- Laya.ClassUtils.regClass("laya.ui.AutoBitmap", AutoBitmap);
- Laya.ClassUtils.regClass("Laya.AutoBitmap", AutoBitmap);
- class Widget extends Laya.Component {
- constructor() {
- super(...arguments);
- this._top = NaN;
- this._bottom = NaN;
- this._left = NaN;
- this._right = NaN;
- this._centerX = NaN;
- this._centerY = NaN;
- }
- onReset() {
- this._top = this._bottom = this._left = this._right = this._centerX = this._centerY = NaN;
- }
- _onEnable() {
- if (this.owner.parent)
- this._onAdded();
- else
- this.owner.once(Laya.Event.ADDED, this, this._onAdded);
- }
- _onDisable() {
- this.owner.off(Laya.Event.ADDED, this, this._onAdded);
- if (this.owner.parent)
- this.owner.parent.off(Laya.Event.RESIZE, this, this._onParentResize);
- }
- _onAdded() {
- if (this.owner.parent)
- this.owner.parent.on(Laya.Event.RESIZE, this, this._onParentResize);
- this.resetLayoutX();
- this.resetLayoutY();
- }
- _onParentResize() {
- var flagX = this.resetLayoutX();
- var flagY = this.resetLayoutY();
- if (flagX || flagY)
- this.owner.event(Laya.Event.RESIZE);
- }
- resetLayoutX() {
- var owner = this.owner;
- if (!owner)
- return false;
- var parent = owner.parent;
- if (parent) {
- if (!isNaN(this.centerX)) {
- owner.x = Math.round((parent.width - owner.displayWidth) * 0.5 + this.centerX + owner.pivotX * owner.scaleX);
- }
- else if (!isNaN(this.left)) {
- owner.x = Math.round(this.left + owner.pivotX * owner.scaleX);
- if (!isNaN(this.right)) {
- var temp = (parent._width - this.left - this.right) / (owner.scaleX || 0.01);
- if (temp != owner.width) {
- owner.width = temp;
- return true;
- }
- }
- }
- else if (!isNaN(this.right)) {
- owner.x = Math.round(parent.width - owner.displayWidth - this.right + owner.pivotX * owner.scaleX);
- }
- }
- return false;
- }
- resetLayoutY() {
- var owner = this.owner;
- if (!owner)
- return false;
- var parent = owner.parent;
- if (parent) {
- if (!isNaN(this.centerY)) {
- owner.y = Math.round((parent.height - owner.displayHeight) * 0.5 + this.centerY + owner.pivotY * owner.scaleY);
- }
- else if (!isNaN(this.top)) {
- owner.y = Math.round(this.top + owner.pivotY * owner.scaleY);
- if (!isNaN(this.bottom)) {
- var temp = (parent._height - this.top - this.bottom) / (owner.scaleY || 0.01);
- if (temp != owner.height) {
- owner.height = temp;
- return true;
- }
- }
- }
- else if (!isNaN(this.bottom)) {
- owner.y = Math.round(parent.height - owner.displayHeight - this.bottom + owner.pivotY * owner.scaleY);
- }
- }
- return false;
- }
- resetLayout() {
- if (this.owner) {
- this.resetLayoutX();
- this.resetLayoutY();
- }
- }
- get top() {
- return this._top;
- }
- set top(value) {
- if (this._top != value) {
- this._top = value;
- this.resetLayoutY();
- }
- }
- get bottom() {
- return this._bottom;
- }
- set bottom(value) {
- if (this._bottom != value) {
- this._bottom = value;
- this.resetLayoutY();
- }
- }
- get left() {
- return this._left;
- }
- set left(value) {
- if (this._left != value) {
- this._left = value;
- this.resetLayoutX();
- }
- }
- get right() {
- return this._right;
- }
- set right(value) {
- if (this._right != value) {
- this._right = value;
- this.resetLayoutX();
- }
- }
- get centerX() {
- return this._centerX;
- }
- set centerX(value) {
- if (this._centerX != value) {
- this._centerX = value;
- this.resetLayoutX();
- }
- }
- get centerY() {
- return this._centerY;
- }
- set centerY(value) {
- if (this._centerY != value) {
- this._centerY = value;
- this.resetLayoutY();
- }
- }
- }
- Widget.EMPTY = null;
- Laya.ILaya.regClass(Widget);
- Widget.EMPTY = new Widget();
- Laya.ClassUtils.regClass("laya.ui.Widget", Widget);
- Laya.ClassUtils.regClass("Laya.Widget", Widget);
- class UIEvent extends Laya.Event {
- }
- UIEvent.SHOW_TIP = "showtip";
- UIEvent.HIDE_TIP = "hidetip";
- Laya.ILaya.regClass(UIEvent);
- Laya.ClassUtils.regClass("laya.ui.UIEvent", UIEvent);
- Laya.ClassUtils.regClass("Laya.UIEvent", UIEvent);
- class UIUtils {
- static fillArray(arr, str, type = null) {
- var temp = arr.concat();
- if (str) {
- var a = str.split(",");
- for (var i = 0, n = Math.min(temp.length, a.length); i < n; i++) {
- var value = a[i];
- temp[i] = (value == "true" ? true : (value == "false" ? false : value));
- if (type != null)
- temp[i] = type(value);
- }
- }
- return temp;
- }
- static toColor(color) {
- return Laya.Utils.toHexColor(color);
- }
- static gray(traget, isGray = true) {
- if (isGray) {
- UIUtils.addFilter(traget, UIUtils.grayFilter);
- }
- else {
- UIUtils.clearFilter(traget, Laya.ColorFilter);
- }
- }
- static addFilter(target, filter) {
- var filters = target.filters || [];
- filters.push(filter);
- target.filters = filters;
- }
- static clearFilter(target, filterType) {
- var filters = target.filters;
- if (filters != null && filters.length > 0) {
- for (var i = filters.length - 1; i > -1; i--) {
- var filter = filters[i];
- if (filter instanceof filterType)
- filters.splice(i, 1);
- }
- target.filters = filters;
- }
- }
- static _getReplaceStr(word) {
- return UIUtils.escapeSequence[word];
- }
- static adptString(str) {
- return str.replace(/\\(\w)/g, UIUtils._getReplaceStr);
- }
- static getBindFun(value) {
- if (!UIUtils._funMap) {
- UIUtils._funMap = new Laya.WeakObject();
- }
- var fun = UIUtils._funMap.get(value);
- if (fun == null) {
- var temp = "\"" + value + "\"";
- temp = temp.replace(/^"\${|}"$/g, "").replace(/\${/g, "\"+").replace(/}/g, "+\"");
- var str = "(function(data){if(data==null)return;with(data){try{\nreturn " + temp + "\n}catch(e){}}})";
- fun = window.Laya._runScript(str);
- UIUtils._funMap.set(value, fun);
- }
- return fun;
- }
- }
- 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]);
- UIUtils.escapeSequence = { "\\n": "\n", "\\t": "\t" };
- UIUtils._funMap = null;
- Laya.ClassUtils.regClass("laya.ui.UIUtils", UIUtils);
- Laya.ClassUtils.regClass("Laya.UIUtils", UIUtils);
- class UIComponent extends Laya.Sprite {
- constructor(createChildren = true) {
- super();
- this._anchorX = NaN;
- this._anchorY = NaN;
- this._widget = Widget.EMPTY;
- if (createChildren) {
- this.preinitialize();
- this.createChildren();
- this.initialize();
- }
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._dataSource = null;
- this._tag = null;
- this._toolTip = null;
- }
- preinitialize() {
- }
- createChildren() {
- }
- initialize() {
- }
- get width() {
- return this.get_width();
- }
- get_width() {
- if (this._width)
- return this._width;
- return this.measureWidth();
- }
- measureWidth() {
- var max = 0;
- this.commitMeasure();
- for (var i = this.numChildren - 1; i > -1; i--) {
- var comp = this.getChildAt(i);
- if (comp._visible) {
- max = Math.max(comp._x + comp.width * comp.scaleX, max);
- }
- }
- return max;
- }
- commitMeasure() {
- }
- get height() {
- return this.get_height();
- }
- get_height() {
- if (this._height)
- return this._height;
- return this.measureHeight();
- }
- measureHeight() {
- var max = 0;
- this.commitMeasure();
- for (var i = this.numChildren - 1; i > -1; i--) {
- var comp = this.getChildAt(i);
- if (comp._visible) {
- max = Math.max(comp._y + comp.height * comp.scaleY, max);
- }
- }
- return max;
- }
- get dataSource() {
- return this.get_dataSource();
- }
- get_dataSource() {
- return this._dataSource;
- }
- set dataSource(value) {
- this.set_dataSource(value);
- }
- set_dataSource(value) {
- this._dataSource = value;
- for (var prop in this._dataSource) {
- if (prop in this && !(typeof (this[prop]) == 'function')) {
- this[prop] = this._dataSource[prop];
- }
- }
- }
- get top() {
- return this.get_top();
- }
- get_top() {
- return this._widget.top;
- }
- set top(value) {
- this.set_top(value);
- }
- set_top(value) {
- if (value != this._widget.top) {
- this._getWidget().top = value;
- }
- }
- get bottom() {
- return this.get_bottom();
- }
- get_bottom() {
- return this._widget.bottom;
- }
- set bottom(value) {
- this.set_bottom(value);
- }
- set_bottom(value) {
- if (value != this._widget.bottom) {
- this._getWidget().bottom = value;
- }
- }
- get left() {
- return this._widget.left;
- }
- set left(value) {
- if (value != this._widget.left) {
- this._getWidget().left = value;
- }
- }
- get right() {
- return this._widget.right;
- }
- set right(value) {
- if (value != this._widget.right) {
- this._getWidget().right = value;
- }
- }
- get centerX() {
- return this._widget.centerX;
- }
- set centerX(value) {
- if (value != this._widget.centerX) {
- this._getWidget().centerX = value;
- }
- }
- get centerY() {
- return this._widget.centerY;
- }
- set centerY(value) {
- if (value != this._widget.centerY) {
- this._getWidget().centerY = value;
- }
- }
- _sizeChanged() {
- if (!isNaN(this._anchorX))
- this.pivotX = this.anchorX * this.width;
- if (!isNaN(this._anchorY))
- this.pivotY = this.anchorY * this.height;
- this.event(Laya.Event.RESIZE);
- if (this._widget !== Widget.EMPTY)
- this._widget.resetLayout();
- }
- get tag() {
- return this._tag;
- }
- set tag(value) {
- this._tag = value;
- }
- get toolTip() {
- return this._toolTip;
- }
- set toolTip(value) {
- if (this._toolTip != value) {
- this._toolTip = value;
- if (value != null) {
- this.on(Laya.Event.MOUSE_OVER, this, this.onMouseOver);
- this.on(Laya.Event.MOUSE_OUT, this, this.onMouseOut);
- }
- else {
- this.off(Laya.Event.MOUSE_OVER, this, this.onMouseOver);
- this.off(Laya.Event.MOUSE_OUT, this, this.onMouseOut);
- }
- }
- }
- onMouseOver(e) {
- Laya.ILaya.stage.event(UIEvent.SHOW_TIP, this._toolTip);
- }
- onMouseOut(e) {
- Laya.ILaya.stage.event(UIEvent.HIDE_TIP, this._toolTip);
- }
- get gray() {
- return this._gray;
- }
- set gray(value) {
- if (value !== this._gray) {
- this._gray = value;
- UIUtils.gray(this, value);
- }
- }
- get disabled() {
- return this._disabled;
- }
- set disabled(value) {
- if (value !== this._disabled) {
- this.gray = this._disabled = value;
- this.mouseEnabled = !value;
- }
- }
- _getWidget() {
- this._widget === Widget.EMPTY && (this._widget = this.addComponent(Widget));
- return this._widget;
- }
- set scaleX(value) {
- this.set_scaleX(value);
- }
- set_scaleX(value) {
- if (super.get_scaleX() == value)
- return;
- super.set_scaleX(value);
- this.callLater(this._sizeChanged);
- }
- get scaleX() {
- return super.scaleX;
- }
- set scaleY(value) {
- this.set_scaleY(value);
- }
- set_scaleY(value) {
- if (super.get_scaleY() == value)
- return;
- super.set_scaleY(value);
- this.callLater(this._sizeChanged);
- }
- get scaleY() {
- return super.scaleY;
- }
- onCompResize() {
- this._sizeChanged();
- }
- set width(value) {
- this.set_width(value);
- }
- set_width(value) {
- if (super.get_width() == value)
- return;
- super.set_width(value);
- this.callLater(this._sizeChanged);
- }
- set height(value) {
- this.set_height(value);
- }
- set_height(value) {
- if (super.get_height() == value)
- return;
- super.set_height(value);
- this.callLater(this._sizeChanged);
- }
- get anchorX() {
- return this.get_anchorX();
- }
- get_anchorX() {
- return this._anchorX;
- }
- set anchorX(value) {
- this.set_anchorX(value);
- }
- set_anchorX(value) {
- if (this._anchorX != value) {
- this._anchorX = value;
- this.callLater(this._sizeChanged);
- }
- }
- get anchorY() {
- return this.get_anchorY();
- }
- get_anchorY() {
- return this._anchorY;
- }
- set anchorY(value) {
- this.set_anchorY(value);
- }
- set_anchorY(value) {
- if (this._anchorY != value) {
- this._anchorY = value;
- this.callLater(this._sizeChanged);
- }
- }
- _childChanged(child = null) {
- this.callLater(this._sizeChanged);
- super._childChanged(child);
- }
- }
- Laya.ILaya.regClass(UIComponent);
- Laya.ClassUtils.regClass("laya.ui.UIComponent", UIComponent);
- Laya.ClassUtils.regClass("Laya.UIComponent", UIComponent);
- class Image extends UIComponent {
- constructor(skin = null) {
- super();
- this.skin = skin;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._bitmap && this._bitmap.destroy();
- this._bitmap = null;
- }
- dispose() {
- this.destroy(true);
- Laya.ILaya.loader.clearRes(this._skin);
- }
- createChildren() {
- this.graphics = this._bitmap = new AutoBitmap();
- this._bitmap.autoCacheCmd = false;
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (this._skin != value) {
- this._skin = value;
- if (value) {
- var source = Laya.Loader.getRes(value);
- if (source) {
- this.source = source;
- this.onCompResize();
- }
- else
- Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this.setSource, [this._skin]), null, Laya.Loader.IMAGE, 1, true, this._group);
- }
- else {
- this.source = null;
- }
- }
- }
- get source() {
- return this._bitmap.source;
- }
- set source(value) {
- if (!this._bitmap)
- return;
- this._bitmap.source = value;
- this.event(Laya.Event.LOADED);
- this.repaint();
- }
- get group() {
- return this._group;
- }
- set group(value) {
- if (value && this._skin)
- Laya.Loader.setGroup(this._skin, value);
- this._group = value;
- }
- setSource(url, img = null) {
- if (url === this._skin && img) {
- this.source = img;
- this.onCompResize();
- }
- }
- measureWidth() {
- return this._bitmap.width;
- }
- measureHeight() {
- return this._bitmap.height;
- }
- set width(value) {
- super.width = value;
- this._bitmap.width = value == 0 ? 0.0000001 : value;
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._bitmap.height = value == 0 ? 0.0000001 : value;
- }
- get height() {
- return super.height;
- }
- get sizeGrid() {
- if (this._bitmap.sizeGrid)
- return this._bitmap.sizeGrid.join(",");
- return null;
- }
- set sizeGrid(value) {
- this._bitmap.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'string')
- this.skin = value;
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- }
- Laya.ILaya.regClass(Image);
- Laya.ClassUtils.regClass("laya.ui.Image", Image);
- Laya.ClassUtils.regClass("Laya.Image", Image);
- class AdvImage extends Image {
- constructor(skin = null) {
- super();
- this.advsListArr = [];
- this.resUrl = "https://unioncdn.layabox.com/config/iconlist.json";
- this._http = new Laya.Browser.window.XMLHttpRequest();
- this._data = [];
- this._resquestTime = 360000;
- this._playIndex = 0;
- this._lunboTime = 5000;
- this.skin = skin;
- this.setLoadUrl();
- this.init();
- this.size(120, 120);
- }
- setLoadUrl() {
- }
- init() {
- if (this.isSupportJump()) {
- if (Laya.Browser.onMiniGame || Laya.Browser.onBDMiniGame) {
- Laya.ILaya.timer.loop(this._resquestTime, this, this.onGetAdvsListData);
- }
- this.onGetAdvsListData();
- this.initEvent();
- }
- else
- this.visible = false;
- }
- initEvent() {
- this.on(Laya.Event.CLICK, this, this.onAdvsImgClick);
- }
- onAdvsImgClick() {
- var currentJumpUrl = this.getCurrentAppidObj();
- if (currentJumpUrl)
- this.jumptoGame();
- }
- revertAdvsData() {
- if (this.advsListArr[this._playIndex]) {
- this.visible = true;
- this.skin = this.advsListArr[this._playIndex];
- }
- }
- isSupportJump() {
- if (Laya.Browser.onMiniGame) {
- var isSupperJump = window.wx.navigateToMiniProgram instanceof Function;
- return isSupperJump;
- }
- else if (Laya.Browser.onBDMiniGame)
- return true;
- return false;
- }
- jumptoGame() {
- var advsObj = this.advsListArr[this._playIndex];
- var desGameId = parseInt(advsObj.gameid);
- var extendInfo = advsObj.extendInfo;
- var path = advsObj.path;
- if (Laya.Browser.onMiniGame) {
- if (this.isSupportJump()) {
- window.wx.navigateToMiniProgram({
- appId: this._appid,
- path: "",
- extraData: "",
- envVersion: "release",
- success: function success() {
- console.log("-------------跳转成功--------------");
- },
- fail: function fail() {
- console.log("-------------跳转失败--------------");
- },
- complete: function complete() {
- console.log("-------------跳转接口调用成功--------------");
- this.updateAdvsInfo();
- }.bind(this)
- });
- }
- }
- else if (Laya.Browser.onBDMiniGame) ;
- else {
- this.visible = false;
- }
- }
- updateAdvsInfo() {
- this.visible = false;
- this.onLunbo();
- Laya.ILaya.timer.loop(this._lunboTime, this, this.onLunbo);
- }
- onLunbo() {
- if (this._playIndex >= this.advsListArr.length - 1)
- this._playIndex = 0;
- else
- this._playIndex += 1;
- this.visible = true;
- this.revertAdvsData();
- }
- getCurrentAppidObj() {
- return this.advsListArr[this._playIndex];
- }
- onGetAdvsListData() {
- var _this = this;
- var random = AdvImage.randRange(10000, 1000000);
- var url = this.resUrl + "?" + random;
- this._http.open("get", url, true);
- this._http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- this._http.responseType = "text";
- this._http.onerror = function (e) {
- _this._onError(e);
- };
- this._http.onload = function (e) {
- _this._onLoad(e);
- };
- this._http.send(null);
- }
- static randRange(minNum, maxNum) {
- return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
- }
- _onError(e) {
- this.error("Request failed Status:" + this._http.status + " text:" + this._http.statusText);
- }
- _onLoad(e) {
- var http = this._http;
- var status = http.status !== undefined ? http.status : 200;
- if (status === 200 || status === 204 || status === 0) {
- this.complete();
- }
- else {
- this.error("[" + http.status + "]" + http.statusText + ":" + http.responseURL);
- }
- }
- error(message) {
- this.event(Laya.Event.ERROR, message);
- }
- complete() {
- try {
- this._data = this._http.response || this._http.responseText;
- this._data = JSON.parse(this._data);
- this.advsListArr = this._data.list;
- this._appid = this._data.appid;
- this.updateAdvsInfo();
- this.revertAdvsData();
- }
- catch (e) {
- this.error(e.message);
- }
- }
- getAdvsQArr(data) {
- var tempArr = [];
- var gameAdvsObj = Laya.LocalStorage.getJSON("gameObj");
- for (var key in data) {
- var tempObj = data[key];
- if (gameAdvsObj && gameAdvsObj[tempObj.gameid] && !tempObj.isQiangZhi)
- continue;
- tempArr.push(tempObj);
- }
- return tempArr;
- }
- clear() {
- var http = this._http;
- http.onerror = http.onabort = http.onprogress = http.onload = null;
- }
- destroy(destroyChild = true) {
- Laya.ILaya.timer.clear(this, this.onLunbo);
- super.destroy(true);
- this.clear();
- Laya.ILaya.timer.clear(this, this.onGetAdvsListData);
- }
- }
- Laya.ClassUtils.regClass("laya.ui.AdvImage", AdvImage);
- Laya.ClassUtils.regClass("Laya.AdvImage", AdvImage);
- class Box extends UIComponent {
- set dataSource(value) {
- this._dataSource = value;
- for (var name in value) {
- var comp = this.getChildByName(name);
- if (comp)
- comp.dataSource = value[name];
- else if (name in this && !(this[name] instanceof Function))
- this[name] = value[name];
- }
- }
- get dataSource() {
- return super.dataSource;
- }
- get bgColor() {
- return this._bgColor;
- }
- set bgColor(value) {
- this._bgColor = value;
- if (value) {
- this._onResize(null);
- this.on(Laya.Event.RESIZE, this, this._onResize);
- }
- else {
- this.graphics.clear();
- this.off(Laya.Event.RESIZE, this, this._onResize);
- }
- }
- _onResize(e) {
- this.graphics.clear();
- this.graphics.drawRect(0, 0, this.width, this.height, this._bgColor);
- }
- }
- Laya.ILaya.regClass(Box);
- Laya.ClassUtils.regClass("laya.ui.Box", Box);
- Laya.ClassUtils.regClass("Laya.Box", Box);
- class Button extends UIComponent {
- constructor(skin = null, label = "") {
- super();
- this._labelColors = Styles.buttonLabelColors;
- this._state = 0;
- this._autoSize = true;
- this._stateNum = Styles.buttonStateNum;
- this._stateChanged = false;
- this.skin = skin;
- this.label = label;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._bitmap && this._bitmap.destroy();
- this._text && this._text.destroy(destroyChild);
- this._bitmap = null;
- this._text = null;
- this._clickHandler = null;
- this._labelColors = this._sources = this._strokeColors = null;
- }
- createChildren() {
- this.graphics = this._bitmap = new AutoBitmap();
- }
- createText() {
- if (!this._text) {
- this._text = new Laya.Text();
- this._text.overflow = Laya.Text.HIDDEN;
- this._text.align = "center";
- this._text.valign = "middle";
- this._text.width = this._width;
- this._text.height = this._height;
- }
- }
- initialize() {
- if (this._mouseState !== 1) {
- this.mouseEnabled = true;
- this._setBit(Laya.Const.HAS_MOUSE, true);
- }
- this._createListener(Laya.Event.MOUSE_OVER, this, this.onMouse, null, false, false);
- this._createListener(Laya.Event.MOUSE_OUT, this, this.onMouse, null, false, false);
- this._createListener(Laya.Event.MOUSE_DOWN, this, this.onMouse, null, false, false);
- this._createListener(Laya.Event.MOUSE_UP, this, this.onMouse, null, false, false);
- this._createListener(Laya.Event.CLICK, this, this.onMouse, null, false, false);
- }
- onMouse(e) {
- if (this.toggle === false && this._selected)
- return;
- if (e.type === Laya.Event.CLICK) {
- this.toggle && (this.selected = !this._selected);
- this._clickHandler && this._clickHandler.run();
- return;
- }
- !this._selected && (this.state = Button.stateMap[e.type]);
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (this._skin != value) {
- this._skin = value;
- if (value) {
- if (!Laya.Loader.getRes(value)) {
- Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
- }
- else {
- this._skinLoaded();
- }
- }
- else {
- this._skinLoaded();
- }
- }
- }
- _skinLoaded() {
- this.callLater(this.changeClips);
- this._setStateChanged();
- this._sizeChanged();
- this.event(Laya.Event.LOADED);
- }
- get stateNum() {
- return this._stateNum;
- }
- set stateNum(value) {
- if (typeof value == 'string') {
- value = parseInt(value);
- }
- if (this._stateNum != value) {
- this._stateNum = value < 1 ? 1 : value > 3 ? 3 : value;
- this.callLater(this.changeClips);
- }
- }
- changeClips() {
- var img = Laya.Loader.getRes(this._skin);
- if (!img) {
- console.log("lose skin", this._skin);
- return;
- }
- var width = img.sourceWidth;
- var height = img.sourceHeight / this._stateNum;
- img.$_GID || (img.$_GID = Laya.Utils.getGID());
- var key = img.$_GID + "-" + this._stateNum;
- var clips = Laya.WeakObject.I.get(key);
- if (!Laya.Utils.isOkTextureList(clips)) {
- clips = null;
- }
- if (clips)
- this._sources = clips;
- else {
- this._sources = [];
- if (this._stateNum === 1) {
- this._sources.push(img);
- }
- else {
- for (var i = 0; i < this._stateNum; i++) {
- this._sources.push(Laya.Texture.createFromTexture(img, 0, height * i, width, height));
- }
- }
- Laya.WeakObject.I.set(key, this._sources);
- }
- if (this._autoSize) {
- this._bitmap.width = this._width || width;
- this._bitmap.height = this._height || height;
- if (this._text) {
- this._text.width = this._bitmap.width;
- this._text.height = this._bitmap.height;
- }
- }
- else {
- this._text && (this._text.x = width);
- }
- }
- measureWidth() {
- this.runCallLater(this.changeClips);
- if (this._autoSize)
- return this._bitmap.width;
- this.runCallLater(this.changeState);
- return this._bitmap.width + (this._text ? this._text.width : 0);
- }
- measureHeight() {
- this.runCallLater(this.changeClips);
- return this._text ? Math.max(this._bitmap.height, this._text.height) : this._bitmap.height;
- }
- get label() {
- return this._text ? this._text.text : null;
- }
- set label(value) {
- if (!this._text && !value)
- return;
- this.createText();
- if (this._text.text != value) {
- value && !this._text.parent && this.addChild(this._text);
- this._text.text = (value + "").replace(/\\n/g, "\n");
- this._setStateChanged();
- }
- }
- get selected() {
- return this._selected;
- }
- set selected(value) {
- if (this._selected != value) {
- this._selected = value;
- this.state = this._selected ? 2 : 0;
- this.event(Laya.Event.CHANGE);
- }
- }
- get state() {
- return this._state;
- }
- set state(value) {
- if (this._state != value) {
- this._state = value;
- this._setStateChanged();
- }
- }
- changeState() {
- this._stateChanged = false;
- this.runCallLater(this.changeClips);
- var index = this._state < this._stateNum ? this._state : this._stateNum - 1;
- this._sources && (this._bitmap.source = this._sources[index]);
- if (this.label) {
- this._text.color = this._labelColors[index];
- if (this._strokeColors)
- this._text.strokeColor = this._strokeColors[index];
- }
- }
- get labelColors() {
- return this._labelColors.join(",");
- }
- set labelColors(value) {
- this._labelColors = UIUtils.fillArray(Styles.buttonLabelColors, value, String);
- this._setStateChanged();
- }
- get strokeColors() {
- return this._strokeColors ? this._strokeColors.join(",") : "";
- }
- set strokeColors(value) {
- this._strokeColors = UIUtils.fillArray(Styles.buttonLabelColors, value, String);
- this._setStateChanged();
- }
- get labelPadding() {
- this.createText();
- return this._text.padding.join(",");
- }
- set labelPadding(value) {
- this.createText();
- this._text.padding = UIUtils.fillArray(Styles.labelPadding, value, Number);
- }
- get labelSize() {
- this.createText();
- return this._text.fontSize;
- }
- set labelSize(value) {
- this.createText();
- this._text.fontSize = value;
- }
- get labelStroke() {
- this.createText();
- return this._text.stroke;
- }
- set labelStroke(value) {
- this.createText();
- this._text.stroke = value;
- }
- get labelStrokeColor() {
- this.createText();
- return this._text.strokeColor;
- }
- set labelStrokeColor(value) {
- this.createText();
- this._text.strokeColor = value;
- }
- get labelBold() {
- this.createText();
- return this._text.bold;
- }
- set labelBold(value) {
- this.createText();
- this._text.bold = value;
- }
- get labelFont() {
- this.createText();
- return this._text.font;
- }
- set labelFont(value) {
- this.createText();
- this._text.font = value;
- }
- get labelAlign() {
- this.createText();
- return this._text.align;
- }
- set labelAlign(value) {
- this.createText();
- this._text.align = value;
- }
- get clickHandler() {
- return this._clickHandler;
- }
- set clickHandler(value) {
- this._clickHandler = value;
- }
- get text() {
- this.createText();
- return this._text;
- }
- get sizeGrid() {
- if (this._bitmap.sizeGrid)
- return this._bitmap.sizeGrid.join(",");
- return null;
- }
- set sizeGrid(value) {
- this._bitmap.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
- }
- set width(value) {
- super.set_width(value);
- if (this._autoSize) {
- this._bitmap.width = value;
- this._text && (this._text.width = value);
- }
- }
- get width() {
- return super.get_width();
- }
- set height(value) {
- super.set_height(value);
- if (this._autoSize) {
- this._bitmap.height = value;
- this._text && (this._text.height = value);
- }
- }
- get height() {
- return super.get_height();
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.label = value + "";
- else
- super.set_dataSource(value);
- }
- get dataSource() {
- return super.get_dataSource();
- }
- get iconOffset() {
- return this._bitmap._offset ? this._bitmap._offset.join(",") : null;
- }
- set iconOffset(value) {
- if (value)
- this._bitmap._offset = UIUtils.fillArray([1, 1], value, Number);
- else
- this._bitmap._offset = [];
- }
- _setStateChanged() {
- if (!this._stateChanged) {
- this._stateChanged = true;
- this.callLater(this.changeState);
- }
- }
- }
- Button.stateMap = { "mouseup": 0, "mouseover": 1, "mousedown": 2, "mouseout": 0 };
- Laya.ILaya.regClass(Button);
- Laya.ClassUtils.regClass("laya.ui.Button", Button);
- Laya.ClassUtils.regClass("Laya.Button", Button);
- class CheckBox extends Button {
- constructor(skin = null, label = "") {
- super(skin, label);
- this.toggle = true;
- this._autoSize = false;
- }
- preinitialize() {
- super.preinitialize();
- this.toggle = true;
- this._autoSize = false;
- }
- initialize() {
- super.initialize();
- this.createText();
- this._text.align = "left";
- this._text.valign = "top";
- this._text.width = 0;
- }
- set dataSource(value) {
- this._dataSource = value;
- if (value instanceof Boolean)
- this.selected = value;
- else if (typeof (value) == 'string')
- this.selected = value === "true";
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- }
- Laya.ILaya.regClass(CheckBox);
- Laya.ClassUtils.regClass("laya.ui.CheckBox", CheckBox);
- Laya.ClassUtils.regClass("Laya.CheckBox", CheckBox);
- class Clip extends UIComponent {
- constructor(url = null, clipX = 1, clipY = 1) {
- super();
- this._clipX = 1;
- this._clipY = 1;
- this._clipWidth = 0;
- this._clipHeight = 0;
- this._interval = 50;
- this._index = 0;
- this._toIndex = -1;
- this._clipX = clipX;
- this._clipY = clipY;
- this.skin = url;
- }
- destroy(destroyChild = true) {
- super.destroy(true);
- this._bitmap && this._bitmap.destroy();
- this._bitmap = null;
- this._sources = null;
- }
- dispose() {
- this.destroy(true);
- Laya.ILaya.loader.clearRes(this._skin);
- }
- createChildren() {
- this.graphics = this._bitmap = new AutoBitmap();
- }
- _onDisplay(e) {
- if (this._isPlaying) {
- if (this._getBit(Laya.Const.DISPLAYED_INSTAGE))
- this.play();
- else
- this.stop();
- }
- else if (this._autoPlay) {
- this.play();
- }
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (this._skin != value) {
- this._skin = value;
- if (value) {
- if (!Laya.Loader.getRes(value)) {
- Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
- }
- else {
- this._skinLoaded();
- }
- }
- else {
- this._bitmap.source = null;
- }
- }
- }
- _skinLoaded() {
- this._setClipChanged();
- this._sizeChanged();
- this.event(Laya.Event.LOADED);
- }
- get clipX() {
- return this._clipX;
- }
- set clipX(value) {
- this._clipX = value || 1;
- this._setClipChanged();
- }
- get clipY() {
- return this._clipY;
- }
- set clipY(value) {
- this._clipY = value || 1;
- this._setClipChanged();
- }
- get clipWidth() {
- return this._clipWidth;
- }
- set clipWidth(value) {
- this._clipWidth = value;
- this._setClipChanged();
- }
- get clipHeight() {
- return this._clipHeight;
- }
- set clipHeight(value) {
- this._clipHeight = value;
- this._setClipChanged();
- }
- changeClip() {
- this._clipChanged = false;
- if (!this._skin)
- return;
- var img = Laya.Loader.getRes(this._skin);
- if (img) {
- this.loadComplete(this._skin, img);
- }
- else {
- Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this.loadComplete, [this._skin]));
- }
- }
- loadComplete(url, img) {
- if (url === this._skin && img) {
- var w = this._clipWidth || Math.ceil(img.sourceWidth / this._clipX);
- var h = this._clipHeight || Math.ceil(img.sourceHeight / this._clipY);
- var key = this._skin + w + h;
- var clips = Laya.WeakObject.I.get(key);
- if (!Laya.Utils.isOkTextureList(clips)) {
- clips = null;
- }
- if (clips)
- this._sources = clips;
- else {
- this._sources = [];
- for (var i = 0; i < this._clipY; i++) {
- for (var j = 0; j < this._clipX; j++) {
- this._sources.push(Laya.Texture.createFromTexture(img, w * j, h * i, w, h));
- }
- }
- Laya.WeakObject.I.set(key, this._sources);
- }
- this.index = this._index;
- this.event(Laya.Event.LOADED);
- this.onCompResize();
- }
- }
- get sources() {
- return this._sources;
- }
- set sources(value) {
- this._sources = value;
- this.index = this._index;
- this.event(Laya.Event.LOADED);
- }
- get group() {
- return this._group;
- }
- set group(value) {
- if (value && this._skin)
- Laya.Loader.setGroup(this._skin, value);
- this._group = value;
- }
- set width(value) {
- super.width = value;
- this._bitmap.width = value;
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._bitmap.height = value;
- }
- get height() {
- return super.height;
- }
- measureWidth() {
- this.runCallLater(this.changeClip);
- return this._bitmap.width;
- }
- measureHeight() {
- this.runCallLater(this.changeClip);
- return this._bitmap.height;
- }
- get sizeGrid() {
- if (this._bitmap.sizeGrid)
- return this._bitmap.sizeGrid.join(",");
- return null;
- }
- set sizeGrid(value) {
- this._bitmap.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
- }
- get index() {
- return this._index;
- }
- set index(value) {
- this._index = value;
- this._bitmap && this._sources && (this._bitmap.source = this._sources[value]);
- this.event(Laya.Event.CHANGE);
- }
- get total() {
- this.runCallLater(this.changeClip);
- return this._sources ? this._sources.length : 0;
- }
- get autoPlay() {
- return this._autoPlay;
- }
- set autoPlay(value) {
- if (this._autoPlay != value) {
- this._autoPlay = value;
- value ? this.play() : this.stop();
- }
- }
- get interval() {
- return this._interval;
- }
- set interval(value) {
- if (this._interval != value) {
- this._interval = value;
- if (this._isPlaying)
- this.play();
- }
- }
- get isPlaying() {
- return this._isPlaying;
- }
- set isPlaying(value) {
- this._isPlaying = value;
- }
- play(from = 0, to = -1) {
- this._isPlaying = true;
- this.index = from;
- this._toIndex = to;
- this._index++;
- Laya.ILaya.timer.loop(this.interval, this, this._loop);
- this.on(Laya.Event.DISPLAY, this, this._onDisplay);
- this.on(Laya.Event.UNDISPLAY, this, this._onDisplay);
- }
- _loop() {
- if (this._visible && this._sources) {
- this._index++;
- if (this._toIndex > -1 && this._index >= this._toIndex)
- this.stop();
- else if (this._index >= this._sources.length)
- this._index = 0;
- this.index = this._index;
- }
- }
- stop() {
- this._isPlaying = false;
- Laya.ILaya.timer.clear(this, this._loop);
- this.event(Laya.Event.COMPLETE);
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.index = parseInt(value);
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- get bitmap() {
- return this._bitmap;
- }
- _setClipChanged() {
- if (!this._clipChanged) {
- this._clipChanged = true;
- this.callLater(this.changeClip);
- }
- }
- }
- Laya.ILaya.regClass(Clip);
- Laya.ClassUtils.regClass("laya.ui.Clip", Clip);
- Laya.ClassUtils.regClass("Laya.Clip", Clip);
- class ColorPicker extends UIComponent {
- constructor(createChildren = true) {
- super(false);
- this._gridSize = 11;
- this._bgColor = "#ffffff";
- this._borderColor = "#000000";
- this._inputColor = "#000000";
- this._inputBgColor = "#efefef";
- this._colors = [];
- this._selectedColor = "#000000";
- if (createChildren) {
- this.preinitialize();
- this.createChildren();
- this.initialize();
- }
- }
- destroy(destroyChild = true) {
- Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this.removeColorBox);
- super.destroy(destroyChild);
- this._colorPanel && this._colorPanel.destroy(destroyChild);
- this._colorButton && this._colorButton.destroy(destroyChild);
- this._colorPanel = null;
- this._colorTiles = null;
- this._colorBlock = null;
- this._colorInput = null;
- this._colorButton = null;
- this._colors = null;
- this.changeHandler = null;
- }
- createChildren() {
- this.addChild(this._colorButton = new Button());
- this._colorPanel = new Box();
- this._colorPanel.size(230, 166);
- this._colorPanel.addChild(this._colorTiles = new Laya.Sprite());
- this._colorPanel.addChild(this._colorBlock = new Laya.Sprite());
- this._colorPanel.addChild(this._colorInput = new Laya.Input());
- }
- initialize() {
- this._colorButton.on(Laya.Event.CLICK, this, this.onColorButtonClick);
- this._colorBlock.pos(5, 5);
- this._colorInput.pos(60, 5);
- this._colorInput.size(60, 20);
- this._colorInput.on(Laya.Event.CHANGE, this, this.onColorInputChange);
- this._colorInput.on(Laya.Event.KEY_DOWN, this, this.onColorFieldKeyDown);
- this._colorTiles.pos(5, 30);
- this._colorTiles.on(Laya.Event.MOUSE_MOVE, this, this.onColorTilesMouseMove);
- this._colorTiles.on(Laya.Event.CLICK, this, this.onColorTilesClick);
- this._colorTiles.size(20 * this._gridSize, 12 * this._gridSize);
- this._colorPanel.on(Laya.Event.MOUSE_DOWN, this, this.onPanelMouseDown);
- this.bgColor = this._bgColor;
- }
- onPanelMouseDown(e) {
- e.stopPropagation();
- }
- changePanel() {
- this._panelChanged = false;
- var g = this._colorPanel.graphics;
- g.clear(true);
- g.drawRect(0, 0, 230, 166, this._bgColor, this._borderColor);
- this.drawBlock(this._selectedColor);
- this._colorInput.borderColor = this._borderColor;
- this._colorInput.bgColor = this._inputBgColor;
- this._colorInput.color = this._inputColor;
- g = this._colorTiles.graphics;
- g.clear(true);
- var mainColors = [0x000000, 0x333333, 0x666666, 0x999999, 0xCCCCCC, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF];
- for (var i = 0; i < 12; i++) {
- for (var j = 0; j < 20; j++) {
- var color;
- if (j === 0)
- color = mainColors[i];
- else if (j === 1)
- color = 0x000000;
- else
- color = (((i * 3 + j / 6) % 3 << 0) + ((i / 6) << 0) * 3) * 0x33 << 16 | j % 6 * 0x33 << 8 | (i << 0) % 6 * 0x33;
- var strColor = UIUtils.toColor(color);
- this._colors.push(strColor);
- var x = j * this._gridSize;
- var y = i * this._gridSize;
- g.drawRect(x, y, this._gridSize, this._gridSize, strColor, "#000000");
- }
- }
- }
- onColorButtonClick(e) {
- if (this._colorPanel.parent)
- this.close();
- else
- this.open();
- }
- open() {
- let stage = Laya.ILaya.stage;
- var p = this.localToGlobal(new Laya.Point());
- var px = p.x + this._colorPanel.width <= stage.width ? p.x : stage.width - this._colorPanel.width;
- var py = p.y + this._colorButton.height;
- py = py + this._colorPanel.height <= stage.height ? py : p.y - this._colorPanel.height;
- this._colorPanel.pos(px, py);
- this._colorPanel.zOrder = 1001;
- stage.addChild(this._colorPanel);
- stage.on(Laya.Event.MOUSE_DOWN, this, this.removeColorBox);
- }
- close() {
- Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this.removeColorBox);
- this._colorPanel.removeSelf();
- }
- removeColorBox(e = null) {
- this.close();
- }
- onColorFieldKeyDown(e) {
- if (e.keyCode == 13) {
- if (this._colorInput.text)
- this.selectedColor = this._colorInput.text;
- else
- this.selectedColor = null;
- this.close();
- e.stopPropagation();
- }
- }
- onColorInputChange(e = null) {
- if (this._colorInput.text)
- this.drawBlock(this._colorInput.text);
- else
- this.drawBlock("#FFFFFF");
- }
- onColorTilesClick(e) {
- this.selectedColor = this.getColorByMouse();
- this.close();
- }
- onColorTilesMouseMove(e) {
- this._colorInput.focus = false;
- var color = this.getColorByMouse();
- this._colorInput.text = color;
- this.drawBlock(color);
- }
- getColorByMouse() {
- var point = this._colorTiles.getMousePoint();
- var x = Math.floor(point.x / this._gridSize);
- var y = Math.floor(point.y / this._gridSize);
- return this._colors[y * 20 + x];
- }
- drawBlock(color) {
- var g = this._colorBlock.graphics;
- g.clear(true);
- var showColor = color ? color : "#ffffff";
- g.drawRect(0, 0, 50, 20, showColor, this._borderColor);
- color || g.drawLine(0, 0, 50, 20, "#ff0000");
- }
- get selectedColor() {
- return this._selectedColor;
- }
- set selectedColor(value) {
- if (this._selectedColor != value) {
- this._selectedColor = this._colorInput.text = value;
- this.drawBlock(value);
- this.changeColor();
- this.changeHandler && this.changeHandler.runWith(this._selectedColor);
- this.event(Laya.Event.CHANGE, Laya.Event.EMPTY.setTo(Laya.Event.CHANGE, this, this));
- }
- }
- get skin() {
- return this._colorButton.skin;
- }
- set skin(value) {
- this._colorButton.once(Laya.Event.LOADED, this, this.changeColor);
- this._colorButton.skin = value;
- }
- changeColor() {
- var g = this.graphics;
- g.clear(true);
- var showColor = this._selectedColor || "#000000";
- g.drawRect(0, 0, this._colorButton.width, this._colorButton.height, showColor);
- }
- get bgColor() {
- return this._bgColor;
- }
- set bgColor(value) {
- this._bgColor = value;
- this._setPanelChanged();
- }
- get borderColor() {
- return this._borderColor;
- }
- set borderColor(value) {
- this._borderColor = value;
- this._setPanelChanged();
- }
- get inputColor() {
- return this._inputColor;
- }
- set inputColor(value) {
- this._inputColor = value;
- this._setPanelChanged();
- }
- get inputBgColor() {
- return this._inputBgColor;
- }
- set inputBgColor(value) {
- this._inputBgColor = value;
- this._setPanelChanged();
- }
- _setPanelChanged() {
- if (!this._panelChanged) {
- this._panelChanged = true;
- this.callLater(this.changePanel);
- }
- }
- }
- Laya.ILaya.regClass(ColorPicker);
- Laya.ClassUtils.regClass("laya.ui.ColorPicker", ColorPicker);
- Laya.ClassUtils.regClass("Laya.ColorPicker", ColorPicker);
- class Label extends UIComponent {
- constructor(text = "") {
- super();
- this.text = text;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._tf = null;
- }
- createChildren() {
- this.addChild(this._tf = new Laya.Text());
- }
- get text() {
- return this._tf.text;
- }
- set text(value) {
- if (this._tf.text != value) {
- if (value)
- value = UIUtils.adptString(value + "");
- this._tf.text = value;
- this.event(Laya.Event.CHANGE);
- if (!this._width || !this._height)
- this.onCompResize();
- }
- }
- changeText(text) {
- this._tf.changeText(text);
- }
- get wordWrap() {
- return this._tf.wordWrap;
- }
- set wordWrap(value) {
- this._tf.wordWrap = value;
- }
- get color() {
- return this._tf.color;
- }
- set color(value) {
- this._tf.color = value;
- }
- get font() {
- return this._tf.font;
- }
- set font(value) {
- this._tf.font = value;
- }
- get align() {
- return this._tf.align;
- }
- set align(value) {
- this._tf.align = value;
- }
- get valign() {
- return this._tf.valign;
- }
- set valign(value) {
- this._tf.valign = value;
- }
- get bold() {
- return this._tf.bold;
- }
- set bold(value) {
- this._tf.bold = value;
- }
- get italic() {
- return this._tf.italic;
- }
- set italic(value) {
- this._tf.italic = value;
- }
- get leading() {
- return this._tf.leading;
- }
- set leading(value) {
- this._tf.leading = value;
- }
- get fontSize() {
- return this._tf.fontSize;
- }
- set fontSize(value) {
- this._tf.fontSize = value;
- }
- get padding() {
- return this._tf.padding.join(",");
- }
- set padding(value) {
- this._tf.padding = UIUtils.fillArray(Styles.labelPadding, value, Number);
- }
- get bgColor() {
- return this._tf.bgColor;
- }
- set bgColor(value) {
- this._tf.bgColor = value;
- }
- get borderColor() {
- return this._tf.borderColor;
- }
- set borderColor(value) {
- this._tf.borderColor = value;
- }
- get stroke() {
- return this._tf.stroke;
- }
- set stroke(value) {
- this._tf.stroke = value;
- }
- get strokeColor() {
- return this._tf.strokeColor;
- }
- set strokeColor(value) {
- this._tf.strokeColor = value;
- }
- get textField() {
- return this._tf;
- }
- measureWidth() {
- return this._tf.width;
- }
- measureHeight() {
- return this._tf.height;
- }
- get width() {
- if (this._width || this._tf.text)
- return super.width;
- return 0;
- }
- set width(value) {
- super.width = value;
- this._tf.width = value;
- }
- get height() {
- if (this._height || this._tf.text)
- return super.height;
- return 0;
- }
- set height(value) {
- super.height = value;
- this._tf.height = value;
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.text = value + "";
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- get overflow() {
- return this._tf.overflow;
- }
- set overflow(value) {
- this._tf.overflow = value;
- }
- get underline() {
- return this._tf.underline;
- }
- set underline(value) {
- this._tf.underline = value;
- }
- get underlineColor() {
- return this._tf.underlineColor;
- }
- set underlineColor(value) {
- this._tf.underlineColor = value;
- }
- }
- Laya.ILaya.regClass(Label);
- Laya.ClassUtils.regClass("laya.ui.Label", Label);
- Laya.ClassUtils.regClass("Laya.Label", Label);
- class Slider extends UIComponent {
- constructor(skin = null) {
- super();
- this.isVertical = true;
- this.showLabel = true;
- this._max = 100;
- this._min = 0;
- this._tick = 1;
- this._value = 0;
- if (!Slider.label) {
- Slider.label = new Label();
- }
- this.skin = skin;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._bg && this._bg.destroy(destroyChild);
- this._bar && this._bar.destroy(destroyChild);
- this._progress && this._progress.destroy(destroyChild);
- this._bg = null;
- this._bar = null;
- this._progress = null;
- this.changeHandler = null;
- }
- createChildren() {
- this.addChild(this._bg = new Image());
- this.addChild(this._bar = new Button());
- }
- initialize() {
- this._bar.on(Laya.Event.MOUSE_DOWN, this, this.onBarMouseDown);
- this._bg.sizeGrid = this._bar.sizeGrid = "4,4,4,4,0";
- if (this._progress)
- this._progress.sizeGrid = this._bar.sizeGrid;
- this.allowClickBack = true;
- }
- onBarMouseDown(e) {
- var Laya$1 = Laya.ILaya;
- this._globalSacle || (this._globalSacle = new Laya.Point());
- this._globalSacle.setTo(this.globalScaleX || 0.01, this.globalScaleY || 0.01);
- this._maxMove = this.isVertical ? (this.height - this._bar.height) : (this.width - this._bar.width);
- this._tx = Laya$1.stage.mouseX;
- this._ty = Laya$1.stage.mouseY;
- Laya$1.stage.on(Laya.Event.MOUSE_MOVE, this, this.mouseMove);
- Laya$1.stage.once(Laya.Event.MOUSE_UP, this, this.mouseUp);
- Laya$1.stage.once(Laya.Event.MOUSE_OUT, this, this.mouseUp);
- this.showValueText();
- }
- showValueText() {
- if (this.showLabel) {
- var label = Slider.label;
- this.addChild(label);
- label.textField.changeText(this._value + "");
- if (this.isVertical) {
- label.x = this._bar._x + 20;
- label.y = (this._bar.height - label.height) * 0.5 + this._bar._y;
- }
- else {
- label.y = this._bar._y - 20;
- label.x = (this._bar.width - label.width) * 0.5 + this._bar._x;
- }
- }
- }
- hideValueText() {
- Slider.label && Slider.label.removeSelf();
- }
- mouseUp(e) {
- let stage = Laya.ILaya.stage;
- stage.off(Laya.Event.MOUSE_MOVE, this, this.mouseMove);
- stage.off(Laya.Event.MOUSE_UP, this, this.mouseUp);
- stage.off(Laya.Event.MOUSE_OUT, this, this.mouseUp);
- this.sendChangeEvent(Laya.Event.CHANGED);
- this.hideValueText();
- }
- mouseMove(e) {
- let stage = Laya.ILaya.stage;
- var oldValue = this._value;
- if (this.isVertical) {
- this._bar.y += (stage.mouseY - this._ty) / this._globalSacle.y;
- if (this._bar._y > this._maxMove)
- this._bar.y = this._maxMove;
- else if (this._bar._y < 0)
- this._bar.y = 0;
- this._value = this._bar._y / this._maxMove * (this._max - this._min) + this._min;
- if (this._progress)
- this._progress.height = this._bar._y + 0.5 * this._bar.height;
- }
- else {
- this._bar.x += (stage.mouseX - this._tx) / this._globalSacle.x;
- if (this._bar._x > this._maxMove)
- this._bar.x = this._maxMove;
- else if (this._bar._x < 0)
- this._bar.x = 0;
- this._value = this._bar._x / this._maxMove * (this._max - this._min) + this._min;
- if (this._progress)
- this._progress.width = this._bar._x + 0.5 * this._bar.width;
- }
- this._tx = stage.mouseX;
- this._ty = stage.mouseY;
- if (this._tick != 0) {
- var pow = Math.pow(10, (this._tick + "").length - 1);
- this._value = Math.round(Math.round(this._value / this._tick) * this._tick * pow) / pow;
- }
- if (this._value != oldValue) {
- this.sendChangeEvent();
- }
- this.showValueText();
- }
- sendChangeEvent(type = Laya.Event.CHANGE) {
- this.event(type);
- this.changeHandler && this.changeHandler.runWith(this._value);
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (this._skin != value) {
- this._skin = value;
- if (this._skin && !Laya.Loader.getRes(this._skin)) {
- Laya.ILaya.loader.load([this._skin, this._skin.replace(".png", "$bar.png")], Laya.Handler.create(this, this._skinLoaded));
- }
- else {
- this._skinLoaded();
- }
- }
- }
- _skinLoaded() {
- this._bg.skin = this._skin;
- this._bar.skin = this._skin.replace(".png", "$bar.png");
- var progressSkin = this._skin.replace(".png", "$progress.png");
- if (Laya.Loader.getRes(progressSkin)) {
- if (!this._progress) {
- this.addChild(this._progress = new Image());
- this._progress.sizeGrid = this._bar.sizeGrid;
- this.setChildIndex(this._progress, 1);
- }
- this._progress.skin = progressSkin;
- }
- this.setBarPoint();
- this.callLater(this.changeValue);
- this._sizeChanged();
- this.event(Laya.Event.LOADED);
- }
- setBarPoint() {
- if (this.isVertical)
- this._bar.x = Math.round((this._bg.width - this._bar.width) * 0.5);
- else
- this._bar.y = Math.round((this._bg.height - this._bar.height) * 0.5);
- }
- measureWidth() {
- return Math.max(this._bg.width, this._bar.width);
- }
- measureHeight() {
- return Math.max(this._bg.height, this._bar.height);
- }
- _sizeChanged() {
- super._sizeChanged();
- if (this.isVertical)
- this._bg.height = this.height;
- else
- this._bg.width = this.width;
- this.setBarPoint();
- this.changeValue();
- }
- get sizeGrid() {
- return this._bg.sizeGrid;
- }
- set sizeGrid(value) {
- this._bg.sizeGrid = value;
- this._bar.sizeGrid = value;
- if (this._progress)
- this._progress.sizeGrid = this._bar.sizeGrid;
- }
- setSlider(min, max, value) {
- this._value = -1;
- this._min = min;
- this._max = max > min ? max : min;
- this.value = value < min ? min : value > max ? max : value;
- }
- get tick() {
- return this._tick;
- }
- set tick(value) {
- if (this._tick != value) {
- this._tick = value;
- this.callLater(this.changeValue);
- }
- }
- changeValue() {
- if (this.tick != 0) {
- var pow = Math.pow(10, (this._tick + "").length - 1);
- this._value = Math.round(Math.round(this._value / this._tick) * this._tick * pow) / pow;
- }
- this._value = this._value > this._max ? this._max : this._value < this._min ? this._min : this._value;
- var num = this._max - this._min;
- if (num === 0)
- num = 1;
- if (this.isVertical) {
- this._bar.y = (this._value - this._min) / num * (this.height - this._bar.height);
- if (this._progress)
- this._progress.height = this._bar._y + 0.5 * this._bar.height;
- }
- else {
- this._bar.x = (this._value - this._min) / num * (this.width - this._bar.width);
- if (this._progress)
- this._progress.width = this._bar._x + 0.5 * this._bar.width;
- }
- }
- get max() {
- return this._max;
- }
- set max(value) {
- if (this._max != value) {
- this._max = value;
- this.callLater(this.changeValue);
- }
- }
- get min() {
- return this._min;
- }
- set min(value) {
- if (this._min != value) {
- this._min = value;
- this.callLater(this.changeValue);
- }
- }
- get value() {
- return this._value;
- }
- set value(num) {
- if (this._value != num) {
- var oldValue = this._value;
- this._value = num;
- this.changeValue();
- if (this._value != oldValue) {
- this.sendChangeEvent();
- }
- }
- }
- get allowClickBack() {
- return this._allowClickBack;
- }
- set allowClickBack(value) {
- if (this._allowClickBack != value) {
- this._allowClickBack = value;
- if (value)
- this._bg.on(Laya.Event.MOUSE_DOWN, this, this.onBgMouseDown);
- else
- this._bg.off(Laya.Event.MOUSE_DOWN, this, this.onBgMouseDown);
- }
- }
- onBgMouseDown(e) {
- var point = this._bg.getMousePoint();
- if (this.isVertical)
- this.value = point.y / (this.height - this._bar.height) * (this._max - this._min) + this._min;
- else
- this.value = point.x / (this.width - this._bar.width) * (this._max - this._min) + this._min;
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.value = Number(value);
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- get bar() {
- return this._bar;
- }
- }
- Slider.label = null;
- Laya.ILaya.regClass(Slider);
- Laya.ClassUtils.regClass("laya.ui.Slider", Slider);
- Laya.ClassUtils.regClass("Laya.Slider", Slider);
- class ScrollBar extends UIComponent {
- constructor(skin = null) {
- super();
- this.rollRatio = 0.97;
- this.scaleBar = true;
- this.autoHide = false;
- this.elasticDistance = 0;
- this.elasticBackTime = 500;
- this._showButtons = UIConfig.showButtons;
- this._scrollSize = 1;
- this._thumbPercent = 1;
- this._lastOffset = 0;
- this._checkElastic = false;
- this._isElastic = false;
- this._hide = false;
- this._clickOnly = true;
- this._touchScrollEnable = UIConfig.touchScrollEnable;
- this._mouseWheelEnable = UIConfig.mouseWheelEnable;
- this.skin = skin;
- this.max = 1;
- }
- destroy(destroyChild = true) {
- this.stopScroll();
- this.target = null;
- super.destroy(destroyChild);
- this.upButton && this.upButton.destroy(destroyChild);
- this.downButton && this.downButton.destroy(destroyChild);
- this.slider && this.slider.destroy(destroyChild);
- this.upButton = this.downButton = null;
- this.slider = null;
- this.changeHandler = null;
- this._offsets = null;
- }
- createChildren() {
- this.addChild(this.slider = new Slider());
- this.addChild(this.upButton = new Button());
- this.addChild(this.downButton = new Button());
- }
- initialize() {
- this.slider.showLabel = false;
- this.slider.tick = 0;
- this.slider.on(Laya.Event.CHANGE, this, this.onSliderChange);
- this.slider.setSlider(0, 0, 0);
- this.upButton.on(Laya.Event.MOUSE_DOWN, this, this.onButtonMouseDown);
- this.downButton.on(Laya.Event.MOUSE_DOWN, this, this.onButtonMouseDown);
- }
- onSliderChange() {
- if (this._value != this.slider.value)
- this.value = this.slider.value;
- }
- onButtonMouseDown(e) {
- var isUp = e.currentTarget === this.upButton;
- this.slide(isUp);
- Laya.ILaya.timer.once(Styles.scrollBarDelayTime, this, this.startLoop, [isUp]);
- Laya.ILaya.stage.once(Laya.Event.MOUSE_UP, this, this.onStageMouseUp);
- }
- startLoop(isUp) {
- Laya.ILaya.timer.frameLoop(1, this, this.slide, [isUp]);
- }
- slide(isUp) {
- if (isUp)
- this.value -= this._scrollSize;
- else
- this.value += this._scrollSize;
- }
- onStageMouseUp(e) {
- Laya.ILaya.timer.clear(this, this.startLoop);
- Laya.ILaya.timer.clear(this, this.slide);
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (value == " ")
- return;
- if (this._skin != value) {
- this._skin = value;
- if (this._skin && !Laya.Loader.getRes(this._skin)) {
- 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));
- }
- else {
- this._skinLoaded();
- }
- }
- }
- _skinLoaded() {
- this.slider.skin = this._skin;
- this.callLater(this.changeScrollBar);
- this._sizeChanged();
- this.event(Laya.Event.LOADED);
- }
- changeScrollBar() {
- this.upButton.visible = this._showButtons;
- this.downButton.visible = this._showButtons;
- if (this._showButtons) {
- this.upButton.skin = this._skin.replace(".png", "$up.png");
- this.downButton.skin = this._skin.replace(".png", "$down.png");
- }
- if (this.slider.isVertical)
- this.slider.y = this._showButtons ? this.upButton.height : 0;
- else
- this.slider.x = this._showButtons ? this.upButton.width : 0;
- this.resetPositions();
- this.repaint();
- }
- _sizeChanged() {
- super._sizeChanged();
- this.repaint();
- this.resetPositions();
- this.event(Laya.Event.CHANGE);
- this.changeHandler && this.changeHandler.runWith(this.value);
- }
- resetPositions() {
- if (this.slider.isVertical)
- this.slider.height = this.height - (this._showButtons ? (this.upButton.height + this.downButton.height) : 0);
- else
- this.slider.width = this.width - (this._showButtons ? (this.upButton.width + this.downButton.width) : 0);
- this.resetButtonPosition();
- }
- resetButtonPosition() {
- if (this.slider.isVertical)
- this.downButton.y = this.slider._y + this.slider.height;
- else
- this.downButton.x = this.slider._x + this.slider.width;
- }
- measureWidth() {
- if (this.slider.isVertical)
- return this.slider.width;
- return 100;
- }
- measureHeight() {
- if (this.slider.isVertical)
- return 100;
- return this.slider.height;
- }
- setScroll(min, max, value) {
- this.runCallLater(this._sizeChanged);
- this.slider.setSlider(min, max, value);
- this.slider.bar.visible = max > 0;
- if (!this._hide && this.autoHide)
- this.visible = false;
- }
- get max() {
- return this.slider.max;
- }
- set max(value) {
- this.slider.max = value;
- }
- get min() {
- return this.slider.min;
- }
- set min(value) {
- this.slider.min = value;
- }
- get value() {
- return this._value;
- }
- set value(v) {
- if (v !== this._value) {
- this._value = v;
- if (!this._isElastic) {
- if (this.slider["_value"] != v) {
- this.slider["_value"] = v;
- this.slider.changeValue();
- }
- this._value = this.slider["_value"];
- }
- this.event(Laya.Event.CHANGE);
- this.changeHandler && this.changeHandler.runWith(this._value);
- }
- }
- get isVertical() {
- return this.slider.isVertical;
- }
- set isVertical(value) {
- this.slider.isVertical = value;
- }
- get sizeGrid() {
- return this.slider.sizeGrid;
- }
- set sizeGrid(value) {
- this.slider.sizeGrid = value;
- }
- get scrollSize() {
- return this._scrollSize;
- }
- set scrollSize(value) {
- this._scrollSize = value;
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.value = Number(value);
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- get thumbPercent() {
- return this._thumbPercent;
- }
- set thumbPercent(value) {
- this.runCallLater(this.changeScrollBar);
- this.runCallLater(this._sizeChanged);
- value = value >= 1 ? 0.99 : value;
- this._thumbPercent = value;
- if (this.scaleBar) {
- if (this.slider.isVertical)
- this.slider.bar.height = Math.max(this.slider.height * value, Styles.scrollBarMinNum);
- else
- this.slider.bar.width = Math.max(this.slider.width * value, Styles.scrollBarMinNum);
- }
- }
- get target() {
- return this._target;
- }
- set target(value) {
- if (this._target) {
- this._target.off(Laya.Event.MOUSE_WHEEL, this, this.onTargetMouseWheel);
- this._target.off(Laya.Event.MOUSE_DOWN, this, this.onTargetMouseDown);
- }
- this._target = value;
- if (value) {
- this._mouseWheelEnable && this._target.on(Laya.Event.MOUSE_WHEEL, this, this.onTargetMouseWheel);
- this._touchScrollEnable && this._target.on(Laya.Event.MOUSE_DOWN, this, this.onTargetMouseDown);
- }
- }
- get hide() {
- return this._hide;
- }
- set hide(value) {
- this._hide = value;
- this.visible = !value;
- }
- get showButtons() {
- return this._showButtons;
- }
- set showButtons(value) {
- this._showButtons = value;
- this.callLater(this.changeScrollBar);
- }
- get touchScrollEnable() {
- return this._touchScrollEnable;
- }
- set touchScrollEnable(value) {
- this._touchScrollEnable = value;
- this.target = this._target;
- }
- get mouseWheelEnable() {
- return this._mouseWheelEnable;
- }
- set mouseWheelEnable(value) {
- this._mouseWheelEnable = value;
- this.target = this._target;
- }
- onTargetMouseWheel(e) {
- this.value -= e.delta * this._scrollSize;
- this.target = this._target;
- }
- onTargetMouseDown(e) {
- if ((this.isLockedFun) && !this.isLockedFun(e))
- return;
- this.event(Laya.Event.END);
- this._clickOnly = true;
- this._lastOffset = 0;
- this._checkElastic = false;
- this._lastPoint || (this._lastPoint = new Laya.Point());
- this._lastPoint.setTo(Laya.ILaya.stage.mouseX, Laya.ILaya.stage.mouseY);
- Laya.ILaya.timer.clear(this, this.tweenMove);
- Laya.Tween.clearTween(this);
- Laya.ILaya.stage.once(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
- Laya.ILaya.stage.once(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
- Laya.ILaya.timer.frameLoop(1, this, this.loop);
- }
- startDragForce() {
- this._clickOnly = true;
- this._lastOffset = 0;
- this._checkElastic = false;
- this._lastPoint || (this._lastPoint = new Laya.Point());
- this._lastPoint.setTo(Laya.ILaya.stage.mouseX, Laya.ILaya.stage.mouseY);
- Laya.ILaya.timer.clear(this, this.tweenMove);
- Laya.Tween.clearTween(this);
- Laya.ILaya.stage.once(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
- Laya.ILaya.stage.once(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
- Laya.ILaya.timer.frameLoop(1, this, this.loop);
- }
- cancelDragOp() {
- Laya.ILaya.stage.off(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
- Laya.ILaya.stage.off(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
- Laya.ILaya.timer.clear(this, this.tweenMove);
- Laya.ILaya.timer.clear(this, this.loop);
- this._target.mouseEnabled = true;
- }
- checkTriggers(isTweenMove = false) {
- if (this.value >= 0 && this.value - this._lastOffset <= 0) {
- if ((this.triggerDownDragLimit) && this.triggerDownDragLimit(isTweenMove)) {
- this.cancelDragOp();
- this.value = 0;
- return true;
- }
- }
- if (this.value <= this.max && (this.value - this._lastOffset >= this.max)) {
- if ((this.triggerUpDragLimit) && this.triggerUpDragLimit(isTweenMove)) {
- this.cancelDragOp();
- this.value = this.max;
- return true;
- }
- }
- return false;
- }
- get lastOffset() {
- return this._lastOffset;
- }
- startTweenMoveForce(lastOffset) {
- this._lastOffset = lastOffset;
- Laya.ILaya.timer.frameLoop(1, this, this.tweenMove, [200]);
- }
- loop() {
- var mouseY = Laya.ILaya.stage.mouseY;
- var mouseX = Laya.ILaya.stage.mouseX;
- this._lastOffset = this.isVertical ? (mouseY - this._lastPoint.y) : (mouseX - this._lastPoint.x);
- if (this._clickOnly) {
- if (Math.abs(this._lastOffset * (this.isVertical ? Laya.ILaya.stage._canvasTransform.getScaleY() : Laya.ILaya.stage._canvasTransform.getScaleX())) > 1) {
- this._clickOnly = false;
- if (this.checkTriggers())
- return;
- this._offsets || (this._offsets = []);
- this._offsets.length = 0;
- this._target.mouseEnabled = false;
- if (!this.hide && this.autoHide) {
- this.alpha = 1;
- this.visible = true;
- }
- this.event(Laya.Event.START);
- }
- else
- return;
- }
- else {
- if (this.checkTriggers())
- return;
- }
- this._offsets.push(this._lastOffset);
- this._lastPoint.x = mouseX;
- this._lastPoint.y = mouseY;
- if (this._lastOffset === 0)
- return;
- if (!this._checkElastic) {
- if (this.elasticDistance > 0) {
- if (!this._checkElastic && this._lastOffset != 0) {
- if ((this._lastOffset > 0 && this._value <= this.min) || (this._lastOffset < 0 && this._value >= this.max)) {
- this._isElastic = true;
- this._checkElastic = true;
- }
- else {
- this._isElastic = false;
- }
- }
- }
- else {
- this._checkElastic = true;
- }
- }
- if (this._isElastic) {
- if (this._value <= this.min) {
- if (this._lastOffset > 0) {
- this.value -= this._lastOffset * Math.max(0, (1 - ((this.min - this._value) / this.elasticDistance)));
- }
- else {
- this.value -= this._lastOffset * 0.5;
- if (this._value >= this.min)
- this._checkElastic = false;
- }
- }
- else if (this._value >= this.max) {
- if (this._lastOffset < 0) {
- this.value -= this._lastOffset * Math.max(0, (1 - ((this._value - this.max) / this.elasticDistance)));
- }
- else {
- this.value -= this._lastOffset * 0.5;
- if (this._value <= this.max)
- this._checkElastic = false;
- }
- }
- }
- else {
- this.value -= this._lastOffset;
- }
- }
- onStageMouseUp2(e) {
- Laya.ILaya.stage.off(Laya.Event.MOUSE_UP, this, this.onStageMouseUp2);
- Laya.ILaya.stage.off(Laya.Event.MOUSE_OUT, this, this.onStageMouseUp2);
- Laya.ILaya.timer.clear(this, this.loop);
- if (this._clickOnly) {
- if (this._value >= this.min && this._value <= this.max)
- return;
- }
- this._target.mouseEnabled = true;
- if (this._isElastic) {
- if (this._value < this.min) {
- Laya.Tween.to(this, { value: this.min }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
- }
- else if (this._value > this.max) {
- Laya.Tween.to(this, { value: this.max }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
- }
- }
- else {
- if (!this._offsets)
- return;
- if (this._offsets.length < 1) {
- this._offsets[0] = this.isVertical ? Laya.ILaya.stage.mouseY - this._lastPoint.y : Laya.ILaya.stage.mouseX - this._lastPoint.x;
- }
- var offset = 0;
- var n = Math.min(this._offsets.length, 3);
- for (var i = 0; i < n; i++) {
- offset += this._offsets[this._offsets.length - 1 - i];
- }
- this._lastOffset = offset / n;
- offset = Math.abs(this._lastOffset);
- if (offset < 2) {
- this.event(Laya.Event.END);
- return;
- }
- if (offset > 250)
- this._lastOffset = this._lastOffset > 0 ? 250 : -250;
- var dis = Math.round(Math.abs(this.elasticDistance * (this._lastOffset / 150)));
- Laya.ILaya.timer.frameLoop(1, this, this.tweenMove, [dis]);
- }
- }
- elasticOver() {
- this._isElastic = false;
- if (!this.hide && this.autoHide) {
- Laya.Tween.to(this, { alpha: 0 }, 500);
- }
- this.event(Laya.Event.END);
- }
- tweenMove(maxDistance) {
- this._lastOffset *= this.rollRatio;
- if (this.checkTriggers(true)) {
- return;
- }
- var tarSpeed;
- if (maxDistance > 0) {
- if (this._lastOffset > 0 && this.value <= this.min) {
- this._isElastic = true;
- tarSpeed = -(this.min - maxDistance - this.value) * 0.5;
- if (this._lastOffset > tarSpeed)
- this._lastOffset = tarSpeed;
- }
- else if (this._lastOffset < 0 && this.value >= this.max) {
- this._isElastic = true;
- tarSpeed = -(this.max + maxDistance - this.value) * 0.5;
- if (this._lastOffset < tarSpeed)
- this._lastOffset = tarSpeed;
- }
- }
- this.value -= this._lastOffset;
- if (Math.abs(this._lastOffset) < 0.1) {
- Laya.ILaya.timer.clear(this, this.tweenMove);
- if (this._isElastic) {
- if (this._value < this.min) {
- Laya.Tween.to(this, { value: this.min }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
- }
- else if (this._value > this.max) {
- Laya.Tween.to(this, { value: this.max }, this.elasticBackTime, Laya.Ease.sineOut, Laya.Handler.create(this, this.elasticOver));
- }
- else {
- this.elasticOver();
- }
- return;
- }
- this.event(Laya.Event.END);
- if (!this.hide && this.autoHide) {
- Laya.Tween.to(this, { alpha: 0 }, 500);
- }
- }
- }
- stopScroll() {
- this.onStageMouseUp2(null);
- Laya.ILaya.timer.clear(this, this.tweenMove);
- Laya.Tween.clearTween(this);
- }
- get tick() {
- return this.slider.tick;
- }
- set tick(value) {
- this.slider.tick = value;
- }
- }
- Laya.ILaya.regClass(ScrollBar);
- Laya.ClassUtils.regClass("laya.ui.ScrollBar", ScrollBar);
- Laya.ClassUtils.regClass("Laya.ScrollBar", ScrollBar);
- class VScrollBar extends ScrollBar {
- }
- Laya.ILaya.regClass(VScrollBar);
- Laya.ClassUtils.regClass("laya.ui.VScrollBar", VScrollBar);
- Laya.ClassUtils.regClass("Laya.VScrollBar", VScrollBar);
- class HScrollBar extends ScrollBar {
- initialize() {
- super.initialize();
- this.slider.isVertical = false;
- }
- }
- Laya.ILaya.regClass(HScrollBar);
- Laya.ClassUtils.regClass("laya.ui.HScrollBar", HScrollBar);
- Laya.ClassUtils.regClass("Laya.HScrollBar", HScrollBar);
- class List extends Box {
- constructor() {
- super(...arguments);
- this.selectEnable = false;
- this.totalPage = 0;
- this._$componentType = "List";
- this._repeatX = 0;
- this._repeatY = 0;
- this._repeatX2 = 0;
- this._repeatY2 = 0;
- this._spaceX = 0;
- this._spaceY = 0;
- this._cells = [];
- this._startIndex = 0;
- this._selectedIndex = -1;
- this._page = 0;
- this._isVertical = true;
- this._cellSize = 20;
- this._cellOffset = 0;
- this._createdLine = 0;
- this._offset = new Laya.Point();
- this._usedCache = null;
- this._elasticEnabled = false;
- this._preLen = 0;
- }
- destroy(destroyChild = true) {
- this._content && this._content.destroy(destroyChild);
- this._scrollBar && this._scrollBar.destroy(destroyChild);
- super.destroy(destroyChild);
- this._content = null;
- this._scrollBar = null;
- this._itemRender = null;
- this._cells = null;
- this._array = null;
- this.selectHandler = this.renderHandler = this.mouseHandler = null;
- }
- createChildren() {
- this.addChild(this._content = new Box());
- }
- set cacheAs(value) {
- super.cacheAs = value;
- if (this._scrollBar) {
- this._usedCache = null;
- if (value !== "none")
- this._scrollBar.on(Laya.Event.START, this, this.onScrollStart);
- else
- this._scrollBar.off(Laya.Event.START, this, this.onScrollStart);
- }
- }
- get cacheAs() {
- return super.cacheAs;
- }
- onScrollStart() {
- this._usedCache || (this._usedCache = super.cacheAs);
- super.cacheAs = "none";
- this._scrollBar.once(Laya.Event.END, this, this.onScrollEnd);
- }
- onScrollEnd() {
- super.cacheAs = this._usedCache || 'none';
- }
- get content() {
- return this._content;
- }
- get vScrollBarSkin() {
- return this._scrollBar ? this._scrollBar.skin : null;
- }
- set vScrollBarSkin(value) {
- this._removePreScrollBar();
- var scrollBar = new VScrollBar();
- scrollBar.name = "scrollBar";
- scrollBar.right = 0;
- scrollBar.skin = value;
- scrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
- this.scrollBar = scrollBar;
- this.addChild(scrollBar);
- this._setCellChanged();
- }
- _removePreScrollBar() {
- var preNode = this.removeChildByName("scrollBar");
- if (preNode)
- preNode.destroy(true);
- }
- get hScrollBarSkin() {
- return this._scrollBar ? this._scrollBar.skin : null;
- }
- set hScrollBarSkin(value) {
- this._removePreScrollBar();
- var scrollBar = new HScrollBar();
- scrollBar.name = "scrollBar";
- scrollBar.bottom = 0;
- scrollBar.skin = value;
- scrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
- this.scrollBar = scrollBar;
- this.addChild(scrollBar);
- this._setCellChanged();
- }
- get scrollBar() {
- return this._scrollBar;
- }
- set scrollBar(value) {
- if (this._scrollBar != value) {
- this._scrollBar = value;
- if (value) {
- this._isVertical = this._scrollBar.isVertical;
- this.addChild(this._scrollBar);
- this._scrollBar.on(Laya.Event.CHANGE, this, this.onScrollBarChange);
- }
- }
- }
- get itemRender() {
- return this._itemRender;
- }
- set itemRender(value) {
- if (this._itemRender != value) {
- this._itemRender = value;
- for (var i = this._cells.length - 1; i > -1; i--) {
- this._cells[i].destroy();
- }
- this._cells.length = 0;
- this._setCellChanged();
- }
- }
- set width(value) {
- if (value != this._width) {
- super.width = value;
- this._setCellChanged();
- }
- }
- get width() {
- return super.width;
- }
- set height(value) {
- if (value != this._height) {
- super.height = value;
- this._setCellChanged();
- }
- }
- get height() {
- return super.height;
- }
- get repeatX() {
- return this._repeatX > 0 ? this._repeatX : this._repeatX2 > 0 ? this._repeatX2 : 1;
- }
- set repeatX(value) {
- this._repeatX = value;
- this._setCellChanged();
- }
- get repeatY() {
- return this._repeatY > 0 ? this._repeatY : this._repeatY2 > 0 ? this._repeatY2 : 1;
- }
- set repeatY(value) {
- this._repeatY = value;
- this._setCellChanged();
- }
- get spaceX() {
- return this._spaceX;
- }
- set spaceX(value) {
- this._spaceX = value;
- this._setCellChanged();
- }
- get spaceY() {
- return this._spaceY;
- }
- set spaceY(value) {
- this._spaceY = value;
- this._setCellChanged();
- }
- changeCells() {
- this._cellChanged = false;
- if (this._itemRender) {
- this.scrollBar = this.getChildByName("scrollBar");
- var cell = this._getOneCell();
- var cellWidth = (cell.width + this._spaceX) || 1;
- var cellHeight = (cell.height + this._spaceY) || 1;
- if (this._width > 0)
- this._repeatX2 = this._isVertical ? Math.round(this._width / cellWidth) : Math.ceil(this._width / cellWidth);
- if (this._height > 0)
- this._repeatY2 = this._isVertical ? Math.ceil(this._height / cellHeight) : Math.round(this._height / cellHeight);
- var listWidth = this._width ? this._width : (cellWidth * this.repeatX - this._spaceX);
- var listHeight = this._height ? this._height : (cellHeight * this.repeatY - this._spaceY);
- this._cellSize = this._isVertical ? cellHeight : cellWidth;
- this._cellOffset = this._isVertical ? (cellHeight * Math.max(this._repeatY2, this._repeatY) - listHeight - this._spaceY) : (cellWidth * Math.max(this._repeatX2, this._repeatX) - listWidth - this._spaceX);
- if (this._isVertical && this.vScrollBarSkin)
- this._scrollBar.height = listHeight;
- else if (!this._isVertical && this.hScrollBarSkin)
- this._scrollBar.width = listWidth;
- this.setContentSize(listWidth, listHeight);
- var numX = this._isVertical ? this.repeatX : this.repeatY;
- var numY = (this._isVertical ? this.repeatY : this.repeatX) + (this._scrollBar ? 1 : 0);
- this._createItems(0, numX, numY);
- this._createdLine = numY;
- if (this._array) {
- this.array = this._array;
- this.runCallLater(this.renderItems);
- }
- }
- }
- _getOneCell() {
- if (this._cells.length === 0) {
- var item = this.createItem();
- this._offset.setTo(item._x, item._y);
- if (this.cacheContent)
- return item;
- this._cells.push(item);
- }
- return this._cells[0];
- }
- _createItems(startY, numX, numY) {
- var box = this._content;
- var cell = this._getOneCell();
- var cellWidth = cell.width + this._spaceX;
- var cellHeight = cell.height + this._spaceY;
- if (this.cacheContent) {
- var cacheBox = new Box();
- cacheBox.cacheAs = "normal";
- cacheBox.pos((this._isVertical ? 0 : startY) * cellWidth, (this._isVertical ? startY : 0) * cellHeight);
- this._content.addChild(cacheBox);
- box = cacheBox;
- }
- else {
- var arr = [];
- for (var i = this._cells.length - 1; i > -1; i--) {
- var item = this._cells[i];
- item.removeSelf();
- arr.push(item);
- }
- this._cells.length = 0;
- }
- for (var k = startY; k < numY; k++) {
- for (var l = 0; l < numX; l++) {
- if (arr && arr.length) {
- cell = arr.pop();
- }
- else {
- cell = this.createItem();
- }
- cell.x = (this._isVertical ? l : k) * cellWidth - box._x;
- cell.y = (this._isVertical ? k : l) * cellHeight - box._y;
- cell.name = "item" + (k * numX + l);
- box.addChild(cell);
- this.addCell(cell);
- }
- }
- }
- createItem() {
- var arr = [];
- if (typeof (this._itemRender) == "function") {
- var box = new this._itemRender();
- }
- else {
- box = Laya.SceneUtils.createComp(this._itemRender, null, null, arr);
- }
- if (arr.length == 0 && box["_watchMap"]) {
- var watchMap = box["_watchMap"];
- for (var name in watchMap) {
- var a = watchMap[name];
- for (var i = 0; i < a.length; i++) {
- var watcher = a[i];
- arr.push(watcher.comp, watcher.prop, watcher.value);
- }
- }
- }
- if (arr.length)
- box["_$bindData"] = arr;
- return box;
- }
- addCell(cell) {
- cell.on(Laya.Event.CLICK, this, this.onCellMouse);
- cell.on(Laya.Event.RIGHT_CLICK, this, this.onCellMouse);
- cell.on(Laya.Event.MOUSE_OVER, this, this.onCellMouse);
- cell.on(Laya.Event.MOUSE_OUT, this, this.onCellMouse);
- cell.on(Laya.Event.MOUSE_DOWN, this, this.onCellMouse);
- cell.on(Laya.Event.MOUSE_UP, this, this.onCellMouse);
- this._cells.push(cell);
- }
- _afterInited() {
- this.initItems();
- }
- initItems() {
- if (!this._itemRender && this.getChildByName("item0") != null) {
- this.repeatX = 1;
- var count;
- count = 0;
- for (var i = 0; i < 10000; i++) {
- var cell = this.getChildByName("item" + i);
- if (cell) {
- this.addCell(cell);
- count++;
- continue;
- }
- break;
- }
- this.repeatY = count;
- }
- }
- setContentSize(width, height) {
- this._content.width = width;
- this._content.height = height;
- if (this._scrollBar || this._offset.x != 0 || this._offset.y != 0) {
- this._content._style.scrollRect || (this._content.scrollRect = Laya.Rectangle.create());
- this._content._style.scrollRect.setTo(-this._offset.x, -this._offset.y, width, height);
- this._content.scrollRect = this._content.scrollRect;
- }
- this.event(Laya.Event.RESIZE);
- }
- onCellMouse(e) {
- if (e.type === Laya.Event.MOUSE_DOWN)
- this._isMoved = false;
- var cell = e.currentTarget;
- var index = this._startIndex + this._cells.indexOf(cell);
- if (index < 0)
- return;
- if (e.type === Laya.Event.CLICK || e.type === Laya.Event.RIGHT_CLICK) {
- if (this.selectEnable && !this._isMoved)
- this.selectedIndex = index;
- else
- this.changeCellState(cell, true, 0);
- }
- else if ((e.type === Laya.Event.MOUSE_OVER || e.type === Laya.Event.MOUSE_OUT) && this._selectedIndex !== index) {
- this.changeCellState(cell, e.type === Laya.Event.MOUSE_OVER, 0);
- }
- this.mouseHandler && this.mouseHandler.runWith([e, index]);
- }
- changeCellState(cell, visible, index) {
- var selectBox = cell.getChildByName("selectBox");
- if (selectBox) {
- this.selectEnable = true;
- selectBox.visible = visible;
- selectBox.index = index;
- }
- }
- _sizeChanged() {
- super._sizeChanged();
- this.setContentSize(this.width, this.height);
- if (this._scrollBar)
- this.callLater(this.onScrollBarChange);
- }
- onScrollBarChange(e = null) {
- this.runCallLater(this.changeCells);
- var scrollValue = this._scrollBar.value;
- var lineX = (this._isVertical ? this.repeatX : this.repeatY);
- var lineY = (this._isVertical ? this.repeatY : this.repeatX);
- var scrollLine = Math.floor(scrollValue / this._cellSize);
- if (!this.cacheContent) {
- var index = scrollLine * lineX;
- var num = 0;
- let down = true;
- var toIndex = 0;
- if (index > this._startIndex) {
- num = index - this._startIndex;
- toIndex = this._startIndex + lineX * (lineY + 1);
- this._isMoved = true;
- }
- else if (index < this._startIndex) {
- num = this._startIndex - index;
- down = false;
- toIndex = this._startIndex - 1;
- this._isMoved = true;
- }
- for (var i = 0; i < num; i++) {
- if (down) {
- var cell = this._cells.shift();
- this._cells[this._cells.length] = cell;
- var cellIndex = toIndex + i;
- }
- else {
- cell = this._cells.pop();
- this._cells.unshift(cell);
- cellIndex = toIndex - i;
- }
- var pos = Math.floor(cellIndex / lineX) * this._cellSize;
- this._isVertical ? cell.y = pos : cell.x = pos;
- this.renderItem(cell, cellIndex);
- }
- this._startIndex = index;
- this.changeSelectStatus();
- }
- else {
- num = (lineY + 1);
- if (this._createdLine - scrollLine < num) {
- this._createItems(this._createdLine, lineX, this._createdLine + num);
- this.renderItems(this._createdLine * lineX, 0);
- this._createdLine += num;
- }
- }
- var r = this._content._style.scrollRect;
- if (this._isVertical) {
- r.y = scrollValue - this._offset.y;
- r.x = -this._offset.x;
- }
- else {
- r.y = -this._offset.y;
- r.x = scrollValue - this._offset.x;
- }
- this._content.scrollRect = r;
- }
- posCell(cell, cellIndex) {
- if (!this._scrollBar)
- return;
- var lineX = (this._isVertical ? this.repeatX : this.repeatY);
- var pos = Math.floor(cellIndex / lineX) * this._cellSize;
- this._isVertical ? cell._y = pos : cell.x = pos;
- }
- get selectedIndex() {
- return this._selectedIndex;
- }
- set selectedIndex(value) {
- if (this._selectedIndex != value) {
- this._selectedIndex = value;
- this.changeSelectStatus();
- this.event(Laya.Event.CHANGE);
- this.selectHandler && this.selectHandler.runWith(value);
- this.startIndex = this._startIndex;
- }
- }
- changeSelectStatus() {
- for (var i = 0, n = this._cells.length; i < n; i++) {
- this.changeCellState(this._cells[i], this._selectedIndex === this._startIndex + i, 1);
- }
- }
- get selectedItem() {
- if (!this._array)
- return null;
- return this._selectedIndex != -1 ? this._array[this._selectedIndex] : null;
- }
- set selectedItem(value) {
- this._array && (this.selectedIndex = this._array.indexOf(value));
- }
- get selection() {
- return this.getCell(this._selectedIndex);
- }
- set selection(value) {
- this.selectedIndex = this._startIndex + this._cells.indexOf(value);
- }
- get startIndex() {
- return this._startIndex;
- }
- set startIndex(value) {
- this._startIndex = value > 0 ? value : 0;
- this.callLater(this.renderItems);
- }
- renderItems(from = 0, to = 0) {
- for (var i = from, n = to || this._cells.length; i < n; i++) {
- this.renderItem(this._cells[i], this._startIndex + i);
- }
- this.changeSelectStatus();
- }
- renderItem(cell, index) {
- if (this._array && index >= 0 && index < this._array.length) {
- cell.visible = true;
- if (cell["_$bindData"]) {
- cell["_dataSource"] = this._array[index];
- this._bindData(cell, this._array[index]);
- }
- else
- cell.dataSource = this._array[index];
- if (!this.cacheContent) {
- this.posCell(cell, index);
- }
- if (this.hasListener(Laya.Event.RENDER))
- this.event(Laya.Event.RENDER, [cell, index]);
- if (this.renderHandler)
- this.renderHandler.runWith([cell, index]);
- }
- else {
- cell.visible = false;
- cell.dataSource = null;
- }
- }
- _bindData(cell, data) {
- var arr = cell._$bindData;
- for (var i = 0, n = arr.length; i < n; i++) {
- var ele = arr[i++];
- var prop = arr[i++];
- var value = arr[i];
- var fun = UIUtils.getBindFun(value);
- ele[prop] = fun.call(this, data);
- }
- }
- get array() {
- return this._array;
- }
- set array(value) {
- this.runCallLater(this.changeCells);
- this._array = value || [];
- this._preLen = this._array.length;
- var length = this._array.length;
- this.totalPage = Math.ceil(length / (this.repeatX * this.repeatY));
- this._selectedIndex = this._selectedIndex < length ? this._selectedIndex : length - 1;
- this.startIndex = this._startIndex;
- if (this._scrollBar) {
- this._scrollBar.stopScroll();
- var numX = this._isVertical ? this.repeatX : this.repeatY;
- var numY = this._isVertical ? this.repeatY : this.repeatX;
- var lineCount = Math.ceil(length / numX);
- var total = this._cellOffset > 0 ? this.totalPage + 1 : this.totalPage;
- if (total > 1 && lineCount >= numY) {
- this._scrollBar.scrollSize = this._cellSize;
- this._scrollBar.thumbPercent = numY / lineCount;
- this._scrollBar.setScroll(0, (lineCount - numY) * this._cellSize + this._cellOffset, this._scrollBar.value);
- this._scrollBar.target = this._content;
- }
- else {
- this._scrollBar.setScroll(0, 0, 0);
- this._scrollBar.target = this._content;
- }
- }
- }
- updateArray(array) {
- this._array = array;
- if (this._array) {
- let freshStart = this._preLen - this._startIndex;
- if (freshStart >= 0)
- this.renderItems(freshStart);
- this._preLen = this._array.length;
- }
- if (this._scrollBar) {
- var length = array.length;
- var numX = this._isVertical ? this.repeatX : this.repeatY;
- var numY = this._isVertical ? this.repeatY : this.repeatX;
- var lineCount = Math.ceil(length / numX);
- if (lineCount >= numY) {
- this._scrollBar.thumbPercent = numY / lineCount;
- this._scrollBar.slider["_max"] = (lineCount - numY) * this._cellSize + this._cellOffset;
- }
- }
- }
- get page() {
- return this._page;
- }
- set page(value) {
- this._page = value;
- if (this._array) {
- this._page = value > 0 ? value : 0;
- this._page = this._page < this.totalPage ? this._page : this.totalPage - 1;
- this.startIndex = this._page * this.repeatX * this.repeatY;
- }
- }
- get length() {
- return this._array ? this._array.length : 0;
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.selectedIndex = parseInt(value);
- else if (value instanceof Array)
- this.array = value;
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- get cells() {
- this.runCallLater(this.changeCells);
- return this._cells;
- }
- get elasticEnabled() {
- return this._elasticEnabled;
- }
- set elasticEnabled(value) {
- this._elasticEnabled = value;
- if (this._scrollBar) {
- this._scrollBar.elasticDistance = value ? 200 : 0;
- }
- }
- refresh() {
- this.array = this._array;
- }
- getItem(index) {
- if (!this._array)
- return null;
- if (index > -1 && index < this._array.length) {
- return this._array[index];
- }
- return null;
- }
- changeItem(index, source) {
- if (index > -1 && this._array && index < this._array.length) {
- this._array[index] = source;
- if (index >= this._startIndex && index < this._startIndex + this._cells.length) {
- this.renderItem(this.getCell(index), index);
- }
- }
- }
- setItem(index, source) {
- this.changeItem(index, source);
- }
- addItem(source) {
- if (!this.array) {
- this.array = [source];
- }
- else {
- this._array.push(source);
- }
- this.array = this._array;
- }
- addItemAt(souce, index) {
- this._array.splice(index, 0, souce);
- this.array = this._array;
- }
- deleteItem(index) {
- if (this._array) {
- this._array.splice(index, 1);
- this.array = this._array;
- }
- }
- getCell(index) {
- this.runCallLater(this.changeCells);
- if (index > -1 && this._cells) {
- return this._cells[(index - this._startIndex) % this._cells.length];
- }
- return null;
- }
- scrollTo(index) {
- if (this._scrollBar) {
- var numX = this._isVertical ? this.repeatX : this.repeatY;
- this._scrollBar.value = Math.floor(index / numX) * this._cellSize;
- }
- else {
- this.startIndex = index;
- }
- }
- tweenTo(index, time = 200, complete = null) {
- if (this._scrollBar) {
- this._scrollBar.stopScroll();
- var numX = this._isVertical ? this.repeatX : this.repeatY;
- Laya.Tween.to(this._scrollBar, { value: Math.floor(index / numX) * this._cellSize }, time, null, complete, 0, true);
- }
- else {
- this.startIndex = index;
- if (complete)
- complete.run();
- }
- }
- _setCellChanged() {
- if (!this._cellChanged) {
- this._cellChanged = true;
- this.callLater(this.changeCells);
- }
- }
- commitMeasure() {
- this.runCallLater(this.changeCells);
- }
- }
- Laya.ILaya.regClass(List);
- Laya.ClassUtils.regClass("laya.ui.List", List);
- Laya.ClassUtils.regClass("Laya.List", List);
- class ComboBox extends UIComponent {
- constructor(skin = null, labels = null) {
- super();
- this._visibleNum = 6;
- this._itemColors = Styles.comboBoxItemColors;
- this._itemSize = 12;
- this._labels = [];
- this._selectedIndex = -1;
- this.itemRender = null;
- this.skin = skin;
- this.labels = labels;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._button && this._button.destroy(destroyChild);
- this._list && this._list.destroy(destroyChild);
- this._button = null;
- this._list = null;
- this._itemColors = null;
- this._labels = null;
- this._selectHandler = null;
- }
- createChildren() {
- this.addChild(this._button = new Button());
- this._button.text.align = "left";
- this._button.labelPadding = "0,0,0,5";
- this._button.on(Laya.Event.MOUSE_DOWN, this, this.onButtonMouseDown);
- }
- _createList() {
- this._list = new List();
- if (this._scrollBarSkin)
- this._list.vScrollBarSkin = this._scrollBarSkin;
- this._setListEvent(this._list);
- }
- _setListEvent(list) {
- this._list.selectEnable = true;
- this._list.on(Laya.Event.MOUSE_DOWN, this, this.onListDown);
- this._list.mouseHandler = Laya.Handler.create(this, this.onlistItemMouse, null, false);
- if (this._list.scrollBar)
- this._list.scrollBar.on(Laya.Event.MOUSE_DOWN, this, this.onScrollBarDown);
- }
- onListDown(e) {
- e.stopPropagation();
- }
- onScrollBarDown(e) {
- e.stopPropagation();
- }
- onButtonMouseDown(e) {
- this.callLater(this.switchTo, [!this._isOpen]);
- }
- get skin() {
- return this._button.skin;
- }
- set skin(value) {
- if (this._button.skin != value) {
- this._button.skin = value;
- this._listChanged = true;
- }
- }
- measureWidth() {
- return this._button.width;
- }
- measureHeight() {
- return this._button.height;
- }
- changeList() {
- this._listChanged = false;
- var labelWidth = this.width - 2;
- var labelColor = this._itemColors[2];
- this._itemHeight = this._itemSize + 6;
- 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 } }] };
- this._list.repeatY = this._visibleNum;
- this._list.refresh();
- }
- onlistItemMouse(e, index) {
- var type = e.type;
- if (type === Laya.Event.MOUSE_OVER || type === Laya.Event.MOUSE_OUT) {
- if (this._isCustomList)
- return;
- var box = this._list.getCell(index);
- if (!box)
- return;
- var label = box.getChildByName("label");
- if (label) {
- if (type === Laya.Event.ROLL_OVER) {
- label.bgColor = this._itemColors[0];
- label.color = this._itemColors[1];
- }
- else {
- label.bgColor = null;
- label.color = this._itemColors[2];
- }
- }
- }
- else if (type === Laya.Event.CLICK) {
- this.selectedIndex = index;
- this.isOpen = false;
- }
- }
- switchTo(value) {
- this.isOpen = value;
- }
- changeOpen() {
- this.isOpen = !this._isOpen;
- }
- set width(value) {
- super.width = value;
- this._button.width = this._width;
- this._itemChanged = true;
- this._listChanged = true;
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._button.height = this._height;
- }
- get height() {
- return super.height;
- }
- get labels() {
- return this._labels.join(",");
- }
- set labels(value) {
- if (this._labels.length > 0)
- this.selectedIndex = -1;
- if (value)
- this._labels = value.split(",");
- else
- this._labels.length = 0;
- this._itemChanged = true;
- }
- changeItem() {
- this._itemChanged = false;
- this._listHeight = this._labels.length > 0 ? Math.min(this._visibleNum, this._labels.length) * this._itemHeight : this._itemHeight;
- if (!this._isCustomList) {
- var g = this._list.graphics;
- g.clear(true);
- g.drawRect(0, 0, this.width - 1, this._listHeight, this._itemColors[4], this._itemColors[3]);
- }
- var a = this._list.array || [];
- a.length = 0;
- for (var i = 0, n = this._labels.length; i < n; i++) {
- a.push({ label: this._labels[i] });
- }
- this._list.height = this._listHeight;
- this._list.array = a;
- }
- get selectedIndex() {
- return this._selectedIndex;
- }
- set selectedIndex(value) {
- if (this._selectedIndex != value) {
- this._selectedIndex = value;
- if (this._labels.length > 0)
- this.changeSelected();
- else
- this.callLater(this.changeSelected);
- this.event(Laya.Event.CHANGE, [Laya.Event.EMPTY.setTo(Laya.Event.CHANGE, this, this)]);
- this._selectHandler && this._selectHandler.runWith(this._selectedIndex);
- }
- }
- changeSelected() {
- this._button.label = this.selectedLabel;
- }
- get selectHandler() {
- return this._selectHandler;
- }
- set selectHandler(value) {
- this._selectHandler = value;
- }
- get selectedLabel() {
- return this._selectedIndex > -1 && this._selectedIndex < this._labels.length ? this._labels[this._selectedIndex] : null;
- }
- set selectedLabel(value) {
- this.selectedIndex = this._labels.indexOf(value);
- }
- get visibleNum() {
- return this._visibleNum;
- }
- set visibleNum(value) {
- this._visibleNum = value;
- this._listChanged = true;
- }
- get itemColors() {
- return String(this._itemColors);
- }
- set itemColors(value) {
- this._itemColors = UIUtils.fillArray(this._itemColors, value, String);
- this._listChanged = true;
- }
- get itemSize() {
- return this._itemSize;
- }
- set itemSize(value) {
- this._itemSize = value;
- this._listChanged = true;
- }
- get isOpen() {
- return this._isOpen;
- }
- set isOpen(value) {
- if (this._isOpen != value) {
- this._isOpen = value;
- this._button.selected = this._isOpen;
- if (this._isOpen) {
- this._list || this._createList();
- this._listChanged && !this._isCustomList && this.changeList();
- this._itemChanged && this.changeItem();
- var p = this.localToGlobal(Laya.Point.TEMP.setTo(0, 0));
- var py = p.y + this._button.height;
- py = py + this._listHeight <= Laya.ILaya.stage.height ? py : p.y - this._listHeight;
- this._list.pos(p.x, py);
- this._list.zOrder = 1001;
- Laya.ILaya.stage.addChild(this._list);
- Laya.ILaya.stage.once(Laya.Event.MOUSE_DOWN, this, this.removeList);
- Laya.ILaya.stage.on(Laya.Event.MOUSE_WHEEL, this, this._onStageMouseWheel);
- this._list.selectedIndex = this._selectedIndex;
- }
- else {
- this._list && this._list.removeSelf();
- }
- }
- }
- _onStageMouseWheel(e) {
- if (!this._list || this._list.contains(e.target))
- return;
- this.removeList(null);
- }
- removeList(e) {
- Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this.removeList);
- Laya.ILaya.stage.off(Laya.Event.MOUSE_WHEEL, this, this._onStageMouseWheel);
- this.isOpen = false;
- }
- get scrollBarSkin() {
- return this._scrollBarSkin;
- }
- set scrollBarSkin(value) {
- this._scrollBarSkin = value;
- }
- get sizeGrid() {
- return this._button.sizeGrid;
- }
- set sizeGrid(value) {
- this._button.sizeGrid = value;
- }
- get scrollBar() {
- return this.list.scrollBar;
- }
- get button() {
- return this._button;
- }
- get list() {
- this._list || this._createList();
- return this._list;
- }
- set list(value) {
- if (value) {
- value.removeSelf();
- this._isCustomList = true;
- this._list = value;
- this._setListEvent(value);
- this._itemHeight = value.getCell(0).height + value.spaceY;
- }
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.selectedIndex = parseInt(value);
- else if (value instanceof Array)
- this.labels = value.join(",");
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- get labelColors() {
- return this._button.labelColors;
- }
- set labelColors(value) {
- if (this._button.labelColors != value) {
- this._button.labelColors = value;
- }
- }
- get labelPadding() {
- return this._button.text.padding.join(",");
- }
- set labelPadding(value) {
- this._button.text.padding = UIUtils.fillArray(Styles.labelPadding, value, Number);
- }
- get labelSize() {
- return this._button.text.fontSize;
- }
- set labelSize(value) {
- this._button.text.fontSize = value;
- }
- get labelBold() {
- return this._button.text.bold;
- }
- set labelBold(value) {
- this._button.text.bold = value;
- }
- get labelFont() {
- return this._button.text.font;
- }
- set labelFont(value) {
- this._button.text.font = value;
- }
- get stateNum() {
- return this._button.stateNum;
- }
- set stateNum(value) {
- this._button.stateNum = value;
- }
- }
- Laya.ILaya.regClass(ComboBox);
- Laya.ClassUtils.regClass("laya.ui.ComboBox", ComboBox);
- Laya.ClassUtils.regClass("Laya.ComboBox", ComboBox);
- class ProgressBar extends UIComponent {
- constructor(skin = null) {
- super();
- this._value = 0.5;
- this.skin = skin;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._bg && this._bg.destroy(destroyChild);
- this._bar && this._bar.destroy(destroyChild);
- this._bg = this._bar = null;
- this.changeHandler = null;
- }
- createChildren() {
- this.addChild(this._bg = new Image());
- this.addChild(this._bar = new Image());
- this._bar._bitmap.autoCacheCmd = false;
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (this._skin != value) {
- this._skin = value;
- if (this._skin && !Laya.Loader.getRes(this._skin)) {
- Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
- }
- else {
- this._skinLoaded();
- }
- }
- }
- _skinLoaded() {
- this._bg.skin = this._skin;
- this._bar.skin = this._skin.replace(".png", "$bar.png");
- this.callLater(this.changeValue);
- this._sizeChanged();
- this.event(Laya.Event.LOADED);
- }
- measureWidth() {
- return this._bg.width;
- }
- measureHeight() {
- return this._bg.height;
- }
- get value() {
- return this._value;
- }
- set value(num) {
- if (this._value != num) {
- num = num > 1 ? 1 : num < 0 ? 0 : num;
- this._value = num;
- this.callLater(this.changeValue);
- this.event(Laya.Event.CHANGE);
- this.changeHandler && this.changeHandler.runWith(num);
- }
- }
- changeValue() {
- if (this.sizeGrid) {
- var grid = this.sizeGrid.split(",");
- var left = Number(grid[3]);
- var right = Number(grid[1]);
- var max = this.width - left - right;
- var sw = max * this._value;
- this._bar.width = left + right + sw;
- this._bar.visible = this._bar.width > left + right;
- }
- else {
- this._bar.width = this.width * this._value;
- }
- }
- get bar() {
- return this._bar;
- }
- get bg() {
- return this._bg;
- }
- get sizeGrid() {
- return this._bg.sizeGrid;
- }
- set sizeGrid(value) {
- this._bg.sizeGrid = this._bar.sizeGrid = value;
- }
- set width(value) {
- super.width = value;
- this._bg.width = this._width;
- this.callLater(this.changeValue);
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._bg.height = this._height;
- this._bar.height = this._height;
- }
- get height() {
- return super.height;
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.value = Number(value);
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- }
- Laya.ILaya.regClass(ProgressBar);
- Laya.ClassUtils.regClass("laya.ui.ProgressBar", ProgressBar);
- Laya.ClassUtils.regClass("Laya.ProgressBar", ProgressBar);
- class Radio extends Button {
- constructor(skin = null, label = "") {
- super(skin, label);
- this.toggle = false;
- this._autoSize = false;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._value = null;
- }
- preinitialize() {
- super.preinitialize();
- this.toggle = false;
- this._autoSize = false;
- }
- initialize() {
- super.initialize();
- this.createText();
- this._text.align = "left";
- this._text.valign = "top";
- this._text.width = 0;
- this.on(Laya.Event.CLICK, this, this.onClick);
- }
- onClick(e) {
- this.selected = true;
- }
- get value() {
- return this._value != null ? this._value : this.label;
- }
- set value(obj) {
- this._value = obj;
- }
- }
- Laya.ILaya.regClass(Radio);
- Laya.ClassUtils.regClass("laya.ui.Radio", Radio);
- Laya.ClassUtils.regClass("Laya.Radio", Radio);
- class UIGroup extends Box {
- constructor(labels = null, skin = null) {
- super();
- this._selectedIndex = -1;
- this._direction = "horizontal";
- this._space = 0;
- this.skin = skin;
- this.labels = labels;
- }
- preinitialize() {
- this.mouseEnabled = true;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._items && (this._items.length = 0);
- this._items = null;
- this.selectHandler = null;
- }
- addItem(item, autoLayOut = true) {
- var display = item;
- var index = this._items.length;
- display.name = "item" + index;
- this.addChild(display);
- this.initItems();
- if (autoLayOut && index > 0) {
- var preItem = this._items[index - 1];
- if (this._direction == "horizontal") {
- display.x = preItem._x + preItem.width + this._space;
- }
- else {
- display.y = preItem._y + preItem.height + this._space;
- }
- }
- else {
- if (autoLayOut) {
- display.x = 0;
- display.y = 0;
- }
- }
- return index;
- }
- delItem(item, autoLayOut = true) {
- var index = this._items.indexOf(item);
- if (index != -1) {
- var display = item;
- this.removeChild(display);
- for (var i = index + 1, n = this._items.length; i < n; i++) {
- var child = this._items[i];
- child.name = "item" + (i - 1);
- if (autoLayOut) {
- if (this._direction == "horizontal") {
- child.x -= display.width + this._space;
- }
- else {
- child.y -= display.height + this._space;
- }
- }
- }
- this.initItems();
- if (this._selectedIndex > -1) {
- var newIndex;
- newIndex = this._selectedIndex < this._items.length ? this._selectedIndex : (this._selectedIndex - 1);
- this._selectedIndex = -1;
- this.selectedIndex = newIndex;
- }
- }
- }
- _afterInited() {
- this.initItems();
- }
- initItems() {
- this._items || (this._items = []);
- this._items.length = 0;
- for (var i = 0; i < 10000; i++) {
- var item = this.getChildByName("item" + i);
- if (item == null)
- break;
- this._items.push(item);
- item.selected = (i === this._selectedIndex);
- item.clickHandler = Laya.Handler.create(this, this.itemClick, [i], false);
- }
- }
- itemClick(index) {
- this.selectedIndex = index;
- }
- get selectedIndex() {
- return this._selectedIndex;
- }
- set selectedIndex(value) {
- if (this._selectedIndex != value) {
- this.setSelect(this._selectedIndex, false);
- this._selectedIndex = value;
- this.setSelect(value, true);
- this.event(Laya.Event.CHANGE);
- this.selectHandler && this.selectHandler.runWith(this._selectedIndex);
- }
- }
- setSelect(index, selected) {
- if (this._items && index > -1 && index < this._items.length)
- this._items[index].selected = selected;
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (this._skin != value) {
- this._skin = value;
- if (this._skin && !Laya.Loader.getRes(this._skin)) {
- Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
- }
- else {
- this._skinLoaded();
- }
- }
- }
- _skinLoaded() {
- this._setLabelChanged();
- this.event(Laya.Event.LOADED);
- }
- get labels() {
- return this._labels;
- }
- set labels(value) {
- if (this._labels != value) {
- this._labels = value;
- this.removeChildren();
- this._setLabelChanged();
- if (this._labels) {
- var a = this._labels.split(",");
- for (var i = 0, n = a.length; i < n; i++) {
- var item = this.createItem(this._skin, a[i]);
- item.name = "item" + i;
- this.addChild(item);
- }
- }
- this.initItems();
- }
- }
- createItem(skin, label) {
- return null;
- }
- get labelColors() {
- return this._labelColors;
- }
- set labelColors(value) {
- if (this._labelColors != value) {
- this._labelColors = value;
- this._setLabelChanged();
- }
- }
- get labelStroke() {
- return this._labelStroke;
- }
- set labelStroke(value) {
- if (this._labelStroke != value) {
- this._labelStroke = value;
- this._setLabelChanged();
- }
- }
- get labelStrokeColor() {
- return this._labelStrokeColor;
- }
- set labelStrokeColor(value) {
- if (this._labelStrokeColor != value) {
- this._labelStrokeColor = value;
- this._setLabelChanged();
- }
- }
- get strokeColors() {
- return this._strokeColors;
- }
- set strokeColors(value) {
- if (this._strokeColors != value) {
- this._strokeColors = value;
- this._setLabelChanged();
- }
- }
- get labelSize() {
- return this._labelSize;
- }
- set labelSize(value) {
- if (this._labelSize != value) {
- this._labelSize = value;
- this._setLabelChanged();
- }
- }
- get stateNum() {
- return this._stateNum;
- }
- set stateNum(value) {
- if (this._stateNum != value) {
- this._stateNum = value;
- this._setLabelChanged();
- }
- }
- get labelBold() {
- return this._labelBold;
- }
- set labelBold(value) {
- if (this._labelBold != value) {
- this._labelBold = value;
- this._setLabelChanged();
- }
- }
- get labelFont() {
- return this._labelFont;
- }
- set labelFont(value) {
- if (this._labelFont != value) {
- this._labelFont = value;
- this._setLabelChanged();
- }
- }
- get labelPadding() {
- return this._labelPadding;
- }
- set labelPadding(value) {
- if (this._labelPadding != value) {
- this._labelPadding = value;
- this._setLabelChanged();
- }
- }
- get direction() {
- return this._direction;
- }
- set direction(value) {
- this._direction = value;
- this._setLabelChanged();
- }
- get space() {
- return this._space;
- }
- set space(value) {
- this._space = value;
- this._setLabelChanged();
- }
- changeLabels() {
- this._labelChanged = false;
- if (this._items) {
- var left = 0;
- for (var i = 0, n = this._items.length; i < n; i++) {
- var btn = this._items[i];
- this._skin && (btn.skin = this._skin);
- this._labelColors && (btn.labelColors = this._labelColors);
- this._labelSize && (btn.labelSize = this._labelSize);
- this._labelStroke && (btn.labelStroke = this._labelStroke);
- this._labelStrokeColor && (btn.labelStrokeColor = this._labelStrokeColor);
- this._strokeColors && (btn.strokeColors = this._strokeColors);
- this._labelBold && (btn.labelBold = this._labelBold);
- this._labelPadding && (btn.labelPadding = this._labelPadding);
- this._labelAlign && (btn.labelAlign = this._labelAlign);
- this._stateNum && (btn.stateNum = this._stateNum);
- this._labelFont && (btn.labelFont = this._labelFont);
- if (this._direction === "horizontal") {
- btn.y = 0;
- btn.x = left;
- left += btn.width + this._space;
- }
- else {
- btn.x = 0;
- btn.y = left;
- left += btn.height + this._space;
- }
- }
- }
- this._sizeChanged();
- }
- commitMeasure() {
- this.runCallLater(this.changeLabels);
- }
- get items() {
- return this._items;
- }
- get selection() {
- return this._selectedIndex > -1 && this._selectedIndex < this._items.length ? this._items[this._selectedIndex] : null;
- }
- set selection(value) {
- this.selectedIndex = this._items.indexOf(value);
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string')
- this.selectedIndex = parseInt(value);
- else if (value instanceof Array)
- this.labels = value.join(",");
- else
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- _setLabelChanged() {
- if (!this._labelChanged) {
- this._labelChanged = true;
- this.callLater(this.changeLabels);
- }
- }
- }
- Laya.ILaya.regClass(UIGroup);
- Laya.ClassUtils.regClass("laya.ui.UIGroup", UIGroup);
- Laya.ClassUtils.regClass("Laya.UIGroup", UIGroup);
- class RadioGroup extends UIGroup {
- createItem(skin, label) {
- return new Radio(skin, label);
- }
- }
- Laya.ILaya.regClass(RadioGroup);
- Laya.ClassUtils.regClass("laya.ui.RadioGroup", RadioGroup);
- Laya.ClassUtils.regClass("Laya.RadioGroup", RadioGroup);
- class Tab extends UIGroup {
- createItem(skin, label) {
- return new Button(skin, label);
- }
- }
- Laya.ILaya.regClass(Tab);
- Laya.ClassUtils.regClass("laya.ui.Tab", Tab);
- Laya.ClassUtils.regClass("Laya.Tab", Tab);
- class ViewStack extends Box {
- constructor() {
- super(...arguments);
- this._setIndexHandler = Laya.Handler.create(this, this.setIndex, null, false);
- }
- setItems(views) {
- this.removeChildren();
- var index = 0;
- for (var i = 0, n = views.length; i < n; i++) {
- var item = views[i];
- if (item) {
- item.name = "item" + index;
- this.addChild(item);
- index++;
- }
- }
- this.initItems();
- }
- addItem(view) {
- view.name = "item" + this._items.length;
- this.addChild(view);
- this.initItems();
- }
- _afterInited() {
- this.initItems();
- }
- initItems() {
- this._items = [];
- for (var i = 0; i < 10000; i++) {
- var item = this.getChildByName("item" + i);
- if (item == null) {
- break;
- }
- this._items.push(item);
- item.visible = (i == this._selectedIndex);
- }
- }
- get selectedIndex() {
- return this._selectedIndex;
- }
- set selectedIndex(value) {
- if (this._selectedIndex != value) {
- this.setSelect(this._selectedIndex, false);
- this._selectedIndex = value;
- this.setSelect(this._selectedIndex, true);
- }
- }
- setSelect(index, selected) {
- if (this._items && index > -1 && index < this._items.length) {
- this._items[index].visible = selected;
- }
- }
- get selection() {
- return this._selectedIndex > -1 && this._selectedIndex < this._items.length ? this._items[this._selectedIndex] : null;
- }
- set selection(value) {
- this.selectedIndex = this._items.indexOf(value);
- }
- get setIndexHandler() {
- return this._setIndexHandler;
- }
- set setIndexHandler(value) {
- this._setIndexHandler = value;
- }
- setIndex(index) {
- this.selectedIndex = index;
- }
- get items() {
- return this._items;
- }
- set dataSource(value) {
- this._dataSource = value;
- if (typeof (value) == 'number' || typeof (value) == 'string') {
- this.selectedIndex = parseInt(value);
- }
- else {
- for (var prop in this._dataSource) {
- if (prop in this) {
- this[prop] = this._dataSource[prop];
- }
- }
- }
- }
- get dataSource() {
- return super.dataSource;
- }
- }
- Laya.ILaya.regClass(ViewStack);
- Laya.ClassUtils.regClass("laya.ui.ViewStack", ViewStack);
- Laya.ClassUtils.regClass("Laya.ViewStack", ViewStack);
- class TextInput extends Label {
- constructor(text = "") {
- super();
- this.text = text;
- this.skin = this.skin;
- }
- preinitialize() {
- this.mouseEnabled = true;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._bg && this._bg.destroy();
- this._bg = null;
- }
- createChildren() {
- this.addChild(this._tf = new Laya.Input());
- this._tf.padding = Styles.inputLabelPadding;
- this._tf.on(Laya.Event.INPUT, this, this._onInput);
- this._tf.on(Laya.Event.ENTER, this, this._onEnter);
- this._tf.on(Laya.Event.BLUR, this, this._onBlur);
- this._tf.on(Laya.Event.FOCUS, this, this._onFocus);
- }
- _onFocus() {
- this.event(Laya.Event.FOCUS, this);
- }
- _onBlur() {
- this.event(Laya.Event.BLUR, this);
- }
- _onInput() {
- this.event(Laya.Event.INPUT, this);
- }
- _onEnter() {
- this.event(Laya.Event.ENTER, this);
- }
- initialize() {
- this.width = 128;
- this.height = 22;
- }
- get bg() {
- return this._bg;
- }
- set bg(value) {
- this.graphics = this._bg = value;
- }
- get skin() {
- return this._skin;
- }
- set skin(value) {
- if (this._skin != value) {
- this._skin = value;
- if (this._skin && !Laya.Loader.getRes(this._skin)) {
- Laya.ILaya.loader.load(this._skin, Laya.Handler.create(this, this._skinLoaded), null, Laya.Loader.IMAGE, 1);
- }
- else {
- this._skinLoaded();
- }
- }
- }
- _skinLoaded() {
- this._bg || (this.graphics = this._bg = new AutoBitmap());
- this._bg.source = Laya.Loader.getRes(this._skin);
- this._width && (this._bg.width = this._width);
- this._height && (this._bg.height = this._height);
- this._sizeChanged();
- this.event(Laya.Event.LOADED);
- }
- get sizeGrid() {
- return this._bg && this._bg.sizeGrid ? this._bg.sizeGrid.join(",") : null;
- }
- set sizeGrid(value) {
- this._bg || (this.graphics = this._bg = new AutoBitmap());
- this._bg.sizeGrid = UIUtils.fillArray(Styles.defaultSizeGrid, value, Number);
- }
- set text(value) {
- if (this._tf.text != value) {
- value = value + "";
- this._tf.text = value;
- this.event(Laya.Event.CHANGE);
- }
- }
- get text() {
- return super.text;
- }
- set width(value) {
- super.width = value;
- this._bg && (this._bg.width = value);
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._bg && (this._bg.height = value);
- }
- get height() {
- return super.height;
- }
- get multiline() {
- return this._tf.multiline;
- }
- set multiline(value) {
- this._tf.multiline = value;
- }
- set editable(value) {
- this._tf.editable = value;
- }
- get editable() {
- return this._tf.editable;
- }
- select() {
- this._tf.select();
- }
- get restrict() {
- return this._tf.restrict;
- }
- set restrict(pattern) {
- this._tf.restrict = pattern;
- }
- get prompt() {
- return this._tf.prompt;
- }
- set prompt(value) {
- this._tf.prompt = value;
- }
- get promptColor() {
- return this._tf.promptColor;
- }
- set promptColor(value) {
- this._tf.promptColor = value;
- }
- get maxChars() {
- return this._tf.maxChars;
- }
- set maxChars(value) {
- this._tf.maxChars = value;
- }
- get focus() {
- return this._tf.focus;
- }
- set focus(value) {
- this._tf.focus = value;
- }
- get type() {
- return this._tf.type;
- }
- set type(value) {
- this._tf.type = value;
- }
- setSelection(startIndex, endIndex) {
- this._tf.setSelection(startIndex, endIndex);
- }
- }
- Laya.ILaya.regClass(TextInput);
- Laya.ClassUtils.regClass("laya.ui.TextInput", TextInput);
- Laya.ClassUtils.regClass("Laya.TextInput", TextInput);
- class TextArea extends TextInput {
- constructor(text = "") {
- super(text);
- this.on(Laya.Event.CHANGE, this, this._onTextChange);
- }
- _onTextChange() {
- this.callLater(this.changeScroll);
- }
- destroy(destroyChild = true) {
- this._vScrollBar && this._vScrollBar.destroy();
- this._hScrollBar && this._hScrollBar.destroy();
- this._vScrollBar = null;
- this._hScrollBar = null;
- super.destroy(destroyChild);
- }
- initialize() {
- this.width = 180;
- this.height = 150;
- this._tf.wordWrap = true;
- this.multiline = true;
- }
- set width(value) {
- super.width = value;
- this.callLater(this.changeScroll);
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this.callLater(this.changeScroll);
- }
- get height() {
- return super.height;
- }
- get vScrollBarSkin() {
- return this._vScrollBar ? this._vScrollBar.skin : null;
- }
- set vScrollBarSkin(value) {
- if (this._vScrollBar == null) {
- this.addChild(this._vScrollBar = new VScrollBar());
- this._vScrollBar.on(Laya.Event.CHANGE, this, this.onVBarChanged);
- this._vScrollBar.target = this._tf;
- this.callLater(this.changeScroll);
- }
- this._vScrollBar.skin = value;
- }
- get hScrollBarSkin() {
- return this._hScrollBar ? this._hScrollBar.skin : null;
- }
- set hScrollBarSkin(value) {
- if (this._hScrollBar == null) {
- this.addChild(this._hScrollBar = new HScrollBar());
- this._hScrollBar.on(Laya.Event.CHANGE, this, this.onHBarChanged);
- this._hScrollBar.mouseWheelEnable = false;
- this._hScrollBar.target = this._tf;
- this.callLater(this.changeScroll);
- }
- this._hScrollBar.skin = value;
- }
- onVBarChanged(e) {
- if (this._tf.scrollY != this._vScrollBar.value) {
- this._tf.scrollY = this._vScrollBar.value;
- }
- }
- onHBarChanged(e) {
- if (this._tf.scrollX != this._hScrollBar.value) {
- this._tf.scrollX = this._hScrollBar.value;
- }
- }
- get vScrollBar() {
- return this._vScrollBar;
- }
- get hScrollBar() {
- return this._hScrollBar;
- }
- get maxScrollY() {
- return this._tf.maxScrollY;
- }
- get scrollY() {
- return this._tf.scrollY;
- }
- get maxScrollX() {
- return this._tf.maxScrollX;
- }
- get scrollX() {
- return this._tf.scrollX;
- }
- changeScroll() {
- var vShow = this._vScrollBar && this._tf.maxScrollY > 0;
- var hShow = this._hScrollBar && this._tf.maxScrollX > 0;
- var showWidth = vShow ? this._width - this._vScrollBar.width : this._width;
- var showHeight = hShow ? this._height - this._hScrollBar.height : this._height;
- var padding = this._tf.padding || Styles.labelPadding;
- this._tf.width = showWidth;
- this._tf.height = showHeight;
- if (this._vScrollBar) {
- this._vScrollBar.x = this._width - this._vScrollBar.width - padding[2];
- this._vScrollBar.y = padding[1];
- this._vScrollBar.height = this._height - (hShow ? this._hScrollBar.height : 0) - padding[1] - padding[3];
- this._vScrollBar.scrollSize = 1;
- this._vScrollBar.thumbPercent = showHeight / Math.max(this._tf.textHeight, showHeight);
- this._vScrollBar.setScroll(1, this._tf.maxScrollY, this._tf.scrollY);
- this._vScrollBar.visible = vShow;
- }
- if (this._hScrollBar) {
- this._hScrollBar.x = padding[0];
- this._hScrollBar.y = this._height - this._hScrollBar.height - padding[3];
- this._hScrollBar.width = this._width - (vShow ? this._vScrollBar.width : 0) - padding[0] - padding[2];
- this._hScrollBar.scrollSize = Math.max(showWidth * 0.033, 1);
- this._hScrollBar.thumbPercent = showWidth / Math.max(this._tf.textWidth, showWidth);
- this._hScrollBar.setScroll(0, this.maxScrollX, this.scrollX);
- this._hScrollBar.visible = hShow;
- }
- }
- scrollTo(y) {
- this.commitMeasure();
- this._tf.scrollY = y;
- }
- }
- Laya.ILaya.regClass(TextArea);
- Laya.ClassUtils.regClass("laya.ui.TextArea", TextArea);
- Laya.ClassUtils.regClass("Laya.TextArea", TextArea);
- class ScaleBox extends Box {
- constructor() {
- super(...arguments);
- this._oldW = 0;
- this._oldH = 0;
- }
- onEnable() {
- Laya.ILaya.stage.on("resize", this, this.onResize);
- this.onResize();
- }
- onDisable() {
- Laya.ILaya.stage.off("resize", this, this.onResize);
- }
- onResize() {
- let stage = Laya.ILaya.stage;
- if (this.width > 0 && this.height > 0) {
- var scale = Math.min(stage.width / this._oldW, stage.height / this._oldH);
- super.width = stage.width;
- super.height = stage.height;
- this.scale(scale, scale);
- }
- }
- set width(value) {
- super.width = value;
- this._oldW = value;
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._oldH = value;
- }
- get height() {
- return super.height;
- }
- }
- Laya.ILaya.regClass(ScaleBox);
- Laya.ClassUtils.regClass("laya.ui.ScaleBox", ScaleBox);
- Laya.ClassUtils.regClass("Laya.ScaleBox", ScaleBox);
- class HSlider extends Slider {
- constructor(skin = null) {
- super(skin);
- this.isVertical = false;
- }
- }
- Laya.ILaya.regClass(HSlider);
- Laya.ClassUtils.regClass("laya.ui.HSlider", HSlider);
- Laya.ClassUtils.regClass("Laya.HSlider", HSlider);
- class Panel extends Box {
- constructor() {
- super();
- this._usedCache = null;
- this._elasticEnabled = false;
- this.width = this.height = 100;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._content && this._content.destroy(destroyChild);
- this._vScrollBar && this._vScrollBar.destroy(destroyChild);
- this._hScrollBar && this._hScrollBar.destroy(destroyChild);
- this._vScrollBar = null;
- this._hScrollBar = null;
- this._content = null;
- }
- destroyChildren() {
- this._content.destroyChildren();
- }
- createChildren() {
- super.addChild(this._content = new Box());
- }
- addChild(child) {
- child.on(Laya.Event.RESIZE, this, this.onResize);
- this._setScrollChanged();
- return this._content.addChild(child);
- }
- onResize() {
- this._setScrollChanged();
- }
- addChildAt(child, index) {
- child.on(Laya.Event.RESIZE, this, this.onResize);
- this._setScrollChanged();
- return this._content.addChildAt(child, index);
- }
- removeChild(child) {
- child.off(Laya.Event.RESIZE, this, this.onResize);
- this._setScrollChanged();
- return this._content.removeChild(child);
- }
- removeChildAt(index) {
- this.getChildAt(index).off(Laya.Event.RESIZE, this, this.onResize);
- this._setScrollChanged();
- return this._content.removeChildAt(index);
- }
- removeChildren(beginIndex = 0, endIndex = 0x7fffffff) {
- this._content.removeChildren(beginIndex, endIndex);
- this._setScrollChanged();
- return this;
- }
- getChildAt(index) {
- return this._content.getChildAt(index);
- }
- getChildByName(name) {
- return this._content.getChildByName(name);
- }
- getChildIndex(child) {
- return this._content.getChildIndex(child);
- }
- get numChildren() {
- return this._content.numChildren;
- }
- changeScroll() {
- this._scrollChanged = false;
- var contentW = this.contentWidth || 1;
- var contentH = this.contentHeight || 1;
- var vscroll = this._vScrollBar;
- var hscroll = this._hScrollBar;
- var vShow = vscroll && contentH > this._height;
- var hShow = hscroll && contentW > this._width;
- var showWidth = vShow ? this._width - vscroll.width : this._width;
- var showHeight = hShow ? this._height - hscroll.height : this._height;
- if (vscroll) {
- vscroll.x = this._width - vscroll.width;
- vscroll.y = 0;
- vscroll.height = this._height - (hShow ? hscroll.height : 0);
- vscroll.scrollSize = Math.max(this._height * 0.033, 1);
- vscroll.thumbPercent = showHeight / contentH;
- vscroll.setScroll(0, contentH - showHeight, vscroll.value);
- }
- if (hscroll) {
- hscroll.x = 0;
- hscroll.y = this._height - hscroll.height;
- hscroll.width = this._width - (vShow ? vscroll.width : 0);
- hscroll.scrollSize = Math.max(this._width * 0.033, 1);
- hscroll.thumbPercent = showWidth / contentW;
- hscroll.setScroll(0, contentW - showWidth, hscroll.value);
- }
- }
- _sizeChanged() {
- super._sizeChanged();
- this.setContentSize(this._width, this._height);
- }
- get contentWidth() {
- var max = 0;
- for (var i = this._content.numChildren - 1; i > -1; i--) {
- var comp = this._content.getChildAt(i);
- max = Math.max(comp._x + comp.width * comp.scaleX - comp.pivotX, max);
- }
- return max;
- }
- get contentHeight() {
- var max = 0;
- for (var i = this._content.numChildren - 1; i > -1; i--) {
- var comp = this._content.getChildAt(i);
- max = Math.max(comp._y + comp.height * comp.scaleY - comp.pivotY, max);
- }
- return max;
- }
- setContentSize(width, height) {
- var content = this._content;
- content.width = width;
- content.height = height;
- content._style.scrollRect || (content.scrollRect = Laya.Rectangle.create());
- content._style.scrollRect.setTo(0, 0, width, height);
- content.scrollRect = content.scrollRect;
- }
- set width(value) {
- super.width = value;
- this._setScrollChanged();
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._setScrollChanged();
- }
- get height() {
- return super.height;
- }
- get vScrollBarSkin() {
- return this._vScrollBar ? this._vScrollBar.skin : null;
- }
- set vScrollBarSkin(value) {
- if (this._vScrollBar == null) {
- super.addChild(this._vScrollBar = new VScrollBar());
- this._vScrollBar.on(Laya.Event.CHANGE, this, this.onScrollBarChange, [this._vScrollBar]);
- this._vScrollBar.target = this._content;
- this._vScrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
- this._setScrollChanged();
- }
- this._vScrollBar.skin = value;
- }
- get hScrollBarSkin() {
- return this._hScrollBar ? this._hScrollBar.skin : null;
- }
- set hScrollBarSkin(value) {
- if (this._hScrollBar == null) {
- super.addChild(this._hScrollBar = new HScrollBar());
- this._hScrollBar.on(Laya.Event.CHANGE, this, this.onScrollBarChange, [this._hScrollBar]);
- this._hScrollBar.target = this._content;
- this._hScrollBar.elasticDistance = this._elasticEnabled ? 200 : 0;
- this._setScrollChanged();
- }
- this._hScrollBar.skin = value;
- }
- get vScrollBar() {
- return this._vScrollBar;
- }
- get hScrollBar() {
- return this._hScrollBar;
- }
- get content() {
- return this._content;
- }
- onScrollBarChange(scrollBar) {
- var rect = this._content._style.scrollRect;
- if (rect) {
- var start = Math.round(scrollBar.value);
- scrollBar.isVertical ? rect.y = start : rect.x = start;
- this._content.scrollRect = rect;
- }
- }
- scrollTo(x = 0, y = 0) {
- if (this.vScrollBar)
- this.vScrollBar.value = y;
- if (this.hScrollBar)
- this.hScrollBar.value = x;
- }
- refresh() {
- this.changeScroll();
- }
- set cacheAs(value) {
- super.cacheAs = value;
- this._usedCache = null;
- if (value !== "none") {
- this._hScrollBar && this._hScrollBar.on(Laya.Event.START, this, this.onScrollStart);
- this._vScrollBar && this._vScrollBar.on(Laya.Event.START, this, this.onScrollStart);
- }
- else {
- this._hScrollBar && this._hScrollBar.off(Laya.Event.START, this, this.onScrollStart);
- this._vScrollBar && this._vScrollBar.off(Laya.Event.START, this, this.onScrollStart);
- }
- }
- get cacheAs() {
- return super.cacheAs;
- }
- get elasticEnabled() {
- return this._elasticEnabled;
- }
- set elasticEnabled(value) {
- this._elasticEnabled = value;
- if (this._vScrollBar) {
- this._vScrollBar.elasticDistance = value ? 200 : 0;
- }
- if (this._hScrollBar) {
- this._hScrollBar.elasticDistance = value ? 200 : 0;
- }
- }
- onScrollStart() {
- this._usedCache || (this._usedCache = super.cacheAs);
- super.cacheAs = "none";
- this._hScrollBar && this._hScrollBar.once(Laya.Event.END, this, this.onScrollEnd);
- this._vScrollBar && this._vScrollBar.once(Laya.Event.END, this, this.onScrollEnd);
- }
- onScrollEnd() {
- super.cacheAs = this._usedCache;
- }
- _setScrollChanged() {
- if (!this._scrollChanged) {
- this._scrollChanged = true;
- this.callLater(this.changeScroll);
- }
- }
- }
- Laya.ILaya.regClass(Panel);
- Laya.ClassUtils.regClass("laya.ui.Panel", Panel);
- Laya.ClassUtils.regClass("Laya.Panel", Panel);
- class VSlider extends Slider {
- }
- Laya.ILaya.regClass(VSlider);
- Laya.ClassUtils.regClass("laya.ui.VSlider", VSlider);
- Laya.ClassUtils.regClass("Laya.VSlider", VSlider);
- class Tree extends Box {
- constructor() {
- super();
- this._spaceLeft = 10;
- this._spaceBottom = 0;
- this._keepStatus = true;
- this.width = this.height = 200;
- }
- destroy(destroyChild = true) {
- super.destroy(destroyChild);
- this._list && this._list.destroy(destroyChild);
- this._list = null;
- this._source = null;
- this._renderHandler = null;
- }
- createChildren() {
- this.addChild(this._list = new List());
- this._list.renderHandler = Laya.Handler.create(this, this.renderItem, null, false);
- this._list.repeatX = 1;
- this._list.on(Laya.Event.CHANGE, this, this.onListChange);
- }
- onListChange(e = null) {
- this.event(Laya.Event.CHANGE);
- }
- get keepStatus() {
- return this._keepStatus;
- }
- set keepStatus(value) {
- this._keepStatus = value;
- }
- get array() {
- return this._list.array;
- }
- set array(value) {
- if (this._keepStatus && this._list.array && value) {
- this.parseOpenStatus(this._list.array, value);
- }
- this._source = value;
- this._list.array = this.getArray();
- }
- get source() {
- return this._source;
- }
- get list() {
- return this._list;
- }
- get itemRender() {
- return this._list.itemRender;
- }
- set itemRender(value) {
- this._list.itemRender = value;
- }
- get scrollBarSkin() {
- return this._list.vScrollBarSkin;
- }
- set scrollBarSkin(value) {
- this._list.vScrollBarSkin = value;
- }
- get scrollBar() {
- return this._list.scrollBar;
- }
- get mouseHandler() {
- return this._list.mouseHandler;
- }
- set mouseHandler(value) {
- this._list.mouseHandler = value;
- }
- get renderHandler() {
- return this._renderHandler;
- }
- set renderHandler(value) {
- this._renderHandler = value;
- }
- get spaceLeft() {
- return this._spaceLeft;
- }
- set spaceLeft(value) {
- this._spaceLeft = value;
- }
- get spaceBottom() {
- return this._list.spaceY;
- }
- set spaceBottom(value) {
- this._list.spaceY = value;
- }
- get selectedIndex() {
- return this._list.selectedIndex;
- }
- set selectedIndex(value) {
- this._list.selectedIndex = value;
- }
- get selectedItem() {
- return this._list.selectedItem;
- }
- set selectedItem(value) {
- this._list.selectedItem = value;
- }
- set width(value) {
- super.width = value;
- this._list.width = value;
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this._list.height = value;
- }
- get height() {
- return super.height;
- }
- getArray() {
- var arr = [];
- for (let key in this._source) {
- let item = this._source[key];
- if (this.getParentOpenStatus(item)) {
- item.x = this._spaceLeft * this.getDepth(item);
- arr.push(item);
- }
- }
- return arr;
- }
- getDepth(item, num = 0) {
- if (item.nodeParent == null)
- return num;
- else
- return this.getDepth(item.nodeParent, num + 1);
- }
- getParentOpenStatus(item) {
- var parent = item.nodeParent;
- if (parent == null) {
- return true;
- }
- else {
- if (parent.isOpen) {
- if (parent.nodeParent != null)
- return this.getParentOpenStatus(parent);
- else
- return true;
- }
- else {
- return false;
- }
- }
- }
- renderItem(cell, index) {
- var item = cell.dataSource;
- if (item) {
- cell.left = item.x;
- var arrow = cell.getChildByName("arrow");
- if (arrow) {
- if (item.hasChild) {
- arrow.visible = true;
- arrow.index = item.isOpen ? 1 : 0;
- arrow.tag = index;
- arrow.off(Laya.Event.CLICK, this, this.onArrowClick);
- arrow.on(Laya.Event.CLICK, this, this.onArrowClick);
- }
- else {
- arrow.visible = false;
- }
- }
- var folder = cell.getChildByName("folder");
- if (folder) {
- if (folder.clipY == 2) {
- folder.index = item.isDirectory ? 0 : 1;
- }
- else {
- folder.index = item.isDirectory ? item.isOpen ? 1 : 0 : 2;
- }
- }
- this._renderHandler && this._renderHandler.runWith([cell, index]);
- }
- }
- onArrowClick(e) {
- var arrow = e.currentTarget;
- var index = arrow.tag;
- this._list.array[index].isOpen = !this._list.array[index].isOpen;
- this.event(Laya.Event.OPEN);
- this._list.array = this.getArray();
- }
- setItemState(index, isOpen) {
- if (!this._list.array[index])
- return;
- this._list.array[index].isOpen = isOpen;
- this._list.array = this.getArray();
- }
- fresh() {
- this._list.array = this.getArray();
- this.repaint();
- }
- set dataSource(value) {
- this._dataSource = value;
- super.dataSource = value;
- }
- get dataSource() {
- return super.dataSource;
- }
- set xml(value) {
- var arr = [];
- this.parseXml(value.childNodes[0], arr, null, true);
- this.array = arr;
- }
- parseXml(xml, source, nodeParent, isRoot) {
- var obj;
- var list = xml.childNodes;
- var childCount = list.length;
- if (!isRoot) {
- obj = {};
- var list2 = xml.attributes;
- for (let key in list2) {
- var attrs = list2[key];
- var prop = attrs.nodeName;
- var value = attrs.nodeValue;
- obj[prop] = value == "true" ? true : value == "false" ? false : value;
- }
- obj.nodeParent = nodeParent;
- if (childCount > 0)
- obj.isDirectory = true;
- obj.hasChild = childCount > 0;
- source.push(obj);
- }
- for (var i = 0; i < childCount; i++) {
- var node = list[i];
- this.parseXml(node, source, obj, false);
- }
- }
- parseOpenStatus(oldSource, newSource) {
- for (var i = 0, n = newSource.length; i < n; i++) {
- var newItem = newSource[i];
- if (newItem.isDirectory) {
- for (var j = 0, m = oldSource.length; j < m; j++) {
- var oldItem = oldSource[j];
- if (oldItem.isDirectory && this.isSameParent(oldItem, newItem) && newItem.label == oldItem.label) {
- newItem.isOpen = oldItem.isOpen;
- break;
- }
- }
- }
- }
- }
- isSameParent(item1, item2) {
- if (item1.nodeParent == null && item2.nodeParent == null)
- return true;
- else if (item1.nodeParent == null || item2.nodeParent == null)
- return false;
- else {
- if (item1.nodeParent.label == item2.nodeParent.label)
- return this.isSameParent(item1.nodeParent, item2.nodeParent);
- else
- return false;
- }
- }
- get selectedPath() {
- if (this._list.selectedItem) {
- return this._list.selectedItem.path;
- }
- return null;
- }
- filter(key) {
- if (Boolean(key)) {
- var result = [];
- this.getFilterSource(this._source, result, key);
- this._list.array = result;
- }
- else {
- this._list.array = this.getArray();
- }
- }
- getFilterSource(array, result, key) {
- key = key.toLocaleLowerCase();
- for (let item of array) {
- if (!item.isDirectory && String(item.label).toLowerCase().indexOf(key) > -1) {
- item.x = 0;
- result.push(item);
- }
- if (item.child && item.child.length > 0) {
- this.getFilterSource(item.child, result, key);
- }
- }
- }
- }
- Laya.ILaya.regClass(Tree);
- Laya.ClassUtils.regClass("laya.ui.Tree", Tree);
- Laya.ClassUtils.regClass("Laya.Tree", Tree);
- class LayoutBox extends Box {
- constructor() {
- super(...arguments);
- this._space = 0;
- this._align = "none";
- this._itemChanged = false;
- }
- addChild(child) {
- child.on(Laya.Event.RESIZE, this, this.onResize);
- this._setItemChanged();
- return super.addChild(child);
- }
- onResize(e) {
- this._setItemChanged();
- }
- addChildAt(child, index) {
- child.on(Laya.Event.RESIZE, this, this.onResize);
- this._setItemChanged();
- return super.addChildAt(child, index);
- }
- removeChildAt(index) {
- this.getChildAt(index).off(Laya.Event.RESIZE, this, this.onResize);
- this._setItemChanged();
- return super.removeChildAt(index);
- }
- refresh() {
- this._setItemChanged();
- }
- changeItems() {
- this._itemChanged = false;
- }
- get space() {
- return this._space;
- }
- set space(value) {
- this._space = value;
- this._setItemChanged();
- }
- get align() {
- return this._align;
- }
- set align(value) {
- this._align = value;
- this._setItemChanged();
- }
- sortItem(items) {
- if (items)
- items.sort(function (a, b) { return a.y - b.y; });
- }
- _setItemChanged() {
- if (!this._itemChanged) {
- this._itemChanged = true;
- this.callLater(this.changeItems);
- }
- }
- }
- Laya.ILaya.regClass(LayoutBox);
- Laya.ClassUtils.regClass("laya.ui.LayoutBox", LayoutBox);
- Laya.ClassUtils.regClass("Laya.LayoutBox", LayoutBox);
- class HBox extends LayoutBox {
- sortItem(items) {
- if (items)
- items.sort(function (a, b) { return a.x - b.x; });
- }
- set height(value) {
- if (this._height != value) {
- super.height = value;
- this.callLater(this.changeItems);
- }
- }
- get height() {
- return super.height;
- }
- changeItems() {
- this._itemChanged = false;
- var items = [];
- var maxHeight = 0;
- for (var i = 0, n = this.numChildren; i < n; i++) {
- var item = this.getChildAt(i);
- if (item) {
- items.push(item);
- maxHeight = this._height ? this._height : Math.max(maxHeight, item.height * item.scaleY);
- }
- }
- this.sortItem(items);
- var left = 0;
- for (i = 0, n = items.length; i < n; i++) {
- item = items[i];
- item.x = left;
- left += item.width * item.scaleX + this._space;
- if (this._align == HBox.TOP) {
- item.y = 0;
- }
- else if (this._align == HBox.MIDDLE) {
- item.y = (maxHeight - item.height * item.scaleY) * 0.5;
- }
- else if (this._align == HBox.BOTTOM) {
- item.y = maxHeight - item.height * item.scaleY;
- }
- }
- this._sizeChanged();
- }
- }
- HBox.NONE = "none";
- HBox.TOP = "top";
- HBox.MIDDLE = "middle";
- HBox.BOTTOM = "bottom";
- Laya.ILaya.regClass(HBox);
- Laya.ClassUtils.regClass("laya.ui.HBox", HBox);
- Laya.ClassUtils.regClass("Laya.HBox", HBox);
- class VBox extends LayoutBox {
- set width(value) {
- if (this._width != value) {
- super.width = value;
- this.callLater(this.changeItems);
- }
- }
- get width() {
- return super.width;
- }
- changeItems() {
- this._itemChanged = false;
- var items = [];
- var maxWidth = 0;
- for (var i = 0, n = this.numChildren; i < n; i++) {
- var item = this.getChildAt(i);
- if (item) {
- items.push(item);
- maxWidth = this._width ? this._width : Math.max(maxWidth, item.width * item.scaleX);
- }
- }
- this.sortItem(items);
- var top = 0;
- for (i = 0, n = items.length; i < n; i++) {
- item = items[i];
- item.y = top;
- top += item.height * item.scaleY + this._space;
- if (this._align == VBox.LEFT) {
- item.x = 0;
- }
- else if (this._align == VBox.CENTER) {
- item.x = (maxWidth - item.width * item.scaleX) * 0.5;
- }
- else if (this._align == VBox.RIGHT) {
- item.x = maxWidth - item.width * item.scaleX;
- }
- }
- this._sizeChanged();
- }
- }
- VBox.NONE = "none";
- VBox.LEFT = "left";
- VBox.CENTER = "center";
- VBox.RIGHT = "right";
- Laya.ILaya.regClass(VBox);
- Laya.ClassUtils.regClass("laya.ui.VBox", VBox);
- Laya.ClassUtils.regClass("Laya.VBox", VBox);
- class FontClip extends Clip {
- constructor(skin = null, sheet = null) {
- super();
- this._valueArr = '';
- this._indexMap = null;
- this._sheet = null;
- this._direction = "horizontal";
- this._spaceX = 0;
- this._spaceY = 0;
- this._align = "left";
- this._wordsW = 0;
- this._wordsH = 0;
- if (skin)
- this.skin = skin;
- if (sheet)
- this.sheet = sheet;
- }
- createChildren() {
- this._bitmap = new AutoBitmap();
- this.on(Laya.Event.LOADED, this, this._onClipLoaded);
- }
- _onClipLoaded() {
- this.callLater(this.changeValue);
- }
- get sheet() {
- return this._sheet;
- }
- set sheet(value) {
- value += "";
- this._sheet = value;
- var arr = value.split(" ");
- this._clipX = String(arr[0]).length;
- this.clipY = arr.length;
- this._indexMap = {};
- for (var i = 0; i < this._clipY; i++) {
- var line = arr[i].split("");
- for (var j = 0, n = line.length; j < n; j++) {
- this._indexMap[line[j]] = i * this._clipX + j;
- }
- }
- }
- get value() {
- if (!this._valueArr)
- return "";
- return this._valueArr;
- }
- set value(value) {
- value += "";
- this._valueArr = value;
- this.callLater(this.changeValue);
- }
- get direction() {
- return this._direction;
- }
- set direction(value) {
- this._direction = value;
- this.callLater(this.changeValue);
- }
- get spaceX() {
- return this._spaceX;
- }
- set spaceX(value) {
- this._spaceX = value;
- if (this._direction === "horizontal")
- this.callLater(this.changeValue);
- }
- get spaceY() {
- return this._spaceY;
- }
- set spaceY(value) {
- this._spaceY = value;
- if (!(this._direction === "horizontal"))
- this.callLater(this.changeValue);
- }
- set align(v) {
- this._align = v;
- this.callLater(this.changeValue);
- }
- get align() {
- return this._align;
- }
- changeValue() {
- if (!this._sources)
- return;
- if (!this._valueArr)
- return;
- this.graphics.clear(true);
- var texture;
- texture = this._sources[0];
- if (!texture)
- return;
- var isHorizontal = (this._direction === "horizontal");
- if (isHorizontal) {
- this._wordsW = this._valueArr.length * (texture.sourceWidth + this.spaceX);
- this._wordsH = texture.sourceHeight;
- }
- else {
- this._wordsW = texture.sourceWidth;
- this._wordsH = (texture.sourceHeight + this.spaceY) * this._valueArr.length;
- }
- var dX = 0;
- if (this._width) {
- switch (this._align) {
- case "center":
- dX = 0.5 * (this._width - this._wordsW);
- break;
- case "right":
- dX = this._width - this._wordsW;
- break;
- default:
- dX = 0;
- }
- }
- for (var i = 0, sz = this._valueArr.length; i < sz; i++) {
- var index = this._indexMap[this._valueArr.charAt(i)];
- if (!this.sources[index])
- continue;
- texture = this.sources[index];
- if (isHorizontal)
- this.graphics.drawImage(texture, dX + i * (texture.sourceWidth + this.spaceX), 0, texture.sourceWidth, texture.sourceHeight);
- else
- this.graphics.drawImage(texture, 0 + dX, i * (texture.sourceHeight + this.spaceY), texture.sourceWidth, texture.sourceHeight);
- }
- if (!this._width) {
- this._widget.resetLayoutX();
- this.callLater(this._sizeChanged);
- }
- if (!this._height) {
- this._widget.resetLayoutY();
- this.callLater(this._sizeChanged);
- }
- }
- set width(value) {
- super.width = value;
- this.callLater(this.changeValue);
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- this.callLater(this.changeValue);
- }
- get height() {
- return super.height;
- }
- measureWidth() {
- return this._wordsW;
- }
- measureHeight() {
- return this._wordsH;
- }
- destroy(destroyChild = true) {
- this._valueArr = null;
- this._indexMap = null;
- this.graphics.clear(true);
- this.removeSelf();
- this.off(Laya.Event.LOADED, this, this._onClipLoaded);
- super.destroy(destroyChild);
- }
- }
- Laya.ILaya.regClass(FontClip);
- Laya.ClassUtils.regClass("laya.ui.FontClip", FontClip);
- Laya.ClassUtils.regClass("Laya.FontClip", FontClip);
- class View extends Laya.Scene {
- constructor() {
- super(false);
- this._watchMap = {};
- this._anchorX = NaN;
- this._anchorY = NaN;
- this._widget = Widget.EMPTY;
- this.createChildren();
- }
- static __init__() {
- Laya.ILaya.ClassUtils.regShortClassName([ViewStack, Button, TextArea, ColorPicker, Box, ScaleBox, CheckBox, Clip, ComboBox, UIComponent,
- HScrollBar, HSlider, Image, Label, List, Panel, ProgressBar, Radio, RadioGroup, ScrollBar, Slider, Tab, TextInput, View,
- VScrollBar, VSlider, Tree, HBox, VBox, Laya.Animation, Laya.Text, FontClip]);
- }
- static regComponent(key, compClass) {
- Laya.ILaya.ClassUtils.regClass(key, compClass);
- }
- static regViewRuntime(key, compClass) {
- Laya.ILaya.ClassUtils.regClass(key, compClass);
- }
- static regUI(url, json) {
- Laya.ILaya.loader.cacheRes(url, json);
- }
- destroy(destroyChild = true) {
- this._watchMap = null;
- super.destroy(destroyChild);
- }
- changeData(key) {
- var arr = this._watchMap[key];
- if (!arr)
- return;
- for (var i = 0, n = arr.length; i < n; i++) {
- var watcher = arr[i];
- watcher.exe(this);
- }
- }
- get top() {
- return this._widget.top;
- }
- set top(value) {
- if (value != this._widget.top) {
- this._getWidget().top = value;
- }
- }
- get bottom() {
- return this._widget.bottom;
- }
- set bottom(value) {
- if (value != this._widget.bottom) {
- this._getWidget().bottom = value;
- }
- }
- get left() {
- return this._widget.left;
- }
- set left(value) {
- if (value != this._widget.left) {
- this._getWidget().left = value;
- }
- }
- get right() {
- return this._widget.right;
- }
- set right(value) {
- if (value != this._widget.right) {
- this._getWidget().right = value;
- }
- }
- get centerX() {
- return this._widget.centerX;
- }
- set centerX(value) {
- if (value != this._widget.centerX) {
- this._getWidget().centerX = value;
- }
- }
- get centerY() {
- return this._widget.centerY;
- }
- set centerY(value) {
- if (value != this._widget.centerY) {
- this._getWidget().centerY = value;
- }
- }
- get anchorX() {
- return this._anchorX;
- }
- set anchorX(value) {
- if (this._anchorX != value) {
- this._anchorX = value;
- this.callLater(this._sizeChanged);
- }
- }
- get anchorY() {
- return this._anchorY;
- }
- set anchorY(value) {
- if (this._anchorY != value) {
- this._anchorY = value;
- this.callLater(this._sizeChanged);
- }
- }
- _sizeChanged() {
- if (!isNaN(this._anchorX))
- this.pivotX = this.anchorX * this.width;
- if (!isNaN(this._anchorY))
- this.pivotY = this.anchorY * this.height;
- this.event(Laya.Event.RESIZE);
- }
- _getWidget() {
- this._widget === Widget.EMPTY && (this._widget = this.addComponent(Widget));
- return this._widget;
- }
- loadUI(path) {
- var uiView = View.uiMap[path];
- View.uiMap && this.createView(uiView);
- }
- get dataSource() {
- return this._dataSource;
- }
- set dataSource(value) {
- this._dataSource = value;
- for (var name in value) {
- var comp = this.getChildByName(name);
- if (comp instanceof UIComponent)
- comp.dataSource = value[name];
- else if (name in this && !(this[name] instanceof Function))
- this[name] = value[name];
- }
- }
- }
- View.uiMap = {};
- Laya.ILaya.regClass(View);
- Laya.ClassUtils.regClass("laya.ui.View", View);
- Laya.ClassUtils.regClass("Laya.View", View);
- class IUI {
- }
- class DialogManager extends Laya.Sprite {
- constructor() {
- super();
- this.maskLayer = new Laya.Sprite();
- this.popupEffect = (dialog) => {
- dialog.scale(1, 1);
- 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);
- };
- this.closeEffect = (dialog) => {
- 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);
- };
- this.popupEffectHandler = new Laya.Handler(this, this.popupEffect);
- this.closeEffectHandler = new Laya.Handler(this, this.closeEffect);
- this.mouseEnabled = this.maskLayer.mouseEnabled = true;
- this.zOrder = 1000;
- Laya.ILaya.stage.addChild(this);
- Laya.ILaya.stage.on(Laya.Event.RESIZE, this, this._onResize);
- if (UIConfig.closeDialogOnSide)
- this.maskLayer.on("click", this, this._closeOnSide);
- this._onResize(null);
- }
- _closeOnSide() {
- var dialog = this.getChildAt(this.numChildren - 1);
- if (dialog instanceof IUI.Dialog)
- dialog.close();
- }
- setLockView(value) {
- if (!this.lockLayer) {
- this.lockLayer = new Box();
- this.lockLayer.mouseEnabled = true;
- this.lockLayer.size(Laya.ILaya.stage.width, Laya.ILaya.stage.height);
- }
- this.lockLayer.removeChildren();
- if (value) {
- value.centerX = value.centerY = 0;
- this.lockLayer.addChild(value);
- }
- }
- _onResize(e = null) {
- var width = this.maskLayer.width = Laya.ILaya.stage.width;
- var height = this.maskLayer.height = Laya.ILaya.stage.height;
- if (this.lockLayer)
- this.lockLayer.size(width, height);
- this.maskLayer.graphics.clear(true);
- this.maskLayer.graphics.drawRect(0, 0, width, height, UIConfig.popupBgColor);
- this.maskLayer.alpha = UIConfig.popupBgAlpha;
- for (var i = this.numChildren - 1; i > -1; i--) {
- var item = this.getChildAt(i);
- if (item.isPopupCenter)
- this._centerDialog(item);
- }
- }
- _centerDialog(dialog) {
- dialog.x = Math.round(((Laya.ILaya.stage.width - dialog.width) >> 1) + dialog.pivotX);
- dialog.y = Math.round(((Laya.ILaya.stage.height - dialog.height) >> 1) + dialog.pivotY);
- }
- open(dialog, closeOther = false, showEffect = false) {
- if (closeOther)
- this._closeAll();
- this._clearDialogEffect(dialog);
- if (dialog.isPopupCenter)
- this._centerDialog(dialog);
- this.addChild(dialog);
- if (dialog.isModal || this._getBit(Laya.Const.HAS_ZORDER))
- Laya.ILaya.timer.callLater(this, this._checkMask);
- if (showEffect && dialog.popupEffect != null)
- dialog.popupEffect.runWith(dialog);
- else
- this.doOpen(dialog);
- this.event(Laya.Event.OPEN);
- }
- _clearDialogEffect(dialog) {
- if (dialog._effectTween) {
- Laya.Tween.clear(dialog._effectTween);
- dialog._effectTween = null;
- }
- }
- doOpen(dialog) {
- dialog.onOpened(dialog._param);
- }
- lock(value) {
- if (this.lockLayer) {
- if (value)
- this.addChild(this.lockLayer);
- else
- this.lockLayer.removeSelf();
- }
- }
- close(dialog) {
- this._clearDialogEffect(dialog);
- if (dialog.isShowEffect && dialog.closeEffect != null)
- dialog.closeEffect.runWith([dialog]);
- else
- this.doClose(dialog);
- this.event(Laya.Event.CLOSE);
- }
- doClose(dialog) {
- dialog.removeSelf();
- dialog.isModal && this._checkMask();
- dialog.closeHandler && dialog.closeHandler.runWith(dialog.closeType);
- dialog.onClosed(dialog.closeType);
- if (dialog.autoDestroyAtClosed)
- dialog.destroy();
- }
- closeAll() {
- this._closeAll();
- this.event(Laya.Event.CLOSE);
- }
- _closeAll() {
- for (var i = this.numChildren - 1; i > -1; i--) {
- var item = this.getChildAt(i);
- if (item && item.close != null) {
- this.doClose(item);
- }
- }
- }
- getDialogsByGroup(group) {
- var arr = [];
- for (var i = this.numChildren - 1; i > -1; i--) {
- var item = this.getChildAt(i);
- if (item && item.group === group) {
- arr.push(item);
- }
- }
- return arr;
- }
- closeByGroup(group) {
- var arr = [];
- for (var i = this.numChildren - 1; i > -1; i--) {
- var item = this.getChildAt(i);
- if (item && item.group === group) {
- item.close();
- arr.push(item);
- }
- }
- return arr;
- }
- _checkMask() {
- this.maskLayer.removeSelf();
- for (var i = this.numChildren - 1; i > -1; i--) {
- var dialog = this.getChildAt(i);
- if (dialog && dialog.isModal) {
- this.addChildAt(this.maskLayer, i);
- return;
- }
- }
- }
- }
- Laya.ClassUtils.regClass("laya.ui.DialogManager", DialogManager);
- Laya.ClassUtils.regClass("Laya.DialogManager", DialogManager);
- class Dialog extends View {
- constructor() {
- super();
- this.isShowEffect = true;
- this.isPopupCenter = true;
- this.popupEffect = Dialog.manager.popupEffectHandler;
- this.closeEffect = Dialog.manager.closeEffectHandler;
- this._dealDragArea();
- this.on(Laya.Event.CLICK, this, this._onClick);
- }
- static get manager() {
- return Dialog._manager = Dialog._manager || new DialogManager();
- }
- static set manager(value) {
- Dialog._manager = value;
- }
- _dealDragArea() {
- var dragTarget = this.getChildByName("drag");
- if (dragTarget) {
- this.dragArea = dragTarget._x + "," + dragTarget._y + "," + dragTarget.width + "," + dragTarget.height;
- dragTarget.removeSelf();
- }
- }
- get dragArea() {
- if (this._dragArea)
- return this._dragArea.toString();
- return null;
- }
- set dragArea(value) {
- if (value) {
- var a = UIUtils.fillArray([0, 0, 0, 0], value, Number);
- this._dragArea = new Laya.Rectangle(a[0], a[1], a[2], a[3]);
- this.on(Laya.Event.MOUSE_DOWN, this, this._onMouseDown);
- }
- else {
- this._dragArea = null;
- this.off(Laya.Event.MOUSE_DOWN, this, this._onMouseDown);
- }
- }
- _onMouseDown(e) {
- var point = this.getMousePoint();
- if (this._dragArea.contains(point.x, point.y))
- this.startDrag();
- else
- this.stopDrag();
- }
- _onClick(e) {
- var btn = e.target;
- if (btn) {
- switch (btn.name) {
- case Dialog.CLOSE:
- case Dialog.CANCEL:
- case Dialog.SURE:
- case Dialog.NO:
- case Dialog.OK:
- case Dialog.YES:
- this.close(btn.name);
- return;
- }
- }
- }
- open(closeOther = true, param = null) {
- this._dealDragArea();
- this._param = param;
- Dialog.manager.open(this, closeOther, this.isShowEffect);
- Dialog.manager.lock(false);
- }
- close(type = null) {
- this.closeType = type;
- Dialog.manager.close(this);
- }
- destroy(destroyChild = true) {
- this.closeHandler = null;
- this.popupEffect = null;
- this.closeEffect = null;
- this._dragArea = null;
- super.destroy(destroyChild);
- }
- show(closeOther = false, showEffect = true) {
- this._open(false, closeOther, showEffect);
- }
- popup(closeOther = false, showEffect = true) {
- this._open(true, closeOther, showEffect);
- }
- _open(modal, closeOther, showEffect) {
- this.isModal = modal;
- this.isShowEffect = showEffect;
- Dialog.manager.lock(true);
- this.open(closeOther);
- }
- get isPopup() {
- return this.parent != null;
- }
- set zOrder(value) {
- super.zOrder = value;
- Dialog.manager._checkMask();
- }
- get zOrder() {
- return super.zOrder;
- }
- static setLockView(view) {
- Dialog.manager.setLockView(view);
- }
- static lock(value) {
- Dialog.manager.lock(value);
- }
- static closeAll() {
- Dialog.manager.closeAll();
- }
- static getDialogsByGroup(group) {
- return Dialog.manager.getDialogsByGroup(group);
- }
- static closeByGroup(group) {
- return Dialog.manager.closeByGroup(group);
- }
- }
- Dialog.CLOSE = "close";
- Dialog.CANCEL = "cancel";
- Dialog.SURE = "sure";
- Dialog.NO = "no";
- Dialog.YES = "yes";
- Dialog.OK = "ok";
- IUI.Dialog = Dialog;
- Laya.ILaya.regClass(Dialog);
- Laya.ClassUtils.regClass("laya.ui.Dialog", Dialog);
- Laya.ClassUtils.regClass("Laya.Dialog", Dialog);
- class TipManager extends UIComponent {
- constructor() {
- super();
- this._tipBox = new UIComponent();
- this._tipBox.addChild(this._tipText = new Laya.Text());
- this._tipText.x = this._tipText.y = 5;
- this._tipText.color = TipManager.tipTextColor;
- this._defaultTipHandler = this._showDefaultTip;
- Laya.ILaya.stage.on(UIEvent.SHOW_TIP, this, this._onStageShowTip);
- Laya.ILaya.stage.on(UIEvent.HIDE_TIP, this, this._onStageHideTip);
- this.zOrder = 1100;
- }
- _onStageHideTip(e) {
- Laya.ILaya.timer.clear(this, this._showTip);
- this.closeAll();
- this.removeSelf();
- }
- _onStageShowTip(data) {
- Laya.ILaya.timer.once(TipManager.tipDelay, this, this._showTip, [data], true);
- }
- _showTip(tip) {
- if (typeof (tip) == 'string') {
- var text = String(tip);
- if (Boolean(text)) {
- this._defaultTipHandler(text);
- }
- }
- else if (tip instanceof Laya.Handler) {
- tip.run();
- }
- else if (tip instanceof Function) {
- tip.apply();
- }
- {
- Laya.ILaya.stage.on(Laya.Event.MOUSE_MOVE, this, this._onStageMouseMove);
- Laya.ILaya.stage.on(Laya.Event.MOUSE_DOWN, this, this._onStageMouseDown);
- }
- this._onStageMouseMove(null);
- }
- _onStageMouseDown(e) {
- this.closeAll();
- }
- _onStageMouseMove(e) {
- this._showToStage(this, TipManager.offsetX, TipManager.offsetY);
- }
- _showToStage(dis, offX = 0, offY = 0) {
- var rec = dis.getBounds();
- dis.x = Laya.ILaya.stage.mouseX + offX;
- dis.y = Laya.ILaya.stage.mouseY + offY;
- if (dis._x + rec.width > Laya.ILaya.stage.width) {
- dis.x -= rec.width + offX;
- }
- if (dis._y + rec.height > Laya.ILaya.stage.height) {
- dis.y -= rec.height + offY;
- }
- }
- closeAll() {
- Laya.ILaya.timer.clear(this, this._showTip);
- Laya.ILaya.stage.off(Laya.Event.MOUSE_MOVE, this, this._onStageMouseMove);
- Laya.ILaya.stage.off(Laya.Event.MOUSE_DOWN, this, this._onStageMouseDown);
- this.removeChildren();
- }
- showDislayTip(tip) {
- this.addChild(tip);
- this._showToStage(this);
- Laya.ILaya.stage.addChild(this);
- }
- _showDefaultTip(text) {
- this._tipText.text = text;
- var g = this._tipBox.graphics;
- g.clear(true);
- g.drawRect(0, 0, this._tipText.width + 10, this._tipText.height + 10, TipManager.tipBackColor);
- this.addChild(this._tipBox);
- this._showToStage(this);
- Laya.ILaya.stage.addChild(this);
- }
- get defaultTipHandler() {
- return this._defaultTipHandler;
- }
- set defaultTipHandler(value) {
- this._defaultTipHandler = value;
- }
- }
- TipManager.offsetX = 10;
- TipManager.offsetY = 15;
- TipManager.tipTextColor = "#ffffff";
- TipManager.tipBackColor = "#111111";
- TipManager.tipDelay = 200;
- Laya.ILaya.regClass(TipManager);
- Laya.ClassUtils.regClass("laya.ui.TipManager", TipManager);
- Laya.ClassUtils.regClass("Laya.TipManager", TipManager);
- class UILib {
- static __init__() {
- }
- }
- class WXOpenDataViewer extends UIComponent {
- constructor() {
- super();
- this._width = this._height = 200;
- var tex = new Laya.Texture();
- tex.bitmap = new Laya.Texture2D();
- this.texture = tex;
- }
- onEnable() {
- this.postMsg({ type: "display", rate: Laya.Laya.stage.frameRate });
- if (window.wx && window.sharedCanvas)
- Laya.Laya.timer.frameLoop(1, this, this._onLoop);
- }
- onDisable() {
- this.postMsg({ type: "undisplay" });
- Laya.Laya.timer.clear(this, this._onLoop);
- }
- _onLoop() {
- let _canvas = window.sharedCanvas;
- this.texture.sourceWidth = _canvas.width;
- this.texture.sourceHeight = _canvas.height;
- this.texture.bitmap.loadImageSource(_canvas);
- }
- set width(value) {
- super.width = value;
- if (window.sharedCanvas)
- window.sharedCanvas.width = value;
- this.callLater(this._postMsg);
- }
- get width() {
- return super.width;
- }
- set height(value) {
- super.height = value;
- if (window.sharedCanvas)
- window.sharedCanvas.height = value;
- this.callLater(this._postMsg);
- }
- get height() {
- return super.height;
- }
- set x(value) {
- super.x = value;
- this.callLater(this._postMsg);
- }
- get x() {
- return super.x;
- }
- set y(value) {
- super.y = value;
- this.callLater(this._postMsg);
- }
- get y() {
- return super.y;
- }
- _postMsg() {
- var mat = new Laya.Matrix();
- mat.translate(this.x, this.y);
- var stage = Laya.Laya.stage;
- mat.scale(stage._canvasTransform.getScaleX() * this.globalScaleX * stage.transform.getScaleX(), stage._canvasTransform.getScaleY() * this.globalScaleY * stage.transform.getScaleY());
- 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 });
- }
- postMsg(msg) {
- if (window.wx && window.wx.getOpenDataContext) {
- var openDataContext = window.wx.getOpenDataContext();
- openDataContext.postMessage(msg);
- }
- }
- }
- Laya.ILaya.regClass(WXOpenDataViewer);
- Laya.ClassUtils.regClass("laya.ui.WXOpenDataViewer", WXOpenDataViewer);
- Laya.ClassUtils.regClass("Laya.WXOpenDataViewer", WXOpenDataViewer);
- exports.AdvImage = AdvImage;
- exports.AutoBitmap = AutoBitmap;
- exports.Box = Box;
- exports.Button = Button;
- exports.CheckBox = CheckBox;
- exports.Clip = Clip;
- exports.ColorPicker = ColorPicker;
- exports.ComboBox = ComboBox;
- exports.Dialog = Dialog;
- exports.DialogManager = DialogManager;
- exports.FontClip = FontClip;
- exports.HBox = HBox;
- exports.HScrollBar = HScrollBar;
- exports.HSlider = HSlider;
- exports.IUI = IUI;
- exports.Image = Image;
- exports.Label = Label;
- exports.LayoutBox = LayoutBox;
- exports.List = List;
- exports.Panel = Panel;
- exports.ProgressBar = ProgressBar;
- exports.Radio = Radio;
- exports.RadioGroup = RadioGroup;
- exports.ScaleBox = ScaleBox;
- exports.ScrollBar = ScrollBar;
- exports.Slider = Slider;
- exports.Styles = Styles;
- exports.Tab = Tab;
- exports.TextArea = TextArea;
- exports.TextInput = TextInput;
- exports.TipManager = TipManager;
- exports.Tree = Tree;
- exports.UIComponent = UIComponent;
- exports.UIConfig = UIConfig;
- exports.UIEvent = UIEvent;
- exports.UIGroup = UIGroup;
- exports.UILib = UILib;
- exports.UIUtils = UIUtils;
- exports.VBox = VBox;
- exports.VScrollBar = VScrollBar;
- exports.VSlider = VSlider;
- exports.View = View;
- exports.ViewStack = ViewStack;
- exports.WXOpenDataViewer = WXOpenDataViewer;
- exports.Widget = Widget;
- }(window.Laya = window.Laya || {}, Laya));
|