| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758 |
- GUI = {}
- local tconcat = table.concat
- local tinsert = table.insert
- local srep = string.rep
- local type = type
- local pairs = pairs
- local tostring = tostring
- local next = next
- local sfind = string.find
- local ssub = string.sub
- local slen = string.len
- local sbyte = string.byte
- local sgsub = string.gsub
- local ssplit = string.split
- local sformat = string.format
- local scheduleActionTag = 9961
- local performActionTag = 9962
- local NONEED_PARENT_CODE = -1
- -------------------------------------------------------------
- local cjson = require("cjson")
- local GUIQuickCell = require("GUI/GUIQuickCell")
- local TableViewEx = requireUtil("TableViewEx")
- -------------------------------------------------------------
- -- defines
- GUI.PATH_FONT2 = "fonts/font2.ttf"
- GUI.PATH_RES_ALPHA = "res/public/alpha_1px.png"
- GUI.FILENAME_PREFIX = "GUILayout/"
- GUI.EXPORTNAME_PREFIX = "GUIExport/"
- -------------------------------------------------------------
- local checkValueValid = function (value)
- if value == nil then
- return true
- end
- if value == global.MMO.MeTaInvalidKey or value == global.MMO.MeTaInvalidValue then
- return true
- end
- return false
- end
- -- helper
- GUI._disableFixPosition = false
- function GUI:DisableFixPosition()
- GUI._disableFixPosition = true
- end
- local function fixPosition(p)
- if type(p) ~= "table" then
- if checkValueValid(p) or p == "" then
- SL:Print("[GUI ERROR] GUI:setPosition, param nil")
- p = 0
- end
- else
- if checkValueValid(p.x) then
- SL:Print("[GUI ERROR] GUI:setPosition, X nil")
- p.x = 0
- end
- if checkValueValid(p.y) then
- SL:Print("[GUI ERROR] GUI:setPosition, Y nil")
- p.y = 0
- end
- end
- if GUI._disableFixPosition then
- return p
- end
- if tonumber(p) then
- return math.floor(p)
- end
- return cc.p(math.floor(p.x), math.floor(p.y))
- end
- -- Button Label offset
- local setButtonLabelOffset = function (widget)
- local x = widget._x_
- local y = widget._y_
- if x and y then
- widget:getTitleRenderer():setPosition(cc.p(x, y))
- elseif x then
- widget:getTitleRenderer():setPositionX(x)
- elseif y then
- widget:getTitleRenderer():setPositionY(y)
- end
- end
- -- check invalid cobj
- local function CheckIsInvalidCObject(widget)
- -- 开关,不检测
- if SL:GetMetaValue("GAME_DATA", "disable_check_cobject") == 1 then
- return false
- end
- --
- if widget == nil then
- release_print("----------------------------------------")
- release_print("LUA ERROR: target is nil value")
- release_print(debug.traceback())
- release_print("----------------------------------------")
- return true
- end
- --
- if tolua.isnull(widget) then
- release_print("----------------------------------------")
- release_print("LUA ERROR: target is invalid cobj")
- release_print(debug.traceback())
- release_print("----------------------------------------")
- return true
- end
- return false
- end
- -------------------------------------------------------------
- -- load ccexport
- local function GUICreateCCSExport(fileName)
- local ui = require(fileName).create()
- if ui.root then
- local new_widget = ccui.Widget:create()
- new_widget:setAnchorPoint(cc.p(0, 0))
- local children = ui.root:getChildren()
- for _, child in pairs(children) do
- child:removeFromParent()
- end
- for _, child in pairs(children) do
- new_widget:addChild(child)
- end
- local name = ui.root:getName()
- -- 自适应代码
- if name ~= "Layer" and name ~= "Node" then
- local visible = cc.Director:getInstance():getVisibleSize()
- new_widget:setContentSize(visible)
- ccui.Helper:doLayout(new_widget)
- else
- new_widget:setContentSize(ui.root:getContentSize())
- end
- rawset(ui, "root", new_widget)
- return new_widget, ui
- end
- return nil
- end
- -- load ccexport
- function GUI:LoadCCSExport(parent, ID, filename)
- if not ID then
- SL:Print("[GUI ERROR] GUI:LoadCCSExport can't set ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadCCSExport can't find parent")
- return nil
- end
- if SL._DEBUG and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:LoadCCSExport ID is exists", ID)
- return nil
- end
- local widget, quickUI = GUICreateCCSExport( filename )
- parent:addChild(widget)
- widget:setName(ID)
- return widget, quickUI
- end
- local GetScriptFunc = function (path)
- if not global.FileUtilCtl:isFileExist(path) then
- return false
- end
- local script = global.FileUtilCtl:getDataFromFileEx(path)
- script = sgsub(script, ";", "")
- local scFunc = load(script)
- if not scFunc then
- return false
- end
- local myfunc = scFunc()
- if not myfunc then
- return false
- end
- local func = myfunc.init or myfunc.main
- if not func then
- return false
- end
- return func
- end
- GUI.WinExports = {}
- function GUI:LoadExport(parent, filename, loadCB)
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadGUIExport can't find parent")
- return nil
- end
- local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
- local newfilename = luafile .. ".lua"
- local clock = os.clock()
- if SL._DEBUG then
- global.FileUtilCtl:purgeCachedEntries()
- local func = GetScriptFunc(newfilename)
- if func then
- func(parent)
- end
- else
- local func = GUI.WinExports[newfilename] or GetScriptFunc(newfilename)
- if func then
- func(parent)
- GUI.WinExports[newfilename] = func
- end
- end
- -- 增加加载回调,兼容H5异步加载写法
- if loadCB then
- loadCB()
- end
- end
- GUI.WinExportsEx = {}
- function GUI:LoadExportEx(parent, filename, page, data)
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadExportEx can't find parent")
- return nil
- end
- local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
- local newfilename = luafile .. ".lua"
- local clock = os.clock()
- if SL._DEBUG then
- global.FileUtilCtl:purgeCachedEntries()
- local func = GetScriptFunc(newfilename)
- if func then
- func(parent, false, page, data)
- GUI.WinExportsEx[newfilename] = func
- end
- else
- local func = GUI.WinExports[newfilename] or GetScriptFunc(newfilename)
- if func then
- func(parent, false, page, data)
- GUI.WinExportsEx[newfilename] = func
- end
- end
- end
- -- 更新Export中变量
- function GUI:UpdateExportEx(parent, filename, page)
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadGUIExport can't find parent")
- return nil
- end
- local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
- local newfilename = luafile .. ".lua"
- local func = GUI.WinExportsEx[newfilename]
- if func then
- func(parent, true, page)
- end
- end
- function GUI:LoadExportVar(parent, filename, data)
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadExportEx can't find parent")
- return nil
- end
- local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
- local newfilename = luafile .. ".lua"
- local clock = os.clock()
- if SL._DEBUG then
- global.FileUtilCtl:purgeCachedEntries()
- local func = GetScriptFunc(newfilename)
- if func then
- func(parent, data)
- GUI.WinExportsEx[newfilename] = func
- end
- else
- local func = GUI.WinExports[newfilename] or GetScriptFunc(newfilename)
- if func then
- func(parent, data)
- GUI.WinExportsEx[newfilename] = func
- end
- end
- end
- -- 更新Export中变量
- function GUI:UpdateExportVar(parent, filename, data)
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadGUIExport can't find parent")
- return nil
- end
- local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
- local newfilename = luafile .. ".lua"
- local func = GUI.WinExportsEx[newfilename]
- if func then
- func(parent, data, true)
- end
- end
- --使用内置的导出目录
- function GUI:LoadInternalExport(parent, filename, loadCB)
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadInternalExport can't find parent")
- return nil
- end
- local luafile = "game/view/export/" .. filename
- if SL._DEBUG then
- package.loaded[luafile] = nil
- end
- local file = require(luafile)
- local func = file.init or file.main
- if func then
- func(parent)
- end
- -- 增加加载回调,兼容H5异步加载写法
- if loadCB then
- loadCB()
- end
- end
- -- load say
- function GUI:LoadSay(parent, ID, str, linkCB)
- if not ID then
- SL:Print("[GUI ERROR] GUI:LoadSay, can't find ID", ID)
- return nil
- end
- local fakeMediator = nil
- if not parent or parent == 0 then -- WIN 同步ssr
- local visibleSize = global.Director:getVisibleSize()
- local _, rootRect = checkNotchPhone()
- local layout = ccui.Layout:create()
- layout:setContentSize(visibleSize.width, visibleSize.height)
- layout:setPositionX(rootRect.x)
- -- mediator
- if nil == GUI.Mediators[ID] then
- local GUIMediator = require("GUI/GUIMediator")
- fakeMediator = GUIMediator.new(ID)
- GUI.Mediators[ID] = fakeMediator
- else
- fakeMediator = GUI.Mediators[ID]
- end
- fakeMediator:setSavedPosition(cc.p(0, 0))
- fakeMediator._type = global.UIZ.UI_NORMAL
- fakeMediator._layer = layout
- fakeMediator._voice = false
- fakeMediator._hideMain = false
- fakeMediator._hideLast = false
- fakeMediator._escClose = false
- fakeMediator._GUI_ID = ID
- fakeMediator._LuaEvent = {}
- fakeMediator._NetMsgEvent = {}
- fakeMediator._LuaNetMsgEvent = {}
- parent = layout
- end
- if parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:LoadSay ID is exists", ID)
- return nil
- end
- local contentSize = parent:getContentSize()
- local rootRect = cc.rect(0, 0, contentSize.width, contentSize.height)
- local LexicalHelper = require("sui/LexicalHelper")
- local elements = LexicalHelper:Parse(str)
- local SUILoader = require("sui/SUILoader").new()
- local trunk, background = SUILoader:loadContent(elements, linkCB, closeCB, rootRect)
- local widget = trunk.render
- parent:addChild(widget)
- widget:setName(ID)
- if fakeMediator then
- local element = background and background.element
- if element then
- fakeMediator._resetPostion = (tonumber(element.attr.reset) or 1) == 1
- fakeMediator._escClose = (tonumber(element.attr.esc) or 1) == 1
- fakeMediator._hideMain = (tonumber(element.attr.hideMain) or 0) == 1
- fakeMediator._adapet = (tonumber(element.attr.show) or 0) == 6 --加黑幕
- end
- fakeMediator:OpenLayer()
- if background and background.render then
- local element = background.element
- local canmove = (element and tonumber(element.attr.move) or 0) == 1
- if canmove then
- fakeMediator:setLayerMoveEnable(background.render)
- end
- end
- return parent
- end
- return widget
- end
- -------------------------------------------------------------
- GUI.ATTACH_LEFTTOP = nil -- 主界面挂接,左上
- GUI.ATTACH_RIGHTTOP = nil -- 主界面挂接,右上
- GUI.ATTACH_LEFTBOTTOM = nil -- 主界面挂接,左下
- GUI.ATTACH_RIGHTBOTTOM = nil -- 主界面挂接,右下
- GUI.ATTACH_MAINMINIMAP = nil -- 主界面挂接,小地图
- GUI.ATTACH_MAINTOP = nil -- 主界面挂接,顶部装饰
- GUI.ATTACH_PARENT = nil -- 当前界面挂节点,挂节点是变化的
- GUI.ATTACH_PARENT_UITOP = nil -- 提供通知层挂接点
- GUI._sceneRootNodeF = nil -- 场景节点,在前
- GUI._sceneRootNodeB = nil -- 场景节点,在后
- GUI._actorRootNode = nil -- ACTOR节点
- -- 主界面最底层
- GUI.ATTACH_LEFTTOP_B = nil
- GUI.ATTACH_RIGHTTOP_B = nil
- GUI.ATTACH_LEFTBOTTOM_B = nil
- GUI.ATTACH_RIGHTBOTTOM_B= nil
- -- 主界面最顶层 (高于小地图)
- GUI.ATTACH_LEFTTOP_T = nil
- GUI.ATTACH_RIGHTTOP_T = nil
- GUI.ATTACH_LEFTBOTTOM_T = nil
- GUI.ATTACH_RIGHTBOTTOM_T= nil
- function GUI:Attach_LeftTop()
- return GUI.ATTACH_LEFTTOP
- end
- function GUI:Attach_RightTop()
- return GUI.ATTACH_RIGHTTOP
- end
- function GUI:Attach_LeftBottom()
- return GUI.ATTACH_LEFTBOTTOM
- end
- function GUI:Attach_RightBottom()
- return GUI.ATTACH_RIGHTBOTTOM
- end
- function GUI:Attach_MainMiniMap()
- return GUI.ATTACH_MAINMINIMAP
- end
- function GUI:Attach_MainTop()
- return GUI.ATTACH_MAINTOP
- end
- function GUI:Attach_Parent()
- return GUI.ATTACH_PARENT
- end
- function GUI:Attach_UITop()
- return GUI.ATTACH_PARENT_UITOP
- end
- function GUI:Attach_SceneF()
- return GUI._sceneRootNodeF
- end
- function GUI:Attach_SceneB()
- return GUI._sceneRootNodeB
- end
- function GUI:Attach_ActorNode()
- return GUI._actorRootNode
- end
- -- bottom
- function GUI:Attach_LeftTop_B()
- return GUI.ATTACH_LEFTTOP_B
- end
- function GUI:Attach_RightTop_B()
- return GUI.ATTACH_RIGHTTOP_B
- end
- function GUI:Attach_LeftBottom_B()
- return GUI.ATTACH_LEFTBOTTOM_B
- end
- function GUI:Attach_RightBottom_B()
- return GUI.ATTACH_RIGHTBOTTOM_B
- end
- -- top
- function GUI:Attach_LeftTop_T()
- return GUI.ATTACH_LEFTTOP_T
- end
- function GUI:Attach_RightTop_T()
- return GUI.ATTACH_RIGHTTOP_T
- end
- function GUI:Attach_LeftBottom_T()
- return GUI.ATTACH_LEFTBOTTOM_T
- end
- function GUI:Attach_RightBottom_T()
- return GUI.ATTACH_RIGHTBOTTOM_T
- end
- -- 父节点
- GUI._Parent = {}
- function GUI:SetGUIParent(index, parent)
- GUI._Parent[index] = parent
- end
- function GUI:Win_FindParent(ID)
- return GUI._Parent[ID or 0] or GUI._Parent[0]
- end
- -------------------------------------------------------------
- -- gui
- function GUI:Win_Open(filename)
- SL:Print("[GUI LOG] GUI:Win_Open", filename)
- local clock = os.clock()
- local fileUtil = global.FileUtilCtl
- local newfilename = GUI.FILENAME_PREFIX .. filename ..".lua"
-
- if not fileUtil:isFileExist(newfilename) then
- SL:Print("[GUI ERROR] GUI:Win_Open, can't find file", newfilename)
- return false
- end
- local clock = os.clock()
- local script = fileUtil:getDataFromFileEx(newfilename)
- local scFunc = nil
- if script ~= "" then
- if SL._DEBUG then
- assert(load(script))
- end
- scFunc = load(script)
- end
- if not scFunc then
- SL:Print("[GUI ERROR] GUI:Win_Open, load lua string error", newfilename)
- return false
- end
- scFunc()
- SL:Print("[GUI LOG] GUI:Win_Open, load cost(milliseconds) ", filename, (os.clock() - clock) * 1000)
- return true
- end
- function GUI:Win_AddFile(parent, filename)
- local newfilename = GUI.FILENAME_PREFIX .. filename ..".lua"
- if not global.FileUtilCtl:isFileExist(newfilename) then
- SL:Print("[GUI ERROR] GUI:Win_Open, can't find file", newfilename)
- return false
- end
-
- local CUILoader = requireCUI("CUILoader")
- CUILoader:ParseLuaFile2(global.FileUtilCtl:getDataFromFileEx(newfilename), parent)
- end
- GUI.WinLayers = {} -- GUI 界面管理
- GUI.Mediators = {} -- GUI 界面管理
- -- orderParam 0主界面 1普通 2通知层
- function GUI:Win_Create(ID, x, y, width, height, hideMain, hideLast, needVoice, escClose, isRevmsg, npcID, orderParam)
- if GET_GAME_STATE() ~= global.MMO.GAME_STATE_WORLD then
- SL:Print("[GUI ERROR] GUI:Win_Create, game world Only", ID)
- return nil
- end
- if not ID then
- SL:Print("[GUI ERROR] GUI:Win_Create, can't find ID", ID)
- return nil
- end
- if GUI.WinLayers[ID] then
- SL:Print("[GUI WARNING] GUI:Win_Create, Win exist, close it", ID)
- -- close, if open
- local window = GUI:GetWindow(nil, ID)
- GUI:Win_Close(window)
- end
- -- 默认值
- hideMain = hideMain or false
- hideLast = hideLast or false
- needVoice = (needVoice == nil or needVoice == true) and true or false
- isRevmsg = (isRevmsg == nil or isRevmsg == true) and true or false
- escClose = (escClose == nil or escClose == true) and true or false
- -- new widget
- local widget = cc.Layer:create()
- widget:setName(ID)
- -- attr
- x = x or 0
- y = y or 0
- -- 屏蔽触摸
- if isRevmsg then
- local touchLayout = ccui.Layout:create()
- widget:addChild(touchLayout)
- touchLayout:setName("__GUI_WIN_TOUCH")
- touchLayout:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- touchLayout:setContentSize(cc.size(width, height))
- touchLayout:setTouchEnabled(true)
- if SL:GetMetaValue("WINPLAYMODE") then
- GUI:setMouseEnabled(touchLayout, true)
- end
- end
- -- mediator
- local fakeMediator = nil
- if nil == GUI.Mediators[ID] then
- local GUIMediator = require("GUI/GUIMediator")
- fakeMediator = GUIMediator.new(ID)
- GUI.Mediators[ID] = fakeMediator
- else
- fakeMediator = GUI.Mediators[ID]
- end
- fakeMediator:setSavedPosition(cc.p(x, y))
- local type = global.UIZ.UI_NORMAL
- if orderParam == 2 then
- type = global.UIZ.UI_NOTICE
- elseif orderParam == 0 then
- type = global.UIZ.UI_MAIN
- end
- fakeMediator._type = type
- fakeMediator._layer = widget
- fakeMediator._voice = needVoice
- fakeMediator._hideMain = hideMain
- fakeMediator._hideLast = hideLast
- fakeMediator._escClose = escClose
- fakeMediator._GUI_ID = ID
- fakeMediator._NPCID = npcID
- fakeMediator._LuaEvent = {}
- fakeMediator._NetMsgEvent = {}
- fakeMediator._LuaNetMsgEvent = {}
- fakeMediator:OpenLayer()
- return widget
- end
- function GUI:Win_BindLuaEvent(widget, eventID, eventTag)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_BindLuaEvent, can't find Win")
- return false
- end
- if not widget.ID then
- SL:Print("[GUI ERROR] GUI:Win_BindLuaEvent, invalid Win")
- return false
- end
- if not eventID then
- SL:Print("[GUI ERROR] eventID is null", eventID)
- return false
- end
- if not eventTag then
- SL:Print("[GUI ERROR] eventTag is null", eventTag)
- return false
- end
-
- local fakeMediator = widget.mediator
- fakeMediator._LuaEvent = fakeMediator._LuaEvent or {}
- fakeMediator._LuaEvent[eventID] = fakeMediator._LuaEvent[eventID] or {}
- fakeMediator._LuaEvent[eventID][eventTag] = true
- end
- local UnBindLuaEvent = function (widget)
- for eID, eTags in pairs(widget.mediator._LuaEvent or {}) do
- for eTag, _ in pairs(eTags or {}) do
- if SLBridge.LUAEvent[eID] and SLBridge.LUAEvent[eID][eTag] then
- SLBridge.LUAEvent[eID][eTag] = nil
- end
- end
- end
- widget.mediator._LuaEvent = {}
- end
- function GUI:Win_BindNetMsgEvent(widget, msgID)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_BindNetMsgEvent, can't find Win")
- return false
- end
- if not widget.ID then
- SL:Print("[GUI ERROR] GUI:Win_BindNetMsgEvent, is valid Win")
- return false
- end
- if not msgID then
- SL:Print("[GUI ERROR] msgID is null", msgID)
- return false
- end
- local fakeMediator = widget.mediator
- fakeMediator._NetMsgEvent = fakeMediator._NetMsgEvent or {}
- fakeMediator._NetMsgEvent[msgID] = true
- end
- local UnBindNetMsgEvent = function (widget)
- for msgID, _ in pairs(widget.mediator._NetMsgEvent or {}) do
- SL.NetworkUtil:UnRegisterNetworkHandler(msgID)
- end
- widget.mediator._NetMsgEvent = {}
- end
- function GUI:Win_BindLuaNetMsgEvent(widget, msgID)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_BindLuaNetMsgEvent, can't find Win")
- return false
- end
- if not widget.ID then
- SL:Print("[GUI ERROR] GUI:Win_BindLuaNetMsgEvent, is valid Win")
- return false
- end
- if not msgID then
- SL:Print("[GUI ERROR] Lua msgID is null", msgID)
- return false
- end
- local fakeMediator = widget.mediator
- fakeMediator._LuaNetMsgEvent = fakeMediator._LuaNetMsgEvent or {}
- fakeMediator._LuaNetMsgEvent[msgID] = true
- end
- local UnBindLuaNetMsgEvent = function (widget)
- for msgID, _ in pairs(widget.mediator._LuaNetMsgEvent or {}) do
- SL.NetworkUtil:UnRegisterLuaNetworkHandler(msgID)
- end
- widget.mediator._LuaNetMsgEvent = {}
- end
- function GUI:Win_Close(widget)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_Close, can't find Win")
- return nil
- end
- if not widget.ID then
- SL:Print("[GUI ERROR] GUI:Win_Close, is valid Win")
- return nil
- end
- UnBindLuaEvent(widget)
- UnBindNetMsgEvent(widget)
- UnBindLuaNetMsgEvent(widget)
- local fakeMediator = widget.mediator
- fakeMediator:CloseLayer()
- end
- function GUI:Win_CloseAll()
- while true do
- local key, window = next(GUI.WinLayers)
- if not key or not window then
- break
- end
- GUI:Win_Close(window)
- end
- end
- function GUI:Win_CloseByID(ID)
- local window = GUI:GetWindow(nil, ID)
- if not window then
- return
- end
- GUI:Win_Close(window)
- end
- function GUI:Win_CloseByNPCID(NPCID)
- for _, v in pairs(GUI.WinLayers) do
- if v.mediator and v.mediator._NPCID == tonumber(NPCID) then
- GUI:Win_Close(v)
- break
- end
- end
- end
- function GUI:GetWindow(parent, ID)
- local slices = ssplit(ID, "/")
- -- find parent
- local window = nil
- if parent == nil then
- window = GUI.WinLayers[slices[1]]
- else
- window = GUI:getChildByName(parent, slices[1])
- end
- if not window then
- return nil
- end
- for i = 2, #slices do
- window = GUI:getChildByName(window, slices[i])
- if not window then
- return nil
- end
- end
- return window
- end
- function GUI:Win_GetParam(widget)
- return widget.param
- end
- function GUI:Win_SetParam(widget, param, uitype)
- widget.param = param
- end
- function GUI:Win_SetESCClose(widget, value)
- if not widget then
- SL:Print("[GUI ERROR] GUI:SetESCClose, can't find Win")
- return
- end
- if not widget.mediator then
- SL:Print("[GUI ERROR] GUI:SetESCClose, win only")
- return
- end
- widget.mediator._escClose = value
- end
- function GUI:Win_SetSwallowRightMouseTouch(widget, state)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if not widget then
- SL:Print("[GUI WARNING] GUI:SetSwallowRightMouseTouch can't find Win")
- return nil
- end
- local function onMouseDown(sender)
- local button = sender:getMouseButton()
- if button == cc.MouseButton.BUTTON_RIGHT then
- sender:stopPropagation()
- end
- end
- local listener = cc.EventListenerMouse:create()
- local eventDispatcher = cc.Director:getInstance():getEventDispatcher()
- if state then
- listener:registerScriptHandler(onMouseDown, cc.Handler.EVENT_MOUSE_DOWN)
- eventDispatcher:addEventListenerWithSceneGraphPriority(listener, widget)
- else
- eventDispatcher:removeEventListenersForTarget(widget)
- end
- end
- function GUI:Win_SetDrag(widget, dragLayer)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_SetDrag, can't find Win")
- return
- end
- if not widget.mediator then
- SL:Print("[GUI ERROR] GUI:Win_SetDrag, win only")
- PrintTraceback()
- return
- end
- widget.mediator:setLayerMoveEnable(dragLayer)
- end
- --拖动页面 透明
- function GUI:SetLayerMovingOpacity(b)
- local layerFacadeMediator = global.Facade:retrieveMediator("LayerFacadeMediator")
- layerFacadeMediator:SetOnMovingOpacity(b)
- end
- function GUI:Win_SetMainHide(widget, value)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_SetDrag, can't find Win")
- return
- end
- if not widget.mediator then
- SL:Print("[GUI ERROR] GUI:Win_SetDrag, win only")
- PrintTraceback()
- return
- end
- widget.mediator:setHideMainUI(value)
- end
- function GUI:Win_BindNPC(widget, npcID)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_BindNPC, can't find Win")
- return
- end
- if not widget.mediator then
- SL:Print("[GUI ERROR] GUI:Win_BindNPC, win only")
- return
- end
- widget.mediator._NPCID = npcID
- end
- function GUI:Win_SetZPanel(widget, zPanel)
- if not widget then
- SL:Print("[GUI ERROR] GUI:Win_SetZPanel, can't find Win")
- return
- end
- if not widget.mediator then
- SL:Print("[GUI ERROR] GUI:Win_SetZPanel, win only")
- return
- end
- widget.mediator:setLayerZPanel(zPanel)
- end
- function GUI:Win_IsNull(widget)
- if not widget then
- return true
- end
- return tolua.isnull(widget)
- end
- function GUI:Win_IsNotNull(widget)
- return not GUI:Win_IsNull(widget)
- end
- function GUI:SetRefreshVarFunc(widget, callback)
- widget._refreshVarFunc = callback
- end
- function GUI:GetRefreshVarFunc(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- return widget._refreshVarFunc
- end
- -------------------------------------------------------------
- function GUI:setColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setColor(SL:ConvertColorFromHexString(value))
- end
- --
- function GUI:setPosition(widget, x, y)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- x = fixPosition(x)
- if type(x) ~= "table" then
- y = fixPosition(y)
- end
- local originX = widget:getPositionX()
- local originY = widget:getPositionY()
- if originX ~= x or originY ~= y then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_POS_CHANGE, true)
- end
- widget:setPosition(cc.p(x, y))
- end
- function GUI:getPosition(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.p(0, 0)
- end
- if widget.getTurePosition then
- return widget:getTurePosition()
- end
- return cc.p(widget:getPosition())
- end
- --
- function GUI:setPositionX(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setPositionX, param nil")
- value = 0
- end
- local x = fixPosition(value)
- local originX = widget:getPositionX()
- if originX ~= x then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_POS_CHANGE, true)
- end
- widget:setPositionX(x)
- end
- function GUI:getPositionX(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
- if widget.getTurePosition then
- return widget:getTurePosition().x
- end
- return widget:getPositionX()
- end
- --
- function GUI:setPositionY(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setPositionY, param nil")
- value = 0
- end
- local y = fixPosition(value)
- local originY = widget:getPositionY()
- if originY ~= y then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_POS_CHANGE, true)
- end
-
- widget:setPositionY(y)
- end
- function GUI:getPositionY(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- if widget.getTurePosition then
- return widget:getTurePosition().y
- end
- return widget:getPositionY()
- end
- --
- function GUI:setAnchorPoint(widget, x, y)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if type(x) ~= "table" and checkValueValid(x) then
- SL:Print("[GUI ERROR] GUI:setAnchorPoint, X nil")
- x = 0
- end
- if type(x) ~= "table" and checkValueValid(y) then
- SL:Print("[GUI ERROR] GUI:setAnchorPoint, Y nil")
- y = 0
- end
- widget:setAnchorPoint(cc.p(x, y))
- end
- function GUI:getAnchorPoint(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.p(0, 0)
- end
- return widget:getAnchorPoint()
- end
- function GUI:setIgnoreContentAdaptWithSize(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:ignoreContentAdaptWithSize(value)
- if tolua.type(widget) == "ccui.Button" then
- setButtonLabelOffset(widget)
- end
- end
- --
- function GUI:setContentSize(widget, sizeW, sizeH)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local size = nil
- if nil == sizeH then
- size = { width = sizeW.width, height = sizeW.height }
- else
- if checkValueValid(sizeW) then
- SL:Print("[GUI ERROR] GUI:setContentSize, width nil")
- sizeW = 0
- end
- if checkValueValid(sizeH) then
- SL:Print("[GUI ERROR] GUI:setContentSize, height nil")
- sizeH = 0
- end
- size = { width = sizeW, height = sizeH }
- end
- local originS = widget:getContentSize()
- if originS.width ~= size.width or originS.height ~= size.height then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
- end
- if widget.ignoreContentAdaptWithSize then
- widget:ignoreContentAdaptWithSize(false)
- end
- widget:setContentSize(size)
- end
- function GUI:getContentSize(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.size(0, 0)
- end
- return widget:getContentSize()
- end
- function GUI:setTag(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setTag, tag nil")
- value = -1
- end
- widget:setTag(value)
- end
- function GUI:getTag(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
- return widget:getTag()
- end
- function GUI:setName(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setName(value)
- end
- function GUI:setGrey(widget, isGrey)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if isGrey then
- Shader_Grey(widget)
- else
- Shader_Normal(widget)
- end
- end
- --
- function GUI:setRotation(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setRotation, rotate nil")
- value = 0
- end
- widget:setRotation(value)
- end
- function GUI:getRotation(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
- return widget:getRotation()
- end
- function GUI:setRotationSkewX(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setRotationSkewX(value)
- end
- function GUI:setRotationSkewY(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setRotationSkewY(value)
- end
- --
- function GUI:setVisible(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setVisible, param nil")
- value = false
- end
- local visible = widget:isVisible()
- if visible ~= value then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_VISIBLE, true)
- end
- widget:setVisible(value)
- end
- function GUI:getVisible(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- return widget:isVisible()
- end
- --
- function GUI:setOpacity(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setOpacity, opacity nil")
- value = 255
- end
- widget:setOpacity(value)
- end
- function GUI:getOpacity(widget)
- if CheckIsInvalidCObject(widget) then
- return 255
- end
- return widget:getOpacity()
- end
- --
- function GUI:setScale(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setScale, scale nil")
- value = 1
- end
- local originScale = widget:getScale()
- if originScale ~= value then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
- end
- widget:setScale(value)
- end
- function GUI:getScale(widget)
- if CheckIsInvalidCObject(widget) then
- return 1
- end
- return widget:getScale()
- end
- --
- function GUI:setScaleX(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setScaleX, X nil")
- value = 1
- end
- local originScaleX = widget:getScaleX()
- if originScaleX ~= value then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
- end
- widget:setScaleX(value)
- end
- function GUI:getScaleX(widget)
- if CheckIsInvalidCObject(widget) then
- return 1
- end
- return widget:getScaleX()
- end
- --
- function GUI:setScaleY(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setScaleY, Y nil")
- value = 1
- end
- local originScaleY = widget:getScaleY()
- if originScaleY ~= value then
- SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
- end
- widget:setScaleY(value)
- end
- function GUI:getScaleY(widget)
- if CheckIsInvalidCObject(widget) then
- return 1
- end
- return widget:getScaleY()
- end
- --
- function GUI:setFlippedX(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setFlippedX, X nil")
- value = 0
- end
- widget:setFlippedX(value)
- end
- function GUI:getFlippedX(widget)
- if CheckIsInvalidCObject(widget) then
- return 1
- end
- return widget:isFlippedX()
- end
- --
- function GUI:setFlippedY(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setFlippedY, Y nil")
- value = 0
- end
- widget:setFlippedY(value)
- end
- function GUI:getFlippedY(widget)
- if CheckIsInvalidCObject(widget) then
- return 1
- end
-
- return widget:isFlippedY()
- end
- function GUI:addChild(widget, child)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if CheckIsInvalidCObject(child) then
- return false
- end
-
- return widget:addChild(child)
- end
- function GUI:Clone(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:clone()
- end
- function GUI:setMouseEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setMouseEnabled(value)
- end
- function GUI:setTouchEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if checkValueValid(value) then
- SL:Print("[GUI ERROR] GUI:setTouchEnabled, param nil")
- value = true
- end
-
- widget:setTouchEnabled(value)
- end
- function GUI:getTouchEnabled(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:isTouchEnabled()
- end
- function GUI:getParent(widget)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
-
- return widget:getParent()
- end
- function GUI:getChildren(widget)
- if CheckIsInvalidCObject(widget) then
- return {}
- end
-
- return widget:getChildren()
- end
- function GUI:getBoundingBox(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.rect(0, 0, 1, 1)
- end
-
- if widget.GetBoundingBox then
- return widget:GetBoundingBox()
- end
- return widget:getBoundingBox()
- end
- function GUI:getName(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- return widget:getName()
- end
- function GUI:getChildByName(widget, name)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
-
- return widget:getChildByName(name)
- end
- function GUI:getChildByTag(widget, tag)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
-
- return widget:getChildByTag(tag)
- end
- function GUI:removeFromParent(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeFromParent()
- end
- function GUI:removeChildByName(widget, name)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeChildByName(name)
- end
- function GUI:removeAllChildren(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeAllChildren()
- end
- function GUI:runAction(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:runAction(value)
- end
- function GUI:stopAllActions(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:stopAllActions()
- end
- function GUI:getActionByTag(widget, tag)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:getActionByTag(tag)
- end
- function GUI:stopActionByTag(widget, tag)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:stopActionByTag(tag)
- end
- function GUI:delayTouchEnabled(widget, delay)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- delay = delay or 0.2
- widget:stopActionByTag(10999)
- widget:setTouchEnabled(false)
- local action = performWithDelay(
- widget,
- function()
- widget:setTouchEnabled(true)
- end,
- delay
- )
- action:setTag(10999)
- end
- function GUI:addOnClickEvent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- -- global.ScriptHandlerMgr:removeObjectAllHandlers(widget)
- widget:_addClickEventListener(value)
- end
- function GUI:addOnTouchEvent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- global.ScriptHandlerMgr:removeObjectAllHandlers(widget)
- widget:addTouchEventListener(value)
- end
- function GUI:addMouseMoveEvent(widget, param)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- global.mouseEventController:registerMouseMoveEvent(
- widget,
- {
- enter = param.onEnterFunc,
- inside = param.onInsideFunc,
- leave = param.onLeaveFunc,
- checkIsVisible = param.checkIsVisible,
- }
- )
- end
- function GUI:addMouseButtonEvent(widget, param)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local function setNoSwallowMouse()
- return -1
- end
- global.mouseEventController:registerMouseButtonEvent(
- widget,
- {
- down_r = (param.onRightDownFunc or param.OnRightDownFunc) or setNoSwallowMouse,
- up_r = param.OnRightUpFunc,
- special_r = param.OnSpecialRFunc,
- double_l = param.OnDoubleLFunc,
- scroll = param.OnScrollFunc,
- moveTouch = param.needTouchPos,
- checkIsVisible = param.checkIsVisible,
- checkTouchEnable = param.checkTouchEnable,
- }
- )
- end
- function GUI:addMouseOverTips(widget, str, pos, anr, param)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addMouseOverTips(str, pos, anr, param)
- end
- function GUI:addMouseStyle(widget, styleType)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addMouseStyle(styleType)
- end
- function GUI:addOnLongTouchEvent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- -- global.ScriptHandlerMgr:removeObjectAllHandlers(widget)
- widget:_addLongTouchEventListener(value)
- end
- function GUI:setLocalZOrder(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setLocalZOrder(value)
- end
- function GUI:getLocalZOrder(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:getLocalZOrder()
- end
- function GUI:setCascadeOpacityEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setCascadeOpacityEnabled(value)
- end
- function GUI:setChildrenCascadeOpacityEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local node_list = {}
- local function seach_child(parente)
- local childCount = parente:getChildrenCount()
- if childCount >= 1 then
- for i = 1, childCount do
- seach_child(parente:getChildren()[i])
- end
- end
- table.insert(node_list, parente)
- end
- seach_child(widget)
- for i,v in ipairs(node_list) do
- v:setCascadeOpacityEnabled(value)
- end
- end
- function GUI:getWorldPosition(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:getWorldPosition()
- end
- function GUI:getTouchMovePosition(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:getTouchMovePosition()
- end
- function GUI:getTouchBeganPosition(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:getTouchBeganPosition()
- end
- function GUI:getTouchEndPosition(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:getTouchEndPosition()
- end
- function GUI:convertToWorldSpace(widget, x, y)
- if CheckIsInvalidCObject(widget) then
- return cc.p(0, 0)
- end
-
- return widget:convertToWorldSpace(cc.p(x, y))
- end
- function GUI:convertToNodeSpace(widget, x, y)
- if CheckIsInvalidCObject(widget) then
- return cc.p(0, 0)
- end
-
- return widget:convertToNodeSpace(cc.p(x, y))
- end
- function GUI:getDescription(widget)
- if CheckIsInvalidCObject(widget) then
- return "nil"
- end
-
- return widget:getDescription()
- end
- function GUI:setSwallowTouches(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setSwallowTouches(value)
- end
- function GUI:getSwallowTouches(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:isSwallowTouches()
- end
- function GUI:setMouseRSwallowTouches(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- global.mouseEventController:registerMouseButtonEvent(widget, {checkSwallowTouches = true})
- end
- function GUI:schedule(widget, callback, delay)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- delay = delay or 1
- local action = schedule(widget, callback, delay)
- action:setTag(scheduleActionTag)
- end
- function GUI:unSchedule(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:stopActionByTag(scheduleActionTag)
- end
- function GUI:performWithDelay(widget, callback, delay)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- delay = delay or 1
- local action = performWithDelay(widget, callback, delay)
- action:setTag(performActionTag)
- end
- function GUI:unPerformWithDelay(widget, callback, delay)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:stopActionByTag(performActionTag)
- end
- function GUI:addKeyboardEvent(codeKeys, pressedCB, releaseCB, checkFullSort)
- local keyCodes = {}
- if type(codeKeys) == "string" then
- table.insert(keyCodes, cc.KeyCode[codeKeys])
- elseif type(codeKeys) == "table" then
- for _, v in ipairs(codeKeys) do
- table.insert(keyCodes, cc.KeyCode[v])
- end
- end
- if not next(keyCodes) then
- SL:Print("[GUI ERROR] keyCode is invalid!")
- return
- end
- global.userInputController:addKeyboardListener(keyCodes, pressedCB, releaseCB, nil, checkFullSort)
- end
- function GUI:removeKeyboardEvent(codeKeys)
- local keyCodes = {}
- if type(codeKeys) == "string" then
- table.insert(keyCodes, cc.KeyCode[codeKeys])
- elseif type(codeKeys) == "table" then
- for _, v in ipairs(codeKeys) do
- table.insert(keyCodes, cc.KeyCode[v])
- end
- end
- global.userInputController:rmvKeyboardListener(keyCodes)
- end
- function GUI:addStateEvent(widget, func)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:registerScriptHandler(func)
- end
- -------------------------------------------------------------
- -- ex
- GUI.getChildByID = GUI.getChildByName
- GUI.removeChildByID = GUI.removeChildByName
- ------------------------------------------------------------
- -- Node
- function GUI:Node_Create(parent, ID, x, y)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Node_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Node_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Node_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Widget:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
-
- return widget
- end
- -------------------------------------------------------------
- -- widget
- function GUI:Widget_Create(parent, ID, x, y, width, height)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Widget_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Widget_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Widget_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Widget:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setContentSize(cc.size(width, height))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- -------------------------------------------------------------
- -- image
- function GUI:Image_Create(parent, ID, x, y, nimg)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Image_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Image_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Image_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.ImageView:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadTexture(FixPath(nimg))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- function GUI:Image_loadTexture(widget, filepath)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:loadTexture(FixPath(filepath))
- end
- function GUI:Image_setScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setScale9Enabled(true)
- local contentSize = widget:getVirtualRendererSize()
- local x = scale9l
- local y = scale9t
- local width = contentSize.width-scale9l-scale9r
- local height = contentSize.height-scale9t-scale9b
- widget:setCapInsets({x = x, y = y, width = width, height = height})
- end
- function GUI:Image_setGrey( widget, isGrey )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if isGrey then
- Shader_Grey(widget)
- else
- Shader_Normal(widget)
- end
- end
- function GUI:Image_getTextureFile(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- local data = widget:getRenderFile() or {}
- return data.file, data.type
- end
- -------------------------------------------------------------
- -- Button
- function GUI:Button_Create(parent, ID, x, y, nimg)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Button_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Button_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Button_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Button:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadTextureNormal(FixPath(nimg))
- widget:setTitleFontName(GUI.PATH_FONT2)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return false
- end
-
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- function GUI:Button_loadTextureNormal(widget, filepath)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:loadTextureNormal(FixPath(filepath))
- end
- function GUI:Button_loadTexturePressed(widget, filepath)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:loadTexturePressed(FixPath(filepath))
- end
- function GUI:Button_loadTextureDisabled(widget, filepath)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:loadTextureDisabled(FixPath(filepath))
- end
- function GUI:Button_getTextureNormalFile(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
- local data = widget:getNormalFile() or {}
- return data.file, data.type
- end
- function GUI:Button_getTexturePressedFile(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- local data = widget:getPressedFile() or {}
- return data.file, data.type
- end
- function GUI:Button_getTextureDisabledFile(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- local data = widget:getDisabledFile() or {}
- return data.file, data.type
- end
- function GUI:Button_loadTextures(widget, Normalfilepath, Pressedfilepath, Disabledfilepath, TextureType)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if Normalfilepath and Pressedfilepath and Disabledfilepath and TextureType then
- widget:loadTextures(FixPath(Normalfilepath), FixPath(Pressedfilepath), FixPath(Disabledfilepath), TextureType)
- elseif Normalfilepath and Pressedfilepath and Disabledfilepath then
- widget:loadTextures(FixPath(Normalfilepath), FixPath(Pressedfilepath), FixPath(Disabledfilepath))
- elseif Normalfilepath and Pressedfilepath then
- widget:loadTextures(FixPath(Normalfilepath), FixPath(Pressedfilepath))
- elseif Normalfilepath then
- widget:loadTextures(FixPath(Normalfilepath))
- end
- end
- function GUI:Button_setTitleText(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local label = widget:getTitleRenderer()
- label:setPosition(cc.p(fixPosition(label:getPositionX()), fixPosition(label:getPositionY())))
- widget:setTitleText(value)
- setButtonLabelOffset(widget)
- end
- function GUI:Button_getTitleText(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- return widget:getTitleText()
- end
- function GUI:Button_setTitleColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTitleColor(SL:ConvertColorFromHexString(value))
- end
- function GUI:Button_setTitleFontSize(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTitleFontSize(value)
- setButtonLabelOffset(widget)
- end
- function GUI:Button_setTitleFontName(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTitleFontName(value)
- setButtonLabelOffset(widget)
- end
- function GUI:Button_setBright(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBright(value)
- end
- function GUI:Button_setBrightEx(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTouchEnabled(value)
- widget:setBright(value)
- end
- function GUI:Button_setZoomScale(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget.invalidZoomScale = true
- widget:setZoomScale(value)
- end
- function GUI:Button_setTitleOffset(widget, x, y)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget._x_ = fixPosition(x)
- widget._y_ = fixPosition(y)
- setButtonLabelOffset(widget)
- end
- function GUI:Button_setBrightStyle(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBrightStyle(value)
- end
- function GUI:Button_setMaxLineWidth(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getTitleRenderer():setMaxLineWidth(tonumber(value) or 0)
- end
- function GUI:Button_titleEnableOutline( widget, color, outline )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getTitleRenderer():enableOutline(SL:ConvertColorFromHexString(color), outline)
- end
- function GUI:Button_titleDisableOutLine( widget )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getTitleRenderer():disableEffect(cc.LabelEffect.OUTLINE)
- end
- function GUI:Button_setGrey( widget, isGrey )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if isGrey then
- Shader_Grey(widget)
- else
- Shader_Normal(widget)
- end
- end
- function GUI:Button_setScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setScale9Enabled(true)
- local contentSize = widget:getVirtualRendererSize()
- local x = scale9l
- local y = scale9t
- local width = contentSize.width-scale9l-scale9r
- local height = contentSize.height-scale9t-scale9b
- widget:setCapInsets({x = x, y = y, width = width, height = height})
- end
- -------------------------------------------------------------
- -- Text
- function GUI:Text_Create(parent, ID, x, y, fontSize, fontColor, str)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Text_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Text_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Text_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Text:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setFontName(GUI.PATH_FONT2)
- widget:setFontSize(fontSize)
- if type(fontColor) == "string" and string.find(fontColor, "#") then
- fontColor = SL:ConvertColorFromHexString(fontColor)
- end
- widget:setTextColor(fontColor)
- widget:setString(str)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- --pc 12号宋体
- function GUI:BmpText_Create(parent, ID, x, y, fontColor, str, fontPath)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Text_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Text_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Text_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Text:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if type(fontColor) == "string" and string.find(fontColor, "#") then
- fontColor = SL:ConvertColorFromHexString(fontColor)
- end
- GUI:SetBmpTextProperties(widget)
- widget:setBMFontFilePath(fontPath)
- widget:setFontSize(12)
- if fontColor then
- widget:setTextColor(fontColor)
- end
- widget:setString(str)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return false
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- function GUI:SetBmpTextProperties(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget.getDescription = function ()
- return "BmpText"
- end
- local labelRenderer = widget:getVirtualRenderer()
- widget.setTextColor = function(self, c4b)
- labelRenderer:setColor(c4b)
- end
- widget.getTextColor = function(self)
- return self:getVirtualRenderer():getColor()
- end
- widget.setFontName = function(self, fontName)
- end
- widget.setBMFontFilePath = function (self, fontPath)
- self:getVirtualRenderer():setBMFontFilePath(fontPath or global.MMO.PATH_ST_FONT, cc.p(0, 0), 0)
- end
- widget.getBMPFontpath = function ()
- return global.MMO.PATH_ST_FONT
- end
- widget.setFontSize = function(self, fontSize)
- self:getVirtualRenderer():setBMFontSize(fontSize)
- end
- widget.getFontSize = function (self)
- return self:getVirtualRenderer():getBMFontSize()
- end
- widget.enableOutline = function(self, ...)
- end
- local color = labelRenderer:getTextColor()
- labelRenderer:setColor(color)
- labelRenderer.setTextColor = function (self, c4b)
- labelRenderer:setColor(c4b)
- end
- labelRenderer.enableOutline = function ( )
- end
- widget.getContentSize = function (self)
- return self:getVirtualRenderer():getContentSize()
- end
- labelRenderer.enableUnderline = function()
- if labelRenderer.underline and ( not tolua.isnull( labelRenderer.underline ) ) then
- labelRenderer.underline:removeFromParent()
- labelRenderer.underline = nil
- end
- local underline = UnderLineComponent:create()
- underline:attachToNode( labelRenderer, labelRenderer:getColor() )
- labelRenderer.underline = underline
- end
- end
- function GUI:Text_setString(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setString(value)
- end
- function GUI:Text_getString(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- return widget:getString()
- end
- function GUI:Text_setTextColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTextColor(SL:ConvertColorFromHexString(value))
- end
- function GUI:Text_setFontSize(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setFontSize(value)
- end
- function GUI:Text_getFontSize(widget)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
-
- return widget:getFontSize()
- end
- function GUI:Text_setFontName(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setFontName(value)
- end
- function GUI:Text_enableOutline(widget, color, size)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:enableOutline(SL:ConvertColorFromHexString(color), size)
- end
- function GUI:Text_enableUnderline(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getVirtualRenderer():enableUnderline()
- end
- function GUI:Text_setMaxLineWidth(widget, width)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getVirtualRenderer():setMaxLineWidth(tonumber(width) or 0)
- end
- function GUI:Text_disableEffect( widget, param )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getVirtualRenderer():disableEffect(param)
- end
- function GUI:Text_disableNormal( widget )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getVirtualRenderer():disableEffect(cc.LabelEffect.NORMAL)
- end
- function GUI:Text_disableOutLine( widget )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getVirtualRenderer():disableEffect(cc.LabelEffect.OUTLINE)
- end
- function GUI:Text_disableShadow( widget )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getVirtualRenderer():disableEffect(cc.LabelEffect.SHADOW)
- end
- function GUI:Text_disableGlow( widget )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:getVirtualRenderer():disableEffect(cc.LabelEffect.GLOW)
- end
- function GUI:Text_setTextVerticalAlignment(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTextVerticalAlignment(value)
- end
- function GUI:Text_setTextHorizontalAlignment(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTextHorizontalAlignment(value)
- end
- function GUI:Text_setTextAreaSize(widget, sizeW, sizeH)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local size = nil
- if nil == sizeH then
- size = { width = sizeW.width, height = sizeW.height }
- else
- size = { width = sizeW, height = sizeH }
- end
- widget:setTextAreaSize(size)
- end
- function GUI:Text_COUNTDOWN(widget, time, callback, showType)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local tag = 9963
- local endTime = SL:GetMetaValue("SERVER_TIME") + time
- local remaining = time
- local type = tonumber(showType) or 0
- widget:stopActionByTag(tag)
- local function scheduleCB()
- remaining = math.max(endTime - SL:GetMetaValue("SERVER_TIME"), 0)
- local str = ""
- if not type or type == 0 then
- str = SecondToHMS(remaining, true)
- elseif type == 1 then
- str = TimeFormatToString(remaining)
- end
- widget:setString(str)
-
- if remaining == 0 then
- if callback then
- callback(remaining)
- end
-
- widget:stopActionByTag(tag)
- end
- end
- local action = schedule(widget, scheduleCB, 1)
- action:setTag(tag)
- scheduleCB()
- end
- function GUI:Text_AutoUpdateMetaValue(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- -- 加入元变量组件管理
- local metaValue = {}
- local content = value
- local isMetaValue = false
- while content and string.len(content) > 0 do
- local find_info = {sfind(content, "$STM%((.-)%)")}
- local begin_pos = find_info[1]
- local end_pos = find_info[2]
- if begin_pos and end_pos then
- isMetaValue = true
- -- prefix
- if begin_pos ~= 1 then
- local substr = string.sub(content, 1, begin_pos - 1)
- table.insert(metaValue, substr)
- end
- -- metaValue
- local slices = ssplit(find_info[3], "_")
- table.insert(metaValue, {key = slices[1], param = slices[2]})
- -- suffix
- content = string.sub(content, end_pos + 1, string.len(content))
- else
- table.insert(metaValue, content)
- content = ""
- end
- end
- if isMetaValue then
- global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget})
- return true
- else
- widget:setString(value)
- return false
- end
- end
- function GUI:AutoUpdateMetaValue(widget, key, param)
- local metaValue = {}
- table.insert(metaValue, {key = key, param = param})
- global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget})
- end
- -- scroll text
- function GUI:ScrollText_Create(parent, ID, x, y, width, fontSize, fontColor, str, scrollTime, fontPath)
- if not ID then
- SL:Print("[GUI ERROR] GUI:ScrollText_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ScrollText_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:ScrollText_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Layout:create()
- widget:setName(ID)
- widget:setClippingEnabled(true)
- widget:setClippingType(0)
- widget:setTouchEnabled(false)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- local Text = ccui.Text:create()
- Text:setName("Text")
- Text:setFontName(fontPath or GUI.PATH_FONT2)
- Text:setFontSize(fontSize)
- Text:setTextColor(SL:ConvertColorFromHexString(fontColor))
- Text:setAnchorPoint(cc.p(0, 0))
- Text:setPosition(cc.p(0, 0))
- Text:setString(str)
- if scrollTime then
- Text._scrollTime = scrollTime
- end
- widget:setContentSize({width = width, height = Text:getContentSize().height})
- widget:addChild(Text)
- GUI:refScrollText(widget, Text, scrollTime)
- return widget
- end
- function GUI:refScrollText(widget, Text, scrollTime)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- Text:stopAllActions()
- scrollTime = scrollTime or 4
- local textWid = Text:getContentSize().width
- local widgetWid = widget:getContentSize().width
- local dis = textWid - widgetWid
- if dis > 0 then
- local anrX = Text:getAnchorPoint().x
- local x = (widgetWid+dis) * anrX
- Text:setPositionX(x)
- Text:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.MoveBy:create(scrollTime, cc.p(-textWid, 0)), cc.MoveBy:create(0, cc.p(textWid, 0)))))
- else
- local anr = Text:getAnchorPoint()
- local x = math.abs(dis/2) + textWid * anr.x
- Text:setPositionX(x)
- end
- end
- function GUI:ScrollText_setString(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local Text = widget:getChildByName("Text")
- if Text then
- Text:setString(value)
- widget:setContentSize({width = widget:getContentSize().width, height = Text:getContentSize().height})
- GUI:refScrollText(widget, Text, Text._scrollTime)
- end
- end
- function GUI:ScrollText_enableOutline(widget, color, size)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local Text = widget:getChildByName("Text")
- if Text then
- Text:enableOutline(SL:ConvertColorFromHexString(color), size)
- widget:setContentSize({width = widget:getContentSize().width, height = Text:getContentSize().height})
- end
- end
- function GUI:ScrollText_getString(widget, value)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- local Text = widget:getChildByName("Text")
- if Text then
- return Text:getString()
- end
- end
- -- value: 1: 左; 2: 中; 3:右
- function GUI:ScrollText_setHorizontalAlignment(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local Text = widget:getChildByName("Text")
- if Text then
- local width = widget:getContentSize().width
- local anrX = value == 2 and 0.5 or (value == 3 and 1 or 0)
- local posX = value == 2 and width / 2 or (value == 3 and width or 0)
- Text:setAnchorPoint(cc.p(anrX, 0))
- Text:setPositionX(posX)
- end
- end
- function GUI:ScrollText_setTextColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local Text = widget:getChildByName("Text")
- if Text then
- Text:setTextColor(SL:ConvertColorFromHexString(value))
- end
- end
- -------------------------------------------------------------
- -- Label
- function GUI:Label_Create(parent, ID, x, y, text, fontPath, fontSize, fontColor)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Label_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Label_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Label_Create ID is exists", ID)
- return nil
- end
- if not fontPath or not SL:IsFileExist(fontPath) then
- SL:Print("[GUI ERROR] GUI:Label_Create can't find fontPath ", fontPath)
- return nil
- end
- local widget = cc.Label:createWithTTF(text, fontPath, fontSize)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if type(fontColor) == "string" and string.find(fontColor, "#") then
- fontColor = SL:ConvertColorFromHexString(fontColor)
- end
- if fontColor then
- widget:setColor(fontColor)
- end
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- -------------------------------------------------------------
- -- Layout
- function GUI:Layout_Create(parent, ID, x, y, width, height, isClip)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Layout_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Layout_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Layout_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Layout:create()
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- elseif "ccui.PageView" == tolua.type(parent) then
- parent:addPage(widget)
- else
- parent:addChild(widget)
- end
- end
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setContentSize(cc.size(width, height))
- if isClip and type(isClip) == "boolean" then
- widget:setClippingEnabled(isClip)
- end
- widget:setClippingType(0)
- return widget
- end
- function GUI:Layout_setBackGroundColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local paramList = {}
- if type(value) == "table" then
- for i, v in ipairs(value) do
- paramList[i] = SL:ConvertColorFromHexString(v)
- end
- else
- paramList[1] = SL:ConvertColorFromHexString(value)
- end
- if #paramList == 2 then
- widget:setBackGroundColor(paramList[1], paramList[2])
- else
- widget:setBackGroundColor(paramList[1])
- end
- end
- function GUI:Layout_setBackGroundColorType(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setBackGroundColorType(value)
- end
- function GUI:Layout_setBackGroundColorOpacity(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundColorOpacity(value)
- end
- function GUI:Layout_setClippingEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setClippingEnabled(value)
- end
- function GUI:Layout_setBackGroundImage(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImage(value, 0)
- end
- function GUI:Layout_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImageScale9Enabled(true)
- local contentSize = widget:getBackGroundImageTextureSize()
- local x = scale9l
- local y = scale9t
- local width = contentSize.width-scale9l-scale9r
- local height = contentSize.height-scale9t-scale9b
- local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
- widget:setBackGroundImageCapInsets(capInsets)
- end
- function GUI:Layout_setBackGroundImageOpacity(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImageOpacity(value)
- end
- function GUI:Layout_removeBackGroundImage(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeBackGroundImage()
- end
- function GUI:Layout_getBackGroundImageFile(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- local data = widget:getRenderFile() or {}
- return data.file, data.type
- end
- function GUI:Layout_debug(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundColorType(1)
- widget:setBackGroundColorOpacity(155)
- widget:setBackGroundColor(cc.c3b(0xff, 0, 0))
- end
- function GUI:Layout_getLayoutType(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getLayoutType()
- end
- function GUI:Layout_setLayoutType(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setLayoutType(value)
- end
- -------------------------------------------------------------
- -- LoadingBar
- function GUI:LoadingBar_Create(parent, ID, x, y, nimg, direction)
- if not ID then
- SL:Print("[GUI ERROR] GUI:LoadingBar_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:LoadingBar_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:LoadingBar_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.LoadingBar:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadTexture(FixPath(nimg))
- widget:setDirection(direction)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:LoadingBar_loadTexture(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:loadTexture(FixPath(value))
- end
- function GUI:LoadingBar_setDirection(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setDirection(value)
- end
- function GUI:LoadingBar_getDirection(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getDirection()
- end
- function GUI:LoadingBar_setPercent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setPercent(value)
- end
- function GUI:LoadingBar_getPercent(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getPercent()
- end
- function GUI:LoadingBar_setColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setColor(SL:ConvertColorFromHexString(value))
- end
- function GUI:LoadingBar_getColor(widget)
- if CheckIsInvalidCObject(widget) then
- return "#ffffff"
- end
-
- return GetColorHexFromRBG(widget:getColor())
- end
- -------------------------------------------------------------
- -- TextInput
- function GUI:TextInput_Create(parent, ID, x, y, width, height, fontSize)
- if not ID then
- SL:Print("[GUI ERROR] GUI:TextInput_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:TextInput_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:TextInput_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.EditBox:create(cc.size(width, height), GUI.PATH_RES_ALPHA)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if global.isMobile then
- widget:setFontName(GUI.PATH_FONT2)
- end
- widget:setFontSize( fontSize )
- widget:setFontColor(cc.c3b(255, 255, 255))
- widget:setPlaceholderFontSize(fontSize)
- if global.Platform == cc.PLATFORM_OS_ANDROID then
- x = x + 1
- y = y + 1
- widget:setNativeOffset(cc.p(0, -13))
- end
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return false
- end
-
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:TextInput_setFontColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setFontColor(SL:ConvertColorFromHexString(value))
- end
- function GUI:TextInput_setFont(widget, value, value2)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if global.isMobile then
- widget:setFont(value, value2)
- else
- widget:setFontSize(value2)
- SL:Print("[GUI LOG] GUI:TextInput_setFont will support on mobile device")
- end
- end
- function GUI:TextInput_setFontSize(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setFontSize(value)
- end
- function GUI:TextInput_setPlaceholderFont(widget, value, value2)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setPlaceholderFont(value, value2)
- end
- function GUI:TextInput_setPlaceholderFontColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setPlaceholderFontColor(SL:ConvertColorFromHexString(value))
- end
- function GUI:TextInput_setPlaceholderFontSize(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setPlaceholderFontSize(value)
- end
- function GUI:TextInput_setPlaceHolder(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setPlaceHolder(value)
- end
- function GUI:TextInput_setMaxLength(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setMaxLength(value)
- end
- function GUI:TextInput_setString(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setString(value)
- end
- function GUI:TextInput_getString(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
-
- return widget:getString()
- end
- function GUI:TextInput_setTextHorizontalAlignment(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTextHorizontalAlignment(value)
- end
- -- 增加空方法防止报错
- function GUI:TextInput_setTextVerticalAlignment(widget, value)
-
- end
- function GUI:TextInput_setInputFlag(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setInputFlag(value)
- end
- function GUI:TextInput_setInputMode(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setInputMode(value)
- end
- function GUI:TextInput_setNativeOffset(widget, value, value1)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setNativeOffset( cc.p( value, value1 ) )
- end
- function GUI:TextInput_setReturnType(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setReturnType(value)
- end
- function GUI:TextInput_addOnEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addEventListener(function(_, eventType)
- eventCB(widget, eventType)
- end)
- end
- function GUI:TextInput_touchDownAction(widget, type)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:touchDownAction(widget, type)
- end
- function GUI:TextInput_closeInput(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if widget.closeKeyboard then
- widget:closeKeyboard()
- end
- end
- -------------------------------------------------------------
- -- TextAtlas
- function GUI:TextAtlas_Create(parent, ID, x, y, stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
- if not ID then
- SL:Print("[GUI ERROR] GUI:TextAtlas_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:TextAtlas_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:TextAtlas_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.TextAtlas:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- -- Custom Func
- if SL._DEBUG then
- GUI:TextAtlas_SetCustomFunc(widget)
- end
- GUI:TextAtlas_setProperty(widget, stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return false
- end
-
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:TextAtlas_SetCustomFunc(widget)
- -- Set Func
- widget.setStringValue = function (self, value)
- self._stringValue_ = value
- end
- widget.setCharMapFile = function (self, value)
- self._charMapFile_ = value
- end
- widget.setItemWidth = function (self, value)
- self._itemWidth_ = value
- end
- widget.setItemHeight = function (self, value)
- self._itemHeight_ = value
- end
- widget.setStartCharMap = function (self, value)
- self._startCharMap_ = value
- end
- -- Get Func
- widget.getStringValue = function (self)
- return self._stringValue_ or ""
- end
- widget.getCharMapFile = function (self)
- return self._charMapFile_ or "res/private/gui_edit/TextAtlas.png"
- end
- widget.getItemWidth = function (self)
- return self._itemWidth_ or 0
- end
- widget.getItemHeight = function (self)
- return self._itemHeight_ or widget:getContentSize().height
- end
- widget.getStartCharMap = function (self)
- return self._startCharMap_ or ""
- end
- end
- function GUI:TextAtlas_setProperty(widget, stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if SL._DEBUG then
- widget:setStringValue(stringValue)
- widget:setCharMapFile(charMapFile)
- widget:setItemWidth(itemWidth)
- widget:setItemHeight(itemHeight)
- widget:setStartCharMap(startCharMap)
- end
- widget:setProperty(stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
- end
- function GUI:TextAtlas_setString(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setString(value)
- end
- function GUI:TextAtlas_getString(widget)
- if CheckIsInvalidCObject(widget) then
- return ""
- end
- return widget:getString()
- end
- -------------------------------------------------------------
- -- Slider
- function GUI:Slider_Create(parent, ID, x, y, barimg, pbarimg, nimg)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Slider_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Slider_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Slider_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.Slider:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadBarTexture(FixPath(barimg) or "res/public/bg_szjm_01.png", 0)
- widget:loadProgressBarTexture(FixPath(pbarimg) or "res/public/bg_szjm_02.png", 0)
- widget:loadSlidBallTextureNormal(FixPath(nimg) or "res/private/setting_basic/icon_xdtzy_17.png", 0)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:Slider_loadBarTexture(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:loadBarTexture(FixPath(value))
- end
- function GUI:Slider_loadProgressBarTexture(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:loadProgressBarTexture(FixPath(value))
- end
- function GUI:Slider_loadSlidBallTextureNormal(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:loadSlidBallTextureNormal(FixPath(value))
- end
- function GUI:Slider_setPercent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setPercent(value)
- end
- function GUI:Slider_getPercent(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
- return widget:getPercent()
- end
- function GUI:Slider_setMaxPercent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setMaxPercent(value)
- end
- function GUI:Slider_addOnEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:addEventListener(function(_, eventType)
- eventCB(widget, eventType)
- end)
- end
- -------------------------------------------------------------
- -- ListView
- function GUI:ListView_Create(parent, ID, x, y, width, height, direction)
- if not ID then
- SL:Print("[GUI ERROR] GUI:ListView_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ListView_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:ListView_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.ListView:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setContentSize(cc.size(width, height))
- widget:setClippingEnabled(true)
- widget:setClippingType(0)
- widget:setTouchEnabled(true)
- widget:setDirection(direction)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
-
- return widget
- end
- function GUI:ListView_setGravity(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setGravity(value)
- end
- function GUI:ListView_setDirection(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setDirection(value)
- end
- function GUI:ListView_getDirection(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getDirection()
- end
- function GUI:ListView_setItemsMargin(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setItemsMargin(value)
- end
- function GUI:ListView_setBounceEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBounceEnabled(value)
- end
- function GUI:ListView_setClippingEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setClippingEnabled(value)
- end
- function GUI:ListView_setBackGroundColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local paramList = {}
- if type(value) == "table" then
- for i, v in ipairs(value) do
- paramList[i] = SL:ConvertColorFromHexString(v)
- end
- else
- paramList[1] = SL:ConvertColorFromHexString(value)
- end
- if #paramList == 2 then
- widget:setBackGroundColor(paramList[1], paramList[2])
- else
- widget:setBackGroundColor(paramList[1])
- end
- end
- function GUI:ListView_setBackGroundColorType(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundColorType(value)
- end
- function GUI:ListView_setBackGroundColorOpacity(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundColorOpacity(value)
- end
- function GUI:ListView_pushBackCustomItem(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:pushBackCustomItem(value)
- end
- function GUI:ListView_insertCustomItem(widget, value, value2)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:insertCustomItem(value, value2)
- end
- function GUI:ListView_removeAllItems(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeAllItems()
- end
- function GUI:ListView_removeItemByIndex(widget, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeItem(index)
- end
- function GUI:ListView_jumpToItem(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local index = math.max(value, 0)
- widget:jumpToItem(index, cc.p(0, 0), cc.p(0, 0))
- end
- function GUI:ListView_getItemIndex(widget, value)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getIndex(value)
- end
- function GUI:ListView_getItemByIndex(widget, value)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
-
- return widget:getItem(value)
- end
- function GUI:ListView_doLayout(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:doLayout()
- end
- function GUI:ListView_setBackGroundImage(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImage(value, 0)
- end
- function GUI:ListView_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImageScale9Enabled(true)
- local contentSize = widget:getBackGroundImageTextureSize()
- local x = scale9l
- local y = scale9t
- local width = contentSize.width-scale9l-scale9r
- local height = contentSize.height-scale9t-scale9b
- local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
- widget:setBackGroundImageCapInsets(capInsets)
- end
- function GUI:ListView_removeBackGroundImage(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeBackGroundImage()
- end
- function GUI:ListView_getItemsMargin(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getItemsMargin()
- end
- function GUI:ListView_getItems(widget)
- if CheckIsInvalidCObject(widget) then
- return {}
- end
-
- return widget:getItems()
- end
- function GUI:ListView_getItemCount(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return #widget:getItems()
- end
- function GUI:ListView_getInnerContainer(widget)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
-
- return widget:getInnerContainer()
- end
- function GUI:ListView_addOnScrollEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addScrollViewEventListener(function(_, eventType)
- eventCB(widget, eventType)
- end)
- end
- function GUI:ListView_paintItems(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:paintItems()
- end
- function GUI:ListView_autoPaintItems(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local function eventCB(_, eventType)
- if eventType == 9 then
- widget:paintItems()
- end
- end
- widget:addScrollViewEventListener(eventCB)
- end
- function GUI:ListView_removeChild(widget, item)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeChild(item, true)
- end
- function GUI:ListView_jumpToBottom(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:jumpToBottom()
- end
- function GUI:ListView_jumpToTop(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:jumpToTop()
- end
- function GUI:ListView_getTopmostItemInCurrentView(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return ({[1] = widget:getTopmostItemInCurrentView(), [2] = widget:getLeftmostItemInCurrentView()})[widget:getDirection()] or nil
- end
- function GUI:ListView_getBottommostItemInCurrentView(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return ({[1] = widget:getBottommostItemInCurrentView(), [2] = widget:getRightmostItemInCurrentView()})[widget:getDirection()] or nil
- end
- function GUI:ListView_scrollToTop(widget,time, boolvalue)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToTop(time, boolvalue)
- end
- function GUI:ListView_scrollToBottom(widget, time, boolvalue)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToBottom(time, boolvalue)
- end
- function GUI:ListView_getInnerContainerSize(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.size(0, 0)
- end
-
- return widget:getInnerContainerSize()
- end
- function GUI:ListView_getInnerContainerPosition(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.p(0, 0)
- end
-
- return widget:getInnerContainerPosition()
- end
- function GUI:ListView_setInnerContainerPosition(widget, value1, value2)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if type(value1) == "table" then
- widget:setInnerContainerPosition(value1)
- elseif value1 and value2 then
- widget:setInnerContainerPosition(cc.p(value1, value2))
- end
- end
- -- bool 是否衰减滚动速度(垂直方向)
- function GUI:ListView_scrollToPercentVertical(widget, percent, time, bool)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToPercentVertical(percent, time, bool)
- end
- -- bool 是否衰减滚动速度(水平方向)
- function GUI:ListView_scrollToPercentHorizontal(widget, percent, time, bool)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToPercentHorizontal(percent, time, bool)
- end
- function GUI:ListView_addMouseScrollPercent(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addMouseScrollPercent()
- end
- function GUI:ListView_setItemModel(widget, itemWidget)
- if CheckIsInvalidCObject(widget) or CheckIsInvalidCObject(itemWidget) then
- return false
- end
-
- widget:setItemModel(itemWidget)
- end
- function GUI:ListView_pushBackDefaultItem(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:pushBackDefaultItem()
- end
- -------------------------------------------------------------
- -- ScrollView
- function GUI:ScrollView_Create(parent, ID, x, y, width, height, direction)
- if not ID then
- SL:Print("[GUI ERROR] GUI:ScrollView_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ScrollView_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:ScrollView_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.ScrollView:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setContentSize(cc.size(width, height))
- widget:setClippingEnabled(true)
- widget:setClippingType(0)
- widget:setTouchEnabled(true)
- widget:setDirection(direction) -- direction: 1-垂直; 2-水平
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
-
- return widget
- end
- function GUI:ScrollView_setInnerContainerSize(widget, sizeW, sizeH)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local size = nil
- if nil == sizeH then
- size = { width = sizeW.width, height = sizeW.height }
- else
- size = { width = sizeW, height = sizeH }
- end
- widget:setInnerContainerSize(size)
- end
- function GUI:ScrollView_getInnerContainerSize(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.size(0, 0)
- end
- return widget:getInnerContainerSize()
- end
- function GUI:ScrollView_getInnerContainerPosition(widget)
- if CheckIsInvalidCObject(widget) then
- return cc.p(0, 0)
- end
-
- return widget:getInnerContainerPosition()
- end
- function GUI:ScrollView_setInnerContainerPosition(widget, value1, value2)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if type(value1) == "table" then
- widget:setInnerContainerPosition(value1)
- elseif value1 and value2 then
- widget:setInnerContainerPosition(cc.p(value1, value2))
- end
- end
- function GUI:ScrollView_setDirection(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setDirection(value)
- end
- function GUI:ScrollView_getDirection(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getDirection()
- end
- function GUI:ScrollView_setBounceEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setBounceEnabled(value)
- end
- function GUI:ScrollView_setClippingEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setClippingEnabled(value)
- end
- function GUI:ScrollView_setBackGroundColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local paramList = {}
- if type(value) == "table" then
- for i, v in ipairs(value) do
- paramList[i] = SL:ConvertColorFromHexString(v)
- end
- else
- paramList[1] = SL:ConvertColorFromHexString(value)
- end
- if #paramList == 2 then
- widget:setBackGroundColor(paramList[1], paramList[2])
- else
- widget:setBackGroundColor(paramList[1])
- end
- end
- function GUI:ScrollView_setBackGroundColorType(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setBackGroundColorType(value)
- end
- function GUI:ScrollView_setBackGroundColorOpacity(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setBackGroundColorOpacity(value)
- end
- function GUI:ScrollView_addChild(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if CheckIsInvalidCObject(value) then
- return false
- end
- widget:addChild(value)
- end
- function GUI:ScrollView_removeAllChildren(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:removeAllChildren()
- end
- function GUI:ScrollView_scrollToTop(widget, time, boolvalue)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:scrollToTop(time, boolvalue)
- end
- function GUI:ScrollView_scrollToBottom(widget, time, boolvalue)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:scrollToBottom(time, boolvalue)
- end
- function GUI:ScrollView_scrollToLeft(widget, time, boolvalue)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:scrollToLeft(time, boolvalue)
- end
- function GUI:ScrollView_scrollToRight(widget, time, boolvalue)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:scrollToRight(time, boolvalue)
- end
- function GUI:ScrollView_scrollToTopLeft(widget, time, boolvalue)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:scrollToTopLeft(time, boolvalue)
- end
- function GUI:ScrollView_setBackGroundImage(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImage(value, 0)
- end
- function GUI:ScrollView_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImageScale9Enabled(true)
- local contentSize = widget:getBackGroundImageTextureSize()
- local x = scale9l
- local y = scale9t
- local width = contentSize.width-scale9l-scale9r
- local height = contentSize.height-scale9t-scale9b
- local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
- widget:setBackGroundImageCapInsets(capInsets)
- end
- function GUI:ScrollView_removeBackGroundImage(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeBackGroundImage()
- end
- function GUI:ScrollView_addOnScrollEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addEventListener(function(_, eventType)
- eventCB(widget, eventType)
- end)
- end
- -- bool 是否衰减滚动速度(垂直方向)
- function GUI:ScrollView_scrollToPercentVertical(widget, percent, time, bool)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToPercentVertical(percent, time, bool)
- end
- -- bool 是否衰减滚动速度(水平方向)
- function GUI:ScrollView_scrollToPercentHorizontal(widget, percent, time, bool)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToPercentHorizontal(percent, time, bool)
- end
- -------------------------------------------------------------
- -- CheckBox
- function GUI:CheckBox_Create(parent, ID, x, y, nimg, pimg)
- if not ID then
- SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:CheckBox_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.CheckBox:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadTextureBackGround(FixPath(nimg))
- widget:loadTextureFrontCross(FixPath(pimg))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:CheckBox_loadTextureBackGround(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:loadTextureBackGround(FixPath(value))
- end
- function GUI:CheckBox_loadTextureFrontCross(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:loadTextureFrontCross(FixPath(value))
- end
- function GUI:CheckBox_loadTextureFrontCrossDisabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:loadTextureFrontCrossDisabled(FixPath(value))
- end
- function GUI:CheckBox_setSelected(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setSelected(value)
- end
- function GUI:CheckBox_isSelected(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:isSelected()
- end
- function GUI:CheckBox_addOnEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addEventListener(function(_, eventType)
- eventCB(widget, eventType)
- end)
- end
- function GUI:CheckBox_setZoomScale(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setZoomScale(value)
- end
- -------------------------------------------------------------
- -- Effect
- function GUI:Effect_Create(parent, ID, x, y, effectType, effectId, sex, act, dir, speed)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Effect_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Effect_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Effect_Create ID is exists", ID)
- return nil
- end
- sex = sex or 0
- act = act or 0
- dir = dir or 0
- speed = speed or 1
- local widget = nil
- if effectType == 0 then
- -- 特效
- widget = global.FrameAnimManager:CreateSFXAnim(effectId)
- widget:Play(0, 0, true, speed)
-
- elseif effectType == 1 then
- -- NPC
- widget = global.FrameAnimManager:CreateActorNpcAnim(effectId)
- widget:Play(act, dir, true, speed)
- elseif effectType == 2 then
- -- 怪物
- widget = global.FrameAnimManager:CreateActorMonsterAnim(effectId, act)
- widget:Play(act, dir, true, speed)
- elseif effectType == 3 then
- -- 技能
- widget = global.FrameAnimManager:CreateSkillEffAnim(effectId, dir)
- widget:Play(act, dir, true, speed)
- elseif effectType == 4 then
- -- 人物
- widget = global.FrameAnimManager:CreateActorPlayerAnim(effectId, sex, act)
- widget:Play(act, dir, true, speed)
- elseif effectType == 5 then
- -- 武器
- widget = global.FrameAnimManager:CreateActorPlayerWeaponAnim(effectId, sex, act)
- widget:Play(act, dir, true, speed)
- elseif effectType == 6 then
- -- 翅膀
- widget = global.FrameAnimManager:CreateActorPlayerWingsAnim(effectId, sex, act)
- widget:Play(act, dir, true, speed)
- elseif effectType == 7 then
- -- 发型
- widget = global.FrameAnimManager:CreateActorPlayerHairAnim(effectId, sex, act)
- widget:Play(act, dir, true, speed)
- elseif effectType == 8 then
- -- 盾牌
- widget = global.FrameAnimManager:CreateActorPlayerShieldAnim(effectId, sex, act)
- widget:Play(act, dir, true, speed)
- else
- widget = global.FrameAnimManager:CreateSFXAnim(1)
- widget:Play(0, 0, true, speed)
- end
-
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:Effect_play(widget, act, dir, isLoop, speed, isSequence)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:Stop()
- widget:Play(act, dir, isLoop, speed, isSequence)
- end
- function GUI:Effect_stop(widget, frameIndex, act, dir)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:Stop(frameIndex, act, dir)
- end
- function GUI:Effect_addOnCompleteEvent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:SetAnimEventCallback(value)
- end
- function GUI:Effect_setGlobalElapseEnable(widget, elapseEnable)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:SetGlobalElapseEnable(elapseEnable)
- end
- function GUI:Effect_setAutoRemoveOnFinish(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local function removeEvent()
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:removeFromParent()
- end
- widget:SetAnimEventCallback(removeEvent)
- end
- -------------------------------------------------------------
- -- RichText
- function GUI:RichText_Create(parent, ID, x, y, str, width, fontSize, fontColor, vspace, hyperlinkCB, defaultFontFace)
- if not ID then
- SL:Print("[GUI ERROR] GUI:RichText_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:RichText_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:RichText_Create ID is exists", ID)
- return nil
- end
- local color
- if type(fontColor) == "table" then
- color = GetColorHexFromRBG(fontColor)
- end
- local RichTextHelp = requireUtil("RichTextHelp")
- local widget = RichTextHelp:CreateRichTextWithXML(str, width, fontSize, color or fontColor, defaultFontFace, hyperlinkCB, vspace)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:formatText()
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- -- 原始富文本
- function GUI:RichTextFCOLOR_Create(parent, ID, x, y, str, width, fontSize, color, vspace, hyperlinkCB, fontPath, outlineParam)
- if not ID then
- SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create ID is exists", ID)
- return nil
- end
- if type(color) == "string" and string.find(color, "#") then
- color = SL:ConvertColorFromHexString(color)
- end
- local RichTextHelp = requireUtil("RichTextHelp")
- local ttfConfig = {
- outlineSize = outlineParam and outlineParam.outlineSize,
- outlineColor= outlineParam and outlineParam.outlineColor
- }
- local widget = RichTextHelp:CreateRichTextWithFCOLOR(str, width, fontSize, color, ttfConfig, hyperlinkCB, vspace, fontPath)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:formatText()
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
-
- parent:addChild(widget)
- end
-
- return widget
- end
- -- 自定义富文本带道具图片
- function GUI:RichTextCustom_Create(parent, ID, x, y, str, width, vspace)
- if not ID then
- SL:Print("[GUI ERROR] GUI:RichTextCustom_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:RichTextCustom_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:RichTextCustom_Create ID is exists", ID)
- return nil
- end
- local RichTextHelpEx = requireUtil("RichTextHelpEx")
- local widget = RichTextHelpEx:CreateRichTextWithCustom(str, width, vspace)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:RichTextFCOLOR_setBackgroundColor(widget, color)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if type(color) == "string" and string.find(color, "#") then
- color = SL:ConvertColorFromHexString(color)
- end
- widget:setBackgroundColor(color)
- widget:setBackgroundColorEnable(true)
- end
- -- SRText富文本
- function GUI:RichTextSR_Create(parent, ID, x, y, str, width, fontSize, color, vspace, hyperlinkCB, fontPath)
- if not ID then
- SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create ID is exists", ID)
- return nil
- end
- local RichTextHelp = requireUtil("RichTextHelp")
- local widget = RichTextHelp:CreateRichTextWidthSRText(str, width, fontSize, color, fontPath, hyperlinkCB, vspace)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:formatText()
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
-
- return widget
-
- end
- -- 自定义组合富文本
- function GUI:RichTextCombine_Create(parent, ID, x, y, width, vspace)
- if not ID then
- SL:Print("[GUI ERROR] GUI:RichTextCombine_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:RichTextCombine_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:RichTextCombine_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.RichText:create()
- widget:ignoreContentAdaptWithSize(false)
- widget:setContentSize(width, 0)
- widget:setVerticalSpace(vspace)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setName(ID)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:RichTextCombine_pushBackElements(widget, elements)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if not elements then
- return
- end
- if next(elements) then
- for _, v in ipairs(elements) do
- widget:pushBackElement(v)
- end
- else
- widget:pushBackElement(elements)
- end
- end
- function GUI:RichTextCombine_format(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:formatText()
- end
- local ELEMENT_TEXT_WAY = {
- ITALICS_FLAG = 1, -- italic text
- BOLD_FLAG = 2, -- bold text
- UNDERLINE_FLAG = 4, -- underline
- STRIKETHROUGH_FLAG = 8, -- strikethrough
- URL_FLAG = 16, -- url of anchor
- OUTLINE_FLAG = 32, -- outline effect
- SHADOW_FLAG = 64, -- shadow effect
- GLOW_FLAG = 128
- }
- function GUI:RichTextCombineCell_Create(parent, ID, x, y, type, param)
- if not ID then
- SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create can't find parent", ID)
- return nil
- end
- if parent ~= NONEED_PARENT_CODE and tolua.type(parent) ~= "ccui.RichText" then
- SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create parent type is wrong", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create ID is exists", ID)
- return nil
- end
- local widget = nil
- local color = param.color and GetColorFromHexString(param.color) or cc.Color3B.WHITE
- local opacity = param.opacity or 255
- local fontPath = param.fontPath or global.MMO.PATH_FONT2
- local fontSize = param.fontSize or global.ConstantConfig.DEFAULT_FONT_SIZE
- local outlineColor = param.outlineColor and GetColorFromHexString(param.outlineColor) or cc.Color3B.BLACK
- local outlineSize = param.outlineSize or 0
- if type == 1 or string.upper(type) == "TEXT" then
- local wayType = ELEMENT_TEXT_WAY.OUTLINE_FLAG
- if param.link then
- wayType = wayType + ELEMENT_TEXT_WAY.URL_FLAG
- end
- widget = ccui.RichElementText:create(0, color, opacity, param.str or "", fontPath, fontSize, wayType, param.link or "", outlineColor, outlineSize)
- elseif type == 2 or string.upper(type) == "NODE" then
- widget = ccui.RichElementCustomNode:create(0, color, opacity, param.node)
- elseif type == 3 or string.upper(type) == "NEWLINE" then
- widget = ccui.RichElementNewLine:create(0, color, opacity)
- end
- if widget and parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:pushBackElement(widget)
- end
- return widget
- end
- function GUI:RichText_setBackgroundColor(widget, color)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if type(color) == "string" and string.find(color, "#") then
- color = SL:ConvertColorFromHexString(color)
- end
- widget:setBackgroundColor(color)
- widget:setBackgroundColorEnable(true)
- end
- function GUI:RichText_setOpenUrlEvent(widget, handle)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setOpenUrlHandler(function(sender, str)
- handle(sender, str)
- end)
- end
- -------------------------------------------------------------
- -- PageView
- function GUI:PageView_Create(parent, ID, x, y, width, height)
- if not ID then
- SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:PageView_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:CheckBox_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.PageView:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setClippingType(0)
- widget:setContentSize(cc.size(width, height))
- widget:setClippingEnabled(true)
- widget:setTouchEnabled(true)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:PageView_setClippingEnabled(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setClippingEnabled(value)
- end
- function GUI:PageView_setBackGroundColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local paramList = {}
- if type(value) == "table" then
- for i, v in ipairs(value) do
- paramList[i] = SL:ConvertColorFromHexString(v)
- end
- else
- paramList[1] = SL:ConvertColorFromHexString(value)
- end
- if #paramList == 2 then
- widget:setBackGroundColor(paramList[1], paramList[2])
- else
- widget:setBackGroundColor(paramList[1])
- end
- end
- function GUI:PageView_setBackGroundColorType(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundColorType(value)
- end
- function GUI:PageView_setBackGroundColorOpacity(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundColorOpacity(value)
- end
- function GUI:PageView_setBackGroundImage(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImage(value, 0)
- end
- function GUI:PageView_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setBackGroundImageScale9Enabled(true)
- local contentSize = widget:getBackGroundImageTextureSize()
- local x = scale9l
- local y = scale9t
- local width = contentSize.width-scale9l-scale9r
- local height = contentSize.height-scale9t-scale9b
- local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
- widget:setBackGroundImageCapInsets(capInsets)
- end
- function GUI:PageView_removeBackGroundImage(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:removeBackGroundImage()
- end
- function GUI:PageView_scrollToItem(widget, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToItem(index)
- end
- function GUI:PageView_setCurrentPageIndex(widget, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setCurrentPageIndex(index)
- end
- function GUI:PageView_getCurrentPageIndex(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getCurrentPageIndex()
- end
- function GUI:PageView_getItems(widget)
- if CheckIsInvalidCObject(widget) then
- return {}
- end
-
- return widget:getItems()
- end
- function GUI:PageView_getItemCount(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return #widget:getItems()
- end
- function GUI:PageView_addPage(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if CheckIsInvalidCObject(value) then
- return false
- end
-
- widget:addPage(value)
- end
- function GUI:PageView_addOnEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addEventListener(function(_, eventType)
- eventCB(widget, eventType)
- end)
- end
- ------------------------------------------------------------
- --- TableView
- function GUI:TableView_Create(parent, ID, x, y, width, height, direction, cellWid, cellHei, num, jumpIndex)
- if not ID then
- SL:Print("[GUI ERROR] GUI:TableView_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:TableView_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:TableView_Create ID is exists", ID)
- return nil
- end
- local tableViewDirection = { -- 1垂直; 2水平
- [1] = cc.SCROLLVIEW_DIRECTION_VERTICAL,
- [2] = cc.SCROLLVIEW_DIRECTION_HORIZONTAL,
- }
- local widget = nil
- widget = TableViewEx.create({
- size = cc.size(width, height),
- direction = direction and tableViewDirection[direction],
- cellSizeForTable = function (tv, view, idx)
- return cellWid, cellHei
- end,
- numberOfCellsInTableView = function (tv, view)
- return num
- end,
- tableCellAtIndex = function (tv, view, idx)
- local i = idx + 1
- local cell = view:dequeueCell()
- if not cell then
- cell = cc.TableViewCell:new()
- else
- cell:removeAllChildren()
- end
- if widget and widget.TableViewCell_Create then
- widget.TableViewCell_Create(cell, i, ID)
- end
- return cell
- end
- })
- widget.getDescription = function()
- return "TableView"
- end
- widget:setCascadeColorEnabled(true)
- widget:setCascadeOpacityEnabled(true)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setContentSize(cc.size(width, height))
- widget:setTouchEnabled(true)
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:TableView_setCellCreateEvent(widget, func)
- if type(func) == "function" then
- widget.TableViewCell_Create = func
- end
- widget:registerScriptHandler()
- end
- function GUI:TableView_setDirection(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local tableViewDirection = {
- [1] = cc.SCROLLVIEW_DIRECTION_VERTICAL,
- [2] = cc.SCROLLVIEW_DIRECTION_HORIZONTAL,
- }
- if value and tableViewDirection[value] then
- widget:setDirection(tableViewDirection[value])
- end
- end
- function GUI:TableView_getDirection(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getDirectionEx()
- end
- function GUI:TableView_setVerticalFillOrder(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setVerticalFillOrder(value)
- end
- function GUI:TableView_setContentOffset(widget, x, y)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setContentOffset(cc.p(x, y))
- end
- function GUI:TableView_getContentOffset(widget)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
- return widget:getContentOffset()
- end
- function GUI:TableView_setBackGroundColor(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if type(value) == "string" and string.find(value, "#") then
- value = GetColorFromHexString(value)
- end
- widget:SetBackColor(value)
- end
- function GUI:TableView_addTableCellAtIndexEvent(widget, func)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTableCellAtIndexHandler(func)
- end
- function GUI:TableView_addOnTouchedCellEvent(widget, func)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTableCellTouchedHandler(func)
- end
- function GUI:TableView_scrollToCell(widget, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:scrollToCell(index)
- end
- function GUI:TableView_addOnScrollEvent(widget, func)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTableViewScrollHandler(func)
- end
- function GUI:TableView_reloadData(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:reloadData()
- end
- function GUI:TableView_reloadDataEx(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:reloadDataEx()
- end
- function GUI:TableView_setTableViewCellsNumHandler(widget, func)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTableViewCellsNumHandler(func)
- end
- function GUI:TableView_addMouseScrollEvent(widget, func)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local call_scrolling = nil
- if func and type(func) == "function" then
- call_scrolling = func
- else
- call_scrolling = function(param)
- local widget = param.widget
- local speed = 40
- local scorllX = param.x
- local scorllY = param.y
- local contentSize = widget:getContentSize()
- local cellSize = widget:getCellSize()
- local innerHei = cellSize.height * widget:getTotalCellNums()
- local innerPos = widget:getContentOffset()
- local vHeight = innerHei - contentSize.height
- if innerHei > contentSize.height then
- local dis = speed * scorllY
- local offsetY = innerPos.y + dis
- offsetY = math.max(math.min(offsetY, 0), - vHeight)
- widget:setContentOffset(cc.p(innerPos.x, offsetY), true)
- end
- end
- end
- widget:addMouseScrollEvent(call_scrolling)
- end
- -- TableViewCell
- function GUI:TableViewCell_getIdx(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if widget.getIdx then
- return widget:getIdx() + 1
- end
- end
- -------------------------------------------------------------
- -- ProgressTimer
- function GUI:ProgressTimer_Create(parent, ID, x, y, img, width, height)
- if not ID then
- SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ProgressTimer_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:CheckBox_Create ID is exists", ID)
- return nil
- end
- local spriteCD = cc.Sprite:create(img)
- if width and height then
- spriteCD:setContentSize(width, height)
- end
- local widget = cc.ProgressTimer:create(spriteCD)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:ProgressTimer_setPercentage(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setPercentage(value)
- end
- function GUI:ProgressTimer_getPercentage(widget)
- if CheckIsInvalidCObject(widget) then
- return 0
- end
-
- return widget:getPercentage()
- end
- -- value顺时针, false逆时针
- function GUI:ProgressTimer_setReverseDirection(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setReverseDirection(value)
- end
- function GUI:ProgressTimer_progressFromTo(widget, time, from, to, completeCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if completeCB then
- widget:runAction(cc.Sequence:create(
- cc.ProgressFromTo:create(time or 0.5, from, to), cc.CallFunc:create(completeCB)
- ))
- else
- widget:runAction(cc.ProgressFromTo:create(time or 0.5, from, to))
- end
- end
- function GUI:ProgressTimer_ChangeImg(widget, img)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local spriteCD = cc.Sprite:create(img)
- if spriteCD then
- widget:setSprite(spriteCD)
- end
- end
- function GUI:ProgressTimer_progressTo(widget, time, to, completeCB, tag)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local action = nil
- if completeCB then
- action = cc.Sequence:create(
- cc.ProgressTo:create(time or 0, to),
- cc.CallFunc:create(completeCB)
- )
- else
- action = cc.ProgressTo:create(time or 0, to)
- end
- widget:runAction(action)
- if tag then
- action:setTag(tag)
- end
- end
- -------------------------------------------------------------
- -- ItemShow
- function GUI:ItemShow_Create(parent, ID, x, y, data)
- if not ID then
- SL:Print("[GUI ERROR] GUI:ItemShow_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ItemShow_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:ItemShow_Create ID is exists", ID)
- return nil
- end
- if not data then
- SL:Print("[GUI ERROR] GUI:ItemShow_Create itemData is nil", ID)
- return nil
- end
- local widget = GoodsItem:create(data)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- function GUI:ItemShow_addReplaceClickEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:addReplaceClickEventListener(eventCB)
- end
- function GUI:ItemShow_addPressEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addPressCallBack(eventCB)
- end
- function GUI:ItemShow_addDoubleEvent(widget, eventCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addDoubleEventListener(eventCB)
- end
- function GUI:ItemShow_setIconGrey( widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setIconGrey(value)
- end
- function GUI:ItemShow_setItemPowerTag(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setItemPowerTag()
- end
- function GUI:ItemShow_setItemShowChooseState(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:SetChooseState(value)
- end
- function GUI:ItemShow_setMoveEable(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:SetMoveEable(value)
- end
- function GUI:ItemShow_GetLayoutExtra(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:GetLayoutExtra()
- end
- function GUI:ItemShow_resetMoveState(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:resetMoveState(value)
- end
- function GUI:ItemShow_RDItem(widget, itemData)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:UpdateItem(itemData)
- end
- function GUI:ItemShow_updateItem(widget, itemData)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:UpdateItem(itemData)
- end
- function GUI:ItemShow_updateItemCount(widget, itemData)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:UpdateGoodsItem(itemData)
- end
- function GUI:ItemShow_OnRunFunc(widget, funcname, ...)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:OnRunFunc(funcname, ...)
- end
- function GUI:ItemShow_setItemTouchSwallow(widget, bool)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setItemTouchSwallow(bool)
- end
- function GUI:ItemShow_setCount(widget, count)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setCount(count)
- end
- function GUI:ItemShow_SetItemIndex(widget, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:SetItemIndex(index)
- end
- -------------------------------------------------------------
- -- ItemBox
- function GUI:ItemBox_Create(parent, ID, x, y, img, boxindex, stdmode)
- if not ID then
- SL:Print("[GUI ERROR] GUI:ItemBox_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ItemBox_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:ItemBox_Create ID is exists", ID)
- return nil
- end
- local setData = {}
- setData.img = img
- setData.boxindex = boxindex
- setData.stdmode = stdmode
- local widget = SItemBox:create(setData)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
-
- return widget
- end
- function GUI:ItemBox_GetItemData(widget, boxindex)
- if CheckIsInvalidCObject(widget) then
- return nil
- end
- local SSRUIManager = global.Facade:retrieveMediator("SSRUIManager")
- return SSRUIManager:GetItemDataByboxIndex(boxindex)
- end
- function GUI:ItemBox_RemoveBoxData(widget, boxindex)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- global.Facade:sendNotification(global.NoticeTable.SSR_ITEMBOXWidget_Remove, {boxindex = boxindex})
- end
- function GUI:ItemBox_UpdateBoxData(widget, boxindex, itemData)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local updateData = true
- if itemData and next(itemData) then
- updateData = false
- end
- global.Facade:sendNotification(global.NoticeTable.SSR_ITEMBOXWidget_Update, {boxindex = boxindex, updateData = updateData, itemData = itemData})
- end
- -------------------------------------------------------------
- -- EquipShow
- function GUI:EquipShow_Create(parent, ID, x, y, pos, isHero, data)
- if not ID then
- SL:Print("[GUI ERROR] GUI:EquipShow_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:EquipShow_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:EquipShow_Create ID is exists", ID)
- return nil
- end
- if not tonumber(pos) then
- SL:Print("[GUI ERROR] GUI:EquipShow_Create pos is nil", ID)
- return nil
- end
- local pos = tonumber(pos)
- local isLookPlayer = data and data.lookPlayer
- local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
- local EquipProxy = isHero and global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy) or global.Facade:retrieveProxy(global.ProxyTable.Equip)
- local LookPlayerProxy = global.Facade:retrieveProxy(global.ProxyTable.LookPlayerProxy)
- local size = cc.size(64, 64)
- local equipData = nil
- if isLookPlayer then
- equipData = LookPlayerProxy:GetLookPlayerItemDataByPos(pos)
- else
- equipData = EquipProxy:GetEquipDataByPos(pos)
- end
- local widget = ccui.Widget:create()
- widget:setContentSize(size)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget._EQUIP_POS = pos
- widget._isHero = isHero
- widget._param = data
-
- if equipData then
- local info = data or {}
- info.index = equipData.Index
- info.itemData = equipData
- info.from = isHero and ItemMoveProxy.ItemFrom.HERO_EQUIP or ItemMoveProxy.ItemFrom.PALYER_EQUIP
- local item = GoodsItem:create(info)
- item:setPosition(cc.p(size.width / 2, size.height / 2))
- widget:addChild(item)
- if data.doubleTakeOff and not isLookPlayer then
- if not (info.look) then
- item:addLookItemInfoEvent(nil, 2)
- end
- item:addDoubleEventListener(function()
- local takeOffEquipData = {
- itemData = equipData,
- pos = equipData.Where
- }
- if isHero then
- ItemMoveProxy:TakeOffEquip_Hero(takeOffEquipData)
- else
- ItemMoveProxy:TakeOffEquip(takeOffEquipData)
- end
- end)
- end
- end
- local function addItemIntoEquip(touchPos)
- local state = ItemMoveProxy:GetMovingItemState()
- local canMove = widget._param and widget._param.movable and not widget._param.lookPlayer
- if state and canMove then
- local goToName = isHero and ItemMoveProxy.ItemGoTo.HERO_EQUIP or ItemMoveProxy.ItemGoTo.PALYER_EQUIP
- local data = {}
- data.target = goToName
- data.pos = touchPos
- data.equipPos = pos
- ItemMoveProxy:CheckAndCallBack(data)
- else
- return -1
- end
- end
- local function setNoswallowMouse(touchPos)
- return -1
- end
- global.mouseEventController:registerMouseButtonEvent(
- widget,
- {
- down_r = setNoswallowMouse,
- special_r = addItemIntoEquip,
- checkIsVisible = true
- }
- )
-
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- return widget
- end
- function GUI:EquipShow_setAutoUpdate(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local lookPlayer = widget._param and widget._param.lookPlayer
- if not widget._EQUIP_POS or lookPlayer then
- return false
- end
- global.Facade:sendNotification(global.NoticeTable.AutoEquipShowWidgetAdd, {widget = widget})
- end
- -------------------------------------------------------------
- -- MoveWidget
- function GUI:MoveWidget_Create(parent, ID, x, y, width, height, from, ext)
- if not ID then
- SL:Print("[GUI ERROR] GUI:MoveWidget_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:MoveWidget_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:MoveWidget_Create ID is exists", ID)
- return nil
- end
- ext = ext or {}
- local widget = ccui.Layout:create()
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- elseif "ccui.PageView" == tolua.type(parent) then
- parent:addPage(widget)
- else
- parent:addChild(widget)
- end
- end
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0.5, 0.5))
- widget:setContentSize(cc.size(width, height))
- widget:setTouchEnabled(true)
- local itemMoveState = {
- begin = 1,
- moving = 2,
- end_move = 3,
- }
- local ITEMFROMUI = SL:GetMetaValue("ITEMFROMUI_ENUM")
- local beginMoveCallBack = ext.beginMoveCB
- local endMoveCallBack = ext.endMoveCB
- local cancelMoveCallBack = ext.cancelMoveCB
- local pressCallBack = ext.pressCB
- local clickCallBack = ext.clickCB
- local pcDoubleCallBack = ext.pcDoubleCB
- local mouseScrollCallBack = ext.mouseScrollCB
- local function resetMoveState(mySelf, bool, isCancel)
- if mySelf and not tolua.isnull(mySelf) then
- mySelf._movingState = bool
- if bool then
- if beginMoveCallBack then
- beginMoveCallBack( mySelf, bool )
- end
- else
- if isCancel then
- if cancelMoveCallBack then
- cancelMoveCallBack( mySelf, bool )
- end
- else
- if endMoveCallBack then
- endMoveCallBack( mySelf, bool )
- end
- end
- end
- end
- end
- local function SetGoodItemState(state, movePos)
- local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
- local itemData = nil
- if from == ITEMFROMUI.PALYER_EQUIP and ext.equipPos then
- itemData = EquipProxy:GetEquipDataByPos(ext.equipPos, ext.equipList == true)
- elseif from == ITEMFROMUI.HERO_EQUIP and ext.equipPos then
- local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
- itemData = HeroEquipProxy:GetEquipDataByPos(ext.equipPos, ext.equipList == true)
- end
-
- if (from == ITEMFROMUI.PALYER_EQUIP or from == ITEMFROMUI.HERO_EQUIP) and not itemData then
- return
- end
- if itemMoveState.begin == state then
- resetMoveState(widget, true)
- global.Facade:sendNotification(global.NoticeTable.Layer_Moved_Begin,{
- pos = movePos,
- itemData = itemData,
- cancelCallBack = function()
- resetMoveState(widget, false, true)
- end,
- from = from,
- movingNode = not itemData and widget:clone()
- })
- elseif itemMoveState.moving == state then
-
- elseif itemMoveState.end_move == state then
- global.Facade:sendNotification(global.NoticeTable.Layer_Moved_End, movePos)
- resetMoveState(widget, false)
- end
- end
- local function clickEventCallBack(node)
- --不在道具移动
- if node._movingState then
- return
- end
- local panelPos = node:getWorldPosition()
- if global.isWinPlayMode then
- SetGoodItemState(itemMoveState.begin, panelPos)
- end
- if clickCallBack then
- clickCallBack(node)
- end
- end
- local function pressEventCallBack(node)
- --不在道具移动
- if node._movingState then
- return
- end
- local panelPos = node:getWorldPosition()
- if global.isWinPlayMode then
- SetGoodItemState(itemMoveState.begin, panelPos)
- end
- if pressCallBack then
- pressCallBack(node)
- end
- end
- local isEventPress = false
- local isMoved = true
- local hasEventCallOnTouchBegin = false --只有在响应了touchbegin 时才会去响应延时方法 因为在延时后 鼠标事件的 状态已经被置掉
- local isMobile = not global.isWinPlayMode
- local clickTimes = 0
- -- 延迟
- local function delayCallback()
- isEventPress = true
- if pressEventCallBack then
- if not pressEventCallBack then
- return false
- end
- if not isMoved then
- pressEventCallBack(widget)
- return false
- end
- local movedPos = widget:getTouchMovePosition()
- local beganPos = widget:getTouchBeganPosition()
- local diff = cc.pSub(movedPos, beganPos)
- local distSq = cc.pLengthSQ(diff)
- if distSq <= 100 then
- pressEventCallBack(widget)
- end
- end
- end
- local function touchEvent(touch, eventType)
- if global.isWinPlayMode then
- local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
- local itemMoving = ItemMoveProxy:GetMovingItemState()
- if itemMoving then --在道具移动中
- resetMoveState(widget, false)
- return
- else -- 辅助清理状态
- if widget and not tolua.isnull(widget) and widget._movingState then
- widget._movingState = false
- end
- end
- end
- if eventType == 0 then
- isEventPress = false
- isMoved = false
- hasEventCallOnTouchBegin = true
- if pressEventCallBack then
- performWithDelay(widget, delayCallback, global.MMO.CLICK_DOUBLE_TIME)
- end
- elseif eventType == 1 then
- local movedPos = widget:getTouchMovePosition()
- local beganPos = widget:getTouchBeganPosition()
- local diff = cc.pSub(movedPos, beganPos)
- local distSq = cc.pLengthSQ(diff)
- if not isMoved and distSq > 100 then
- isMoved = true
- if isMobile then
- local beginMovePos = widget:getWorldPosition()
- SetGoodItemState(itemMoveState.begin, beginMovePos)
- end
- end
- if isMobile then
- local movedPos = widget:getTouchMovePosition()
- global.Facade:sendNotification(global.NoticeTable.Layer_Moved_Moving, {pos = movedPos})
- end
- elseif eventType == 2 then
- widget:stopAllActions()
- if not isMoved then
- if not isEventPress then
- local stateOnbegin = hasEventCallOnTouchBegin
- if clickEventCallBack and stateOnbegin then
- clickEventCallBack(widget, eventType)
- end
- if global.isWinPlayMode and pcDoubleCallBack then
- clickTimes = clickTimes + 1
- if clickTimes >= 2 then
- clickTimes = 0
- if widget._clickDelayHandler then
- UnSchedule(widget._clickDelayHandler)
- widget._clickDelayHandler = nil
- end
- if pcDoubleCallBack then
- pcDoubleCallBack()
- end
- return
- end
- widget._clickDelayHandler = PerformWithDelayGlobal(function()
- clickTimes = 0
- end, global.MMO.CLICK_DOUBLE_TIME)
- end
- end
- else
- if isMobile then
- local endPos = widget:getTouchEndPosition()
- SetGoodItemState(itemMoveState.end_move, endPos)
- end
- end
- hasEventCallOnTouchBegin = false
- elseif eventType == 3 then
- if isMobile then
- local endPos = widget:getTouchEndPosition()
- SetGoodItemState(itemMoveState.end_move, endPos)
- end
- hasEventCallOnTouchBegin = false
- end
- end
- widget:addTouchEventListener(touchEvent)
- local function addIntoPanel(touchPos)
- local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
- local state = ItemMoveProxy:GetMovingItemState()
- if state then
- local goToName = from
- local data = {}
- data.target = goToName
- data.pos = touchPos
- data.equipPos = ext.equipPos
- ItemMoveProxy:CheckAndCallBack( data )
- else
- return -1
- end
- end
- local function setNoswallowMouse(touchPos)
- --不在道具移动
- local itemData = SL:GetMetaValue("EQUIP_DATA", ext.equipPos)
- if ((from == ITEMFROMUI.PALYER_EQUIP or from == ITEMFROMUI.HERO_EQUIP) and not itemData) or widget._movingState then
- return
- end
- local panelPos = widget:getWorldPosition()
- SetGoodItemState(itemMoveState.begin, panelPos)
- end
- global.mouseEventController:registerMouseButtonEvent(
- widget,
- {
- down_r = setNoswallowMouse,
- special_r = addIntoPanel,
- scroll = mouseScrollCallBack,
- checkIsVisible = true
- }
- )
- return widget
- end
- function GUI:AddMoveWidgetTypeEvent(from, to, fromToEvent, toFromEvent)
- if not from or not to then
- SL:Print("[GUI ERROR] GUI:AddMoveWidgetTypeEvent can't find type")
- return
- end
- if not fromToEvent and not toFromEvent then
- SL:Print("[GUI ERROR] GUI:AddMoveWidgetTypeEvent can't find event")
- return
- end
- local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
- ItemMoveProxy:AddMoveTypeAndFunc(from, to, fromToEvent, toFromEvent)
- end
- -------------------------------------------------------------
- -- Frames
- function GUI:Frames_Create(parent, ID, x, y, prefix, suffix, beginframe, finishframe, ext)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Frames_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Frames_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Frames_Create ID is exists", ID)
- return nil
- end
- finishframe = tonumber(finishframe)
- local speed = ext and tonumber(ext.speed) or 100
- local count = ext and tonumber(ext.count) or 1
- local loop = ext and tonumber(ext.loop) or -1
- local finishhide = ext and tonumber(ext.finishhide)
- local callback = ext and ext.callback
- local fullPath = string.format("%s%s%s", prefix, beginframe or "1", suffix)
- local widget = ccui.ImageView:create()
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadTexture(FixPath(fullPath))
-
- local function finishCB()
- if finishframe then
- fullPath = string.format("%s%s%s", prefix, finishframe, suffix)
- widget:loadTexture(FixPath(fullPath))
- end
- if finishhide == 1 then
- widget:setVisible(false)
- end
- if callback then
- callback()
- end
- end
- local index = beginframe and tonumber(beginframe) or 1
- local counting = 0
- local function delayCB()
- fullPath = string.format("%s%s%s", prefix, index, suffix)
- widget:loadTexture(FixPath(fullPath))
-
- index = index + 1
- if index > (count + beginframe) then
- index = beginframe and tonumber(beginframe) or 1
- counting = counting + 1
- if loop ~= -1 and counting >= loop then
- widget:stopAllActions()
- finishCB()
- end
- elseif finishframe and index == finishframe then
- if loop ~= -1 and counting + 1 == loop then
- widget:stopAllActions()
- performWithDelay(widget, finishCB, speed*0.001)
- end
- end
- end
- schedule(widget, delayCB, speed*0.001)
- delayCB()
- return widget
- end
- -------------------------------------------------------------
- -- CircleBar
- function GUI:CircleBar_Create(parent, ID, x, y, bgImg, barImg, startper, endper, time)
- if not ID then
- SL:Print("[GUI ERROR] GUI:CircleBar_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:CircleBar_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:CircleBar_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.ImageView:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadTexture(FixPath(bgImg))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- local contentSize = widget:getContentSize()
- local progressTimer = cc.ProgressTimer:create(cc.Sprite:create(FixPath(barImg)))
- widget:addChild(progressTimer)
- progressTimer:setName("PROGRESS_TIMER")
- progressTimer:setPosition(cc.p(contentSize.width / 2 , contentSize.height / 2 ))
- progressTimer:setPercentage(startper)
- local function loadCompleteCB()
- progressTimer:stopAllActions()
- -- event
- local completeCB = widget.completeCB
- if completeCB then
- completeCB()
- end
- end
- progressTimer:runAction(
- cc.Sequence:create(
- cc.ProgressFromTo:create(time, startper, endper),
- cc.DelayTime:create(0.1),
- cc.CallFunc:create(loadCompleteCB)
- )
- )
- return widget
- end
- function GUI:CircleBar_setBarOffSet(widget, offsetX, offsetY)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if widget and widget:getChildByName("PROGRESS_TIMER") then
- local bar = widget:getChildByName("PROGRESS_TIMER")
- local contentSize = widget:getContentSize()
- bar:setPosition(cc.p(contentSize.width / 2 + offsetX, contentSize.height / 2 + offsetY))
- end
- end
- function GUI:CircleBar_addOnCompleteEvent(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget.completeCB = value
- end
- -------------------------------------------------------------
- -- PercentImg
- function GUI:PercentImg_Create(parent, ID, x, y, img, direction, minValue, maxValue)
- if not ID then
- SL:Print("[GUI ERROR] GUI:PercentImg_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:PercentImg_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:PercentImg_Create ID is exists", ID)
- return nil
- end
- local widget = ccui.LoadingBar:create()
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- widget:loadTexture(FixPath(img))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- direction = tonumber(direction) or 0
- local min = tonumber(minValue) or 100
- local max = tonumber(maxValue) or 100
- local percent = math.floor(min / max * 100) or 100
- if direction == 0 or direction == 1 then
- widget:setPercent(percent)
- if direction == 1 then
- widget:setDirection(1)
- end
- elseif direction == 2 or direction == 3 then
- local barRenderer = widget:getVirtualRenderer()
- local barRendererTextureSize = widget:getVirtualRendererSize()
- local innerSprite = barRenderer:getSprite()
- local contentSize = widget:getContentSize()
- if direction == 2 then
- barRenderer:setAnchorPoint(0, 0)
- barRenderer:setPosition(0, 0)
- else
- barRenderer:setAnchorPoint(0, 1)
- barRenderer:setPosition(0, contentSize.height)
- end
- if innerSprite then
- local rect = innerSprite:getTextureRect()
- rect.height = barRendererTextureSize.height * percent / 100
- innerSprite:setTextureRect(rect, innerSprite:isTextureRectRotated(), cc.size(rect.width, rect.height))
- if direction == 2 then
- innerSprite:setFlippedY(true)
- else
- innerSprite:setFlippedY(false)
- end
- end
- end
- return widget
- end
- -------------------------------------------------------------
- -- UIModel
- function GUI:UIModel_Create(parent, ID, x, y, sex, feature, scale, useStaticScale, job, ext_param)
- if not ID then
- SL:Print("[GUI ERROR] GUI:UIModel_Create can't find ID")
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:UIModel_Create ID is exists", ID)
- return nil
- end
- local param = not useStaticScale and {ignoreStaticScale = true} or nil
- if job then
- param = param or {}
- param.job = job
- end
- if ext_param and next(ext_param) then
- param = param or {}
- for k, v in pairs(ext_param) do
- param[k] = v
- end
- end
- local widget = CreateStaticUIModel(sex, feature, scale, param)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- -------------------------------------------------------------
- -- QuickCell
- function GUI:QuickCell_Create(parent, ID, x, y, w, h, createCB, activeCheckCB, ext_param)
- if not ID then
- SL:Print("[GUI ERROR] GUI:QuickCell_Create can't find ID")
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:QuickCell_Create ID is exists", ID)
- return nil
- end
- local widget = GUIQuickCell:Create({
- wid = w,
- hei = h,
- activeEvent = activeCheckCB,
- eventX = ext_param and ext_param.event_x,
- tick_interval = ext_param and ext_param.tick_interval
- })
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- widget:Update({createCell = createCB})
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- return widget
- end
- function GUI:QuickCell_Refresh(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:Refresh()
- end
- function GUI:QuickCell_Exit(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:Exit()
- end
- function GUI:QuickCell_Sleep(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:Sleep()
- end
- function GUI:QuickCell_Active(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:Active()
- end
- -------------------------------------------------------------
- -- Animation
- function GUI:Animation_Create()
- local widget = cc.Animation:create()
- return widget
- end
- function GUI:Animation_addSpriteFrame(widget, frame)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:addSpriteFrame(frame)
- end
- function GUI:Animation_setDelayPerUnit(widget, time)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setDelayPerUnit(time)
- end
- function GUI:Animation_setLoops(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setLoops(value)
- end
- function GUI:Animation_setRestoreOriginalFrame(widget, bool)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setRestoreOriginalFrame(bool)
- end
- ------------------------------------------------------------
- -- Sprite
- function GUI:Sprite_Create(parent, ID, x, y, path)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Sprite_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Sprite_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Sprite_Create ID is exists", ID)
- return nil
- end
- local widget = nil
- if path and SL:IsFileExist(path) then
- widget = cc.Sprite:create(path)
- else
- widget = cc.Sprite:create()
- end
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:Sprite_getSpriteFrame(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- return widget:getSpriteFrame()
- end
- -----------------------------------------------------------
- --- LineWidget
- local LineWidget = class("LineWidget", function()
- return ccui.Widget:create()
- end)
- function LineWidget:ctor()
- self._size = cc.size(0, 0)
- self._cells = {}
- self._offset = {}
- end
- function LineWidget:pushCell(cell, offset, isadd)
- if not cell then return end
- if isadd then
- self:addChild(cell)
- end
- local size = cell:getContentSize()
- cell:setPositionX(self._size.width + size.width / 2 + offset.x)
- table.insert(self._cells, cell)
- self._offset[#self._cells] = offset
- self._size.width = self._size.width + size.width
- self._size.height = self._size.height + size.height
- end
- function LineWidget:getSize()
- return self._size
- end
- function LineWidget:reSize()
- self:setContentSize(self._size)
- for i,cell in pairs(self._cells) do
- local offset = self._offset[i] or cc.p(0, 0)
- cell:setPositionY(self._size.height / 2 + offset.y)
- end
- end
- function GUI:TipLineWidget_Create(parent, ID, x, y)
- if not ID then
- SL:Print("[GUI ERROR] GUI:TipLineWidget_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:TipLineWidget_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:TipLineWidget_Create ID is exists", ID)
- return nil
- end
- local widget = LineWidget.new()
- widget:setTouchEnabled(false)
- widget:setAnchorPoint(0,0)
- widget:setName(ID)
- widget:setPosition(cc.p(x, y))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:TipLineWidget_updateSize( widget )
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if widget.reSize then
- widget:reSize()
- end
- end
- function GUI:TipLineWidget_getSize( widget )
- if CheckIsInvalidCObject(widget) then
- return cc.size(0, 0)
- end
- return widget:getSize()
- end
- function GUI:TipLineWidget_pushCell( widget , cell, offset )
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:pushCell(cell, offset)
- end
- function GUI:TipLineWidget_pushChildCell( widget , cell, offset )
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:pushCell(cell, offset, true)
- end
- ------------------------------------------------------------
- -- 粒子特效
- function GUI:ParticleEffect_Create(parent, ID, x, y, res)
- if not ID then
- SL:Print("[GUI ERROR] GUI:ParticleEffect_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ParticleEffect_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:ParticleEffect_Create ID is exists", ID)
- return nil
- end
- local widget = cc.ParticleSystemQuad:create(res)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:ParticleEffect_setTotalParticles(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setTotalParticles(value)
- end
- function GUI:ParticleEffect_setSpeed(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setSpeed(value)
- end
- function GUI:ParticleEffect_setSpeedVar(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setSpeedVar(value)
- end
- function GUI:ParticleEffect_setAngle(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setAngle(widget, value)
- end
- function GUI:ParticleEffect_setAngleVar(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setAngleVar(widget, value)
- end
- -- 持续时间 -1 永久
- function GUI:ParticleEffect_setDuration(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setDuration(value)
- end
- -- 开始大小
- function GUI:ParticleEffect_setStartSize(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setStartSize(value)
- end
- function GUI:ParticleEffect_setStartSizeVar(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setStartSizeVar(value)
- end
- -- 结束大小
- function GUI:ParticleEffect_setEndSize(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setEndSize(value)
- end
- function GUI:ParticleEffect_setEndSizeVar(widget, value)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setEndSizeVar(value)
- end
- --------------------------------------------------------------
- local function checkSpineVer(jsonPath, needVer)
- if not global.FileUtilCtl:isFileExist(jsonPath) then
- return false
- end
- local jsonStr = global.FileUtilCtl:getDataFromFileEx(jsonPath)
- if not jsonStr or jsonStr == "" or jsonStr == jsonPath then
- return false
- end
- local jsonData = cjson.decode(jsonStr)
- if not jsonData then
- return false
- end
- local ver = jsonData["skeleton"] and jsonData["skeleton"]["spine"] or ""
- local t = string.split(ver, ".")
- if tonumber(t[1]) and tonumber(t[2]) then
- local curVer = tonumber(t[1]) * 10 + tonumber(t[2])
- if curVer == needVer then
- return true
- end
- end
- return false
- end
- -- 骨骼动画
- function GUI:SpineAnim_Create(parent, ID, x, y, jsonPath, atlasPath, trackIndex, name, loop)
- if not ID then
- SL:Print("[GUI ERROR] GUI:SpineAnim_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:SpineAnim_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:SpineAnim_Create ID is exists", ID)
- return nil
- end
- local widget = nil
- if not (spine and spine.SkeletonAnimation) then
- SL:release_print("Warning! The current version of exe does not support spine2.1 version!")
- widget = ccui.Widget:create()
- widget.notSpine = true
- elseif not checkSpineVer(jsonPath, 21) then
- SL:release_print("Warning! The current spine animation file is not spine2.1 version!")
- widget = ccui.Widget:create()
- widget.notSpine = true
- else
- widget = spine.SkeletonAnimation:createWithFile(jsonPath, atlasPath)
- widget:setAnimation(trackIndex, name, loop)
- end
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- function GUI:Spine38Anim_Create(parent, ID, x, y, jsonPath, atlasPath, trackIndex, name, loop, scale)
- if not ID then
- SL:Print("[GUI ERROR] GUI:Spine38Anim_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:Spine38Anim_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:Spine38Anim_Create ID is exists", ID)
- return nil
- end
- if not (sp and sp.SkeletonAnimation) then
- SL:release_print("Error! The current version of exe does not support spine3.8 version!")
- return nil
- end
- local widget = sp.SkeletonAnimation:create(jsonPath, atlasPath, scale or 1)
- widget:setAnimation(trackIndex, name, loop)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- -- trackIndex: 轨道索引 name: 动画名 loop: 是否循环
- function GUI:SpineAnim_setAnimation(widget, trackIndex, name, loop)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setAnimation(trackIndex, name, loop)
- end
- function GUI:SpineAnim_addAnimation(widget, trackIndex, name, loop)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:addAnimation(trackIndex, name, loop)
- end
- -- duration 过渡时间
- function GUI:SpineAnim_setMix(widget, fromAnimName, toAnimName, duration)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setMix(fromAnimName, toAnimName, duration)
- end
- -------- spine 3.8 新增接口 begin -----------
- -- 清除轨道所有动画
- function GUI:SpineAnim_clearTracks(widget)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:clearTracks()
- end
- -- 清除指定轨道动画 trackIndex: 轨道索引
- function GUI:SpineAnim_clearTrack(widget, trackIndex)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:clearTrack(trackIndex)
- end
- -- 播放时间缩放 / 播放速度 默认: 1, 数值越大 播放越快
- function GUI:SpineAnim_getTimeScale(widget)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- return widget:getTimeScale()
- end
- function GUI:SpineAnim_setTimeScale(widget, scale)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setTimeScale(scale)
- end
- -- 重置到初始姿态, 主要用于处理切换动画时上个动画留下的残影
- -- [setBonesToSetupPose 和 setSlotsToSetupPose]
- function GUI:SpineAnim_setToSetupPose(widget)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setToSetupPose()
- end
- -- 重置插槽到初始设定
- function GUI:SpineAnim_setSlotsToSetupPose(widget)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setSlotsToSetupPose()
- end
- -- 查找动画 name: 动画名称
- function GUI:SpineAnim_findAnimation(widget, name)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- return widget:findAnimation(name)
- end
- -- 设置皮肤 skinName: 皮肤名称
- function GUI:SpineAnim_setSkin(widget, skinName)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setSkin(skinName)
- end
- -- 绕X轴翻转
- function GUI:SpineAnim_setFlipX(widget, bool)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setScaleX(bool and -1 or 1)
- end
- -- 绕Y轴翻转
- function GUI:SpineAnim_setFlipY(widget, bool)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setScaleY(bool and -1 or 1)
- end
- -- 设置插槽内附件 slotName: 插槽名字 attachmentName: 附件名称 [此附件在本插槽内]
- function GUI:SpineAnim_setAttachment(widget, slotName, attachmentName)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:setAttachment(slotName, attachmentName)
- end
- -- 获取插槽内附件
- -- return sp.Attachment 附件
- function GUI:SpineAnim_getAttachment(widget, slotName, attachmentName)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- return widget:getAttachment(slotName, attachmentName)
- end
- -- 查找插槽对象 slotName: 插槽名字
- -- return sp.Slot 插槽对象
- function GUI:SpineAnim_findSlot(widget, slotName)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- return widget:findSlot(slotName)
- end
- -- 返回所有插槽对象列表
- function GUI:SpineAnim_getSlots(widget)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- return widget:getSlots()
- end
- -- 注册监听事件回调
- --[[
- handler 回调参数:
- {
- animation: "xxanimation", -- 动画名
- loopCount: 1, -- 循环次数
- trackIndex: 0, -- 轨道索引
- type: "xxx" -- 事件类型 "start" "interrupt" "end" "dispose" "complete" "event"
- eventData: table -- 自定义事件数据 {name: "xx", floatValue: 0, intValue: 0, stringValue: ""}
- }
- ]]
- -- handler: function eventType: sp.EventType
- function GUI:SpineAnim_registerSpineEventHandler(widget, handler, eventType)
- if CheckIsInvalidCObject(widget) or widget.notSpine then
- return false
- end
- widget:registerSpineEventHandler(handler, eventType)
- end
- ------- [sp.Slot] 插槽对象
- -- 获取插槽对象颜色table
- -- {r = 1, g = 1, b = 1, a = 1} 数值0-1
- function GUI:SpineSlot_getColor(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- return widget:getColor()
- end
- -- 设置插槽对象颜色 数值0-1
- function GUI:SpineSlot_setColor(widget, r, g, b, a)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setColor(r, g, b, a)
- end
- -- 设置插槽对象可见性
- function GUI:SpineSlot_setVisible(widget, isVisible)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setVisible(isVisible)
- end
- -- 设置插槽对象的附件 attachment: sp.Attachment附件对象
- function GUI:SpineSlot_setAttachment(widget, attachment)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:setAttachment(attachment)
- end
- -------- spine 3.8 新增接口 end -----------
- -------------------------------------------------------------
- -- WebView
- function GUI:WebView_Create(parent, ID, x, y, width, height, index)
- if not ID then
- SL:Print("[GUI ERROR] GUI:WebView_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:WebView_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:WebView_Create ID is exists", ID)
- return nil
- end
- local widget = ccexp.CustomView and ccexp.CustomView:create() or (ccexp.WebView and ccexp.WebView:create())
- local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
- local URLList = envProxy:GetCustomDataByKey("useUrlList")
- if widget then
- widget:setName(ID)
- widget:setContentSize(cc.size(width, height))
- if URLList and URLList[index] then
- widget:loadURL(URLList[index])
- else
- ShowSystemTips("链接未配置!")
- end
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- widget:setAnchorPoint(cc.p(0, 0))
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- end
- return widget
- end
- -------------------------------------------------------------
- -- ScrapePic
- function GUI:ScrapePic_Create(parent, ID, x, y, bgImg, maskImg, clearHei, moveTime, beginTime, callback)
- if not ID then
- SL:Print("[GUI ERROR] GUI:ScrapePic_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:ScrapePic_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:ScrapePic_Create ID is exists", ID)
- return nil
- end
- if not bgImg or not global.FileUtilCtl:isFileExist(bgImg) then
- SL:Print("[GUI ERROR] GUI:ScrapePic_Create showImg can't find res path! ")
- return nil
- end
- local widget = ccui.Layout:create()
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- if "ccui.ListView" == tolua.type(parent) then
- parent:pushBackCustomItem(widget)
- else
- parent:addChild(widget)
- end
- end
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- widget:setAnchorPoint(cc.p(0, 0))
- local img = ccui.ImageView:create()
- img:loadTexture(bgImg)
- local imgSize = img:getContentSize()
- widget:setContentSize(imgSize)
- widget:addChild(img)
- img:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
- local radius = clearHei and math.floor(clearHei / 2) or 8
- local drawNode = cc.DrawNode:create()
- widget:addChild(drawNode)
- drawNode:retain()
- drawNode:drawSolidCircle(cc.p(0, 0), radius, 0, radius, 1, 1, cc.c4b(0, 0, 0, 0))
- drawNode:setVisible(false)
- local renderTexture = cc.RenderTexture:create(imgSize.width, imgSize.height)
- renderTexture:retain()
- renderTexture:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
- widget:addChild(renderTexture, 10)
- local mask = ccui.ImageView:create()
- mask:loadTexture(maskImg)
- mask:ignoreContentAdaptWithSize(false)
- mask:setContentSize(imgSize)
- mask:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
- renderTexture:begin()
- mask:visit()
- renderTexture:endToLua()
- local lastMovePos = nil
- local moveBT = nil
- local iMoveTime = 0
- local iBeginAct = nil
- local releaseCount = 0
- local touchPosList = {}
- local function timeCB()
- if releaseCount == 0 then
- releaseCount = releaseCount + 1
- if drawNode then
- drawNode:removeFromParent()
- drawNode:autorelease()
- drawNode = nil
- end
- if renderTexture then
- renderTexture:removeFromParent()
- renderTexture:autorelease()
- renderTexture = nil
- end
- if callback and type(callback) == "function" then
- callback()
- end
- end
- end
- local function getKey(x, y)
- return x * 10000 + y
- end
- local function addTouchPoint(x, y)
- local key = getKey(x, y)
- if touchPosList[key] then
- return
- end
- if x <= 0 or x >= imgSize.width then
- return
- end
- if y <= 0 or y >= imgSize.height then
- return
- end
-
- if not touchPosList[key] then
- touchPosList[key] = true
- end
- end
- widget:setTouchEnabled(true)
- widget:addTouchEventListener(function (node, eventType)
- if eventType == 0 then
- local beganPos = node:getTouchBeganPosition()
- lastMovePos = nil
- moveBT = os.clock()
- if tonumber(beginTime) and not iBeginAct then
- iBeginAct = performWithDelay(widget, function()
- timeCB()
- end, tonumber(beginTime))
- end
- elseif eventType == 1 then
- if releaseCount > 0 then
- return
- end
- local movedPos = node:getTouchMovePosition()
- local beganPos = node:getTouchBeganPosition()
- local tt = GUI:convertToNodeSpace(widget, movedPos.x, movedPos.y)
- tt = fixPosition(tt)
- local key = getKey(tt.x, tt.y)
- if touchPosList[key] then
- return
- end
- drawNode:setPosition(tt)
- drawNode:setBlendFunc({src = gl.ONE, dst = gl.ZERO})
- drawNode:setVisible(true)
- renderTexture:begin()
- drawNode:visit()
- renderTexture:endToLua()
- drawNode:setVisible(false)
- if lastMovePos then
- local distance = math.abs(cc.pGetDistance(lastMovePos, movedPos))
- local pos = cc.pSub(lastMovePos, movedPos)
- local angle = 180 * (cc.pToAngleSelf(pos) / math.pi)
- local height = radius * 2
- local midPos = cc.pMidpoint(lastMovePos, movedPos)
- local rectNode = cc.DrawNode:create()
- local posList = {
- cc.p(- distance / 2 , - height / 2),
- cc.p(- distance / 2 , height / 2),
- cc.p(distance / 2 , height / 2),
- cc.p(distance / 2 , - height / 2)
- }
- rectNode:drawSolidPoly(posList, 4, cc.c4b(0,0,0,0))
- midPos = fixPosition(GUI:convertToNodeSpace(widget, midPos.x, midPos.y))
- rectNode:setPosition(midPos)
- rectNode:setRotation(angle)
- rectNode:setBlendFunc({src = gl.ONE, dst = gl.ZERO})
- renderTexture:begin()
- rectNode:visit()
- renderTexture:endToLua()
- end
- -- pos
- local mPos = GUI:convertToNodeSpace(widget, movedPos.x, movedPos.y)
- mPos = fixPosition(mPos)
- for i = mPos.x - radius, mPos.x + radius do
- for j = mPos.y - radius, mPos.y + radius do
- if math.pow(i - mPos.x, 2) + math.pow(j - mPos.y, 2) <= math.pow(radius, 2) then
- addTouchPoint(i, j)
- end
- end
- end
- if moveBT then
- iMoveTime = iMoveTime + (os.clock() - moveBT)
- end
- moveBT = os.clock()
- if tonumber(moveTime) then
- if iMoveTime >= tonumber(moveTime) then
- timeCB()
- end
- end
-
- lastMovePos = movedPos
- elseif eventType == 2 or eventType == 3 then
- local endPos = node:getTouchEndPosition()
- lastMovePos = nil
- moveBT = nil
- end
- end)
- return widget
- end
- -------------------------------------------------------------
- -- MotionStreak
- function GUI:MotionStreak_Create(parent, ID, x, y, fadeTime, minSeg, width, path, color)
- if not ID then
- SL:Print("[GUI ERROR] GUI:MotionStreak_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:MotionStreak_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:MotionStreak_Create ID is exists", ID)
- return nil
- end
- color = color or cc.c3b(255, 255, 255)
- if type(color) == "string" and string.find(color, "#") then
- color = SL:ConvertColorFromHexString(color)
- end
- local widget = cc.MotionStreak:create(fadeTime, minSeg, width, color, path)
- widget:setName(ID)
- widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
- if parent ~= NONEED_PARENT_CODE then
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- parent:addChild(widget)
- end
- return widget
- end
- -- 重置
- function GUI:MotionStreak_reset(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:reset()
- end
- -------------------------------------------------------------
- -- MoveTo
- function GUI:ActionMoveTo(time, x, y)
- return cc.MoveTo:create(time, cc.p(x, y))
- end
- -- MoveBy
- function GUI:ActionMoveBy(time, x, y)
- return cc.MoveBy:create(time, cc.p(x, y))
- end
- -- ScaleTo
- function GUI:ActionScaleTo(time, ratio, ...)
- return cc.ScaleTo:create(time, ratio, ...)
- end
- -- ScaleBy
- function GUI:ActionScaleBy(time, ratio, ...)
- return cc.ScaleBy:create(time, ratio, ...)
- end
- function GUI:ActionScaleXTo(time, x)
- return cc.ScaleTo:create(time, x, 1)
- end
- function GUI:ActionScaleYTo(time, y)
- return cc.ScaleTo:create(time, 1, y)
- end
- function GUI:ActionScaleXBy(time, x)
- return cc.ScaleBy:create(time, x, 1)
- end
- function GUI:ActionScaleYBy(time, y)
- return cc.ScaleBy:create(time, 1, y)
- end
- -- RotateTo
- function GUI:ActionRotateTo(time, angle)
- return cc.RotateTo:create(time, angle)
- end
- -- RotateBy
- function GUI:ActionRotateBy(time, angle)
- return cc.RotateBy:create(time, angle)
- end
- -- FadeIn
- function GUI:ActionFadeIn(time)
- return cc.FadeIn:create(time)
- end
- -- FadeOut
- function GUI:ActionFadeOut(time)
- return cc.FadeOut:create(time)
- end
- -- FadeTo
- function GUI:ActionFadeTo(time, opacity)
- return cc.FadeTo:create(time, opacity)
- end
- -- Blink
- function GUI:ActionBlink(time, num)
- return cc.Blink:create(time, num)
- end
- -- CallFunc
- function GUI:CallFunc(callback)
- return cc.CallFunc:create(callback)
- end
- -- DelayTime
- function GUI:DelayTime(time)
- return cc.DelayTime:create(time)
- end
- function GUI:ActionShow()
- return cc.Show:create()
- end
- function GUI:ActionHide()
- return cc.Hide:create()
- end
- -- Sequence
- function GUI:ActionSequence( ... )
- return cc.Sequence:create( ... )
- end
- -- Spawn
- function GUI:ActionSpawn( ... )
- return cc.Spawn:create( ... )
- end
- -- Repeat
- function GUI:ActionRepeat(action, time)
- return cc.Repeat:create(action, time)
- end
- -- RepeatForever
- function GUI:ActionRepeatForever(action)
- return cc.RepeatForever:create(action)
- end
- -- RemoveSelf
- function GUI:ActionRemoveSelf()
- return cc.RemoveSelf:create()
- end
- -- EaseBounceIn
- function GUI:ActionEaseBounceIn(action)
- return cc.EaseBounceIn:create(action)
- end
- -- EaseBounceOut
- function GUI:ActionEaseBounceOut(action)
- return cc.EaseBounceOut:create(action)
- end
- -- EaseBounceInOut
- function GUI:ActionEaseBounceInOut(action)
- return cc.EaseBounceInOut:create(action)
- end
- -- EaseBackIn
- function GUI:ActionEaseBackIn(action)
- return cc.EaseBackIn:create(action)
- end
- -- EaseBackOut
- function GUI:ActionEaseBackOut(action)
- return cc.EaseBackOut:create(action)
- end
- -- EaseBackInOut
- function GUI:ActionEaseBackInOut(action)
- return cc.EaseBackInOut:create(action)
- end
- -- EaseBackInOut
- function GUI:ActionEaseSineInOut(action)
- return cc.EaseSineInOut:create(action)
- end
- --EaseElasticIn
- function GUI:ActionEaseElasticIn(action)
- return cc.EaseElasticIn:create(action)
- end
- --EaseElasticOut
- function GUI:ActionEaseElasticOut(action)
- return cc.EaseElasticOut:create(action)
- end
- --EaseElasticInOut
- function GUI:ActionEaseElasticInOut(action)
- return cc.EaseElasticInOut:create(action)
- end
- -- BezierTo
- function GUI:ActionBezierTo(time, ...)
- return cc.BezierTo:create(time, { ... })
- end
- -- Animate
- function GUI:ActionAnimate(animation)
- return cc.Animate:create(animation)
- end
- -- EaseExponentialIn
- function GUI:ActionEaseExponentialIn(action)
- return cc.EaseExponentialIn:create(action)
- end
- -- EaseExponentialOut
- function GUI:ActionEaseExponentialOut(action)
- return cc.EaseExponentialOut:create(action)
- end
- -- EaseExponentialOut
- function GUI:ActionEaseExponentialInOut(action)
- return cc.EaseExponentialInOut:create(action)
- end
- ------------------------------------------
- -- timeline
- function GUI:Timeline_Window1(widget, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 0.8),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
- cc.CallFunc:create(timelineCB)
- )
- else
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 0.8),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
- )
- end
- widget:runAction(action)
- end
- function GUI:Timeline_Window2(widget, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 0.5),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
- cc.CallFunc:create(timelineCB)
- )
- else
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 0.5),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
- )
- end
- widget:runAction(action)
- end
- function GUI:Timeline_Window3(widget, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 0),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
- cc.CallFunc:create(timelineCB)
- )
- else
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 0),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
- )
- end
- widget:runAction(action)
- end
- function GUI:Timeline_Window4(widget, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 1.2),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
- cc.CallFunc:create(timelineCB)
- )
- else
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 1.2),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
- )
- end
- widget:runAction(action)
- end
- function GUI:Timeline_Window5(widget, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 1.5),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
- cc.CallFunc:create(timelineCB)
- )
- else
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 1.5),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
- )
- end
- widget:runAction(action)
- end
- function GUI:Timeline_Window6(widget, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 2),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
- cc.CallFunc:create(timelineCB)
- )
- else
- action = cc.Sequence:create(
- cc.ScaleTo:create(0, 2),
- cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
- )
- end
- widget:runAction(action)
- end
- function GUI:Timeline_StopAll(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:stopAllActions()
- end
- function GUI:Timeline_SetTag(action, tag)
- if CheckIsInvalidCObject(action) then
- return false
- end
-
- action:setTag(tag)
- end
- function GUI:Timeline_StopByTag(widget, tag)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:stopActionByTag(tag)
- end
- function GUI:Timeline_FadeOut(widget, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.FadeOut:create(time), cc.CallFunc:create(timelineCB))
- else
- action = cc.FadeOut:create(time)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_FadeIn(widget, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.FadeIn:create(time), cc.CallFunc:create(timelineCB))
- else
- action = cc.FadeIn:create(time)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_FadeTo(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or 1
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.FadeTo:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.FadeTo:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_ScaleTo(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- value = value or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.ScaleTo:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.ScaleTo:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_RotateTo(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or 1
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.RotateTo:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.RotateTo:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_MoveTo(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or cc.p(0, 0)
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.MoveTo:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.MoveTo:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_DelayTime(widget, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.DelayTime:create(time), cc.CallFunc:create(timelineCB))
- else
- action = cc.DelayTime:create(time)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_Blink(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or 1
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.Blink:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.Blink:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_MoveBy(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or cc.p(0, 0)
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.MoveBy:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.MoveBy:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_ScaleBy(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- value = value or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.ScaleBy:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.ScaleBy:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_ScaleBy(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- value = value or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.ScaleBy:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.ScaleBy:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_RotateBy(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or 1
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.RotateBy:create(time, value), cc.CallFunc:create(timelineCB))
- else
- action = cc.RotateBy:create(time, value)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_CallFunc(widget, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.DelayTime:create(time), cc.CallFunc:create(timelineCB))
- else
- action = cc.CallFunc:create(timelineCB)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_Show(widget, time)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- local action = nil
- if time then
- action = cc.Sequence:create(cc.DelayTime:create(time), cc.Show:create())
- else
- action = cc.Show:create()
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_Hide(widget, time)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- local action = nil
- if time then
- action = cc.Sequence:create(cc.DelayTime:create(time), cc.Hide:create())
- else
- action = cc.Hide:create()
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_Shake(widget, time, x, y, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 1
- x = x or 10
- y = y or 10
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.ActionShake:create(time, x, y), cc.CallFunc:create(timelineCB))
- else
- action = cc.ActionShake:create(time, x, y)
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_EaseSineIn_MoveTo(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or cc.p(0, 0)
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.EaseSineIn:create(cc.MoveTo:create(time, value)), cc.CallFunc:create(timelineCB))
- else
- action = cc.EaseSineIn:create(cc.MoveTo:create(time, value))
- end
- widget:runAction(action)
- return action
- end
- function GUI:Timeline_EaseSineOut_MoveTo(widget, value, time, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- value = value or cc.p(0, 0)
- time = time or 1
- local action = nil
- if timelineCB then
- action = cc.Sequence:create(cc.EaseSineOut:create(cc.MoveTo:create(time, value)), cc.CallFunc:create(timelineCB))
- else
- action = cc.EaseSineOut:create(cc.MoveTo:create(time, value))
- end
- widget:runAction(action)
- return action
- end
- function GUI:TimeLine_BezierTo(time, ...)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return cc.BezierTo:create(time, { ... })
- end
- function GUI:Timeline_Waggle(widget, time, angle)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- time = time or 0.05
- angle = angle or 20
- widget:runAction(
- cc.RepeatForever:create(
- cc.Sequence:create(
- cc.RotateBy:create(time, angle),
- cc.RotateBy:create(time, -angle),
- cc.RotateBy:create(time, -angle),
- cc.RotateBy:create(time, angle),
- cc.RotateBy:create(time, angle),
- cc.RotateBy:create(time, -angle),
- cc.RotateBy:create(time, -angle),
- cc.RotateBy:create(time, angle),
- cc.RotateBy:create(time, angle),
- cc.RotateBy:create(time, -angle),
- cc.RotateBy:create(time, -angle),
- cc.RotateBy:create(time, angle),
- cc.DelayTime:create(3)
- )
- )
- )
- end
- function GUI:Timeline_OrbitCamera(widget, time, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX, timelineCB)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local oribitAction = cc.OrbitCamera:create(time, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX)
- if timelineCB then
- widget:runAction(cc.Sequence:create(
- oribitAction,
- cc.CallFunc:create(timelineCB)
- ))
- else
- widget:runAction(oribitAction)
- end
- end
- -- 点击间隔
- function GUI:setClickDelay(widget, time)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- DelayTouchEnabled(widget, time or global.MMO.CLICK_DOUBLE_TIME)
- end
- function GUI:ui_delegate(nativeUI)
- return ui_delegate(nativeUI)
- end
- -- 数字滚动动画
- function GUI:Timeline_DigitChange(widget, cur, target, interval)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- if tolua.isnull(widget) then
- return false
- end
- local _SetText = {
- ["Label"] = function (widget, value) widget:setString(value) end,
- ["Button"] = function (widget, value) widget:setTitleText(value) end,
- ["TextAtlas"] = function (widget, value) widget:setString(value) end,
- }
- local descript = widget:getDescription()
- if not _SetText[descript] then
- return false
- end
- -- 数字动态变化(val1 -> val2)
- local function _ChangeNum(val1, val2)
- local isUp = val2 > val1
- local str = isUp and tostring(val2) or tostring(val1)
- for i=1,string.len(str) do
- if val1 % 10 ^ i ~= val2 % 10 ^ i then
- if isUp then -- 递增
- return val1 + 10 ^ (i-1)
- else -- 递减
- return val1 - 10 ^ (i-1)
- end
- end
- end
- end
- local function _Stop()
- if SL.DigitChangeTimerID then
- SL:UnSchedule(SL.DigitChangeTimerID)
- SL.DigitChangeTimerID = nil
- end
- end
- _Stop()
- local isUp = target > cur
- SL.DigitChangeTimerID = SL:Schedule(function ()
- if isUp then
- if cur >= target then
- return _Stop()
- end
- else
- if cur <= target then
- return _Stop()
- end
- end
- cur = _ChangeNum(cur, target)
- if widget and not tolua.isnull(widget) then
- _SetText[descript](widget, cur)
- else
- _Stop()
- end
-
- end, interval or 0.01)
- end
- -- 进度条动画
- -- widget:进度条
- -- widgetBg:进度条变化时的底(背景是进度条的话 type传值1或者不传; 如果Layout的话 必须传一个值,这个值不能是1)
- -- param = {
- -- count: 重置次数
- -- num: 当前剩余血条的数量
- -- to: 目标进度值
- -- step: 动画步长
- -- interval: 增长的速度, 默认0.01
- -- colors: 血条颜色变化顺序
- -- callback: 回调函数
- -- opacity: 血条透明度
- -- type: 进度条类型
- -- }
- function GUI:Timeline_Progress(widget, widgetBg, param)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- local count = param.count or 0
- local num = param.num or 1
- local to = param.to or 0
- local step = param.step or 0
- local interval = param.interval or 0.01
- local colors = param.colors or nil
- local callback = param.callback or nil
- local opacity = param.opacity or 255
- local type = param.type or 1
-
- local from = widget:getPercent()
- widget:setPercent(from)
- local function _GetColor(n)
- return colors[n] or colors[#colors]
- end
- local k = 0
- local function _CallFunc()
- from = from + step
- if k == count then
- if step > 0 and from > to then
- from = to
- elseif step < 0 and from < to then
- from = to
- end
- end
-
- local percent = from
- if k < count then
- if step < 0 then
- if from <= 0 then
- from = 100
- k = k + 1
- if colors then
- local n = #colors
- if type == 1 then
- widget:loadTexture(_GetColor(k % n))
- else
- widget:setColor(SL:ConvertColorFromHexString(_GetColor(k % n)))
- end
- if widgetBg then
- if num == 1 then
- widgetBg:setOpacity(0)
- else
- if type == 1 then
- widgetBg:loadTexture(_GetColor((k+1) % n))
- widgetBg:setPercent(100)
- else
- widgetBg:setBackGroundColor(SL:ConvertColorFromHexString(_GetColor((k+1) % n)))
- end
- widgetBg:setOpacity(255)
- end
- end
- end
- if callback then
- callback(k)
- end
- end
- else
- if from >= 100 then
- from = 0
- k = k + 1
- if colors then
- local n = #colors
- if type == 1 then
- widget:loadTexture(_GetColor(k % n))
- else
- widget:setColor(SL:ConvertColorFromHexString(_GetColor(k % n)))
- end
- if widgetBg then
- if num == 1 then
- widgetBg:setOpacity(0)
- else
- if type == 1 then
- widgetBg:loadTexture(_GetColor((k+1) % n))
- widgetBg:setPercent(100)
- else
- widgetBg:setBackGroundColor(SL:ConvertColorFromHexString(_GetColor((k+1) % n)))
- end
- widgetBg:setOpacity(255)
- end
- end
- end
- if callback then
- callback(k)
- end
- end
- end
- else
- local isStop = (step < 0 and from <= to) or (step >= 0 and from >= to)
- if isStop then
- from = to
- widget:stopAllActions()
-
- if callback then
- callback(k, true)
- end
- end
- if colors then
- if type == 1 then
- widget:loadTexture(_GetColor(1))
- else
- widget:setColor(SL:ConvertColorFromHexString(_GetColor(1)))
- end
- if widgetBg then
- if num == 1 then
- widgetBg:setOpacity(0)
- else
- if type == 1 then
- widgetBg:loadTexture(_GetColor(2))
- widgetBg:setPercent(100)
- else
- widgetBg:setBackGroundColor(SL:ConvertColorFromHexString(_GetColor(2)))
- end
- widgetBg:setOpacity(255)
- end
- end
- end
- end
- widget:setPercent(percent)
- end
- schedule(widget, _CallFunc, interval)
- end
- -- 自适应布局
- -- pNode: ScrollView(常用)、Panel(pNode 中的子控件不显示,则不参与排版)
- -- param = {
- -- dir: 1:垂直; 2: 水平; 3: 两者
- -- gap: x: 左右间距; y: 上下间距; l: 左边距; t: 上边距
- -- addDir: 动画增长方式 1: 从上到下(从左到右)(多行从左上角), 2:中间到两边(多行从右上角), 3:从下到上(从右到左)
- -- colnum: 多行列数(dir必须是2)
- -- autosize: 根据内容自适应容器
- -- sortfunc: 排序函数
- -- interval:增长方式动画播放时间间隔, 不传值则不播放动画
- -- rownums : 每一行的数量table ; 例如:rownums = {3, 2} (第一行3个元素,第二行2个元素)
- -- }
- function GUI:UserUILayout(pNode, param)
- if CheckIsInvalidCObject(pNode) then
- return false
- end
- local isScrollView = tolua.type(pNode) == "ccui.ScrollView"
- pNode:stopAllActions()
- --初始化默认值
- param = param or {}
- local dir = param.dir and param.dir or (isScrollView and pNode:getDirection() or 3)
- dir = math.min(dir, 3)
- local gap = param.gap
- local addDir = param.addDir or 1
- local colnum = param.colnum or 0
- local autosize = param.autosize or false
- local sortfunc = param.sortfunc
- local interval = param.play and 0.01 or param.interval
- local rownums = param.rownums or {}
- local loadStyle = param.loadStyle or 1
- local xGap = (gap and gap.x) and gap.x or (param.x or 0) -- 控件左右间距
- local yGap = (gap and gap.y) and gap.y or (param.y or 0) -- 控件上下间距
- local xMar = (gap and gap.l) and gap.l or (param.l or 0) -- 左边距
- local yMar = (gap and gap.t) and gap.t or (param.t or 0) -- 上边距
- --水平和垂直方向只能有一个
- local visibleChildren = {}
- for i,v in ipairs(pNode:getChildren()) do
- if v and v:isVisible() then
- v:setAnchorPoint({x = 0.5, y = 0.5})
- table.insert(visibleChildren, v)
- end
- end
- local num = #visibleChildren
- if num == 0 then
- return cc.size(0, 0)
- end
- if isScrollView then
- pNode:setDirection(dir)
- end
- local cSize = visibleChildren[1]:getContentSize()
- local pSize = pNode:getContentSize()
- local width = xMar * 2
- local height = yMar * 2
- local offX = 0
- local offY = 0
-
- if dir == 1 then -- 垂直
- height = height + num * (cSize.height + yGap) - yGap
- width = pSize.width
- if width > cSize.width then
- width = cSize.width
- end
- elseif dir == 2 then -- 水平
- width = width + num * (cSize.width + xGap) - xGap
- height = pSize.height
- if height > cSize.height then
- height = cSize.height
- end
- else -- 多行多列
- local rownum = 0
- for i,cnt in ipairs(rownums) do
- if cnt and tonumber(cnt) then
- colnum = math.max(colnum, cnt)
- if autosize then
- if cnt > 0 then
- rownum = rownum + 1
- end
- else
- rownum = rownum + 1
- end
- end
- end
- if colnum < 1 then
- colnum = math.max(1, math.floor(pSize.width / cSize.width))
- end
- if rownum == 0 then
- rownum = math.ceil(num / colnum)
- end
- width = width + colnum * (cSize.width + xGap) - xGap
- height = height + rownum * (cSize.height + yGap) - yGap
- end
- -- 设置容器的尺寸
- if autosize then
- pNode:setContentSize({width = width, height = height})
- if isScrollView then
- pNode:setInnerContainerSize({width = width, height = height})
- end
- else
- if pSize.width > width then
- offX = (pSize.width - width) / 2
- end
- if pSize.height > height then
- offY = (pSize.height - height) / 2
- end
- width = math.max(pSize.width, width)
- height = math.max(pSize.height, height)
- if isScrollView then
- pNode:setInnerContainerSize({width = width, height = height})
- else
- pNode:setContentSize({width = width, height = height})
- end
- end
-
- -- 自己排序
- if sortfunc then
- sortfunc(visibleChildren)
- end
- local scrollFunc = {
- [1] = function ()
- if addDir == 2 then
- pNode:scrollToPercentVertical(50, 0.01, false)
- elseif addDir == 3 then
- pNode:scrollToPercentVertical(100, 0.01, false)
- end
- end,
- [2] = function ()
- if addDir == 2 then
- pNode:scrollToPercentHorizontal(50, 0.01, false)
- elseif addDir == 3 then
- pNode:scrollToPercentHorizontal(100, 0.01, false)
- end
- end
- }
- -- 水平垂直滚动指定位置
- if isScrollView and (dir == 1 or dir == 2) then
- local func = scrollFunc[dir]
- if func then
- func()
- end
- end
- if dir > 2 then -- 双方向
- local rows = {}
- local cnum = 0
- for i,cnt in ipairs(rownums) do
- if cnt and tonumber(cnt) then
- cnum = cnum + cnt
- if autosize then
- if cnt > 0 then
- rows[#rows+1] = cnum
- end
- else
- rows[i] = cnum
- end
- end
- end
- for i,item in ipairs(visibleChildren) do
- local hang = math.ceil(i / colnum)
- local k = i
- for r,v in ipairs(rows) do
- if i <= v then
- hang = r
- if rows[r-1] then
- k = i - rows[r-1]
- end
- break
- end
- end
- local x = 0
- local y = 0
- local mod = k % colnum
- if addDir == 2 then
- if autosize then
- x = mod == 0 and xMar + offX + cSize.width/2 or (xMar + (colnum - mod + 1-0.5) * (cSize.width + xGap) - xGap/2) + offX
- else
- x = mod == 0 and xMar + offX * 2 + cSize.width/2 or (xMar + (colnum - mod + 1-0.5) * (cSize.width + xGap) - xGap/2) + offX * 2
- end
- else
- if autosize then
- x = mod == 0 and (width - xMar - cSize.width/2) - offX or (xMar + (mod-0.5) * (cSize.width + xGap) - xGap/2) + offX
- else
- x = mod == 0 and (width - xMar - cSize.width/2) - offX * 2 or (xMar + (mod-0.5) * (cSize.width + xGap) - xGap/2)
- end
- end
- if loadStyle == 3 then
- y = yMar + (hang - 0.5) * cSize.height + (hang - 1) * yGap
- elseif loadStyle == 2 then
- y = height - yMar - (hang - 0.5) * cSize.height - (hang - 1) * yGap - offY
- else
- y = height - yMar - (hang - 0.5) * cSize.height - (hang - 1) * yGap
- end
- item:setPosition({x = x, y = y})
- if interval then
- item:setVisible(false)
- item:runAction(cc.Sequence:create(cc.DelayTime:create(i*interval), cc.Show:create()))
- else
- item:setVisible(true)
- end
- end
- else -- 水平、垂直
- for i,item in ipairs(visibleChildren) do
- local x = 0
- local y = 0
- if dir == 1 then
- x = width / 2
- if addDir == 1 then -- 上到下
- y = height - yMar - cSize.height*(i-0.5) - (i-1) * yGap
- elseif addDir == 3 then -- 下到上
- y = yMar + cSize.height*(i-0.5) + (i-1) * yGap
- else -- 居中
- y = height - yMar - cSize.height*(i-0.5) - (i-1) * yGap - offY
- item.__pos = clone({x = x, y = y})
- y = height / 2
- end
- elseif dir == 2 then
- y = height / 2
- if addDir == 1 then -- 左到右
- x = xMar + cSize.width*(i-0.5) + (i-1) * xGap
- elseif addDir == 3 then -- 右到左
- x = width - xMar - cSize.width*(i-0.5) - (i-1) * xGap
- else -- 居中
- x = width - xMar - cSize.width*(i-0.5) - (i-1) * xGap - offX
- item.__pos = clone({x = x, y = y})
- x = width / 2
- end
- end
- item:setPosition({x = x, y = y})
- if interval then
- item:setVisible(false)
- else
- item:setVisible(true)
- end
- end
- if interval then
- if addDir == 2 then
- local r = math.floor(num / 2)
- local minR = num % 2 == 0 and r or r + 1
- local maxR = r + 1
- for i=1,num do
- local item = visibleChildren[i]
- if item then
- local t = 1
- t = i > maxR and i - maxR or t
- t = i < minR and minR - i or t
- item:setLocalZOrder(t)
- item:setVisible(true)
- item:setOpacity(0)
- item:runAction(cc.Spawn:create(cc.FadeTo:create(interval * t, 255), cc.EaseExponentialOut:create(cc.MoveTo:create(interval * t, item.__pos))))
- end
- end
- else
- for i=1,num do
- local item = visibleChildren[i]
- if item then
- item:runAction(cc.Sequence:create(cc.DelayTime:create(i*interval), cc.Show:create()))
- end
- end
- end
- end
- end
- return cc.size(width, height)
- end
- --[[
- param = {
- bgPic: 背景图
- barPic: 滑动按钮图片
- Arr1PicN: 上(正常图)
- Arr1PicP: 上(按下图)可不传
- Arr2PicN: 下(正常图)
- Arr2PicP: 下(按下图)可不传
- default: 进度条值(默认是0)
- x: 进度条坐标 x
- y: 进度条坐标 y
- list: 滚动的容器 list
- callFunc: 容器滚动的回调函数
- }
- ]]
- function GUI:SetScrollViewVerticalBar(parent, param)
- if CheckIsInvalidCObject(parent) then
- return false
- end
-
- local bgPic = FixPath(param.bgPic)
- local barPic = FixPath(param.barPic)
- local Arr1PicN = FixPath(param.Arr1PicN)
- local Arr1PicP = FixPath(param.Arr1PicP)
- local Arr2PicN = FixPath(param.Arr2PicN)
- local Arr2PicP = FixPath(param.Arr2PicP)
- local default = param.default or 0
- local x = param.x
- local y = param.y
- local list = param.list
- local callFunc = param.callFunc
- -- 背景
- local bar_bg = GUI:Image_Create(parent, "bar_bg", x, y, bgPic)
- local bgWidth = GUI:getContentSize(bar_bg).width
- local bgHeight = GUI:getContentSize(list).height
- GUI:setContentSize(bar_bg, bgWidth, bgHeight)
- -- 上
- local btnArr_1 = GUI:Button_Create(bar_bg, "btnArr_1", bgWidth/2, bgHeight, Arr1PicN)
- if Arr1PicP then
- GUI:Button_loadTexturePressed(btnArr_1, Arr1PicP)
- end
- GUI:setAnchorPoint(btnArr_1, 0.5, 1)
- -- 下
- local btnArr_2 = GUI:Button_Create(bar_bg, "btnArr_2", bgWidth/2, 0, Arr2PicN)
- if Arr2PicP then
- GUI:Button_loadTexturePressed(btnArr_2, Arr2PicP)
- end
- GUI:setAnchorPoint(btnArr_2, 0.5, 0)
- --bar
- local sliderBar = GUI:Slider_Create(bar_bg, "sliderBar", bgWidth/2, bgHeight/2, "res/public/0.png", "res/public/0.png", barPic)
- local btnArr_1_hh = GUI:getContentSize(btnArr_1).height
- local btnArr2Pichh = GUI:getContentSize(btnArr_2).height
- local Image = ccui.ImageView:create(barPic)
- local imageWidth = GUI:getContentSize(Image).width
- local imageHeight = GUI:getContentSize(Image).height
- GUI:setContentSize(sliderBar, bgHeight - btnArr_1_hh - btnArr2Pichh - imageHeight , imageWidth)
- GUI:setAnchorPoint(sliderBar, 0.5, 0.5)
- GUI:setRotation(sliderBar, 90)
- GUI:Slider_setPercent(sliderBar, default)
- -- 计算偏移
- local function GetListOffY()
- return list:getInnerContainerSize().height - list:getContentSize().height
- end
- -- list_cells
- local function listCallback(sender, eventType)
- if callFunc then
- callFunc(sender, eventType)
- end
- local setBarPercent = function ()
- local posY = list:getInnerContainerPosition().y
- local offY = GetListOffY()
- local percent = 100
- if offY > 0 then
- percent = math.min(math.max(0, (offY + posY) / offY * 100), 100)
- end
- sliderBar:setPercent(percent)
- end
- performWithDelay(sliderBar, setBarPercent, 0.01)
- end
- if tolua.type(list) == "ccui.ListView" then
- list:addScrollViewEventListener(listCallback)
- else
- list:addEventListener(listCallback)
- end
- list:addMouseScrollPercent()
- -- Slider_bar
- sliderBar:addEventListener(function ()
- local offY = GetListOffY()
- if offY > 0 then
- list:scrollToPercentVertical(sliderBar:getPercent(), 0.03, false)
- else
- sliderBar:setPercent(100)
- end
- end)
- local function UpOrDown(percent)
- sliderBar:setPercent(percent)
- list:scrollToPercentVertical(percent, 0.03, false)
- end
-
- btnArr_1:addClickEventListener(function ()
- local offY = GetListOffY()
- if offY > 0 then
- UpOrDown(0)
- end
- end)
- btnArr_1:setTouchEnabled(true)
- btnArr_2:addClickEventListener(function ()
- local offY = GetListOffY()
- if offY > 0 then
- UpOrDown(100)
- end
- end)
- btnArr_2:setTouchEnabled(true)
- end
- function GUI:ShowWorldTips(tips, worldPos, anchorPoint)
- showWorldTips(tips, worldPos, anchorPoint)
- end
- function GUI:HideWorldTips()
- hideMouseOverTips()
- end
- --创建技能item
- function GUI:CreateSkillItem(parent, skillID)
- if CheckIsInvalidCObject(parent) then
- return false
- end
-
- local item = SkillItem:create(skillID)
- parent:addChild(item)
- return item
- end
- function GUI:Retain(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:retain()
- end
- function GUI:addRef(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:retain()
- end
- function GUI:Release(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- widget:release()
- end
- function GUI:decRef(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:release()
- end
- -- FIXME: 写错了方法名,但是不能删
- function GUI:defRef(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:release()
- end
- function GUI:autoDecRef(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:autorelease()
- end
- -- FIXME: 写错了方法名,但是不能删
- function GUI:autoDefRef(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:autorelease()
- end
- function GUI:Rect(x, y, width, height)
- return cc.rect(x, y, width, height)
- end
- function GUI:RectContainsPoint(Rect, position)
- return cc.rectContainsPoint(Rect, position)
- end
- function GUI:Size(width, height)
- return cc.size(width, height)
- end
- function GUI:p(x, y)
- return cc.p(x, y)
- end
- --获取图片尺寸
- function GUI:getImageContentSize(path)
- local img = ccui.ImageView:create(path)
- return img:getContentSize()
- end
- --[[
- 文本提示框
- str文本
- width文本宽度
- ]]
- function GUI:GetWordTips(str, width)
- return GetWordTips({str = str,width = width})
- end
- function GUI:isClippingParentContainsPoint(widget, position)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- return widget:isClippingParentContainsPoint(position)
- end
- function GUI:setEnabled(widget, enable)
- if CheckIsInvalidCObject(widget) then
- return false
- end
-
- widget:setEnabled(enable)
- end
- -- 刷坐标整数
- function GUI:RefPosByParent(widget)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if widget then
- refPositionByParent(widget)
- end
- end
- -- 旋转滑动 容器
- function GUI:RotateView_Create(parent, ID, x, y, width, height, scrollGap, param)
- if not ID then
- SL:Print("[GUI ERROR] GUI:RotateView_Create can't find ID")
- return nil
- end
- if not parent then
- SL:Print("[GUI ERROR] GUI:RotateView_Create can't find parent", ID)
- return nil
- end
- if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
- SL:Print("[GUI ERROR] GUI:RotateView_Create ID is exists", ID)
- return nil
- end
- if CheckIsInvalidCObject(parent) then
- return nil
- end
- SL:RequireFile(SLDefine.LUAFile.LUA_FILE_UI_ROTATEVIEW)
- local rotateView = UIRotateView.main(parent, ID, x, y, width, height, scrollGap, param)
- return rotateView
- end
- function GUI:RotateView_addChild(widget, value, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if CheckIsInvalidCObject(value) then
- return false
- end
- if not index then
- SL:Print("[GUI ERROR] GUI:RotateView_addChild index is nil")
- return false
- end
- UIRotateView.addRotateViewChild(widget, value, index)
- end
- function GUI:RotateView_getChildByIndex(widget, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if not index then
- SL:Print("[GUI ERROR] GUI:RotateView_getChildByIndex index is nil")
- return false
- end
- return UIRotateView.getRotateViewChildByIndex(widget, index)
- end
- function GUI:RotateView_getItemByIndex(widget, index)
- if CheckIsInvalidCObject(widget) then
- return false
- end
- if not index then
- SL:Print("[GUI ERROR] GUI:RotateView_getChildByIndex index is nil")
- return false
- end
- return UIRotateView.getRotateViewItemByIndex(widget, index)
- end
- -- 不提供对外函数 --------------------------------------------------------------------------------------------------------------------------
- function GUI:setChineseName(widget, value)
- widget._chinesename = value
- end
- function GUI:getChineseName(widget)
- return widget._chinesename or ""
- end
- function GUI:setID(widget, value)
- widget._ID = value
- end
- function GUI:getID(widget)
- return widget._ID or 0
- end
- function GUI:setChildID(widget, value)
- widget._childID = value
- end
- function GUI:getChildID(widget)
- return widget._childID or 0
- end
- function GUI:setJumpIndex(widget, value)
- widget._jump_index = value
- end
- function GUI:getJumpIndex(widget)
- return widget._jump_index or 0
- end
- function GUI:setClickStatus(widget, value)
- widget._Click_Status = value
- end
- function GUI:setContainerIndexTable(widget, value)
- widget._Container_table = value
- end
- function GUI:setButtonPage(widget, value)
- widget._Button_page = value
- end
- function GUI:setButtonPressColor(widget, value)
- widget._Button_press_C = value
- end
- function GUI:setUIIDs(widget, value)
- widget._uiIDs = value
- end
- function GUI:getRedID(widget)
- if tolua.isnull(widget) then
- return false
- end
- if widget._uiIDs then
- return false
- end
- return tonumber(widget._uiIDs.redID)
- end
- function GUI:getGuideID(widget)
- if tolua.isnull(widget) then
- return false
- end
- if widget._uiIDs then
- return false
- end
- return tonumber(widget._uiIDs.guideID)
- end
- -----------------------------------------------------------------------------------------------------------------------------------------------
|