GUI.lua 238 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758
  1. GUI = {}
  2. local tconcat = table.concat
  3. local tinsert = table.insert
  4. local srep = string.rep
  5. local type = type
  6. local pairs = pairs
  7. local tostring = tostring
  8. local next = next
  9. local sfind = string.find
  10. local ssub = string.sub
  11. local slen = string.len
  12. local sbyte = string.byte
  13. local sgsub = string.gsub
  14. local ssplit = string.split
  15. local sformat = string.format
  16. local scheduleActionTag = 9961
  17. local performActionTag = 9962
  18. local NONEED_PARENT_CODE = -1
  19. -------------------------------------------------------------
  20. local cjson = require("cjson")
  21. local GUIQuickCell = require("GUI/GUIQuickCell")
  22. local TableViewEx = requireUtil("TableViewEx")
  23. -------------------------------------------------------------
  24. -- defines
  25. GUI.PATH_FONT2 = "fonts/font2.ttf"
  26. GUI.PATH_RES_ALPHA = "res/public/alpha_1px.png"
  27. GUI.FILENAME_PREFIX = "GUILayout/"
  28. GUI.EXPORTNAME_PREFIX = "GUIExport/"
  29. -------------------------------------------------------------
  30. local checkValueValid = function (value)
  31. if value == nil then
  32. return true
  33. end
  34. if value == global.MMO.MeTaInvalidKey or value == global.MMO.MeTaInvalidValue then
  35. return true
  36. end
  37. return false
  38. end
  39. -- helper
  40. GUI._disableFixPosition = false
  41. function GUI:DisableFixPosition()
  42. GUI._disableFixPosition = true
  43. end
  44. local function fixPosition(p)
  45. if type(p) ~= "table" then
  46. if checkValueValid(p) or p == "" then
  47. SL:Print("[GUI ERROR] GUI:setPosition, param nil")
  48. p = 0
  49. end
  50. else
  51. if checkValueValid(p.x) then
  52. SL:Print("[GUI ERROR] GUI:setPosition, X nil")
  53. p.x = 0
  54. end
  55. if checkValueValid(p.y) then
  56. SL:Print("[GUI ERROR] GUI:setPosition, Y nil")
  57. p.y = 0
  58. end
  59. end
  60. if GUI._disableFixPosition then
  61. return p
  62. end
  63. if tonumber(p) then
  64. return math.floor(p)
  65. end
  66. return cc.p(math.floor(p.x), math.floor(p.y))
  67. end
  68. -- Button Label offset
  69. local setButtonLabelOffset = function (widget)
  70. local x = widget._x_
  71. local y = widget._y_
  72. if x and y then
  73. widget:getTitleRenderer():setPosition(cc.p(x, y))
  74. elseif x then
  75. widget:getTitleRenderer():setPositionX(x)
  76. elseif y then
  77. widget:getTitleRenderer():setPositionY(y)
  78. end
  79. end
  80. -- check invalid cobj
  81. local function CheckIsInvalidCObject(widget)
  82. -- 开关,不检测
  83. if SL:GetMetaValue("GAME_DATA", "disable_check_cobject") == 1 then
  84. return false
  85. end
  86. --
  87. if widget == nil then
  88. release_print("----------------------------------------")
  89. release_print("LUA ERROR: target is nil value")
  90. release_print(debug.traceback())
  91. release_print("----------------------------------------")
  92. return true
  93. end
  94. --
  95. if tolua.isnull(widget) then
  96. release_print("----------------------------------------")
  97. release_print("LUA ERROR: target is invalid cobj")
  98. release_print(debug.traceback())
  99. release_print("----------------------------------------")
  100. return true
  101. end
  102. return false
  103. end
  104. -------------------------------------------------------------
  105. -- load ccexport
  106. local function GUICreateCCSExport(fileName)
  107. local ui = require(fileName).create()
  108. if ui.root then
  109. local new_widget = ccui.Widget:create()
  110. new_widget:setAnchorPoint(cc.p(0, 0))
  111. local children = ui.root:getChildren()
  112. for _, child in pairs(children) do
  113. child:removeFromParent()
  114. end
  115. for _, child in pairs(children) do
  116. new_widget:addChild(child)
  117. end
  118. local name = ui.root:getName()
  119. -- 自适应代码
  120. if name ~= "Layer" and name ~= "Node" then
  121. local visible = cc.Director:getInstance():getVisibleSize()
  122. new_widget:setContentSize(visible)
  123. ccui.Helper:doLayout(new_widget)
  124. else
  125. new_widget:setContentSize(ui.root:getContentSize())
  126. end
  127. rawset(ui, "root", new_widget)
  128. return new_widget, ui
  129. end
  130. return nil
  131. end
  132. -- load ccexport
  133. function GUI:LoadCCSExport(parent, ID, filename)
  134. if not ID then
  135. SL:Print("[GUI ERROR] GUI:LoadCCSExport can't set ID")
  136. return nil
  137. end
  138. if not parent then
  139. SL:Print("[GUI ERROR] GUI:LoadCCSExport can't find parent")
  140. return nil
  141. end
  142. if SL._DEBUG and parent:getChildByName(ID) then
  143. SL:Print("[GUI ERROR] GUI:LoadCCSExport ID is exists", ID)
  144. return nil
  145. end
  146. local widget, quickUI = GUICreateCCSExport( filename )
  147. parent:addChild(widget)
  148. widget:setName(ID)
  149. return widget, quickUI
  150. end
  151. local GetScriptFunc = function (path)
  152. if not global.FileUtilCtl:isFileExist(path) then
  153. return false
  154. end
  155. local script = global.FileUtilCtl:getDataFromFileEx(path)
  156. script = sgsub(script, ";", "")
  157. local scFunc = load(script)
  158. if not scFunc then
  159. return false
  160. end
  161. local myfunc = scFunc()
  162. if not myfunc then
  163. return false
  164. end
  165. local func = myfunc.init or myfunc.main
  166. if not func then
  167. return false
  168. end
  169. return func
  170. end
  171. GUI.WinExports = {}
  172. function GUI:LoadExport(parent, filename, loadCB)
  173. if not parent then
  174. SL:Print("[GUI ERROR] GUI:LoadGUIExport can't find parent")
  175. return nil
  176. end
  177. local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
  178. local newfilename = luafile .. ".lua"
  179. local clock = os.clock()
  180. if SL._DEBUG then
  181. global.FileUtilCtl:purgeCachedEntries()
  182. local func = GetScriptFunc(newfilename)
  183. if func then
  184. func(parent)
  185. end
  186. else
  187. local func = GUI.WinExports[newfilename] or GetScriptFunc(newfilename)
  188. if func then
  189. func(parent)
  190. GUI.WinExports[newfilename] = func
  191. end
  192. end
  193. -- 增加加载回调,兼容H5异步加载写法
  194. if loadCB then
  195. loadCB()
  196. end
  197. end
  198. GUI.WinExportsEx = {}
  199. function GUI:LoadExportEx(parent, filename, page, data)
  200. if not parent then
  201. SL:Print("[GUI ERROR] GUI:LoadExportEx can't find parent")
  202. return nil
  203. end
  204. local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
  205. local newfilename = luafile .. ".lua"
  206. local clock = os.clock()
  207. if SL._DEBUG then
  208. global.FileUtilCtl:purgeCachedEntries()
  209. local func = GetScriptFunc(newfilename)
  210. if func then
  211. func(parent, false, page, data)
  212. GUI.WinExportsEx[newfilename] = func
  213. end
  214. else
  215. local func = GUI.WinExports[newfilename] or GetScriptFunc(newfilename)
  216. if func then
  217. func(parent, false, page, data)
  218. GUI.WinExportsEx[newfilename] = func
  219. end
  220. end
  221. end
  222. -- 更新Export中变量
  223. function GUI:UpdateExportEx(parent, filename, page)
  224. if not parent then
  225. SL:Print("[GUI ERROR] GUI:LoadGUIExport can't find parent")
  226. return nil
  227. end
  228. local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
  229. local newfilename = luafile .. ".lua"
  230. local func = GUI.WinExportsEx[newfilename]
  231. if func then
  232. func(parent, true, page)
  233. end
  234. end
  235. function GUI:LoadExportVar(parent, filename, data)
  236. if not parent then
  237. SL:Print("[GUI ERROR] GUI:LoadExportEx can't find parent")
  238. return nil
  239. end
  240. local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
  241. local newfilename = luafile .. ".lua"
  242. local clock = os.clock()
  243. if SL._DEBUG then
  244. global.FileUtilCtl:purgeCachedEntries()
  245. local func = GetScriptFunc(newfilename)
  246. if func then
  247. func(parent, data)
  248. GUI.WinExportsEx[newfilename] = func
  249. end
  250. else
  251. local func = GUI.WinExports[newfilename] or GetScriptFunc(newfilename)
  252. if func then
  253. func(parent, data)
  254. GUI.WinExportsEx[newfilename] = func
  255. end
  256. end
  257. end
  258. -- 更新Export中变量
  259. function GUI:UpdateExportVar(parent, filename, data)
  260. if not parent then
  261. SL:Print("[GUI ERROR] GUI:LoadGUIExport can't find parent")
  262. return nil
  263. end
  264. local luafile = GUI.EXPORTNAME_PREFIX .. sgsub(filename, ".lua$", "")
  265. local newfilename = luafile .. ".lua"
  266. local func = GUI.WinExportsEx[newfilename]
  267. if func then
  268. func(parent, data, true)
  269. end
  270. end
  271. --使用内置的导出目录
  272. function GUI:LoadInternalExport(parent, filename, loadCB)
  273. if not parent then
  274. SL:Print("[GUI ERROR] GUI:LoadInternalExport can't find parent")
  275. return nil
  276. end
  277. local luafile = "game/view/export/" .. filename
  278. if SL._DEBUG then
  279. package.loaded[luafile] = nil
  280. end
  281. local file = require(luafile)
  282. local func = file.init or file.main
  283. if func then
  284. func(parent)
  285. end
  286. -- 增加加载回调,兼容H5异步加载写法
  287. if loadCB then
  288. loadCB()
  289. end
  290. end
  291. -- load say
  292. function GUI:LoadSay(parent, ID, str, linkCB)
  293. if not ID then
  294. SL:Print("[GUI ERROR] GUI:LoadSay, can't find ID", ID)
  295. return nil
  296. end
  297. local fakeMediator = nil
  298. if not parent or parent == 0 then -- WIN 同步ssr
  299. local visibleSize = global.Director:getVisibleSize()
  300. local _, rootRect = checkNotchPhone()
  301. local layout = ccui.Layout:create()
  302. layout:setContentSize(visibleSize.width, visibleSize.height)
  303. layout:setPositionX(rootRect.x)
  304. -- mediator
  305. if nil == GUI.Mediators[ID] then
  306. local GUIMediator = require("GUI/GUIMediator")
  307. fakeMediator = GUIMediator.new(ID)
  308. GUI.Mediators[ID] = fakeMediator
  309. else
  310. fakeMediator = GUI.Mediators[ID]
  311. end
  312. fakeMediator:setSavedPosition(cc.p(0, 0))
  313. fakeMediator._type = global.UIZ.UI_NORMAL
  314. fakeMediator._layer = layout
  315. fakeMediator._voice = false
  316. fakeMediator._hideMain = false
  317. fakeMediator._hideLast = false
  318. fakeMediator._escClose = false
  319. fakeMediator._GUI_ID = ID
  320. fakeMediator._LuaEvent = {}
  321. fakeMediator._NetMsgEvent = {}
  322. fakeMediator._LuaNetMsgEvent = {}
  323. parent = layout
  324. end
  325. if parent:getChildByName(ID) then
  326. SL:Print("[GUI ERROR] GUI:LoadSay ID is exists", ID)
  327. return nil
  328. end
  329. local contentSize = parent:getContentSize()
  330. local rootRect = cc.rect(0, 0, contentSize.width, contentSize.height)
  331. local LexicalHelper = require("sui/LexicalHelper")
  332. local elements = LexicalHelper:Parse(str)
  333. local SUILoader = require("sui/SUILoader").new()
  334. local trunk, background = SUILoader:loadContent(elements, linkCB, closeCB, rootRect)
  335. local widget = trunk.render
  336. parent:addChild(widget)
  337. widget:setName(ID)
  338. if fakeMediator then
  339. local element = background and background.element
  340. if element then
  341. fakeMediator._resetPostion = (tonumber(element.attr.reset) or 1) == 1
  342. fakeMediator._escClose = (tonumber(element.attr.esc) or 1) == 1
  343. fakeMediator._hideMain = (tonumber(element.attr.hideMain) or 0) == 1
  344. fakeMediator._adapet = (tonumber(element.attr.show) or 0) == 6 --加黑幕
  345. end
  346. fakeMediator:OpenLayer()
  347. if background and background.render then
  348. local element = background.element
  349. local canmove = (element and tonumber(element.attr.move) or 0) == 1
  350. if canmove then
  351. fakeMediator:setLayerMoveEnable(background.render)
  352. end
  353. end
  354. return parent
  355. end
  356. return widget
  357. end
  358. -------------------------------------------------------------
  359. GUI.ATTACH_LEFTTOP = nil -- 主界面挂接,左上
  360. GUI.ATTACH_RIGHTTOP = nil -- 主界面挂接,右上
  361. GUI.ATTACH_LEFTBOTTOM = nil -- 主界面挂接,左下
  362. GUI.ATTACH_RIGHTBOTTOM = nil -- 主界面挂接,右下
  363. GUI.ATTACH_MAINMINIMAP = nil -- 主界面挂接,小地图
  364. GUI.ATTACH_MAINTOP = nil -- 主界面挂接,顶部装饰
  365. GUI.ATTACH_PARENT = nil -- 当前界面挂节点,挂节点是变化的
  366. GUI.ATTACH_PARENT_UITOP = nil -- 提供通知层挂接点
  367. GUI._sceneRootNodeF = nil -- 场景节点,在前
  368. GUI._sceneRootNodeB = nil -- 场景节点,在后
  369. GUI._actorRootNode = nil -- ACTOR节点
  370. -- 主界面最底层
  371. GUI.ATTACH_LEFTTOP_B = nil
  372. GUI.ATTACH_RIGHTTOP_B = nil
  373. GUI.ATTACH_LEFTBOTTOM_B = nil
  374. GUI.ATTACH_RIGHTBOTTOM_B= nil
  375. -- 主界面最顶层 (高于小地图)
  376. GUI.ATTACH_LEFTTOP_T = nil
  377. GUI.ATTACH_RIGHTTOP_T = nil
  378. GUI.ATTACH_LEFTBOTTOM_T = nil
  379. GUI.ATTACH_RIGHTBOTTOM_T= nil
  380. function GUI:Attach_LeftTop()
  381. return GUI.ATTACH_LEFTTOP
  382. end
  383. function GUI:Attach_RightTop()
  384. return GUI.ATTACH_RIGHTTOP
  385. end
  386. function GUI:Attach_LeftBottom()
  387. return GUI.ATTACH_LEFTBOTTOM
  388. end
  389. function GUI:Attach_RightBottom()
  390. return GUI.ATTACH_RIGHTBOTTOM
  391. end
  392. function GUI:Attach_MainMiniMap()
  393. return GUI.ATTACH_MAINMINIMAP
  394. end
  395. function GUI:Attach_MainTop()
  396. return GUI.ATTACH_MAINTOP
  397. end
  398. function GUI:Attach_Parent()
  399. return GUI.ATTACH_PARENT
  400. end
  401. function GUI:Attach_UITop()
  402. return GUI.ATTACH_PARENT_UITOP
  403. end
  404. function GUI:Attach_SceneF()
  405. return GUI._sceneRootNodeF
  406. end
  407. function GUI:Attach_SceneB()
  408. return GUI._sceneRootNodeB
  409. end
  410. function GUI:Attach_ActorNode()
  411. return GUI._actorRootNode
  412. end
  413. -- bottom
  414. function GUI:Attach_LeftTop_B()
  415. return GUI.ATTACH_LEFTTOP_B
  416. end
  417. function GUI:Attach_RightTop_B()
  418. return GUI.ATTACH_RIGHTTOP_B
  419. end
  420. function GUI:Attach_LeftBottom_B()
  421. return GUI.ATTACH_LEFTBOTTOM_B
  422. end
  423. function GUI:Attach_RightBottom_B()
  424. return GUI.ATTACH_RIGHTBOTTOM_B
  425. end
  426. -- top
  427. function GUI:Attach_LeftTop_T()
  428. return GUI.ATTACH_LEFTTOP_T
  429. end
  430. function GUI:Attach_RightTop_T()
  431. return GUI.ATTACH_RIGHTTOP_T
  432. end
  433. function GUI:Attach_LeftBottom_T()
  434. return GUI.ATTACH_LEFTBOTTOM_T
  435. end
  436. function GUI:Attach_RightBottom_T()
  437. return GUI.ATTACH_RIGHTBOTTOM_T
  438. end
  439. -- 父节点
  440. GUI._Parent = {}
  441. function GUI:SetGUIParent(index, parent)
  442. GUI._Parent[index] = parent
  443. end
  444. function GUI:Win_FindParent(ID)
  445. return GUI._Parent[ID or 0] or GUI._Parent[0]
  446. end
  447. -------------------------------------------------------------
  448. -- gui
  449. function GUI:Win_Open(filename)
  450. SL:Print("[GUI LOG] GUI:Win_Open", filename)
  451. local clock = os.clock()
  452. local fileUtil = global.FileUtilCtl
  453. local newfilename = GUI.FILENAME_PREFIX .. filename ..".lua"
  454. if not fileUtil:isFileExist(newfilename) then
  455. SL:Print("[GUI ERROR] GUI:Win_Open, can't find file", newfilename)
  456. return false
  457. end
  458. local clock = os.clock()
  459. local script = fileUtil:getDataFromFileEx(newfilename)
  460. local scFunc = nil
  461. if script ~= "" then
  462. if SL._DEBUG then
  463. assert(load(script))
  464. end
  465. scFunc = load(script)
  466. end
  467. if not scFunc then
  468. SL:Print("[GUI ERROR] GUI:Win_Open, load lua string error", newfilename)
  469. return false
  470. end
  471. scFunc()
  472. SL:Print("[GUI LOG] GUI:Win_Open, load cost(milliseconds) ", filename, (os.clock() - clock) * 1000)
  473. return true
  474. end
  475. function GUI:Win_AddFile(parent, filename)
  476. local newfilename = GUI.FILENAME_PREFIX .. filename ..".lua"
  477. if not global.FileUtilCtl:isFileExist(newfilename) then
  478. SL:Print("[GUI ERROR] GUI:Win_Open, can't find file", newfilename)
  479. return false
  480. end
  481. local CUILoader = requireCUI("CUILoader")
  482. CUILoader:ParseLuaFile2(global.FileUtilCtl:getDataFromFileEx(newfilename), parent)
  483. end
  484. GUI.WinLayers = {} -- GUI 界面管理
  485. GUI.Mediators = {} -- GUI 界面管理
  486. -- orderParam 0主界面 1普通 2通知层
  487. function GUI:Win_Create(ID, x, y, width, height, hideMain, hideLast, needVoice, escClose, isRevmsg, npcID, orderParam)
  488. if GET_GAME_STATE() ~= global.MMO.GAME_STATE_WORLD then
  489. SL:Print("[GUI ERROR] GUI:Win_Create, game world Only", ID)
  490. return nil
  491. end
  492. if not ID then
  493. SL:Print("[GUI ERROR] GUI:Win_Create, can't find ID", ID)
  494. return nil
  495. end
  496. if GUI.WinLayers[ID] then
  497. SL:Print("[GUI WARNING] GUI:Win_Create, Win exist, close it", ID)
  498. -- close, if open
  499. local window = GUI:GetWindow(nil, ID)
  500. GUI:Win_Close(window)
  501. end
  502. -- 默认值
  503. hideMain = hideMain or false
  504. hideLast = hideLast or false
  505. needVoice = (needVoice == nil or needVoice == true) and true or false
  506. isRevmsg = (isRevmsg == nil or isRevmsg == true) and true or false
  507. escClose = (escClose == nil or escClose == true) and true or false
  508. -- new widget
  509. local widget = cc.Layer:create()
  510. widget:setName(ID)
  511. -- attr
  512. x = x or 0
  513. y = y or 0
  514. -- 屏蔽触摸
  515. if isRevmsg then
  516. local touchLayout = ccui.Layout:create()
  517. widget:addChild(touchLayout)
  518. touchLayout:setName("__GUI_WIN_TOUCH")
  519. touchLayout:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  520. touchLayout:setContentSize(cc.size(width, height))
  521. touchLayout:setTouchEnabled(true)
  522. if SL:GetMetaValue("WINPLAYMODE") then
  523. GUI:setMouseEnabled(touchLayout, true)
  524. end
  525. end
  526. -- mediator
  527. local fakeMediator = nil
  528. if nil == GUI.Mediators[ID] then
  529. local GUIMediator = require("GUI/GUIMediator")
  530. fakeMediator = GUIMediator.new(ID)
  531. GUI.Mediators[ID] = fakeMediator
  532. else
  533. fakeMediator = GUI.Mediators[ID]
  534. end
  535. fakeMediator:setSavedPosition(cc.p(x, y))
  536. local type = global.UIZ.UI_NORMAL
  537. if orderParam == 2 then
  538. type = global.UIZ.UI_NOTICE
  539. elseif orderParam == 0 then
  540. type = global.UIZ.UI_MAIN
  541. end
  542. fakeMediator._type = type
  543. fakeMediator._layer = widget
  544. fakeMediator._voice = needVoice
  545. fakeMediator._hideMain = hideMain
  546. fakeMediator._hideLast = hideLast
  547. fakeMediator._escClose = escClose
  548. fakeMediator._GUI_ID = ID
  549. fakeMediator._NPCID = npcID
  550. fakeMediator._LuaEvent = {}
  551. fakeMediator._NetMsgEvent = {}
  552. fakeMediator._LuaNetMsgEvent = {}
  553. fakeMediator:OpenLayer()
  554. return widget
  555. end
  556. function GUI:Win_BindLuaEvent(widget, eventID, eventTag)
  557. if not widget then
  558. SL:Print("[GUI ERROR] GUI:Win_BindLuaEvent, can't find Win")
  559. return false
  560. end
  561. if not widget.ID then
  562. SL:Print("[GUI ERROR] GUI:Win_BindLuaEvent, invalid Win")
  563. return false
  564. end
  565. if not eventID then
  566. SL:Print("[GUI ERROR] eventID is null", eventID)
  567. return false
  568. end
  569. if not eventTag then
  570. SL:Print("[GUI ERROR] eventTag is null", eventTag)
  571. return false
  572. end
  573. local fakeMediator = widget.mediator
  574. fakeMediator._LuaEvent = fakeMediator._LuaEvent or {}
  575. fakeMediator._LuaEvent[eventID] = fakeMediator._LuaEvent[eventID] or {}
  576. fakeMediator._LuaEvent[eventID][eventTag] = true
  577. end
  578. local UnBindLuaEvent = function (widget)
  579. for eID, eTags in pairs(widget.mediator._LuaEvent or {}) do
  580. for eTag, _ in pairs(eTags or {}) do
  581. if SLBridge.LUAEvent[eID] and SLBridge.LUAEvent[eID][eTag] then
  582. SLBridge.LUAEvent[eID][eTag] = nil
  583. end
  584. end
  585. end
  586. widget.mediator._LuaEvent = {}
  587. end
  588. function GUI:Win_BindNetMsgEvent(widget, msgID)
  589. if not widget then
  590. SL:Print("[GUI ERROR] GUI:Win_BindNetMsgEvent, can't find Win")
  591. return false
  592. end
  593. if not widget.ID then
  594. SL:Print("[GUI ERROR] GUI:Win_BindNetMsgEvent, is valid Win")
  595. return false
  596. end
  597. if not msgID then
  598. SL:Print("[GUI ERROR] msgID is null", msgID)
  599. return false
  600. end
  601. local fakeMediator = widget.mediator
  602. fakeMediator._NetMsgEvent = fakeMediator._NetMsgEvent or {}
  603. fakeMediator._NetMsgEvent[msgID] = true
  604. end
  605. local UnBindNetMsgEvent = function (widget)
  606. for msgID, _ in pairs(widget.mediator._NetMsgEvent or {}) do
  607. SL.NetworkUtil:UnRegisterNetworkHandler(msgID)
  608. end
  609. widget.mediator._NetMsgEvent = {}
  610. end
  611. function GUI:Win_BindLuaNetMsgEvent(widget, msgID)
  612. if not widget then
  613. SL:Print("[GUI ERROR] GUI:Win_BindLuaNetMsgEvent, can't find Win")
  614. return false
  615. end
  616. if not widget.ID then
  617. SL:Print("[GUI ERROR] GUI:Win_BindLuaNetMsgEvent, is valid Win")
  618. return false
  619. end
  620. if not msgID then
  621. SL:Print("[GUI ERROR] Lua msgID is null", msgID)
  622. return false
  623. end
  624. local fakeMediator = widget.mediator
  625. fakeMediator._LuaNetMsgEvent = fakeMediator._LuaNetMsgEvent or {}
  626. fakeMediator._LuaNetMsgEvent[msgID] = true
  627. end
  628. local UnBindLuaNetMsgEvent = function (widget)
  629. for msgID, _ in pairs(widget.mediator._LuaNetMsgEvent or {}) do
  630. SL.NetworkUtil:UnRegisterLuaNetworkHandler(msgID)
  631. end
  632. widget.mediator._LuaNetMsgEvent = {}
  633. end
  634. function GUI:Win_Close(widget)
  635. if not widget then
  636. SL:Print("[GUI ERROR] GUI:Win_Close, can't find Win")
  637. return nil
  638. end
  639. if not widget.ID then
  640. SL:Print("[GUI ERROR] GUI:Win_Close, is valid Win")
  641. return nil
  642. end
  643. UnBindLuaEvent(widget)
  644. UnBindNetMsgEvent(widget)
  645. UnBindLuaNetMsgEvent(widget)
  646. local fakeMediator = widget.mediator
  647. fakeMediator:CloseLayer()
  648. end
  649. function GUI:Win_CloseAll()
  650. while true do
  651. local key, window = next(GUI.WinLayers)
  652. if not key or not window then
  653. break
  654. end
  655. GUI:Win_Close(window)
  656. end
  657. end
  658. function GUI:Win_CloseByID(ID)
  659. local window = GUI:GetWindow(nil, ID)
  660. if not window then
  661. return
  662. end
  663. GUI:Win_Close(window)
  664. end
  665. function GUI:Win_CloseByNPCID(NPCID)
  666. for _, v in pairs(GUI.WinLayers) do
  667. if v.mediator and v.mediator._NPCID == tonumber(NPCID) then
  668. GUI:Win_Close(v)
  669. break
  670. end
  671. end
  672. end
  673. function GUI:GetWindow(parent, ID)
  674. local slices = ssplit(ID, "/")
  675. -- find parent
  676. local window = nil
  677. if parent == nil then
  678. window = GUI.WinLayers[slices[1]]
  679. else
  680. window = GUI:getChildByName(parent, slices[1])
  681. end
  682. if not window then
  683. return nil
  684. end
  685. for i = 2, #slices do
  686. window = GUI:getChildByName(window, slices[i])
  687. if not window then
  688. return nil
  689. end
  690. end
  691. return window
  692. end
  693. function GUI:Win_GetParam(widget)
  694. return widget.param
  695. end
  696. function GUI:Win_SetParam(widget, param, uitype)
  697. widget.param = param
  698. end
  699. function GUI:Win_SetESCClose(widget, value)
  700. if not widget then
  701. SL:Print("[GUI ERROR] GUI:SetESCClose, can't find Win")
  702. return
  703. end
  704. if not widget.mediator then
  705. SL:Print("[GUI ERROR] GUI:SetESCClose, win only")
  706. return
  707. end
  708. widget.mediator._escClose = value
  709. end
  710. function GUI:Win_SetSwallowRightMouseTouch(widget, state)
  711. if CheckIsInvalidCObject(widget) then
  712. return false
  713. end
  714. if not widget then
  715. SL:Print("[GUI WARNING] GUI:SetSwallowRightMouseTouch can't find Win")
  716. return nil
  717. end
  718. local function onMouseDown(sender)
  719. local button = sender:getMouseButton()
  720. if button == cc.MouseButton.BUTTON_RIGHT then
  721. sender:stopPropagation()
  722. end
  723. end
  724. local listener = cc.EventListenerMouse:create()
  725. local eventDispatcher = cc.Director:getInstance():getEventDispatcher()
  726. if state then
  727. listener:registerScriptHandler(onMouseDown, cc.Handler.EVENT_MOUSE_DOWN)
  728. eventDispatcher:addEventListenerWithSceneGraphPriority(listener, widget)
  729. else
  730. eventDispatcher:removeEventListenersForTarget(widget)
  731. end
  732. end
  733. function GUI:Win_SetDrag(widget, dragLayer)
  734. if not widget then
  735. SL:Print("[GUI ERROR] GUI:Win_SetDrag, can't find Win")
  736. return
  737. end
  738. if not widget.mediator then
  739. SL:Print("[GUI ERROR] GUI:Win_SetDrag, win only")
  740. PrintTraceback()
  741. return
  742. end
  743. widget.mediator:setLayerMoveEnable(dragLayer)
  744. end
  745. --拖动页面 透明
  746. function GUI:SetLayerMovingOpacity(b)
  747. local layerFacadeMediator = global.Facade:retrieveMediator("LayerFacadeMediator")
  748. layerFacadeMediator:SetOnMovingOpacity(b)
  749. end
  750. function GUI:Win_SetMainHide(widget, value)
  751. if not widget then
  752. SL:Print("[GUI ERROR] GUI:Win_SetDrag, can't find Win")
  753. return
  754. end
  755. if not widget.mediator then
  756. SL:Print("[GUI ERROR] GUI:Win_SetDrag, win only")
  757. PrintTraceback()
  758. return
  759. end
  760. widget.mediator:setHideMainUI(value)
  761. end
  762. function GUI:Win_BindNPC(widget, npcID)
  763. if not widget then
  764. SL:Print("[GUI ERROR] GUI:Win_BindNPC, can't find Win")
  765. return
  766. end
  767. if not widget.mediator then
  768. SL:Print("[GUI ERROR] GUI:Win_BindNPC, win only")
  769. return
  770. end
  771. widget.mediator._NPCID = npcID
  772. end
  773. function GUI:Win_SetZPanel(widget, zPanel)
  774. if not widget then
  775. SL:Print("[GUI ERROR] GUI:Win_SetZPanel, can't find Win")
  776. return
  777. end
  778. if not widget.mediator then
  779. SL:Print("[GUI ERROR] GUI:Win_SetZPanel, win only")
  780. return
  781. end
  782. widget.mediator:setLayerZPanel(zPanel)
  783. end
  784. function GUI:Win_IsNull(widget)
  785. if not widget then
  786. return true
  787. end
  788. return tolua.isnull(widget)
  789. end
  790. function GUI:Win_IsNotNull(widget)
  791. return not GUI:Win_IsNull(widget)
  792. end
  793. function GUI:SetRefreshVarFunc(widget, callback)
  794. widget._refreshVarFunc = callback
  795. end
  796. function GUI:GetRefreshVarFunc(widget)
  797. if CheckIsInvalidCObject(widget) then
  798. return false
  799. end
  800. return widget._refreshVarFunc
  801. end
  802. -------------------------------------------------------------
  803. function GUI:setColor(widget, value)
  804. if CheckIsInvalidCObject(widget) then
  805. return false
  806. end
  807. widget:setColor(SL:ConvertColorFromHexString(value))
  808. end
  809. --
  810. function GUI:setPosition(widget, x, y)
  811. if CheckIsInvalidCObject(widget) then
  812. return false
  813. end
  814. x = fixPosition(x)
  815. if type(x) ~= "table" then
  816. y = fixPosition(y)
  817. end
  818. local originX = widget:getPositionX()
  819. local originY = widget:getPositionY()
  820. if originX ~= x or originY ~= y then
  821. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_POS_CHANGE, true)
  822. end
  823. widget:setPosition(cc.p(x, y))
  824. end
  825. function GUI:getPosition(widget)
  826. if CheckIsInvalidCObject(widget) then
  827. return cc.p(0, 0)
  828. end
  829. if widget.getTurePosition then
  830. return widget:getTurePosition()
  831. end
  832. return cc.p(widget:getPosition())
  833. end
  834. --
  835. function GUI:setPositionX(widget, value)
  836. if CheckIsInvalidCObject(widget) then
  837. return false
  838. end
  839. if checkValueValid(value) then
  840. SL:Print("[GUI ERROR] GUI:setPositionX, param nil")
  841. value = 0
  842. end
  843. local x = fixPosition(value)
  844. local originX = widget:getPositionX()
  845. if originX ~= x then
  846. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_POS_CHANGE, true)
  847. end
  848. widget:setPositionX(x)
  849. end
  850. function GUI:getPositionX(widget)
  851. if CheckIsInvalidCObject(widget) then
  852. return 0
  853. end
  854. if widget.getTurePosition then
  855. return widget:getTurePosition().x
  856. end
  857. return widget:getPositionX()
  858. end
  859. --
  860. function GUI:setPositionY(widget, value)
  861. if CheckIsInvalidCObject(widget) then
  862. return false
  863. end
  864. if checkValueValid(value) then
  865. SL:Print("[GUI ERROR] GUI:setPositionY, param nil")
  866. value = 0
  867. end
  868. local y = fixPosition(value)
  869. local originY = widget:getPositionY()
  870. if originY ~= y then
  871. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_POS_CHANGE, true)
  872. end
  873. widget:setPositionY(y)
  874. end
  875. function GUI:getPositionY(widget)
  876. if CheckIsInvalidCObject(widget) then
  877. return 0
  878. end
  879. if widget.getTurePosition then
  880. return widget:getTurePosition().y
  881. end
  882. return widget:getPositionY()
  883. end
  884. --
  885. function GUI:setAnchorPoint(widget, x, y)
  886. if CheckIsInvalidCObject(widget) then
  887. return false
  888. end
  889. if type(x) ~= "table" and checkValueValid(x) then
  890. SL:Print("[GUI ERROR] GUI:setAnchorPoint, X nil")
  891. x = 0
  892. end
  893. if type(x) ~= "table" and checkValueValid(y) then
  894. SL:Print("[GUI ERROR] GUI:setAnchorPoint, Y nil")
  895. y = 0
  896. end
  897. widget:setAnchorPoint(cc.p(x, y))
  898. end
  899. function GUI:getAnchorPoint(widget)
  900. if CheckIsInvalidCObject(widget) then
  901. return cc.p(0, 0)
  902. end
  903. return widget:getAnchorPoint()
  904. end
  905. function GUI:setIgnoreContentAdaptWithSize(widget, value)
  906. if CheckIsInvalidCObject(widget) then
  907. return false
  908. end
  909. widget:ignoreContentAdaptWithSize(value)
  910. if tolua.type(widget) == "ccui.Button" then
  911. setButtonLabelOffset(widget)
  912. end
  913. end
  914. --
  915. function GUI:setContentSize(widget, sizeW, sizeH)
  916. if CheckIsInvalidCObject(widget) then
  917. return false
  918. end
  919. local size = nil
  920. if nil == sizeH then
  921. size = { width = sizeW.width, height = sizeW.height }
  922. else
  923. if checkValueValid(sizeW) then
  924. SL:Print("[GUI ERROR] GUI:setContentSize, width nil")
  925. sizeW = 0
  926. end
  927. if checkValueValid(sizeH) then
  928. SL:Print("[GUI ERROR] GUI:setContentSize, height nil")
  929. sizeH = 0
  930. end
  931. size = { width = sizeW, height = sizeH }
  932. end
  933. local originS = widget:getContentSize()
  934. if originS.width ~= size.width or originS.height ~= size.height then
  935. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
  936. end
  937. if widget.ignoreContentAdaptWithSize then
  938. widget:ignoreContentAdaptWithSize(false)
  939. end
  940. widget:setContentSize(size)
  941. end
  942. function GUI:getContentSize(widget)
  943. if CheckIsInvalidCObject(widget) then
  944. return cc.size(0, 0)
  945. end
  946. return widget:getContentSize()
  947. end
  948. function GUI:setTag(widget, value)
  949. if CheckIsInvalidCObject(widget) then
  950. return false
  951. end
  952. if checkValueValid(value) then
  953. SL:Print("[GUI ERROR] GUI:setTag, tag nil")
  954. value = -1
  955. end
  956. widget:setTag(value)
  957. end
  958. function GUI:getTag(widget)
  959. if CheckIsInvalidCObject(widget) then
  960. return 0
  961. end
  962. return widget:getTag()
  963. end
  964. function GUI:setName(widget, value)
  965. if CheckIsInvalidCObject(widget) then
  966. return false
  967. end
  968. widget:setName(value)
  969. end
  970. function GUI:setGrey(widget, isGrey)
  971. if CheckIsInvalidCObject(widget) then
  972. return false
  973. end
  974. if isGrey then
  975. Shader_Grey(widget)
  976. else
  977. Shader_Normal(widget)
  978. end
  979. end
  980. --
  981. function GUI:setRotation(widget, value)
  982. if CheckIsInvalidCObject(widget) then
  983. return false
  984. end
  985. if checkValueValid(value) then
  986. SL:Print("[GUI ERROR] GUI:setRotation, rotate nil")
  987. value = 0
  988. end
  989. widget:setRotation(value)
  990. end
  991. function GUI:getRotation(widget)
  992. if CheckIsInvalidCObject(widget) then
  993. return 0
  994. end
  995. return widget:getRotation()
  996. end
  997. function GUI:setRotationSkewX(widget, value)
  998. if CheckIsInvalidCObject(widget) then
  999. return false
  1000. end
  1001. widget:setRotationSkewX(value)
  1002. end
  1003. function GUI:setRotationSkewY(widget, value)
  1004. if CheckIsInvalidCObject(widget) then
  1005. return false
  1006. end
  1007. widget:setRotationSkewY(value)
  1008. end
  1009. --
  1010. function GUI:setVisible(widget, value)
  1011. if CheckIsInvalidCObject(widget) then
  1012. return false
  1013. end
  1014. if checkValueValid(value) then
  1015. SL:Print("[GUI ERROR] GUI:setVisible, param nil")
  1016. value = false
  1017. end
  1018. local visible = widget:isVisible()
  1019. if visible ~= value then
  1020. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_VISIBLE, true)
  1021. end
  1022. widget:setVisible(value)
  1023. end
  1024. function GUI:getVisible(widget)
  1025. if CheckIsInvalidCObject(widget) then
  1026. return false
  1027. end
  1028. return widget:isVisible()
  1029. end
  1030. --
  1031. function GUI:setOpacity(widget, value)
  1032. if CheckIsInvalidCObject(widget) then
  1033. return false
  1034. end
  1035. if checkValueValid(value) then
  1036. SL:Print("[GUI ERROR] GUI:setOpacity, opacity nil")
  1037. value = 255
  1038. end
  1039. widget:setOpacity(value)
  1040. end
  1041. function GUI:getOpacity(widget)
  1042. if CheckIsInvalidCObject(widget) then
  1043. return 255
  1044. end
  1045. return widget:getOpacity()
  1046. end
  1047. --
  1048. function GUI:setScale(widget, value)
  1049. if CheckIsInvalidCObject(widget) then
  1050. return false
  1051. end
  1052. if checkValueValid(value) then
  1053. SL:Print("[GUI ERROR] GUI:setScale, scale nil")
  1054. value = 1
  1055. end
  1056. local originScale = widget:getScale()
  1057. if originScale ~= value then
  1058. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
  1059. end
  1060. widget:setScale(value)
  1061. end
  1062. function GUI:getScale(widget)
  1063. if CheckIsInvalidCObject(widget) then
  1064. return 1
  1065. end
  1066. return widget:getScale()
  1067. end
  1068. --
  1069. function GUI:setScaleX(widget, value)
  1070. if CheckIsInvalidCObject(widget) then
  1071. return false
  1072. end
  1073. if checkValueValid(value) then
  1074. SL:Print("[GUI ERROR] GUI:setScaleX, X nil")
  1075. value = 1
  1076. end
  1077. local originScaleX = widget:getScaleX()
  1078. if originScaleX ~= value then
  1079. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
  1080. end
  1081. widget:setScaleX(value)
  1082. end
  1083. function GUI:getScaleX(widget)
  1084. if CheckIsInvalidCObject(widget) then
  1085. return 1
  1086. end
  1087. return widget:getScaleX()
  1088. end
  1089. --
  1090. function GUI:setScaleY(widget, value)
  1091. if CheckIsInvalidCObject(widget) then
  1092. return false
  1093. end
  1094. if checkValueValid(value) then
  1095. SL:Print("[GUI ERROR] GUI:setScaleY, Y nil")
  1096. value = 1
  1097. end
  1098. local originScaleY = widget:getScaleY()
  1099. if originScaleY ~= value then
  1100. SLHandlerEvent:GetCallBack(widget, WND_EVENT_WND_SIZECHANGE, true)
  1101. end
  1102. widget:setScaleY(value)
  1103. end
  1104. function GUI:getScaleY(widget)
  1105. if CheckIsInvalidCObject(widget) then
  1106. return 1
  1107. end
  1108. return widget:getScaleY()
  1109. end
  1110. --
  1111. function GUI:setFlippedX(widget, value)
  1112. if CheckIsInvalidCObject(widget) then
  1113. return false
  1114. end
  1115. if checkValueValid(value) then
  1116. SL:Print("[GUI ERROR] GUI:setFlippedX, X nil")
  1117. value = 0
  1118. end
  1119. widget:setFlippedX(value)
  1120. end
  1121. function GUI:getFlippedX(widget)
  1122. if CheckIsInvalidCObject(widget) then
  1123. return 1
  1124. end
  1125. return widget:isFlippedX()
  1126. end
  1127. --
  1128. function GUI:setFlippedY(widget, value)
  1129. if CheckIsInvalidCObject(widget) then
  1130. return false
  1131. end
  1132. if checkValueValid(value) then
  1133. SL:Print("[GUI ERROR] GUI:setFlippedY, Y nil")
  1134. value = 0
  1135. end
  1136. widget:setFlippedY(value)
  1137. end
  1138. function GUI:getFlippedY(widget)
  1139. if CheckIsInvalidCObject(widget) then
  1140. return 1
  1141. end
  1142. return widget:isFlippedY()
  1143. end
  1144. function GUI:addChild(widget, child)
  1145. if CheckIsInvalidCObject(widget) then
  1146. return false
  1147. end
  1148. if CheckIsInvalidCObject(child) then
  1149. return false
  1150. end
  1151. return widget:addChild(child)
  1152. end
  1153. function GUI:Clone(widget)
  1154. if CheckIsInvalidCObject(widget) then
  1155. return false
  1156. end
  1157. return widget:clone()
  1158. end
  1159. function GUI:setMouseEnabled(widget, value)
  1160. if CheckIsInvalidCObject(widget) then
  1161. return false
  1162. end
  1163. widget:setMouseEnabled(value)
  1164. end
  1165. function GUI:setTouchEnabled(widget, value)
  1166. if CheckIsInvalidCObject(widget) then
  1167. return false
  1168. end
  1169. if checkValueValid(value) then
  1170. SL:Print("[GUI ERROR] GUI:setTouchEnabled, param nil")
  1171. value = true
  1172. end
  1173. widget:setTouchEnabled(value)
  1174. end
  1175. function GUI:getTouchEnabled(widget)
  1176. if CheckIsInvalidCObject(widget) then
  1177. return false
  1178. end
  1179. return widget:isTouchEnabled()
  1180. end
  1181. function GUI:getParent(widget)
  1182. if CheckIsInvalidCObject(widget) then
  1183. return nil
  1184. end
  1185. return widget:getParent()
  1186. end
  1187. function GUI:getChildren(widget)
  1188. if CheckIsInvalidCObject(widget) then
  1189. return {}
  1190. end
  1191. return widget:getChildren()
  1192. end
  1193. function GUI:getBoundingBox(widget)
  1194. if CheckIsInvalidCObject(widget) then
  1195. return cc.rect(0, 0, 1, 1)
  1196. end
  1197. if widget.GetBoundingBox then
  1198. return widget:GetBoundingBox()
  1199. end
  1200. return widget:getBoundingBox()
  1201. end
  1202. function GUI:getName(widget)
  1203. if CheckIsInvalidCObject(widget) then
  1204. return ""
  1205. end
  1206. return widget:getName()
  1207. end
  1208. function GUI:getChildByName(widget, name)
  1209. if CheckIsInvalidCObject(widget) then
  1210. return nil
  1211. end
  1212. return widget:getChildByName(name)
  1213. end
  1214. function GUI:getChildByTag(widget, tag)
  1215. if CheckIsInvalidCObject(widget) then
  1216. return nil
  1217. end
  1218. return widget:getChildByTag(tag)
  1219. end
  1220. function GUI:removeFromParent(widget)
  1221. if CheckIsInvalidCObject(widget) then
  1222. return false
  1223. end
  1224. widget:removeFromParent()
  1225. end
  1226. function GUI:removeChildByName(widget, name)
  1227. if CheckIsInvalidCObject(widget) then
  1228. return false
  1229. end
  1230. widget:removeChildByName(name)
  1231. end
  1232. function GUI:removeAllChildren(widget)
  1233. if CheckIsInvalidCObject(widget) then
  1234. return false
  1235. end
  1236. widget:removeAllChildren()
  1237. end
  1238. function GUI:runAction(widget, value)
  1239. if CheckIsInvalidCObject(widget) then
  1240. return false
  1241. end
  1242. widget:runAction(value)
  1243. end
  1244. function GUI:stopAllActions(widget)
  1245. if CheckIsInvalidCObject(widget) then
  1246. return false
  1247. end
  1248. widget:stopAllActions()
  1249. end
  1250. function GUI:getActionByTag(widget, tag)
  1251. if CheckIsInvalidCObject(widget) then
  1252. return false
  1253. end
  1254. return widget:getActionByTag(tag)
  1255. end
  1256. function GUI:stopActionByTag(widget, tag)
  1257. if CheckIsInvalidCObject(widget) then
  1258. return false
  1259. end
  1260. widget:stopActionByTag(tag)
  1261. end
  1262. function GUI:delayTouchEnabled(widget, delay)
  1263. if CheckIsInvalidCObject(widget) then
  1264. return false
  1265. end
  1266. delay = delay or 0.2
  1267. widget:stopActionByTag(10999)
  1268. widget:setTouchEnabled(false)
  1269. local action = performWithDelay(
  1270. widget,
  1271. function()
  1272. widget:setTouchEnabled(true)
  1273. end,
  1274. delay
  1275. )
  1276. action:setTag(10999)
  1277. end
  1278. function GUI:addOnClickEvent(widget, value)
  1279. if CheckIsInvalidCObject(widget) then
  1280. return false
  1281. end
  1282. -- global.ScriptHandlerMgr:removeObjectAllHandlers(widget)
  1283. widget:_addClickEventListener(value)
  1284. end
  1285. function GUI:addOnTouchEvent(widget, value)
  1286. if CheckIsInvalidCObject(widget) then
  1287. return false
  1288. end
  1289. global.ScriptHandlerMgr:removeObjectAllHandlers(widget)
  1290. widget:addTouchEventListener(value)
  1291. end
  1292. function GUI:addMouseMoveEvent(widget, param)
  1293. if CheckIsInvalidCObject(widget) then
  1294. return false
  1295. end
  1296. global.mouseEventController:registerMouseMoveEvent(
  1297. widget,
  1298. {
  1299. enter = param.onEnterFunc,
  1300. inside = param.onInsideFunc,
  1301. leave = param.onLeaveFunc,
  1302. checkIsVisible = param.checkIsVisible,
  1303. }
  1304. )
  1305. end
  1306. function GUI:addMouseButtonEvent(widget, param)
  1307. if CheckIsInvalidCObject(widget) then
  1308. return false
  1309. end
  1310. local function setNoSwallowMouse()
  1311. return -1
  1312. end
  1313. global.mouseEventController:registerMouseButtonEvent(
  1314. widget,
  1315. {
  1316. down_r = (param.onRightDownFunc or param.OnRightDownFunc) or setNoSwallowMouse,
  1317. up_r = param.OnRightUpFunc,
  1318. special_r = param.OnSpecialRFunc,
  1319. double_l = param.OnDoubleLFunc,
  1320. scroll = param.OnScrollFunc,
  1321. moveTouch = param.needTouchPos,
  1322. checkIsVisible = param.checkIsVisible,
  1323. checkTouchEnable = param.checkTouchEnable,
  1324. }
  1325. )
  1326. end
  1327. function GUI:addMouseOverTips(widget, str, pos, anr, param)
  1328. if CheckIsInvalidCObject(widget) then
  1329. return false
  1330. end
  1331. widget:addMouseOverTips(str, pos, anr, param)
  1332. end
  1333. function GUI:addMouseStyle(widget, styleType)
  1334. if CheckIsInvalidCObject(widget) then
  1335. return false
  1336. end
  1337. widget:addMouseStyle(styleType)
  1338. end
  1339. function GUI:addOnLongTouchEvent(widget, value)
  1340. if CheckIsInvalidCObject(widget) then
  1341. return false
  1342. end
  1343. -- global.ScriptHandlerMgr:removeObjectAllHandlers(widget)
  1344. widget:_addLongTouchEventListener(value)
  1345. end
  1346. function GUI:setLocalZOrder(widget, value)
  1347. if CheckIsInvalidCObject(widget) then
  1348. return false
  1349. end
  1350. widget:setLocalZOrder(value)
  1351. end
  1352. function GUI:getLocalZOrder(widget)
  1353. if CheckIsInvalidCObject(widget) then
  1354. return false
  1355. end
  1356. return widget:getLocalZOrder()
  1357. end
  1358. function GUI:setCascadeOpacityEnabled(widget, value)
  1359. if CheckIsInvalidCObject(widget) then
  1360. return false
  1361. end
  1362. widget:setCascadeOpacityEnabled(value)
  1363. end
  1364. function GUI:setChildrenCascadeOpacityEnabled(widget, value)
  1365. if CheckIsInvalidCObject(widget) then
  1366. return false
  1367. end
  1368. local node_list = {}
  1369. local function seach_child(parente)
  1370. local childCount = parente:getChildrenCount()
  1371. if childCount >= 1 then
  1372. for i = 1, childCount do
  1373. seach_child(parente:getChildren()[i])
  1374. end
  1375. end
  1376. table.insert(node_list, parente)
  1377. end
  1378. seach_child(widget)
  1379. for i,v in ipairs(node_list) do
  1380. v:setCascadeOpacityEnabled(value)
  1381. end
  1382. end
  1383. function GUI:getWorldPosition(widget)
  1384. if CheckIsInvalidCObject(widget) then
  1385. return false
  1386. end
  1387. return widget:getWorldPosition()
  1388. end
  1389. function GUI:getTouchMovePosition(widget)
  1390. if CheckIsInvalidCObject(widget) then
  1391. return false
  1392. end
  1393. return widget:getTouchMovePosition()
  1394. end
  1395. function GUI:getTouchBeganPosition(widget)
  1396. if CheckIsInvalidCObject(widget) then
  1397. return false
  1398. end
  1399. return widget:getTouchBeganPosition()
  1400. end
  1401. function GUI:getTouchEndPosition(widget)
  1402. if CheckIsInvalidCObject(widget) then
  1403. return false
  1404. end
  1405. return widget:getTouchEndPosition()
  1406. end
  1407. function GUI:convertToWorldSpace(widget, x, y)
  1408. if CheckIsInvalidCObject(widget) then
  1409. return cc.p(0, 0)
  1410. end
  1411. return widget:convertToWorldSpace(cc.p(x, y))
  1412. end
  1413. function GUI:convertToNodeSpace(widget, x, y)
  1414. if CheckIsInvalidCObject(widget) then
  1415. return cc.p(0, 0)
  1416. end
  1417. return widget:convertToNodeSpace(cc.p(x, y))
  1418. end
  1419. function GUI:getDescription(widget)
  1420. if CheckIsInvalidCObject(widget) then
  1421. return "nil"
  1422. end
  1423. return widget:getDescription()
  1424. end
  1425. function GUI:setSwallowTouches(widget, value)
  1426. if CheckIsInvalidCObject(widget) then
  1427. return false
  1428. end
  1429. widget:setSwallowTouches(value)
  1430. end
  1431. function GUI:getSwallowTouches(widget)
  1432. if CheckIsInvalidCObject(widget) then
  1433. return false
  1434. end
  1435. return widget:isSwallowTouches()
  1436. end
  1437. function GUI:setMouseRSwallowTouches(widget)
  1438. if CheckIsInvalidCObject(widget) then
  1439. return false
  1440. end
  1441. global.mouseEventController:registerMouseButtonEvent(widget, {checkSwallowTouches = true})
  1442. end
  1443. function GUI:schedule(widget, callback, delay)
  1444. if CheckIsInvalidCObject(widget) then
  1445. return false
  1446. end
  1447. delay = delay or 1
  1448. local action = schedule(widget, callback, delay)
  1449. action:setTag(scheduleActionTag)
  1450. end
  1451. function GUI:unSchedule(widget)
  1452. if CheckIsInvalidCObject(widget) then
  1453. return false
  1454. end
  1455. widget:stopActionByTag(scheduleActionTag)
  1456. end
  1457. function GUI:performWithDelay(widget, callback, delay)
  1458. if CheckIsInvalidCObject(widget) then
  1459. return false
  1460. end
  1461. delay = delay or 1
  1462. local action = performWithDelay(widget, callback, delay)
  1463. action:setTag(performActionTag)
  1464. end
  1465. function GUI:unPerformWithDelay(widget, callback, delay)
  1466. if CheckIsInvalidCObject(widget) then
  1467. return false
  1468. end
  1469. widget:stopActionByTag(performActionTag)
  1470. end
  1471. function GUI:addKeyboardEvent(codeKeys, pressedCB, releaseCB, checkFullSort)
  1472. local keyCodes = {}
  1473. if type(codeKeys) == "string" then
  1474. table.insert(keyCodes, cc.KeyCode[codeKeys])
  1475. elseif type(codeKeys) == "table" then
  1476. for _, v in ipairs(codeKeys) do
  1477. table.insert(keyCodes, cc.KeyCode[v])
  1478. end
  1479. end
  1480. if not next(keyCodes) then
  1481. SL:Print("[GUI ERROR] keyCode is invalid!")
  1482. return
  1483. end
  1484. global.userInputController:addKeyboardListener(keyCodes, pressedCB, releaseCB, nil, checkFullSort)
  1485. end
  1486. function GUI:removeKeyboardEvent(codeKeys)
  1487. local keyCodes = {}
  1488. if type(codeKeys) == "string" then
  1489. table.insert(keyCodes, cc.KeyCode[codeKeys])
  1490. elseif type(codeKeys) == "table" then
  1491. for _, v in ipairs(codeKeys) do
  1492. table.insert(keyCodes, cc.KeyCode[v])
  1493. end
  1494. end
  1495. global.userInputController:rmvKeyboardListener(keyCodes)
  1496. end
  1497. function GUI:addStateEvent(widget, func)
  1498. if CheckIsInvalidCObject(widget) then
  1499. return false
  1500. end
  1501. widget:registerScriptHandler(func)
  1502. end
  1503. -------------------------------------------------------------
  1504. -- ex
  1505. GUI.getChildByID = GUI.getChildByName
  1506. GUI.removeChildByID = GUI.removeChildByName
  1507. ------------------------------------------------------------
  1508. -- Node
  1509. function GUI:Node_Create(parent, ID, x, y)
  1510. if not ID then
  1511. SL:Print("[GUI ERROR] GUI:Node_Create can't find ID")
  1512. return nil
  1513. end
  1514. if not parent then
  1515. SL:Print("[GUI ERROR] GUI:Node_Create can't find parent", ID)
  1516. return nil
  1517. end
  1518. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  1519. SL:Print("[GUI ERROR] GUI:Node_Create ID is exists", ID)
  1520. return nil
  1521. end
  1522. local widget = ccui.Widget:create()
  1523. widget:setName(ID)
  1524. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  1525. if parent ~= NONEED_PARENT_CODE then
  1526. if CheckIsInvalidCObject(parent) then
  1527. return nil
  1528. end
  1529. if "ccui.ListView" == tolua.type(parent) then
  1530. parent:pushBackCustomItem(widget)
  1531. else
  1532. parent:addChild(widget)
  1533. end
  1534. end
  1535. return widget
  1536. end
  1537. -------------------------------------------------------------
  1538. -- widget
  1539. function GUI:Widget_Create(parent, ID, x, y, width, height)
  1540. if not ID then
  1541. SL:Print("[GUI ERROR] GUI:Widget_Create can't find ID")
  1542. return nil
  1543. end
  1544. if not parent then
  1545. SL:Print("[GUI ERROR] GUI:Widget_Create can't find parent", ID)
  1546. return nil
  1547. end
  1548. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  1549. SL:Print("[GUI ERROR] GUI:Widget_Create ID is exists", ID)
  1550. return nil
  1551. end
  1552. local widget = ccui.Widget:create()
  1553. widget:setName(ID)
  1554. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  1555. widget:setAnchorPoint(cc.p(0, 0))
  1556. widget:setContentSize(cc.size(width, height))
  1557. if parent ~= NONEED_PARENT_CODE then
  1558. if CheckIsInvalidCObject(parent) then
  1559. return nil
  1560. end
  1561. if "ccui.ListView" == tolua.type(parent) then
  1562. parent:pushBackCustomItem(widget)
  1563. else
  1564. parent:addChild(widget)
  1565. end
  1566. end
  1567. return widget
  1568. end
  1569. -------------------------------------------------------------
  1570. -- image
  1571. function GUI:Image_Create(parent, ID, x, y, nimg)
  1572. if not ID then
  1573. SL:Print("[GUI ERROR] GUI:Image_Create can't find ID")
  1574. return nil
  1575. end
  1576. if not parent then
  1577. SL:Print("[GUI ERROR] GUI:Image_Create can't find parent", ID)
  1578. return nil
  1579. end
  1580. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  1581. SL:Print("[GUI ERROR] GUI:Image_Create ID is exists", ID)
  1582. return nil
  1583. end
  1584. local widget = ccui.ImageView:create()
  1585. widget:setName(ID)
  1586. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  1587. widget:setAnchorPoint(cc.p(0, 0))
  1588. widget:loadTexture(FixPath(nimg))
  1589. if parent ~= NONEED_PARENT_CODE then
  1590. if CheckIsInvalidCObject(parent) then
  1591. return nil
  1592. end
  1593. if "ccui.ListView" == tolua.type(parent) then
  1594. parent:pushBackCustomItem(widget)
  1595. else
  1596. parent:addChild(widget)
  1597. end
  1598. end
  1599. return widget
  1600. end
  1601. function GUI:Image_loadTexture(widget, filepath)
  1602. if CheckIsInvalidCObject(widget) then
  1603. return false
  1604. end
  1605. widget:loadTexture(FixPath(filepath))
  1606. end
  1607. function GUI:Image_setScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
  1608. if CheckIsInvalidCObject(widget) then
  1609. return false
  1610. end
  1611. widget:setScale9Enabled(true)
  1612. local contentSize = widget:getVirtualRendererSize()
  1613. local x = scale9l
  1614. local y = scale9t
  1615. local width = contentSize.width-scale9l-scale9r
  1616. local height = contentSize.height-scale9t-scale9b
  1617. widget:setCapInsets({x = x, y = y, width = width, height = height})
  1618. end
  1619. function GUI:Image_setGrey( widget, isGrey )
  1620. if CheckIsInvalidCObject(widget) then
  1621. return false
  1622. end
  1623. if isGrey then
  1624. Shader_Grey(widget)
  1625. else
  1626. Shader_Normal(widget)
  1627. end
  1628. end
  1629. function GUI:Image_getTextureFile(widget)
  1630. if CheckIsInvalidCObject(widget) then
  1631. return ""
  1632. end
  1633. local data = widget:getRenderFile() or {}
  1634. return data.file, data.type
  1635. end
  1636. -------------------------------------------------------------
  1637. -- Button
  1638. function GUI:Button_Create(parent, ID, x, y, nimg)
  1639. if not ID then
  1640. SL:Print("[GUI ERROR] GUI:Button_Create can't find ID")
  1641. return nil
  1642. end
  1643. if not parent then
  1644. SL:Print("[GUI ERROR] GUI:Button_Create can't find parent", ID)
  1645. return nil
  1646. end
  1647. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  1648. SL:Print("[GUI ERROR] GUI:Button_Create ID is exists", ID)
  1649. return nil
  1650. end
  1651. local widget = ccui.Button:create()
  1652. widget:setName(ID)
  1653. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  1654. widget:setAnchorPoint(cc.p(0, 0))
  1655. widget:loadTextureNormal(FixPath(nimg))
  1656. widget:setTitleFontName(GUI.PATH_FONT2)
  1657. if parent ~= NONEED_PARENT_CODE then
  1658. if CheckIsInvalidCObject(parent) then
  1659. return false
  1660. end
  1661. if "ccui.ListView" == tolua.type(parent) then
  1662. parent:pushBackCustomItem(widget)
  1663. else
  1664. parent:addChild(widget)
  1665. end
  1666. end
  1667. return widget
  1668. end
  1669. function GUI:Button_loadTextureNormal(widget, filepath)
  1670. if CheckIsInvalidCObject(widget) then
  1671. return false
  1672. end
  1673. widget:loadTextureNormal(FixPath(filepath))
  1674. end
  1675. function GUI:Button_loadTexturePressed(widget, filepath)
  1676. if CheckIsInvalidCObject(widget) then
  1677. return false
  1678. end
  1679. widget:loadTexturePressed(FixPath(filepath))
  1680. end
  1681. function GUI:Button_loadTextureDisabled(widget, filepath)
  1682. if CheckIsInvalidCObject(widget) then
  1683. return false
  1684. end
  1685. widget:loadTextureDisabled(FixPath(filepath))
  1686. end
  1687. function GUI:Button_getTextureNormalFile(widget)
  1688. if CheckIsInvalidCObject(widget) then
  1689. return ""
  1690. end
  1691. local data = widget:getNormalFile() or {}
  1692. return data.file, data.type
  1693. end
  1694. function GUI:Button_getTexturePressedFile(widget)
  1695. if CheckIsInvalidCObject(widget) then
  1696. return ""
  1697. end
  1698. local data = widget:getPressedFile() or {}
  1699. return data.file, data.type
  1700. end
  1701. function GUI:Button_getTextureDisabledFile(widget)
  1702. if CheckIsInvalidCObject(widget) then
  1703. return ""
  1704. end
  1705. local data = widget:getDisabledFile() or {}
  1706. return data.file, data.type
  1707. end
  1708. function GUI:Button_loadTextures(widget, Normalfilepath, Pressedfilepath, Disabledfilepath, TextureType)
  1709. if CheckIsInvalidCObject(widget) then
  1710. return false
  1711. end
  1712. if Normalfilepath and Pressedfilepath and Disabledfilepath and TextureType then
  1713. widget:loadTextures(FixPath(Normalfilepath), FixPath(Pressedfilepath), FixPath(Disabledfilepath), TextureType)
  1714. elseif Normalfilepath and Pressedfilepath and Disabledfilepath then
  1715. widget:loadTextures(FixPath(Normalfilepath), FixPath(Pressedfilepath), FixPath(Disabledfilepath))
  1716. elseif Normalfilepath and Pressedfilepath then
  1717. widget:loadTextures(FixPath(Normalfilepath), FixPath(Pressedfilepath))
  1718. elseif Normalfilepath then
  1719. widget:loadTextures(FixPath(Normalfilepath))
  1720. end
  1721. end
  1722. function GUI:Button_setTitleText(widget, value)
  1723. if CheckIsInvalidCObject(widget) then
  1724. return false
  1725. end
  1726. local label = widget:getTitleRenderer()
  1727. label:setPosition(cc.p(fixPosition(label:getPositionX()), fixPosition(label:getPositionY())))
  1728. widget:setTitleText(value)
  1729. setButtonLabelOffset(widget)
  1730. end
  1731. function GUI:Button_getTitleText(widget)
  1732. if CheckIsInvalidCObject(widget) then
  1733. return ""
  1734. end
  1735. return widget:getTitleText()
  1736. end
  1737. function GUI:Button_setTitleColor(widget, value)
  1738. if CheckIsInvalidCObject(widget) then
  1739. return false
  1740. end
  1741. widget:setTitleColor(SL:ConvertColorFromHexString(value))
  1742. end
  1743. function GUI:Button_setTitleFontSize(widget, value)
  1744. if CheckIsInvalidCObject(widget) then
  1745. return false
  1746. end
  1747. widget:setTitleFontSize(value)
  1748. setButtonLabelOffset(widget)
  1749. end
  1750. function GUI:Button_setTitleFontName(widget, value)
  1751. if CheckIsInvalidCObject(widget) then
  1752. return false
  1753. end
  1754. widget:setTitleFontName(value)
  1755. setButtonLabelOffset(widget)
  1756. end
  1757. function GUI:Button_setBright(widget, value)
  1758. if CheckIsInvalidCObject(widget) then
  1759. return false
  1760. end
  1761. widget:setBright(value)
  1762. end
  1763. function GUI:Button_setBrightEx(widget, value)
  1764. if CheckIsInvalidCObject(widget) then
  1765. return false
  1766. end
  1767. widget:setTouchEnabled(value)
  1768. widget:setBright(value)
  1769. end
  1770. function GUI:Button_setZoomScale(widget, value)
  1771. if CheckIsInvalidCObject(widget) then
  1772. return false
  1773. end
  1774. widget.invalidZoomScale = true
  1775. widget:setZoomScale(value)
  1776. end
  1777. function GUI:Button_setTitleOffset(widget, x, y)
  1778. if CheckIsInvalidCObject(widget) then
  1779. return false
  1780. end
  1781. widget._x_ = fixPosition(x)
  1782. widget._y_ = fixPosition(y)
  1783. setButtonLabelOffset(widget)
  1784. end
  1785. function GUI:Button_setBrightStyle(widget, value)
  1786. if CheckIsInvalidCObject(widget) then
  1787. return false
  1788. end
  1789. widget:setBrightStyle(value)
  1790. end
  1791. function GUI:Button_setMaxLineWidth(widget, value)
  1792. if CheckIsInvalidCObject(widget) then
  1793. return false
  1794. end
  1795. widget:getTitleRenderer():setMaxLineWidth(tonumber(value) or 0)
  1796. end
  1797. function GUI:Button_titleEnableOutline( widget, color, outline )
  1798. if CheckIsInvalidCObject(widget) then
  1799. return false
  1800. end
  1801. widget:getTitleRenderer():enableOutline(SL:ConvertColorFromHexString(color), outline)
  1802. end
  1803. function GUI:Button_titleDisableOutLine( widget )
  1804. if CheckIsInvalidCObject(widget) then
  1805. return false
  1806. end
  1807. widget:getTitleRenderer():disableEffect(cc.LabelEffect.OUTLINE)
  1808. end
  1809. function GUI:Button_setGrey( widget, isGrey )
  1810. if CheckIsInvalidCObject(widget) then
  1811. return false
  1812. end
  1813. if isGrey then
  1814. Shader_Grey(widget)
  1815. else
  1816. Shader_Normal(widget)
  1817. end
  1818. end
  1819. function GUI:Button_setScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
  1820. if CheckIsInvalidCObject(widget) then
  1821. return false
  1822. end
  1823. widget:setScale9Enabled(true)
  1824. local contentSize = widget:getVirtualRendererSize()
  1825. local x = scale9l
  1826. local y = scale9t
  1827. local width = contentSize.width-scale9l-scale9r
  1828. local height = contentSize.height-scale9t-scale9b
  1829. widget:setCapInsets({x = x, y = y, width = width, height = height})
  1830. end
  1831. -------------------------------------------------------------
  1832. -- Text
  1833. function GUI:Text_Create(parent, ID, x, y, fontSize, fontColor, str)
  1834. if not ID then
  1835. SL:Print("[GUI ERROR] GUI:Text_Create can't find ID")
  1836. return nil
  1837. end
  1838. if not parent then
  1839. SL:Print("[GUI ERROR] GUI:Text_Create can't find parent", ID)
  1840. return nil
  1841. end
  1842. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  1843. SL:Print("[GUI ERROR] GUI:Text_Create ID is exists", ID)
  1844. return nil
  1845. end
  1846. local widget = ccui.Text:create()
  1847. widget:setName(ID)
  1848. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  1849. widget:setAnchorPoint(cc.p(0, 0))
  1850. widget:setFontName(GUI.PATH_FONT2)
  1851. widget:setFontSize(fontSize)
  1852. if type(fontColor) == "string" and string.find(fontColor, "#") then
  1853. fontColor = SL:ConvertColorFromHexString(fontColor)
  1854. end
  1855. widget:setTextColor(fontColor)
  1856. widget:setString(str)
  1857. if parent ~= NONEED_PARENT_CODE then
  1858. if CheckIsInvalidCObject(parent) then
  1859. return nil
  1860. end
  1861. if "ccui.ListView" == tolua.type(parent) then
  1862. parent:pushBackCustomItem(widget)
  1863. else
  1864. parent:addChild(widget)
  1865. end
  1866. end
  1867. return widget
  1868. end
  1869. --pc 12号宋体
  1870. function GUI:BmpText_Create(parent, ID, x, y, fontColor, str, fontPath)
  1871. if not ID then
  1872. SL:Print("[GUI ERROR] GUI:Text_Create can't find ID")
  1873. return nil
  1874. end
  1875. if not parent then
  1876. SL:Print("[GUI ERROR] GUI:Text_Create can't find parent", ID)
  1877. return nil
  1878. end
  1879. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  1880. SL:Print("[GUI ERROR] GUI:Text_Create ID is exists", ID)
  1881. return nil
  1882. end
  1883. local widget = ccui.Text:create()
  1884. widget:setName(ID)
  1885. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  1886. widget:setAnchorPoint(cc.p(0, 0))
  1887. if type(fontColor) == "string" and string.find(fontColor, "#") then
  1888. fontColor = SL:ConvertColorFromHexString(fontColor)
  1889. end
  1890. GUI:SetBmpTextProperties(widget)
  1891. widget:setBMFontFilePath(fontPath)
  1892. widget:setFontSize(12)
  1893. if fontColor then
  1894. widget:setTextColor(fontColor)
  1895. end
  1896. widget:setString(str)
  1897. if parent ~= NONEED_PARENT_CODE then
  1898. if CheckIsInvalidCObject(parent) then
  1899. return false
  1900. end
  1901. if "ccui.ListView" == tolua.type(parent) then
  1902. parent:pushBackCustomItem(widget)
  1903. else
  1904. parent:addChild(widget)
  1905. end
  1906. end
  1907. return widget
  1908. end
  1909. function GUI:SetBmpTextProperties(widget)
  1910. if CheckIsInvalidCObject(widget) then
  1911. return false
  1912. end
  1913. widget.getDescription = function ()
  1914. return "BmpText"
  1915. end
  1916. local labelRenderer = widget:getVirtualRenderer()
  1917. widget.setTextColor = function(self, c4b)
  1918. labelRenderer:setColor(c4b)
  1919. end
  1920. widget.getTextColor = function(self)
  1921. return self:getVirtualRenderer():getColor()
  1922. end
  1923. widget.setFontName = function(self, fontName)
  1924. end
  1925. widget.setBMFontFilePath = function (self, fontPath)
  1926. self:getVirtualRenderer():setBMFontFilePath(fontPath or global.MMO.PATH_ST_FONT, cc.p(0, 0), 0)
  1927. end
  1928. widget.getBMPFontpath = function ()
  1929. return global.MMO.PATH_ST_FONT
  1930. end
  1931. widget.setFontSize = function(self, fontSize)
  1932. self:getVirtualRenderer():setBMFontSize(fontSize)
  1933. end
  1934. widget.getFontSize = function (self)
  1935. return self:getVirtualRenderer():getBMFontSize()
  1936. end
  1937. widget.enableOutline = function(self, ...)
  1938. end
  1939. local color = labelRenderer:getTextColor()
  1940. labelRenderer:setColor(color)
  1941. labelRenderer.setTextColor = function (self, c4b)
  1942. labelRenderer:setColor(c4b)
  1943. end
  1944. labelRenderer.enableOutline = function ( )
  1945. end
  1946. widget.getContentSize = function (self)
  1947. return self:getVirtualRenderer():getContentSize()
  1948. end
  1949. labelRenderer.enableUnderline = function()
  1950. if labelRenderer.underline and ( not tolua.isnull( labelRenderer.underline ) ) then
  1951. labelRenderer.underline:removeFromParent()
  1952. labelRenderer.underline = nil
  1953. end
  1954. local underline = UnderLineComponent:create()
  1955. underline:attachToNode( labelRenderer, labelRenderer:getColor() )
  1956. labelRenderer.underline = underline
  1957. end
  1958. end
  1959. function GUI:Text_setString(widget, value)
  1960. if CheckIsInvalidCObject(widget) then
  1961. return false
  1962. end
  1963. widget:setString(value)
  1964. end
  1965. function GUI:Text_getString(widget)
  1966. if CheckIsInvalidCObject(widget) then
  1967. return ""
  1968. end
  1969. return widget:getString()
  1970. end
  1971. function GUI:Text_setTextColor(widget, value)
  1972. if CheckIsInvalidCObject(widget) then
  1973. return false
  1974. end
  1975. widget:setTextColor(SL:ConvertColorFromHexString(value))
  1976. end
  1977. function GUI:Text_setFontSize(widget, value)
  1978. if CheckIsInvalidCObject(widget) then
  1979. return false
  1980. end
  1981. widget:setFontSize(value)
  1982. end
  1983. function GUI:Text_getFontSize(widget)
  1984. if CheckIsInvalidCObject(widget) then
  1985. return nil
  1986. end
  1987. return widget:getFontSize()
  1988. end
  1989. function GUI:Text_setFontName(widget, value)
  1990. if CheckIsInvalidCObject(widget) then
  1991. return false
  1992. end
  1993. widget:setFontName(value)
  1994. end
  1995. function GUI:Text_enableOutline(widget, color, size)
  1996. if CheckIsInvalidCObject(widget) then
  1997. return false
  1998. end
  1999. widget:enableOutline(SL:ConvertColorFromHexString(color), size)
  2000. end
  2001. function GUI:Text_enableUnderline(widget)
  2002. if CheckIsInvalidCObject(widget) then
  2003. return false
  2004. end
  2005. widget:getVirtualRenderer():enableUnderline()
  2006. end
  2007. function GUI:Text_setMaxLineWidth(widget, width)
  2008. if CheckIsInvalidCObject(widget) then
  2009. return false
  2010. end
  2011. widget:getVirtualRenderer():setMaxLineWidth(tonumber(width) or 0)
  2012. end
  2013. function GUI:Text_disableEffect( widget, param )
  2014. if CheckIsInvalidCObject(widget) then
  2015. return false
  2016. end
  2017. widget:getVirtualRenderer():disableEffect(param)
  2018. end
  2019. function GUI:Text_disableNormal( widget )
  2020. if CheckIsInvalidCObject(widget) then
  2021. return false
  2022. end
  2023. widget:getVirtualRenderer():disableEffect(cc.LabelEffect.NORMAL)
  2024. end
  2025. function GUI:Text_disableOutLine( widget )
  2026. if CheckIsInvalidCObject(widget) then
  2027. return false
  2028. end
  2029. widget:getVirtualRenderer():disableEffect(cc.LabelEffect.OUTLINE)
  2030. end
  2031. function GUI:Text_disableShadow( widget )
  2032. if CheckIsInvalidCObject(widget) then
  2033. return false
  2034. end
  2035. widget:getVirtualRenderer():disableEffect(cc.LabelEffect.SHADOW)
  2036. end
  2037. function GUI:Text_disableGlow( widget )
  2038. if CheckIsInvalidCObject(widget) then
  2039. return false
  2040. end
  2041. widget:getVirtualRenderer():disableEffect(cc.LabelEffect.GLOW)
  2042. end
  2043. function GUI:Text_setTextVerticalAlignment(widget, value)
  2044. if CheckIsInvalidCObject(widget) then
  2045. return false
  2046. end
  2047. widget:setTextVerticalAlignment(value)
  2048. end
  2049. function GUI:Text_setTextHorizontalAlignment(widget, value)
  2050. if CheckIsInvalidCObject(widget) then
  2051. return false
  2052. end
  2053. widget:setTextHorizontalAlignment(value)
  2054. end
  2055. function GUI:Text_setTextAreaSize(widget, sizeW, sizeH)
  2056. if CheckIsInvalidCObject(widget) then
  2057. return false
  2058. end
  2059. local size = nil
  2060. if nil == sizeH then
  2061. size = { width = sizeW.width, height = sizeW.height }
  2062. else
  2063. size = { width = sizeW, height = sizeH }
  2064. end
  2065. widget:setTextAreaSize(size)
  2066. end
  2067. function GUI:Text_COUNTDOWN(widget, time, callback, showType)
  2068. if CheckIsInvalidCObject(widget) then
  2069. return false
  2070. end
  2071. local tag = 9963
  2072. local endTime = SL:GetMetaValue("SERVER_TIME") + time
  2073. local remaining = time
  2074. local type = tonumber(showType) or 0
  2075. widget:stopActionByTag(tag)
  2076. local function scheduleCB()
  2077. remaining = math.max(endTime - SL:GetMetaValue("SERVER_TIME"), 0)
  2078. local str = ""
  2079. if not type or type == 0 then
  2080. str = SecondToHMS(remaining, true)
  2081. elseif type == 1 then
  2082. str = TimeFormatToString(remaining)
  2083. end
  2084. widget:setString(str)
  2085. if remaining == 0 then
  2086. if callback then
  2087. callback(remaining)
  2088. end
  2089. widget:stopActionByTag(tag)
  2090. end
  2091. end
  2092. local action = schedule(widget, scheduleCB, 1)
  2093. action:setTag(tag)
  2094. scheduleCB()
  2095. end
  2096. function GUI:Text_AutoUpdateMetaValue(widget, value)
  2097. if CheckIsInvalidCObject(widget) then
  2098. return false
  2099. end
  2100. -- 加入元变量组件管理
  2101. local metaValue = {}
  2102. local content = value
  2103. local isMetaValue = false
  2104. while content and string.len(content) > 0 do
  2105. local find_info = {sfind(content, "$STM%((.-)%)")}
  2106. local begin_pos = find_info[1]
  2107. local end_pos = find_info[2]
  2108. if begin_pos and end_pos then
  2109. isMetaValue = true
  2110. -- prefix
  2111. if begin_pos ~= 1 then
  2112. local substr = string.sub(content, 1, begin_pos - 1)
  2113. table.insert(metaValue, substr)
  2114. end
  2115. -- metaValue
  2116. local slices = ssplit(find_info[3], "_")
  2117. table.insert(metaValue, {key = slices[1], param = slices[2]})
  2118. -- suffix
  2119. content = string.sub(content, end_pos + 1, string.len(content))
  2120. else
  2121. table.insert(metaValue, content)
  2122. content = ""
  2123. end
  2124. end
  2125. if isMetaValue then
  2126. global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget})
  2127. return true
  2128. else
  2129. widget:setString(value)
  2130. return false
  2131. end
  2132. end
  2133. function GUI:AutoUpdateMetaValue(widget, key, param)
  2134. local metaValue = {}
  2135. table.insert(metaValue, {key = key, param = param})
  2136. global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget})
  2137. end
  2138. -- scroll text
  2139. function GUI:ScrollText_Create(parent, ID, x, y, width, fontSize, fontColor, str, scrollTime, fontPath)
  2140. if not ID then
  2141. SL:Print("[GUI ERROR] GUI:ScrollText_Create can't find ID")
  2142. return nil
  2143. end
  2144. if not parent then
  2145. SL:Print("[GUI ERROR] GUI:ScrollText_Create can't find parent", ID)
  2146. return nil
  2147. end
  2148. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2149. SL:Print("[GUI ERROR] GUI:ScrollText_Create ID is exists", ID)
  2150. return nil
  2151. end
  2152. local widget = ccui.Layout:create()
  2153. widget:setName(ID)
  2154. widget:setClippingEnabled(true)
  2155. widget:setClippingType(0)
  2156. widget:setTouchEnabled(false)
  2157. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2158. if parent ~= NONEED_PARENT_CODE then
  2159. if CheckIsInvalidCObject(parent) then
  2160. return nil
  2161. end
  2162. if "ccui.ListView" == tolua.type(parent) then
  2163. parent:pushBackCustomItem(widget)
  2164. else
  2165. parent:addChild(widget)
  2166. end
  2167. end
  2168. local Text = ccui.Text:create()
  2169. Text:setName("Text")
  2170. Text:setFontName(fontPath or GUI.PATH_FONT2)
  2171. Text:setFontSize(fontSize)
  2172. Text:setTextColor(SL:ConvertColorFromHexString(fontColor))
  2173. Text:setAnchorPoint(cc.p(0, 0))
  2174. Text:setPosition(cc.p(0, 0))
  2175. Text:setString(str)
  2176. if scrollTime then
  2177. Text._scrollTime = scrollTime
  2178. end
  2179. widget:setContentSize({width = width, height = Text:getContentSize().height})
  2180. widget:addChild(Text)
  2181. GUI:refScrollText(widget, Text, scrollTime)
  2182. return widget
  2183. end
  2184. function GUI:refScrollText(widget, Text, scrollTime)
  2185. if CheckIsInvalidCObject(widget) then
  2186. return false
  2187. end
  2188. Text:stopAllActions()
  2189. scrollTime = scrollTime or 4
  2190. local textWid = Text:getContentSize().width
  2191. local widgetWid = widget:getContentSize().width
  2192. local dis = textWid - widgetWid
  2193. if dis > 0 then
  2194. local anrX = Text:getAnchorPoint().x
  2195. local x = (widgetWid+dis) * anrX
  2196. Text:setPositionX(x)
  2197. Text:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.MoveBy:create(scrollTime, cc.p(-textWid, 0)), cc.MoveBy:create(0, cc.p(textWid, 0)))))
  2198. else
  2199. local anr = Text:getAnchorPoint()
  2200. local x = math.abs(dis/2) + textWid * anr.x
  2201. Text:setPositionX(x)
  2202. end
  2203. end
  2204. function GUI:ScrollText_setString(widget, value)
  2205. if CheckIsInvalidCObject(widget) then
  2206. return false
  2207. end
  2208. local Text = widget:getChildByName("Text")
  2209. if Text then
  2210. Text:setString(value)
  2211. widget:setContentSize({width = widget:getContentSize().width, height = Text:getContentSize().height})
  2212. GUI:refScrollText(widget, Text, Text._scrollTime)
  2213. end
  2214. end
  2215. function GUI:ScrollText_enableOutline(widget, color, size)
  2216. if CheckIsInvalidCObject(widget) then
  2217. return false
  2218. end
  2219. local Text = widget:getChildByName("Text")
  2220. if Text then
  2221. Text:enableOutline(SL:ConvertColorFromHexString(color), size)
  2222. widget:setContentSize({width = widget:getContentSize().width, height = Text:getContentSize().height})
  2223. end
  2224. end
  2225. function GUI:ScrollText_getString(widget, value)
  2226. if CheckIsInvalidCObject(widget) then
  2227. return ""
  2228. end
  2229. local Text = widget:getChildByName("Text")
  2230. if Text then
  2231. return Text:getString()
  2232. end
  2233. end
  2234. -- value: 1: 左; 2: 中; 3:右
  2235. function GUI:ScrollText_setHorizontalAlignment(widget, value)
  2236. if CheckIsInvalidCObject(widget) then
  2237. return false
  2238. end
  2239. local Text = widget:getChildByName("Text")
  2240. if Text then
  2241. local width = widget:getContentSize().width
  2242. local anrX = value == 2 and 0.5 or (value == 3 and 1 or 0)
  2243. local posX = value == 2 and width / 2 or (value == 3 and width or 0)
  2244. Text:setAnchorPoint(cc.p(anrX, 0))
  2245. Text:setPositionX(posX)
  2246. end
  2247. end
  2248. function GUI:ScrollText_setTextColor(widget, value)
  2249. if CheckIsInvalidCObject(widget) then
  2250. return false
  2251. end
  2252. local Text = widget:getChildByName("Text")
  2253. if Text then
  2254. Text:setTextColor(SL:ConvertColorFromHexString(value))
  2255. end
  2256. end
  2257. -------------------------------------------------------------
  2258. -- Label
  2259. function GUI:Label_Create(parent, ID, x, y, text, fontPath, fontSize, fontColor)
  2260. if not ID then
  2261. SL:Print("[GUI ERROR] GUI:Label_Create can't find ID")
  2262. return nil
  2263. end
  2264. if not parent then
  2265. SL:Print("[GUI ERROR] GUI:Label_Create can't find parent", ID)
  2266. return nil
  2267. end
  2268. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2269. SL:Print("[GUI ERROR] GUI:Label_Create ID is exists", ID)
  2270. return nil
  2271. end
  2272. if not fontPath or not SL:IsFileExist(fontPath) then
  2273. SL:Print("[GUI ERROR] GUI:Label_Create can't find fontPath ", fontPath)
  2274. return nil
  2275. end
  2276. local widget = cc.Label:createWithTTF(text, fontPath, fontSize)
  2277. widget:setName(ID)
  2278. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2279. widget:setAnchorPoint(cc.p(0, 0))
  2280. if type(fontColor) == "string" and string.find(fontColor, "#") then
  2281. fontColor = SL:ConvertColorFromHexString(fontColor)
  2282. end
  2283. if fontColor then
  2284. widget:setColor(fontColor)
  2285. end
  2286. if parent ~= NONEED_PARENT_CODE then
  2287. if CheckIsInvalidCObject(parent) then
  2288. return nil
  2289. end
  2290. if "ccui.ListView" == tolua.type(parent) then
  2291. parent:pushBackCustomItem(widget)
  2292. else
  2293. parent:addChild(widget)
  2294. end
  2295. end
  2296. return widget
  2297. end
  2298. -------------------------------------------------------------
  2299. -- Layout
  2300. function GUI:Layout_Create(parent, ID, x, y, width, height, isClip)
  2301. if not ID then
  2302. SL:Print("[GUI ERROR] GUI:Layout_Create can't find ID")
  2303. return nil
  2304. end
  2305. if not parent then
  2306. SL:Print("[GUI ERROR] GUI:Layout_Create can't find parent", ID)
  2307. return nil
  2308. end
  2309. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2310. SL:Print("[GUI ERROR] GUI:Layout_Create ID is exists", ID)
  2311. return nil
  2312. end
  2313. local widget = ccui.Layout:create()
  2314. if parent ~= NONEED_PARENT_CODE then
  2315. if CheckIsInvalidCObject(parent) then
  2316. return nil
  2317. end
  2318. if "ccui.ListView" == tolua.type(parent) then
  2319. parent:pushBackCustomItem(widget)
  2320. elseif "ccui.PageView" == tolua.type(parent) then
  2321. parent:addPage(widget)
  2322. else
  2323. parent:addChild(widget)
  2324. end
  2325. end
  2326. widget:setName(ID)
  2327. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2328. widget:setAnchorPoint(cc.p(0, 0))
  2329. widget:setContentSize(cc.size(width, height))
  2330. if isClip and type(isClip) == "boolean" then
  2331. widget:setClippingEnabled(isClip)
  2332. end
  2333. widget:setClippingType(0)
  2334. return widget
  2335. end
  2336. function GUI:Layout_setBackGroundColor(widget, value)
  2337. if CheckIsInvalidCObject(widget) then
  2338. return false
  2339. end
  2340. local paramList = {}
  2341. if type(value) == "table" then
  2342. for i, v in ipairs(value) do
  2343. paramList[i] = SL:ConvertColorFromHexString(v)
  2344. end
  2345. else
  2346. paramList[1] = SL:ConvertColorFromHexString(value)
  2347. end
  2348. if #paramList == 2 then
  2349. widget:setBackGroundColor(paramList[1], paramList[2])
  2350. else
  2351. widget:setBackGroundColor(paramList[1])
  2352. end
  2353. end
  2354. function GUI:Layout_setBackGroundColorType(widget, value)
  2355. if CheckIsInvalidCObject(widget) then
  2356. return false
  2357. end
  2358. widget:setBackGroundColorType(value)
  2359. end
  2360. function GUI:Layout_setBackGroundColorOpacity(widget, value)
  2361. if CheckIsInvalidCObject(widget) then
  2362. return false
  2363. end
  2364. widget:setBackGroundColorOpacity(value)
  2365. end
  2366. function GUI:Layout_setClippingEnabled(widget, value)
  2367. if CheckIsInvalidCObject(widget) then
  2368. return false
  2369. end
  2370. widget:setClippingEnabled(value)
  2371. end
  2372. function GUI:Layout_setBackGroundImage(widget, value)
  2373. if CheckIsInvalidCObject(widget) then
  2374. return false
  2375. end
  2376. widget:setBackGroundImage(value, 0)
  2377. end
  2378. function GUI:Layout_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
  2379. if CheckIsInvalidCObject(widget) then
  2380. return false
  2381. end
  2382. widget:setBackGroundImageScale9Enabled(true)
  2383. local contentSize = widget:getBackGroundImageTextureSize()
  2384. local x = scale9l
  2385. local y = scale9t
  2386. local width = contentSize.width-scale9l-scale9r
  2387. local height = contentSize.height-scale9t-scale9b
  2388. local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
  2389. widget:setBackGroundImageCapInsets(capInsets)
  2390. end
  2391. function GUI:Layout_setBackGroundImageOpacity(widget, value)
  2392. if CheckIsInvalidCObject(widget) then
  2393. return false
  2394. end
  2395. widget:setBackGroundImageOpacity(value)
  2396. end
  2397. function GUI:Layout_removeBackGroundImage(widget)
  2398. if CheckIsInvalidCObject(widget) then
  2399. return false
  2400. end
  2401. widget:removeBackGroundImage()
  2402. end
  2403. function GUI:Layout_getBackGroundImageFile(widget)
  2404. if CheckIsInvalidCObject(widget) then
  2405. return ""
  2406. end
  2407. local data = widget:getRenderFile() or {}
  2408. return data.file, data.type
  2409. end
  2410. function GUI:Layout_debug(widget)
  2411. if CheckIsInvalidCObject(widget) then
  2412. return false
  2413. end
  2414. widget:setBackGroundColorType(1)
  2415. widget:setBackGroundColorOpacity(155)
  2416. widget:setBackGroundColor(cc.c3b(0xff, 0, 0))
  2417. end
  2418. function GUI:Layout_getLayoutType(widget)
  2419. if CheckIsInvalidCObject(widget) then
  2420. return 0
  2421. end
  2422. return widget:getLayoutType()
  2423. end
  2424. function GUI:Layout_setLayoutType(widget, value)
  2425. if CheckIsInvalidCObject(widget) then
  2426. return false
  2427. end
  2428. widget:setLayoutType(value)
  2429. end
  2430. -------------------------------------------------------------
  2431. -- LoadingBar
  2432. function GUI:LoadingBar_Create(parent, ID, x, y, nimg, direction)
  2433. if not ID then
  2434. SL:Print("[GUI ERROR] GUI:LoadingBar_Create can't find ID")
  2435. return nil
  2436. end
  2437. if not parent then
  2438. SL:Print("[GUI ERROR] GUI:LoadingBar_Create can't find parent", ID)
  2439. return nil
  2440. end
  2441. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2442. SL:Print("[GUI ERROR] GUI:LoadingBar_Create ID is exists", ID)
  2443. return nil
  2444. end
  2445. local widget = ccui.LoadingBar:create()
  2446. widget:setName(ID)
  2447. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2448. widget:setAnchorPoint(cc.p(0, 0))
  2449. widget:loadTexture(FixPath(nimg))
  2450. widget:setDirection(direction)
  2451. if parent ~= NONEED_PARENT_CODE then
  2452. if CheckIsInvalidCObject(parent) then
  2453. return nil
  2454. end
  2455. parent:addChild(widget)
  2456. end
  2457. return widget
  2458. end
  2459. function GUI:LoadingBar_loadTexture(widget, value)
  2460. if CheckIsInvalidCObject(widget) then
  2461. return false
  2462. end
  2463. widget:loadTexture(FixPath(value))
  2464. end
  2465. function GUI:LoadingBar_setDirection(widget, value)
  2466. if CheckIsInvalidCObject(widget) then
  2467. return false
  2468. end
  2469. widget:setDirection(value)
  2470. end
  2471. function GUI:LoadingBar_getDirection(widget)
  2472. if CheckIsInvalidCObject(widget) then
  2473. return 0
  2474. end
  2475. return widget:getDirection()
  2476. end
  2477. function GUI:LoadingBar_setPercent(widget, value)
  2478. if CheckIsInvalidCObject(widget) then
  2479. return false
  2480. end
  2481. widget:setPercent(value)
  2482. end
  2483. function GUI:LoadingBar_getPercent(widget)
  2484. if CheckIsInvalidCObject(widget) then
  2485. return 0
  2486. end
  2487. return widget:getPercent()
  2488. end
  2489. function GUI:LoadingBar_setColor(widget, value)
  2490. if CheckIsInvalidCObject(widget) then
  2491. return false
  2492. end
  2493. widget:setColor(SL:ConvertColorFromHexString(value))
  2494. end
  2495. function GUI:LoadingBar_getColor(widget)
  2496. if CheckIsInvalidCObject(widget) then
  2497. return "#ffffff"
  2498. end
  2499. return GetColorHexFromRBG(widget:getColor())
  2500. end
  2501. -------------------------------------------------------------
  2502. -- TextInput
  2503. function GUI:TextInput_Create(parent, ID, x, y, width, height, fontSize)
  2504. if not ID then
  2505. SL:Print("[GUI ERROR] GUI:TextInput_Create can't find ID")
  2506. return nil
  2507. end
  2508. if not parent then
  2509. SL:Print("[GUI ERROR] GUI:TextInput_Create can't find parent", ID)
  2510. return nil
  2511. end
  2512. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2513. SL:Print("[GUI ERROR] GUI:TextInput_Create ID is exists", ID)
  2514. return nil
  2515. end
  2516. local widget = ccui.EditBox:create(cc.size(width, height), GUI.PATH_RES_ALPHA)
  2517. widget:setName(ID)
  2518. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2519. widget:setAnchorPoint(cc.p(0, 0))
  2520. if global.isMobile then
  2521. widget:setFontName(GUI.PATH_FONT2)
  2522. end
  2523. widget:setFontSize( fontSize )
  2524. widget:setFontColor(cc.c3b(255, 255, 255))
  2525. widget:setPlaceholderFontSize(fontSize)
  2526. if global.Platform == cc.PLATFORM_OS_ANDROID then
  2527. x = x + 1
  2528. y = y + 1
  2529. widget:setNativeOffset(cc.p(0, -13))
  2530. end
  2531. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2532. if parent ~= NONEED_PARENT_CODE then
  2533. if CheckIsInvalidCObject(parent) then
  2534. return false
  2535. end
  2536. parent:addChild(widget)
  2537. end
  2538. return widget
  2539. end
  2540. function GUI:TextInput_setFontColor(widget, value)
  2541. if CheckIsInvalidCObject(widget) then
  2542. return false
  2543. end
  2544. widget:setFontColor(SL:ConvertColorFromHexString(value))
  2545. end
  2546. function GUI:TextInput_setFont(widget, value, value2)
  2547. if CheckIsInvalidCObject(widget) then
  2548. return false
  2549. end
  2550. if global.isMobile then
  2551. widget:setFont(value, value2)
  2552. else
  2553. widget:setFontSize(value2)
  2554. SL:Print("[GUI LOG] GUI:TextInput_setFont will support on mobile device")
  2555. end
  2556. end
  2557. function GUI:TextInput_setFontSize(widget, value)
  2558. if CheckIsInvalidCObject(widget) then
  2559. return false
  2560. end
  2561. widget:setFontSize(value)
  2562. end
  2563. function GUI:TextInput_setPlaceholderFont(widget, value, value2)
  2564. if CheckIsInvalidCObject(widget) then
  2565. return false
  2566. end
  2567. widget:setPlaceholderFont(value, value2)
  2568. end
  2569. function GUI:TextInput_setPlaceholderFontColor(widget, value)
  2570. if CheckIsInvalidCObject(widget) then
  2571. return false
  2572. end
  2573. widget:setPlaceholderFontColor(SL:ConvertColorFromHexString(value))
  2574. end
  2575. function GUI:TextInput_setPlaceholderFontSize(widget, value)
  2576. if CheckIsInvalidCObject(widget) then
  2577. return false
  2578. end
  2579. widget:setPlaceholderFontSize(value)
  2580. end
  2581. function GUI:TextInput_setPlaceHolder(widget, value)
  2582. if CheckIsInvalidCObject(widget) then
  2583. return false
  2584. end
  2585. widget:setPlaceHolder(value)
  2586. end
  2587. function GUI:TextInput_setMaxLength(widget, value)
  2588. if CheckIsInvalidCObject(widget) then
  2589. return false
  2590. end
  2591. widget:setMaxLength(value)
  2592. end
  2593. function GUI:TextInput_setString(widget, value)
  2594. if CheckIsInvalidCObject(widget) then
  2595. return false
  2596. end
  2597. widget:setString(value)
  2598. end
  2599. function GUI:TextInput_getString(widget)
  2600. if CheckIsInvalidCObject(widget) then
  2601. return ""
  2602. end
  2603. return widget:getString()
  2604. end
  2605. function GUI:TextInput_setTextHorizontalAlignment(widget, value)
  2606. if CheckIsInvalidCObject(widget) then
  2607. return false
  2608. end
  2609. widget:setTextHorizontalAlignment(value)
  2610. end
  2611. -- 增加空方法防止报错
  2612. function GUI:TextInput_setTextVerticalAlignment(widget, value)
  2613. end
  2614. function GUI:TextInput_setInputFlag(widget, value)
  2615. if CheckIsInvalidCObject(widget) then
  2616. return false
  2617. end
  2618. widget:setInputFlag(value)
  2619. end
  2620. function GUI:TextInput_setInputMode(widget, value)
  2621. if CheckIsInvalidCObject(widget) then
  2622. return false
  2623. end
  2624. widget:setInputMode(value)
  2625. end
  2626. function GUI:TextInput_setNativeOffset(widget, value, value1)
  2627. if CheckIsInvalidCObject(widget) then
  2628. return false
  2629. end
  2630. widget:setNativeOffset( cc.p( value, value1 ) )
  2631. end
  2632. function GUI:TextInput_setReturnType(widget, value)
  2633. if CheckIsInvalidCObject(widget) then
  2634. return false
  2635. end
  2636. widget:setReturnType(value)
  2637. end
  2638. function GUI:TextInput_addOnEvent(widget, eventCB)
  2639. if CheckIsInvalidCObject(widget) then
  2640. return false
  2641. end
  2642. widget:addEventListener(function(_, eventType)
  2643. eventCB(widget, eventType)
  2644. end)
  2645. end
  2646. function GUI:TextInput_touchDownAction(widget, type)
  2647. if CheckIsInvalidCObject(widget) then
  2648. return false
  2649. end
  2650. widget:touchDownAction(widget, type)
  2651. end
  2652. function GUI:TextInput_closeInput(widget)
  2653. if CheckIsInvalidCObject(widget) then
  2654. return false
  2655. end
  2656. if widget.closeKeyboard then
  2657. widget:closeKeyboard()
  2658. end
  2659. end
  2660. -------------------------------------------------------------
  2661. -- TextAtlas
  2662. function GUI:TextAtlas_Create(parent, ID, x, y, stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
  2663. if not ID then
  2664. SL:Print("[GUI ERROR] GUI:TextAtlas_Create can't find ID")
  2665. return nil
  2666. end
  2667. if not parent then
  2668. SL:Print("[GUI ERROR] GUI:TextAtlas_Create can't find parent", ID)
  2669. return nil
  2670. end
  2671. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2672. SL:Print("[GUI ERROR] GUI:TextAtlas_Create ID is exists", ID)
  2673. return nil
  2674. end
  2675. local widget = ccui.TextAtlas:create()
  2676. widget:setName(ID)
  2677. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2678. widget:setAnchorPoint(cc.p(0, 0))
  2679. -- Custom Func
  2680. if SL._DEBUG then
  2681. GUI:TextAtlas_SetCustomFunc(widget)
  2682. end
  2683. GUI:TextAtlas_setProperty(widget, stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
  2684. if parent ~= NONEED_PARENT_CODE then
  2685. if CheckIsInvalidCObject(parent) then
  2686. return false
  2687. end
  2688. parent:addChild(widget)
  2689. end
  2690. return widget
  2691. end
  2692. function GUI:TextAtlas_SetCustomFunc(widget)
  2693. -- Set Func
  2694. widget.setStringValue = function (self, value)
  2695. self._stringValue_ = value
  2696. end
  2697. widget.setCharMapFile = function (self, value)
  2698. self._charMapFile_ = value
  2699. end
  2700. widget.setItemWidth = function (self, value)
  2701. self._itemWidth_ = value
  2702. end
  2703. widget.setItemHeight = function (self, value)
  2704. self._itemHeight_ = value
  2705. end
  2706. widget.setStartCharMap = function (self, value)
  2707. self._startCharMap_ = value
  2708. end
  2709. -- Get Func
  2710. widget.getStringValue = function (self)
  2711. return self._stringValue_ or ""
  2712. end
  2713. widget.getCharMapFile = function (self)
  2714. return self._charMapFile_ or "res/private/gui_edit/TextAtlas.png"
  2715. end
  2716. widget.getItemWidth = function (self)
  2717. return self._itemWidth_ or 0
  2718. end
  2719. widget.getItemHeight = function (self)
  2720. return self._itemHeight_ or widget:getContentSize().height
  2721. end
  2722. widget.getStartCharMap = function (self)
  2723. return self._startCharMap_ or ""
  2724. end
  2725. end
  2726. function GUI:TextAtlas_setProperty(widget, stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
  2727. if CheckIsInvalidCObject(widget) then
  2728. return false
  2729. end
  2730. if SL._DEBUG then
  2731. widget:setStringValue(stringValue)
  2732. widget:setCharMapFile(charMapFile)
  2733. widget:setItemWidth(itemWidth)
  2734. widget:setItemHeight(itemHeight)
  2735. widget:setStartCharMap(startCharMap)
  2736. end
  2737. widget:setProperty(stringValue, charMapFile, itemWidth, itemHeight, startCharMap)
  2738. end
  2739. function GUI:TextAtlas_setString(widget, value)
  2740. if CheckIsInvalidCObject(widget) then
  2741. return false
  2742. end
  2743. widget:setString(value)
  2744. end
  2745. function GUI:TextAtlas_getString(widget)
  2746. if CheckIsInvalidCObject(widget) then
  2747. return ""
  2748. end
  2749. return widget:getString()
  2750. end
  2751. -------------------------------------------------------------
  2752. -- Slider
  2753. function GUI:Slider_Create(parent, ID, x, y, barimg, pbarimg, nimg)
  2754. if not ID then
  2755. SL:Print("[GUI ERROR] GUI:Slider_Create can't find ID")
  2756. return nil
  2757. end
  2758. if not parent then
  2759. SL:Print("[GUI ERROR] GUI:Slider_Create can't find parent", ID)
  2760. return nil
  2761. end
  2762. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2763. SL:Print("[GUI ERROR] GUI:Slider_Create ID is exists", ID)
  2764. return nil
  2765. end
  2766. local widget = ccui.Slider:create()
  2767. widget:setName(ID)
  2768. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2769. widget:setAnchorPoint(cc.p(0, 0))
  2770. widget:loadBarTexture(FixPath(barimg) or "res/public/bg_szjm_01.png", 0)
  2771. widget:loadProgressBarTexture(FixPath(pbarimg) or "res/public/bg_szjm_02.png", 0)
  2772. widget:loadSlidBallTextureNormal(FixPath(nimg) or "res/private/setting_basic/icon_xdtzy_17.png", 0)
  2773. if parent ~= NONEED_PARENT_CODE then
  2774. if CheckIsInvalidCObject(parent) then
  2775. return nil
  2776. end
  2777. parent:addChild(widget)
  2778. end
  2779. return widget
  2780. end
  2781. function GUI:Slider_loadBarTexture(widget, value)
  2782. if CheckIsInvalidCObject(widget) then
  2783. return false
  2784. end
  2785. widget:loadBarTexture(FixPath(value))
  2786. end
  2787. function GUI:Slider_loadProgressBarTexture(widget, value)
  2788. if CheckIsInvalidCObject(widget) then
  2789. return false
  2790. end
  2791. widget:loadProgressBarTexture(FixPath(value))
  2792. end
  2793. function GUI:Slider_loadSlidBallTextureNormal(widget, value)
  2794. if CheckIsInvalidCObject(widget) then
  2795. return false
  2796. end
  2797. widget:loadSlidBallTextureNormal(FixPath(value))
  2798. end
  2799. function GUI:Slider_setPercent(widget, value)
  2800. if CheckIsInvalidCObject(widget) then
  2801. return false
  2802. end
  2803. widget:setPercent(value)
  2804. end
  2805. function GUI:Slider_getPercent(widget)
  2806. if CheckIsInvalidCObject(widget) then
  2807. return 0
  2808. end
  2809. return widget:getPercent()
  2810. end
  2811. function GUI:Slider_setMaxPercent(widget, value)
  2812. if CheckIsInvalidCObject(widget) then
  2813. return false
  2814. end
  2815. widget:setMaxPercent(value)
  2816. end
  2817. function GUI:Slider_addOnEvent(widget, eventCB)
  2818. if CheckIsInvalidCObject(widget) then
  2819. return false
  2820. end
  2821. widget:addEventListener(function(_, eventType)
  2822. eventCB(widget, eventType)
  2823. end)
  2824. end
  2825. -------------------------------------------------------------
  2826. -- ListView
  2827. function GUI:ListView_Create(parent, ID, x, y, width, height, direction)
  2828. if not ID then
  2829. SL:Print("[GUI ERROR] GUI:ListView_Create can't find ID")
  2830. return nil
  2831. end
  2832. if not parent then
  2833. SL:Print("[GUI ERROR] GUI:ListView_Create can't find parent", ID)
  2834. return nil
  2835. end
  2836. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  2837. SL:Print("[GUI ERROR] GUI:ListView_Create ID is exists", ID)
  2838. return nil
  2839. end
  2840. local widget = ccui.ListView:create()
  2841. widget:setName(ID)
  2842. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  2843. widget:setAnchorPoint(cc.p(0, 0))
  2844. widget:setContentSize(cc.size(width, height))
  2845. widget:setClippingEnabled(true)
  2846. widget:setClippingType(0)
  2847. widget:setTouchEnabled(true)
  2848. widget:setDirection(direction)
  2849. if parent ~= NONEED_PARENT_CODE then
  2850. if CheckIsInvalidCObject(parent) then
  2851. return nil
  2852. end
  2853. if "ccui.ListView" == tolua.type(parent) then
  2854. parent:pushBackCustomItem(widget)
  2855. else
  2856. parent:addChild(widget)
  2857. end
  2858. end
  2859. return widget
  2860. end
  2861. function GUI:ListView_setGravity(widget, value)
  2862. if CheckIsInvalidCObject(widget) then
  2863. return false
  2864. end
  2865. widget:setGravity(value)
  2866. end
  2867. function GUI:ListView_setDirection(widget, value)
  2868. if CheckIsInvalidCObject(widget) then
  2869. return false
  2870. end
  2871. widget:setDirection(value)
  2872. end
  2873. function GUI:ListView_getDirection(widget)
  2874. if CheckIsInvalidCObject(widget) then
  2875. return 0
  2876. end
  2877. return widget:getDirection()
  2878. end
  2879. function GUI:ListView_setItemsMargin(widget, value)
  2880. if CheckIsInvalidCObject(widget) then
  2881. return false
  2882. end
  2883. widget:setItemsMargin(value)
  2884. end
  2885. function GUI:ListView_setBounceEnabled(widget, value)
  2886. if CheckIsInvalidCObject(widget) then
  2887. return false
  2888. end
  2889. widget:setBounceEnabled(value)
  2890. end
  2891. function GUI:ListView_setClippingEnabled(widget, value)
  2892. if CheckIsInvalidCObject(widget) then
  2893. return false
  2894. end
  2895. widget:setClippingEnabled(value)
  2896. end
  2897. function GUI:ListView_setBackGroundColor(widget, value)
  2898. if CheckIsInvalidCObject(widget) then
  2899. return false
  2900. end
  2901. local paramList = {}
  2902. if type(value) == "table" then
  2903. for i, v in ipairs(value) do
  2904. paramList[i] = SL:ConvertColorFromHexString(v)
  2905. end
  2906. else
  2907. paramList[1] = SL:ConvertColorFromHexString(value)
  2908. end
  2909. if #paramList == 2 then
  2910. widget:setBackGroundColor(paramList[1], paramList[2])
  2911. else
  2912. widget:setBackGroundColor(paramList[1])
  2913. end
  2914. end
  2915. function GUI:ListView_setBackGroundColorType(widget, value)
  2916. if CheckIsInvalidCObject(widget) then
  2917. return false
  2918. end
  2919. widget:setBackGroundColorType(value)
  2920. end
  2921. function GUI:ListView_setBackGroundColorOpacity(widget, value)
  2922. if CheckIsInvalidCObject(widget) then
  2923. return false
  2924. end
  2925. widget:setBackGroundColorOpacity(value)
  2926. end
  2927. function GUI:ListView_pushBackCustomItem(widget, value)
  2928. if CheckIsInvalidCObject(widget) then
  2929. return false
  2930. end
  2931. widget:pushBackCustomItem(value)
  2932. end
  2933. function GUI:ListView_insertCustomItem(widget, value, value2)
  2934. if CheckIsInvalidCObject(widget) then
  2935. return false
  2936. end
  2937. widget:insertCustomItem(value, value2)
  2938. end
  2939. function GUI:ListView_removeAllItems(widget)
  2940. if CheckIsInvalidCObject(widget) then
  2941. return false
  2942. end
  2943. widget:removeAllItems()
  2944. end
  2945. function GUI:ListView_removeItemByIndex(widget, index)
  2946. if CheckIsInvalidCObject(widget) then
  2947. return false
  2948. end
  2949. widget:removeItem(index)
  2950. end
  2951. function GUI:ListView_jumpToItem(widget, value)
  2952. if CheckIsInvalidCObject(widget) then
  2953. return false
  2954. end
  2955. local index = math.max(value, 0)
  2956. widget:jumpToItem(index, cc.p(0, 0), cc.p(0, 0))
  2957. end
  2958. function GUI:ListView_getItemIndex(widget, value)
  2959. if CheckIsInvalidCObject(widget) then
  2960. return 0
  2961. end
  2962. return widget:getIndex(value)
  2963. end
  2964. function GUI:ListView_getItemByIndex(widget, value)
  2965. if CheckIsInvalidCObject(widget) then
  2966. return nil
  2967. end
  2968. return widget:getItem(value)
  2969. end
  2970. function GUI:ListView_doLayout(widget)
  2971. if CheckIsInvalidCObject(widget) then
  2972. return false
  2973. end
  2974. widget:doLayout()
  2975. end
  2976. function GUI:ListView_setBackGroundImage(widget, value)
  2977. if CheckIsInvalidCObject(widget) then
  2978. return false
  2979. end
  2980. widget:setBackGroundImage(value, 0)
  2981. end
  2982. function GUI:ListView_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
  2983. if CheckIsInvalidCObject(widget) then
  2984. return false
  2985. end
  2986. widget:setBackGroundImageScale9Enabled(true)
  2987. local contentSize = widget:getBackGroundImageTextureSize()
  2988. local x = scale9l
  2989. local y = scale9t
  2990. local width = contentSize.width-scale9l-scale9r
  2991. local height = contentSize.height-scale9t-scale9b
  2992. local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
  2993. widget:setBackGroundImageCapInsets(capInsets)
  2994. end
  2995. function GUI:ListView_removeBackGroundImage(widget)
  2996. if CheckIsInvalidCObject(widget) then
  2997. return false
  2998. end
  2999. widget:removeBackGroundImage()
  3000. end
  3001. function GUI:ListView_getItemsMargin(widget)
  3002. if CheckIsInvalidCObject(widget) then
  3003. return 0
  3004. end
  3005. return widget:getItemsMargin()
  3006. end
  3007. function GUI:ListView_getItems(widget)
  3008. if CheckIsInvalidCObject(widget) then
  3009. return {}
  3010. end
  3011. return widget:getItems()
  3012. end
  3013. function GUI:ListView_getItemCount(widget)
  3014. if CheckIsInvalidCObject(widget) then
  3015. return 0
  3016. end
  3017. return #widget:getItems()
  3018. end
  3019. function GUI:ListView_getInnerContainer(widget)
  3020. if CheckIsInvalidCObject(widget) then
  3021. return nil
  3022. end
  3023. return widget:getInnerContainer()
  3024. end
  3025. function GUI:ListView_addOnScrollEvent(widget, eventCB)
  3026. if CheckIsInvalidCObject(widget) then
  3027. return false
  3028. end
  3029. widget:addScrollViewEventListener(function(_, eventType)
  3030. eventCB(widget, eventType)
  3031. end)
  3032. end
  3033. function GUI:ListView_paintItems(widget)
  3034. if CheckIsInvalidCObject(widget) then
  3035. return false
  3036. end
  3037. widget:paintItems()
  3038. end
  3039. function GUI:ListView_autoPaintItems(widget)
  3040. if CheckIsInvalidCObject(widget) then
  3041. return false
  3042. end
  3043. local function eventCB(_, eventType)
  3044. if eventType == 9 then
  3045. widget:paintItems()
  3046. end
  3047. end
  3048. widget:addScrollViewEventListener(eventCB)
  3049. end
  3050. function GUI:ListView_removeChild(widget, item)
  3051. if CheckIsInvalidCObject(widget) then
  3052. return false
  3053. end
  3054. widget:removeChild(item, true)
  3055. end
  3056. function GUI:ListView_jumpToBottom(widget)
  3057. if CheckIsInvalidCObject(widget) then
  3058. return false
  3059. end
  3060. widget:jumpToBottom()
  3061. end
  3062. function GUI:ListView_jumpToTop(widget)
  3063. if CheckIsInvalidCObject(widget) then
  3064. return false
  3065. end
  3066. widget:jumpToTop()
  3067. end
  3068. function GUI:ListView_getTopmostItemInCurrentView(widget)
  3069. if CheckIsInvalidCObject(widget) then
  3070. return false
  3071. end
  3072. return ({[1] = widget:getTopmostItemInCurrentView(), [2] = widget:getLeftmostItemInCurrentView()})[widget:getDirection()] or nil
  3073. end
  3074. function GUI:ListView_getBottommostItemInCurrentView(widget)
  3075. if CheckIsInvalidCObject(widget) then
  3076. return false
  3077. end
  3078. return ({[1] = widget:getBottommostItemInCurrentView(), [2] = widget:getRightmostItemInCurrentView()})[widget:getDirection()] or nil
  3079. end
  3080. function GUI:ListView_scrollToTop(widget,time, boolvalue)
  3081. if CheckIsInvalidCObject(widget) then
  3082. return false
  3083. end
  3084. widget:scrollToTop(time, boolvalue)
  3085. end
  3086. function GUI:ListView_scrollToBottom(widget, time, boolvalue)
  3087. if CheckIsInvalidCObject(widget) then
  3088. return false
  3089. end
  3090. widget:scrollToBottom(time, boolvalue)
  3091. end
  3092. function GUI:ListView_getInnerContainerSize(widget)
  3093. if CheckIsInvalidCObject(widget) then
  3094. return cc.size(0, 0)
  3095. end
  3096. return widget:getInnerContainerSize()
  3097. end
  3098. function GUI:ListView_getInnerContainerPosition(widget)
  3099. if CheckIsInvalidCObject(widget) then
  3100. return cc.p(0, 0)
  3101. end
  3102. return widget:getInnerContainerPosition()
  3103. end
  3104. function GUI:ListView_setInnerContainerPosition(widget, value1, value2)
  3105. if CheckIsInvalidCObject(widget) then
  3106. return false
  3107. end
  3108. if type(value1) == "table" then
  3109. widget:setInnerContainerPosition(value1)
  3110. elseif value1 and value2 then
  3111. widget:setInnerContainerPosition(cc.p(value1, value2))
  3112. end
  3113. end
  3114. -- bool 是否衰减滚动速度(垂直方向)
  3115. function GUI:ListView_scrollToPercentVertical(widget, percent, time, bool)
  3116. if CheckIsInvalidCObject(widget) then
  3117. return false
  3118. end
  3119. widget:scrollToPercentVertical(percent, time, bool)
  3120. end
  3121. -- bool 是否衰减滚动速度(水平方向)
  3122. function GUI:ListView_scrollToPercentHorizontal(widget, percent, time, bool)
  3123. if CheckIsInvalidCObject(widget) then
  3124. return false
  3125. end
  3126. widget:scrollToPercentHorizontal(percent, time, bool)
  3127. end
  3128. function GUI:ListView_addMouseScrollPercent(widget)
  3129. if CheckIsInvalidCObject(widget) then
  3130. return false
  3131. end
  3132. widget:addMouseScrollPercent()
  3133. end
  3134. function GUI:ListView_setItemModel(widget, itemWidget)
  3135. if CheckIsInvalidCObject(widget) or CheckIsInvalidCObject(itemWidget) then
  3136. return false
  3137. end
  3138. widget:setItemModel(itemWidget)
  3139. end
  3140. function GUI:ListView_pushBackDefaultItem(widget)
  3141. if CheckIsInvalidCObject(widget) then
  3142. return false
  3143. end
  3144. widget:pushBackDefaultItem()
  3145. end
  3146. -------------------------------------------------------------
  3147. -- ScrollView
  3148. function GUI:ScrollView_Create(parent, ID, x, y, width, height, direction)
  3149. if not ID then
  3150. SL:Print("[GUI ERROR] GUI:ScrollView_Create can't find ID")
  3151. return nil
  3152. end
  3153. if not parent then
  3154. SL:Print("[GUI ERROR] GUI:ScrollView_Create can't find parent", ID)
  3155. return nil
  3156. end
  3157. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3158. SL:Print("[GUI ERROR] GUI:ScrollView_Create ID is exists", ID)
  3159. return nil
  3160. end
  3161. local widget = ccui.ScrollView:create()
  3162. widget:setName(ID)
  3163. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3164. widget:setAnchorPoint(cc.p(0, 0))
  3165. widget:setContentSize(cc.size(width, height))
  3166. widget:setClippingEnabled(true)
  3167. widget:setClippingType(0)
  3168. widget:setTouchEnabled(true)
  3169. widget:setDirection(direction) -- direction: 1-垂直; 2-水平
  3170. if parent ~= NONEED_PARENT_CODE then
  3171. if CheckIsInvalidCObject(parent) then
  3172. return nil
  3173. end
  3174. parent:addChild(widget)
  3175. end
  3176. return widget
  3177. end
  3178. function GUI:ScrollView_setInnerContainerSize(widget, sizeW, sizeH)
  3179. if CheckIsInvalidCObject(widget) then
  3180. return false
  3181. end
  3182. local size = nil
  3183. if nil == sizeH then
  3184. size = { width = sizeW.width, height = sizeW.height }
  3185. else
  3186. size = { width = sizeW, height = sizeH }
  3187. end
  3188. widget:setInnerContainerSize(size)
  3189. end
  3190. function GUI:ScrollView_getInnerContainerSize(widget)
  3191. if CheckIsInvalidCObject(widget) then
  3192. return cc.size(0, 0)
  3193. end
  3194. return widget:getInnerContainerSize()
  3195. end
  3196. function GUI:ScrollView_getInnerContainerPosition(widget)
  3197. if CheckIsInvalidCObject(widget) then
  3198. return cc.p(0, 0)
  3199. end
  3200. return widget:getInnerContainerPosition()
  3201. end
  3202. function GUI:ScrollView_setInnerContainerPosition(widget, value1, value2)
  3203. if CheckIsInvalidCObject(widget) then
  3204. return false
  3205. end
  3206. if type(value1) == "table" then
  3207. widget:setInnerContainerPosition(value1)
  3208. elseif value1 and value2 then
  3209. widget:setInnerContainerPosition(cc.p(value1, value2))
  3210. end
  3211. end
  3212. function GUI:ScrollView_setDirection(widget, value)
  3213. if CheckIsInvalidCObject(widget) then
  3214. return false
  3215. end
  3216. widget:setDirection(value)
  3217. end
  3218. function GUI:ScrollView_getDirection(widget)
  3219. if CheckIsInvalidCObject(widget) then
  3220. return 0
  3221. end
  3222. return widget:getDirection()
  3223. end
  3224. function GUI:ScrollView_setBounceEnabled(widget, value)
  3225. if CheckIsInvalidCObject(widget) then
  3226. return false
  3227. end
  3228. widget:setBounceEnabled(value)
  3229. end
  3230. function GUI:ScrollView_setClippingEnabled(widget, value)
  3231. if CheckIsInvalidCObject(widget) then
  3232. return false
  3233. end
  3234. widget:setClippingEnabled(value)
  3235. end
  3236. function GUI:ScrollView_setBackGroundColor(widget, value)
  3237. if CheckIsInvalidCObject(widget) then
  3238. return false
  3239. end
  3240. local paramList = {}
  3241. if type(value) == "table" then
  3242. for i, v in ipairs(value) do
  3243. paramList[i] = SL:ConvertColorFromHexString(v)
  3244. end
  3245. else
  3246. paramList[1] = SL:ConvertColorFromHexString(value)
  3247. end
  3248. if #paramList == 2 then
  3249. widget:setBackGroundColor(paramList[1], paramList[2])
  3250. else
  3251. widget:setBackGroundColor(paramList[1])
  3252. end
  3253. end
  3254. function GUI:ScrollView_setBackGroundColorType(widget, value)
  3255. if CheckIsInvalidCObject(widget) then
  3256. return false
  3257. end
  3258. widget:setBackGroundColorType(value)
  3259. end
  3260. function GUI:ScrollView_setBackGroundColorOpacity(widget, value)
  3261. if CheckIsInvalidCObject(widget) then
  3262. return false
  3263. end
  3264. widget:setBackGroundColorOpacity(value)
  3265. end
  3266. function GUI:ScrollView_addChild(widget, value)
  3267. if CheckIsInvalidCObject(widget) then
  3268. return false
  3269. end
  3270. if CheckIsInvalidCObject(value) then
  3271. return false
  3272. end
  3273. widget:addChild(value)
  3274. end
  3275. function GUI:ScrollView_removeAllChildren(widget)
  3276. if CheckIsInvalidCObject(widget) then
  3277. return false
  3278. end
  3279. widget:removeAllChildren()
  3280. end
  3281. function GUI:ScrollView_scrollToTop(widget, time, boolvalue)
  3282. if CheckIsInvalidCObject(widget) then
  3283. return false
  3284. end
  3285. widget:scrollToTop(time, boolvalue)
  3286. end
  3287. function GUI:ScrollView_scrollToBottom(widget, time, boolvalue)
  3288. if CheckIsInvalidCObject(widget) then
  3289. return false
  3290. end
  3291. widget:scrollToBottom(time, boolvalue)
  3292. end
  3293. function GUI:ScrollView_scrollToLeft(widget, time, boolvalue)
  3294. if CheckIsInvalidCObject(widget) then
  3295. return false
  3296. end
  3297. widget:scrollToLeft(time, boolvalue)
  3298. end
  3299. function GUI:ScrollView_scrollToRight(widget, time, boolvalue)
  3300. if CheckIsInvalidCObject(widget) then
  3301. return false
  3302. end
  3303. widget:scrollToRight(time, boolvalue)
  3304. end
  3305. function GUI:ScrollView_scrollToTopLeft(widget, time, boolvalue)
  3306. if CheckIsInvalidCObject(widget) then
  3307. return false
  3308. end
  3309. widget:scrollToTopLeft(time, boolvalue)
  3310. end
  3311. function GUI:ScrollView_setBackGroundImage(widget, value)
  3312. if CheckIsInvalidCObject(widget) then
  3313. return false
  3314. end
  3315. widget:setBackGroundImage(value, 0)
  3316. end
  3317. function GUI:ScrollView_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
  3318. if CheckIsInvalidCObject(widget) then
  3319. return false
  3320. end
  3321. widget:setBackGroundImageScale9Enabled(true)
  3322. local contentSize = widget:getBackGroundImageTextureSize()
  3323. local x = scale9l
  3324. local y = scale9t
  3325. local width = contentSize.width-scale9l-scale9r
  3326. local height = contentSize.height-scale9t-scale9b
  3327. local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
  3328. widget:setBackGroundImageCapInsets(capInsets)
  3329. end
  3330. function GUI:ScrollView_removeBackGroundImage(widget)
  3331. if CheckIsInvalidCObject(widget) then
  3332. return false
  3333. end
  3334. widget:removeBackGroundImage()
  3335. end
  3336. function GUI:ScrollView_addOnScrollEvent(widget, eventCB)
  3337. if CheckIsInvalidCObject(widget) then
  3338. return false
  3339. end
  3340. widget:addEventListener(function(_, eventType)
  3341. eventCB(widget, eventType)
  3342. end)
  3343. end
  3344. -- bool 是否衰减滚动速度(垂直方向)
  3345. function GUI:ScrollView_scrollToPercentVertical(widget, percent, time, bool)
  3346. if CheckIsInvalidCObject(widget) then
  3347. return false
  3348. end
  3349. widget:scrollToPercentVertical(percent, time, bool)
  3350. end
  3351. -- bool 是否衰减滚动速度(水平方向)
  3352. function GUI:ScrollView_scrollToPercentHorizontal(widget, percent, time, bool)
  3353. if CheckIsInvalidCObject(widget) then
  3354. return false
  3355. end
  3356. widget:scrollToPercentHorizontal(percent, time, bool)
  3357. end
  3358. -------------------------------------------------------------
  3359. -- CheckBox
  3360. function GUI:CheckBox_Create(parent, ID, x, y, nimg, pimg)
  3361. if not ID then
  3362. SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find ID")
  3363. return nil
  3364. end
  3365. if not parent then
  3366. SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find parent", ID)
  3367. return nil
  3368. end
  3369. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3370. SL:Print("[GUI ERROR] GUI:CheckBox_Create ID is exists", ID)
  3371. return nil
  3372. end
  3373. local widget = ccui.CheckBox:create()
  3374. widget:setName(ID)
  3375. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3376. widget:setAnchorPoint(cc.p(0, 0))
  3377. widget:loadTextureBackGround(FixPath(nimg))
  3378. widget:loadTextureFrontCross(FixPath(pimg))
  3379. if parent ~= NONEED_PARENT_CODE then
  3380. if CheckIsInvalidCObject(parent) then
  3381. return nil
  3382. end
  3383. parent:addChild(widget)
  3384. end
  3385. return widget
  3386. end
  3387. function GUI:CheckBox_loadTextureBackGround(widget, value)
  3388. if CheckIsInvalidCObject(widget) then
  3389. return false
  3390. end
  3391. widget:loadTextureBackGround(FixPath(value))
  3392. end
  3393. function GUI:CheckBox_loadTextureFrontCross(widget, value)
  3394. if CheckIsInvalidCObject(widget) then
  3395. return false
  3396. end
  3397. widget:loadTextureFrontCross(FixPath(value))
  3398. end
  3399. function GUI:CheckBox_loadTextureFrontCrossDisabled(widget, value)
  3400. if CheckIsInvalidCObject(widget) then
  3401. return false
  3402. end
  3403. widget:loadTextureFrontCrossDisabled(FixPath(value))
  3404. end
  3405. function GUI:CheckBox_setSelected(widget, value)
  3406. if CheckIsInvalidCObject(widget) then
  3407. return false
  3408. end
  3409. widget:setSelected(value)
  3410. end
  3411. function GUI:CheckBox_isSelected(widget)
  3412. if CheckIsInvalidCObject(widget) then
  3413. return false
  3414. end
  3415. return widget:isSelected()
  3416. end
  3417. function GUI:CheckBox_addOnEvent(widget, eventCB)
  3418. if CheckIsInvalidCObject(widget) then
  3419. return false
  3420. end
  3421. widget:addEventListener(function(_, eventType)
  3422. eventCB(widget, eventType)
  3423. end)
  3424. end
  3425. function GUI:CheckBox_setZoomScale(widget, value)
  3426. if CheckIsInvalidCObject(widget) then
  3427. return false
  3428. end
  3429. widget:setZoomScale(value)
  3430. end
  3431. -------------------------------------------------------------
  3432. -- Effect
  3433. function GUI:Effect_Create(parent, ID, x, y, effectType, effectId, sex, act, dir, speed)
  3434. if not ID then
  3435. SL:Print("[GUI ERROR] GUI:Effect_Create can't find ID")
  3436. return nil
  3437. end
  3438. if not parent then
  3439. SL:Print("[GUI ERROR] GUI:Effect_Create can't find parent", ID)
  3440. return nil
  3441. end
  3442. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3443. SL:Print("[GUI ERROR] GUI:Effect_Create ID is exists", ID)
  3444. return nil
  3445. end
  3446. sex = sex or 0
  3447. act = act or 0
  3448. dir = dir or 0
  3449. speed = speed or 1
  3450. local widget = nil
  3451. if effectType == 0 then
  3452. -- 特效
  3453. widget = global.FrameAnimManager:CreateSFXAnim(effectId)
  3454. widget:Play(0, 0, true, speed)
  3455. elseif effectType == 1 then
  3456. -- NPC
  3457. widget = global.FrameAnimManager:CreateActorNpcAnim(effectId)
  3458. widget:Play(act, dir, true, speed)
  3459. elseif effectType == 2 then
  3460. -- 怪物
  3461. widget = global.FrameAnimManager:CreateActorMonsterAnim(effectId, act)
  3462. widget:Play(act, dir, true, speed)
  3463. elseif effectType == 3 then
  3464. -- 技能
  3465. widget = global.FrameAnimManager:CreateSkillEffAnim(effectId, dir)
  3466. widget:Play(act, dir, true, speed)
  3467. elseif effectType == 4 then
  3468. -- 人物
  3469. widget = global.FrameAnimManager:CreateActorPlayerAnim(effectId, sex, act)
  3470. widget:Play(act, dir, true, speed)
  3471. elseif effectType == 5 then
  3472. -- 武器
  3473. widget = global.FrameAnimManager:CreateActorPlayerWeaponAnim(effectId, sex, act)
  3474. widget:Play(act, dir, true, speed)
  3475. elseif effectType == 6 then
  3476. -- 翅膀
  3477. widget = global.FrameAnimManager:CreateActorPlayerWingsAnim(effectId, sex, act)
  3478. widget:Play(act, dir, true, speed)
  3479. elseif effectType == 7 then
  3480. -- 发型
  3481. widget = global.FrameAnimManager:CreateActorPlayerHairAnim(effectId, sex, act)
  3482. widget:Play(act, dir, true, speed)
  3483. elseif effectType == 8 then
  3484. -- 盾牌
  3485. widget = global.FrameAnimManager:CreateActorPlayerShieldAnim(effectId, sex, act)
  3486. widget:Play(act, dir, true, speed)
  3487. else
  3488. widget = global.FrameAnimManager:CreateSFXAnim(1)
  3489. widget:Play(0, 0, true, speed)
  3490. end
  3491. widget:setName(ID)
  3492. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3493. if parent ~= NONEED_PARENT_CODE then
  3494. if CheckIsInvalidCObject(parent) then
  3495. return nil
  3496. end
  3497. parent:addChild(widget)
  3498. end
  3499. return widget
  3500. end
  3501. function GUI:Effect_play(widget, act, dir, isLoop, speed, isSequence)
  3502. if CheckIsInvalidCObject(widget) then
  3503. return false
  3504. end
  3505. widget:Stop()
  3506. widget:Play(act, dir, isLoop, speed, isSequence)
  3507. end
  3508. function GUI:Effect_stop(widget, frameIndex, act, dir)
  3509. if CheckIsInvalidCObject(widget) then
  3510. return false
  3511. end
  3512. widget:Stop(frameIndex, act, dir)
  3513. end
  3514. function GUI:Effect_addOnCompleteEvent(widget, value)
  3515. if CheckIsInvalidCObject(widget) then
  3516. return false
  3517. end
  3518. widget:SetAnimEventCallback(value)
  3519. end
  3520. function GUI:Effect_setGlobalElapseEnable(widget, elapseEnable)
  3521. if CheckIsInvalidCObject(widget) then
  3522. return false
  3523. end
  3524. widget:SetGlobalElapseEnable(elapseEnable)
  3525. end
  3526. function GUI:Effect_setAutoRemoveOnFinish(widget)
  3527. if CheckIsInvalidCObject(widget) then
  3528. return false
  3529. end
  3530. local function removeEvent()
  3531. if CheckIsInvalidCObject(widget) then
  3532. return false
  3533. end
  3534. widget:removeFromParent()
  3535. end
  3536. widget:SetAnimEventCallback(removeEvent)
  3537. end
  3538. -------------------------------------------------------------
  3539. -- RichText
  3540. function GUI:RichText_Create(parent, ID, x, y, str, width, fontSize, fontColor, vspace, hyperlinkCB, defaultFontFace)
  3541. if not ID then
  3542. SL:Print("[GUI ERROR] GUI:RichText_Create can't find ID")
  3543. return nil
  3544. end
  3545. if not parent then
  3546. SL:Print("[GUI ERROR] GUI:RichText_Create can't find parent", ID)
  3547. return nil
  3548. end
  3549. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3550. SL:Print("[GUI ERROR] GUI:RichText_Create ID is exists", ID)
  3551. return nil
  3552. end
  3553. local color
  3554. if type(fontColor) == "table" then
  3555. color = GetColorHexFromRBG(fontColor)
  3556. end
  3557. local RichTextHelp = requireUtil("RichTextHelp")
  3558. local widget = RichTextHelp:CreateRichTextWithXML(str, width, fontSize, color or fontColor, defaultFontFace, hyperlinkCB, vspace)
  3559. widget:setName(ID)
  3560. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3561. widget:setAnchorPoint(cc.p(0, 0))
  3562. widget:formatText()
  3563. if parent ~= NONEED_PARENT_CODE then
  3564. if CheckIsInvalidCObject(parent) then
  3565. return nil
  3566. end
  3567. parent:addChild(widget)
  3568. end
  3569. return widget
  3570. end
  3571. -- 原始富文本
  3572. function GUI:RichTextFCOLOR_Create(parent, ID, x, y, str, width, fontSize, color, vspace, hyperlinkCB, fontPath, outlineParam)
  3573. if not ID then
  3574. SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find ID")
  3575. return nil
  3576. end
  3577. if not parent then
  3578. SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find parent", ID)
  3579. return nil
  3580. end
  3581. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3582. SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create ID is exists", ID)
  3583. return nil
  3584. end
  3585. if type(color) == "string" and string.find(color, "#") then
  3586. color = SL:ConvertColorFromHexString(color)
  3587. end
  3588. local RichTextHelp = requireUtil("RichTextHelp")
  3589. local ttfConfig = {
  3590. outlineSize = outlineParam and outlineParam.outlineSize,
  3591. outlineColor= outlineParam and outlineParam.outlineColor
  3592. }
  3593. local widget = RichTextHelp:CreateRichTextWithFCOLOR(str, width, fontSize, color, ttfConfig, hyperlinkCB, vspace, fontPath)
  3594. widget:setName(ID)
  3595. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3596. widget:setAnchorPoint(cc.p(0, 0))
  3597. widget:formatText()
  3598. if parent ~= NONEED_PARENT_CODE then
  3599. if CheckIsInvalidCObject(parent) then
  3600. return nil
  3601. end
  3602. parent:addChild(widget)
  3603. end
  3604. return widget
  3605. end
  3606. -- 自定义富文本带道具图片
  3607. function GUI:RichTextCustom_Create(parent, ID, x, y, str, width, vspace)
  3608. if not ID then
  3609. SL:Print("[GUI ERROR] GUI:RichTextCustom_Create can't find ID")
  3610. return nil
  3611. end
  3612. if not parent then
  3613. SL:Print("[GUI ERROR] GUI:RichTextCustom_Create can't find parent", ID)
  3614. return nil
  3615. end
  3616. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3617. SL:Print("[GUI ERROR] GUI:RichTextCustom_Create ID is exists", ID)
  3618. return nil
  3619. end
  3620. local RichTextHelpEx = requireUtil("RichTextHelpEx")
  3621. local widget = RichTextHelpEx:CreateRichTextWithCustom(str, width, vspace)
  3622. widget:setName(ID)
  3623. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3624. widget:setAnchorPoint(cc.p(0, 0))
  3625. if parent ~= NONEED_PARENT_CODE then
  3626. if CheckIsInvalidCObject(parent) then
  3627. return nil
  3628. end
  3629. parent:addChild(widget)
  3630. end
  3631. return widget
  3632. end
  3633. function GUI:RichTextFCOLOR_setBackgroundColor(widget, color)
  3634. if CheckIsInvalidCObject(widget) then
  3635. return false
  3636. end
  3637. if type(color) == "string" and string.find(color, "#") then
  3638. color = SL:ConvertColorFromHexString(color)
  3639. end
  3640. widget:setBackgroundColor(color)
  3641. widget:setBackgroundColorEnable(true)
  3642. end
  3643. -- SRText富文本
  3644. function GUI:RichTextSR_Create(parent, ID, x, y, str, width, fontSize, color, vspace, hyperlinkCB, fontPath)
  3645. if not ID then
  3646. SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find ID")
  3647. return nil
  3648. end
  3649. if not parent then
  3650. SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create can't find parent", ID)
  3651. return nil
  3652. end
  3653. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3654. SL:Print("[GUI ERROR] GUI:RichTextFCOLOR_Create ID is exists", ID)
  3655. return nil
  3656. end
  3657. local RichTextHelp = requireUtil("RichTextHelp")
  3658. local widget = RichTextHelp:CreateRichTextWidthSRText(str, width, fontSize, color, fontPath, hyperlinkCB, vspace)
  3659. widget:setName(ID)
  3660. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3661. widget:setAnchorPoint(cc.p(0, 0))
  3662. widget:formatText()
  3663. if parent ~= NONEED_PARENT_CODE then
  3664. if CheckIsInvalidCObject(parent) then
  3665. return nil
  3666. end
  3667. parent:addChild(widget)
  3668. end
  3669. return widget
  3670. end
  3671. -- 自定义组合富文本
  3672. function GUI:RichTextCombine_Create(parent, ID, x, y, width, vspace)
  3673. if not ID then
  3674. SL:Print("[GUI ERROR] GUI:RichTextCombine_Create can't find ID")
  3675. return nil
  3676. end
  3677. if not parent then
  3678. SL:Print("[GUI ERROR] GUI:RichTextCombine_Create can't find parent", ID)
  3679. return nil
  3680. end
  3681. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3682. SL:Print("[GUI ERROR] GUI:RichTextCombine_Create ID is exists", ID)
  3683. return nil
  3684. end
  3685. local widget = ccui.RichText:create()
  3686. widget:ignoreContentAdaptWithSize(false)
  3687. widget:setContentSize(width, 0)
  3688. widget:setVerticalSpace(vspace)
  3689. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3690. widget:setAnchorPoint(cc.p(0, 0))
  3691. widget:setName(ID)
  3692. if parent ~= NONEED_PARENT_CODE then
  3693. if CheckIsInvalidCObject(parent) then
  3694. return nil
  3695. end
  3696. parent:addChild(widget)
  3697. end
  3698. return widget
  3699. end
  3700. function GUI:RichTextCombine_pushBackElements(widget, elements)
  3701. if CheckIsInvalidCObject(widget) then
  3702. return false
  3703. end
  3704. if not elements then
  3705. return
  3706. end
  3707. if next(elements) then
  3708. for _, v in ipairs(elements) do
  3709. widget:pushBackElement(v)
  3710. end
  3711. else
  3712. widget:pushBackElement(elements)
  3713. end
  3714. end
  3715. function GUI:RichTextCombine_format(widget)
  3716. if CheckIsInvalidCObject(widget) then
  3717. return false
  3718. end
  3719. widget:formatText()
  3720. end
  3721. local ELEMENT_TEXT_WAY = {
  3722. ITALICS_FLAG = 1, -- italic text
  3723. BOLD_FLAG = 2, -- bold text
  3724. UNDERLINE_FLAG = 4, -- underline
  3725. STRIKETHROUGH_FLAG = 8, -- strikethrough
  3726. URL_FLAG = 16, -- url of anchor
  3727. OUTLINE_FLAG = 32, -- outline effect
  3728. SHADOW_FLAG = 64, -- shadow effect
  3729. GLOW_FLAG = 128
  3730. }
  3731. function GUI:RichTextCombineCell_Create(parent, ID, x, y, type, param)
  3732. if not ID then
  3733. SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create can't find ID")
  3734. return nil
  3735. end
  3736. if not parent then
  3737. SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create can't find parent", ID)
  3738. return nil
  3739. end
  3740. if parent ~= NONEED_PARENT_CODE and tolua.type(parent) ~= "ccui.RichText" then
  3741. SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create parent type is wrong", ID)
  3742. return nil
  3743. end
  3744. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3745. SL:Print("[GUI ERROR] GUI:RichTextCombineCell_Create ID is exists", ID)
  3746. return nil
  3747. end
  3748. local widget = nil
  3749. local color = param.color and GetColorFromHexString(param.color) or cc.Color3B.WHITE
  3750. local opacity = param.opacity or 255
  3751. local fontPath = param.fontPath or global.MMO.PATH_FONT2
  3752. local fontSize = param.fontSize or global.ConstantConfig.DEFAULT_FONT_SIZE
  3753. local outlineColor = param.outlineColor and GetColorFromHexString(param.outlineColor) or cc.Color3B.BLACK
  3754. local outlineSize = param.outlineSize or 0
  3755. if type == 1 or string.upper(type) == "TEXT" then
  3756. local wayType = ELEMENT_TEXT_WAY.OUTLINE_FLAG
  3757. if param.link then
  3758. wayType = wayType + ELEMENT_TEXT_WAY.URL_FLAG
  3759. end
  3760. widget = ccui.RichElementText:create(0, color, opacity, param.str or "", fontPath, fontSize, wayType, param.link or "", outlineColor, outlineSize)
  3761. elseif type == 2 or string.upper(type) == "NODE" then
  3762. widget = ccui.RichElementCustomNode:create(0, color, opacity, param.node)
  3763. elseif type == 3 or string.upper(type) == "NEWLINE" then
  3764. widget = ccui.RichElementNewLine:create(0, color, opacity)
  3765. end
  3766. if widget and parent ~= NONEED_PARENT_CODE then
  3767. if CheckIsInvalidCObject(parent) then
  3768. return nil
  3769. end
  3770. parent:pushBackElement(widget)
  3771. end
  3772. return widget
  3773. end
  3774. function GUI:RichText_setBackgroundColor(widget, color)
  3775. if CheckIsInvalidCObject(widget) then
  3776. return false
  3777. end
  3778. if type(color) == "string" and string.find(color, "#") then
  3779. color = SL:ConvertColorFromHexString(color)
  3780. end
  3781. widget:setBackgroundColor(color)
  3782. widget:setBackgroundColorEnable(true)
  3783. end
  3784. function GUI:RichText_setOpenUrlEvent(widget, handle)
  3785. if CheckIsInvalidCObject(widget) then
  3786. return false
  3787. end
  3788. widget:setOpenUrlHandler(function(sender, str)
  3789. handle(sender, str)
  3790. end)
  3791. end
  3792. -------------------------------------------------------------
  3793. -- PageView
  3794. function GUI:PageView_Create(parent, ID, x, y, width, height)
  3795. if not ID then
  3796. SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find ID")
  3797. return nil
  3798. end
  3799. if not parent then
  3800. SL:Print("[GUI ERROR] GUI:PageView_Create can't find parent", ID)
  3801. return nil
  3802. end
  3803. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3804. SL:Print("[GUI ERROR] GUI:CheckBox_Create ID is exists", ID)
  3805. return nil
  3806. end
  3807. local widget = ccui.PageView:create()
  3808. widget:setName(ID)
  3809. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3810. widget:setAnchorPoint(cc.p(0, 0))
  3811. widget:setClippingType(0)
  3812. widget:setContentSize(cc.size(width, height))
  3813. widget:setClippingEnabled(true)
  3814. widget:setTouchEnabled(true)
  3815. if parent ~= NONEED_PARENT_CODE then
  3816. if CheckIsInvalidCObject(parent) then
  3817. return nil
  3818. end
  3819. parent:addChild(widget)
  3820. end
  3821. return widget
  3822. end
  3823. function GUI:PageView_setClippingEnabled(widget, value)
  3824. if CheckIsInvalidCObject(widget) then
  3825. return false
  3826. end
  3827. widget:setClippingEnabled(value)
  3828. end
  3829. function GUI:PageView_setBackGroundColor(widget, value)
  3830. if CheckIsInvalidCObject(widget) then
  3831. return false
  3832. end
  3833. local paramList = {}
  3834. if type(value) == "table" then
  3835. for i, v in ipairs(value) do
  3836. paramList[i] = SL:ConvertColorFromHexString(v)
  3837. end
  3838. else
  3839. paramList[1] = SL:ConvertColorFromHexString(value)
  3840. end
  3841. if #paramList == 2 then
  3842. widget:setBackGroundColor(paramList[1], paramList[2])
  3843. else
  3844. widget:setBackGroundColor(paramList[1])
  3845. end
  3846. end
  3847. function GUI:PageView_setBackGroundColorType(widget, value)
  3848. if CheckIsInvalidCObject(widget) then
  3849. return false
  3850. end
  3851. widget:setBackGroundColorType(value)
  3852. end
  3853. function GUI:PageView_setBackGroundColorOpacity(widget, value)
  3854. if CheckIsInvalidCObject(widget) then
  3855. return false
  3856. end
  3857. widget:setBackGroundColorOpacity(value)
  3858. end
  3859. function GUI:PageView_setBackGroundImage(widget, value)
  3860. if CheckIsInvalidCObject(widget) then
  3861. return false
  3862. end
  3863. widget:setBackGroundImage(value, 0)
  3864. end
  3865. function GUI:PageView_setBackGroundImageScale9Slice(widget, scale9l, scale9r, scale9t, scale9b)
  3866. if CheckIsInvalidCObject(widget) then
  3867. return false
  3868. end
  3869. widget:setBackGroundImageScale9Enabled(true)
  3870. local contentSize = widget:getBackGroundImageTextureSize()
  3871. local x = scale9l
  3872. local y = scale9t
  3873. local width = contentSize.width-scale9l-scale9r
  3874. local height = contentSize.height-scale9t-scale9b
  3875. local capInsets = RestrictCapInsetRect({x = x, y = y, width = width, height = height}, contentSize)
  3876. widget:setBackGroundImageCapInsets(capInsets)
  3877. end
  3878. function GUI:PageView_removeBackGroundImage(widget)
  3879. if CheckIsInvalidCObject(widget) then
  3880. return false
  3881. end
  3882. widget:removeBackGroundImage()
  3883. end
  3884. function GUI:PageView_scrollToItem(widget, index)
  3885. if CheckIsInvalidCObject(widget) then
  3886. return false
  3887. end
  3888. widget:scrollToItem(index)
  3889. end
  3890. function GUI:PageView_setCurrentPageIndex(widget, index)
  3891. if CheckIsInvalidCObject(widget) then
  3892. return false
  3893. end
  3894. widget:setCurrentPageIndex(index)
  3895. end
  3896. function GUI:PageView_getCurrentPageIndex(widget)
  3897. if CheckIsInvalidCObject(widget) then
  3898. return 0
  3899. end
  3900. return widget:getCurrentPageIndex()
  3901. end
  3902. function GUI:PageView_getItems(widget)
  3903. if CheckIsInvalidCObject(widget) then
  3904. return {}
  3905. end
  3906. return widget:getItems()
  3907. end
  3908. function GUI:PageView_getItemCount(widget)
  3909. if CheckIsInvalidCObject(widget) then
  3910. return 0
  3911. end
  3912. return #widget:getItems()
  3913. end
  3914. function GUI:PageView_addPage(widget, value)
  3915. if CheckIsInvalidCObject(widget) then
  3916. return false
  3917. end
  3918. if CheckIsInvalidCObject(value) then
  3919. return false
  3920. end
  3921. widget:addPage(value)
  3922. end
  3923. function GUI:PageView_addOnEvent(widget, eventCB)
  3924. if CheckIsInvalidCObject(widget) then
  3925. return false
  3926. end
  3927. widget:addEventListener(function(_, eventType)
  3928. eventCB(widget, eventType)
  3929. end)
  3930. end
  3931. ------------------------------------------------------------
  3932. --- TableView
  3933. function GUI:TableView_Create(parent, ID, x, y, width, height, direction, cellWid, cellHei, num, jumpIndex)
  3934. if not ID then
  3935. SL:Print("[GUI ERROR] GUI:TableView_Create can't find ID")
  3936. return nil
  3937. end
  3938. if not parent then
  3939. SL:Print("[GUI ERROR] GUI:TableView_Create can't find parent", ID)
  3940. return nil
  3941. end
  3942. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  3943. SL:Print("[GUI ERROR] GUI:TableView_Create ID is exists", ID)
  3944. return nil
  3945. end
  3946. local tableViewDirection = { -- 1垂直; 2水平
  3947. [1] = cc.SCROLLVIEW_DIRECTION_VERTICAL,
  3948. [2] = cc.SCROLLVIEW_DIRECTION_HORIZONTAL,
  3949. }
  3950. local widget = nil
  3951. widget = TableViewEx.create({
  3952. size = cc.size(width, height),
  3953. direction = direction and tableViewDirection[direction],
  3954. cellSizeForTable = function (tv, view, idx)
  3955. return cellWid, cellHei
  3956. end,
  3957. numberOfCellsInTableView = function (tv, view)
  3958. return num
  3959. end,
  3960. tableCellAtIndex = function (tv, view, idx)
  3961. local i = idx + 1
  3962. local cell = view:dequeueCell()
  3963. if not cell then
  3964. cell = cc.TableViewCell:new()
  3965. else
  3966. cell:removeAllChildren()
  3967. end
  3968. if widget and widget.TableViewCell_Create then
  3969. widget.TableViewCell_Create(cell, i, ID)
  3970. end
  3971. return cell
  3972. end
  3973. })
  3974. widget.getDescription = function()
  3975. return "TableView"
  3976. end
  3977. widget:setCascadeColorEnabled(true)
  3978. widget:setCascadeOpacityEnabled(true)
  3979. widget:setName(ID)
  3980. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  3981. widget:setAnchorPoint(cc.p(0, 0))
  3982. widget:setContentSize(cc.size(width, height))
  3983. widget:setTouchEnabled(true)
  3984. if parent ~= NONEED_PARENT_CODE then
  3985. if CheckIsInvalidCObject(parent) then
  3986. return nil
  3987. end
  3988. parent:addChild(widget)
  3989. end
  3990. return widget
  3991. end
  3992. function GUI:TableView_setCellCreateEvent(widget, func)
  3993. if type(func) == "function" then
  3994. widget.TableViewCell_Create = func
  3995. end
  3996. widget:registerScriptHandler()
  3997. end
  3998. function GUI:TableView_setDirection(widget, value)
  3999. if CheckIsInvalidCObject(widget) then
  4000. return false
  4001. end
  4002. local tableViewDirection = {
  4003. [1] = cc.SCROLLVIEW_DIRECTION_VERTICAL,
  4004. [2] = cc.SCROLLVIEW_DIRECTION_HORIZONTAL,
  4005. }
  4006. if value and tableViewDirection[value] then
  4007. widget:setDirection(tableViewDirection[value])
  4008. end
  4009. end
  4010. function GUI:TableView_getDirection(widget)
  4011. if CheckIsInvalidCObject(widget) then
  4012. return 0
  4013. end
  4014. return widget:getDirectionEx()
  4015. end
  4016. function GUI:TableView_setVerticalFillOrder(widget, value)
  4017. if CheckIsInvalidCObject(widget) then
  4018. return false
  4019. end
  4020. widget:setVerticalFillOrder(value)
  4021. end
  4022. function GUI:TableView_setContentOffset(widget, x, y)
  4023. if CheckIsInvalidCObject(widget) then
  4024. return false
  4025. end
  4026. widget:setContentOffset(cc.p(x, y))
  4027. end
  4028. function GUI:TableView_getContentOffset(widget)
  4029. if CheckIsInvalidCObject(widget) then
  4030. return nil
  4031. end
  4032. return widget:getContentOffset()
  4033. end
  4034. function GUI:TableView_setBackGroundColor(widget, value)
  4035. if CheckIsInvalidCObject(widget) then
  4036. return false
  4037. end
  4038. if type(value) == "string" and string.find(value, "#") then
  4039. value = GetColorFromHexString(value)
  4040. end
  4041. widget:SetBackColor(value)
  4042. end
  4043. function GUI:TableView_addTableCellAtIndexEvent(widget, func)
  4044. if CheckIsInvalidCObject(widget) then
  4045. return false
  4046. end
  4047. widget:setTableCellAtIndexHandler(func)
  4048. end
  4049. function GUI:TableView_addOnTouchedCellEvent(widget, func)
  4050. if CheckIsInvalidCObject(widget) then
  4051. return false
  4052. end
  4053. widget:setTableCellTouchedHandler(func)
  4054. end
  4055. function GUI:TableView_scrollToCell(widget, index)
  4056. if CheckIsInvalidCObject(widget) then
  4057. return false
  4058. end
  4059. widget:scrollToCell(index)
  4060. end
  4061. function GUI:TableView_addOnScrollEvent(widget, func)
  4062. if CheckIsInvalidCObject(widget) then
  4063. return false
  4064. end
  4065. widget:setTableViewScrollHandler(func)
  4066. end
  4067. function GUI:TableView_reloadData(widget)
  4068. if CheckIsInvalidCObject(widget) then
  4069. return false
  4070. end
  4071. widget:reloadData()
  4072. end
  4073. function GUI:TableView_reloadDataEx(widget)
  4074. if CheckIsInvalidCObject(widget) then
  4075. return false
  4076. end
  4077. widget:reloadDataEx()
  4078. end
  4079. function GUI:TableView_setTableViewCellsNumHandler(widget, func)
  4080. if CheckIsInvalidCObject(widget) then
  4081. return false
  4082. end
  4083. widget:setTableViewCellsNumHandler(func)
  4084. end
  4085. function GUI:TableView_addMouseScrollEvent(widget, func)
  4086. if CheckIsInvalidCObject(widget) then
  4087. return false
  4088. end
  4089. local call_scrolling = nil
  4090. if func and type(func) == "function" then
  4091. call_scrolling = func
  4092. else
  4093. call_scrolling = function(param)
  4094. local widget = param.widget
  4095. local speed = 40
  4096. local scorllX = param.x
  4097. local scorllY = param.y
  4098. local contentSize = widget:getContentSize()
  4099. local cellSize = widget:getCellSize()
  4100. local innerHei = cellSize.height * widget:getTotalCellNums()
  4101. local innerPos = widget:getContentOffset()
  4102. local vHeight = innerHei - contentSize.height
  4103. if innerHei > contentSize.height then
  4104. local dis = speed * scorllY
  4105. local offsetY = innerPos.y + dis
  4106. offsetY = math.max(math.min(offsetY, 0), - vHeight)
  4107. widget:setContentOffset(cc.p(innerPos.x, offsetY), true)
  4108. end
  4109. end
  4110. end
  4111. widget:addMouseScrollEvent(call_scrolling)
  4112. end
  4113. -- TableViewCell
  4114. function GUI:TableViewCell_getIdx(widget)
  4115. if CheckIsInvalidCObject(widget) then
  4116. return false
  4117. end
  4118. if widget.getIdx then
  4119. return widget:getIdx() + 1
  4120. end
  4121. end
  4122. -------------------------------------------------------------
  4123. -- ProgressTimer
  4124. function GUI:ProgressTimer_Create(parent, ID, x, y, img, width, height)
  4125. if not ID then
  4126. SL:Print("[GUI ERROR] GUI:CheckBox_Create can't find ID")
  4127. return nil
  4128. end
  4129. if not parent then
  4130. SL:Print("[GUI ERROR] GUI:ProgressTimer_Create can't find parent", ID)
  4131. return nil
  4132. end
  4133. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4134. SL:Print("[GUI ERROR] GUI:CheckBox_Create ID is exists", ID)
  4135. return nil
  4136. end
  4137. local spriteCD = cc.Sprite:create(img)
  4138. if width and height then
  4139. spriteCD:setContentSize(width, height)
  4140. end
  4141. local widget = cc.ProgressTimer:create(spriteCD)
  4142. widget:setName(ID)
  4143. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4144. widget:setAnchorPoint(cc.p(0, 0))
  4145. if parent ~= NONEED_PARENT_CODE then
  4146. if CheckIsInvalidCObject(parent) then
  4147. return nil
  4148. end
  4149. parent:addChild(widget)
  4150. end
  4151. return widget
  4152. end
  4153. function GUI:ProgressTimer_setPercentage(widget, value)
  4154. if CheckIsInvalidCObject(widget) then
  4155. return false
  4156. end
  4157. widget:setPercentage(value)
  4158. end
  4159. function GUI:ProgressTimer_getPercentage(widget)
  4160. if CheckIsInvalidCObject(widget) then
  4161. return 0
  4162. end
  4163. return widget:getPercentage()
  4164. end
  4165. -- value顺时针, false逆时针
  4166. function GUI:ProgressTimer_setReverseDirection(widget, value)
  4167. if CheckIsInvalidCObject(widget) then
  4168. return false
  4169. end
  4170. widget:setReverseDirection(value)
  4171. end
  4172. function GUI:ProgressTimer_progressFromTo(widget, time, from, to, completeCB)
  4173. if CheckIsInvalidCObject(widget) then
  4174. return false
  4175. end
  4176. if completeCB then
  4177. widget:runAction(cc.Sequence:create(
  4178. cc.ProgressFromTo:create(time or 0.5, from, to), cc.CallFunc:create(completeCB)
  4179. ))
  4180. else
  4181. widget:runAction(cc.ProgressFromTo:create(time or 0.5, from, to))
  4182. end
  4183. end
  4184. function GUI:ProgressTimer_ChangeImg(widget, img)
  4185. if CheckIsInvalidCObject(widget) then
  4186. return false
  4187. end
  4188. local spriteCD = cc.Sprite:create(img)
  4189. if spriteCD then
  4190. widget:setSprite(spriteCD)
  4191. end
  4192. end
  4193. function GUI:ProgressTimer_progressTo(widget, time, to, completeCB, tag)
  4194. if CheckIsInvalidCObject(widget) then
  4195. return false
  4196. end
  4197. local action = nil
  4198. if completeCB then
  4199. action = cc.Sequence:create(
  4200. cc.ProgressTo:create(time or 0, to),
  4201. cc.CallFunc:create(completeCB)
  4202. )
  4203. else
  4204. action = cc.ProgressTo:create(time or 0, to)
  4205. end
  4206. widget:runAction(action)
  4207. if tag then
  4208. action:setTag(tag)
  4209. end
  4210. end
  4211. -------------------------------------------------------------
  4212. -- ItemShow
  4213. function GUI:ItemShow_Create(parent, ID, x, y, data)
  4214. if not ID then
  4215. SL:Print("[GUI ERROR] GUI:ItemShow_Create can't find ID")
  4216. return nil
  4217. end
  4218. if not parent then
  4219. SL:Print("[GUI ERROR] GUI:ItemShow_Create can't find parent", ID)
  4220. return nil
  4221. end
  4222. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4223. SL:Print("[GUI ERROR] GUI:ItemShow_Create ID is exists", ID)
  4224. return nil
  4225. end
  4226. if not data then
  4227. SL:Print("[GUI ERROR] GUI:ItemShow_Create itemData is nil", ID)
  4228. return nil
  4229. end
  4230. local widget = GoodsItem:create(data)
  4231. widget:setName(ID)
  4232. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4233. widget:setAnchorPoint(cc.p(0, 0))
  4234. if parent ~= NONEED_PARENT_CODE then
  4235. if CheckIsInvalidCObject(parent) then
  4236. return nil
  4237. end
  4238. if "ccui.ListView" == tolua.type(parent) then
  4239. parent:pushBackCustomItem(widget)
  4240. else
  4241. parent:addChild(widget)
  4242. end
  4243. end
  4244. return widget
  4245. end
  4246. function GUI:ItemShow_addReplaceClickEvent(widget, eventCB)
  4247. if CheckIsInvalidCObject(widget) then
  4248. return false
  4249. end
  4250. widget:addReplaceClickEventListener(eventCB)
  4251. end
  4252. function GUI:ItemShow_addPressEvent(widget, eventCB)
  4253. if CheckIsInvalidCObject(widget) then
  4254. return false
  4255. end
  4256. widget:addPressCallBack(eventCB)
  4257. end
  4258. function GUI:ItemShow_addDoubleEvent(widget, eventCB)
  4259. if CheckIsInvalidCObject(widget) then
  4260. return false
  4261. end
  4262. widget:addDoubleEventListener(eventCB)
  4263. end
  4264. function GUI:ItemShow_setIconGrey( widget, value)
  4265. if CheckIsInvalidCObject(widget) then
  4266. return false
  4267. end
  4268. widget:setIconGrey(value)
  4269. end
  4270. function GUI:ItemShow_setItemPowerTag(widget)
  4271. if CheckIsInvalidCObject(widget) then
  4272. return false
  4273. end
  4274. widget:setItemPowerTag()
  4275. end
  4276. function GUI:ItemShow_setItemShowChooseState(widget, value)
  4277. if CheckIsInvalidCObject(widget) then
  4278. return false
  4279. end
  4280. widget:SetChooseState(value)
  4281. end
  4282. function GUI:ItemShow_setMoveEable(widget, value)
  4283. if CheckIsInvalidCObject(widget) then
  4284. return false
  4285. end
  4286. widget:SetMoveEable(value)
  4287. end
  4288. function GUI:ItemShow_GetLayoutExtra(widget)
  4289. if CheckIsInvalidCObject(widget) then
  4290. return false
  4291. end
  4292. return widget:GetLayoutExtra()
  4293. end
  4294. function GUI:ItemShow_resetMoveState(widget, value)
  4295. if CheckIsInvalidCObject(widget) then
  4296. return false
  4297. end
  4298. widget:resetMoveState(value)
  4299. end
  4300. function GUI:ItemShow_RDItem(widget, itemData)
  4301. if CheckIsInvalidCObject(widget) then
  4302. return false
  4303. end
  4304. widget:UpdateItem(itemData)
  4305. end
  4306. function GUI:ItemShow_updateItem(widget, itemData)
  4307. if CheckIsInvalidCObject(widget) then
  4308. return false
  4309. end
  4310. widget:UpdateItem(itemData)
  4311. end
  4312. function GUI:ItemShow_updateItemCount(widget, itemData)
  4313. if CheckIsInvalidCObject(widget) then
  4314. return false
  4315. end
  4316. widget:UpdateGoodsItem(itemData)
  4317. end
  4318. function GUI:ItemShow_OnRunFunc(widget, funcname, ...)
  4319. if CheckIsInvalidCObject(widget) then
  4320. return false
  4321. end
  4322. return widget:OnRunFunc(funcname, ...)
  4323. end
  4324. function GUI:ItemShow_setItemTouchSwallow(widget, bool)
  4325. if CheckIsInvalidCObject(widget) then
  4326. return false
  4327. end
  4328. widget:setItemTouchSwallow(bool)
  4329. end
  4330. function GUI:ItemShow_setCount(widget, count)
  4331. if CheckIsInvalidCObject(widget) then
  4332. return false
  4333. end
  4334. widget:setCount(count)
  4335. end
  4336. function GUI:ItemShow_SetItemIndex(widget, index)
  4337. if CheckIsInvalidCObject(widget) then
  4338. return false
  4339. end
  4340. widget:SetItemIndex(index)
  4341. end
  4342. -------------------------------------------------------------
  4343. -- ItemBox
  4344. function GUI:ItemBox_Create(parent, ID, x, y, img, boxindex, stdmode)
  4345. if not ID then
  4346. SL:Print("[GUI ERROR] GUI:ItemBox_Create can't find ID")
  4347. return nil
  4348. end
  4349. if not parent then
  4350. SL:Print("[GUI ERROR] GUI:ItemBox_Create can't find parent", ID)
  4351. return nil
  4352. end
  4353. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4354. SL:Print("[GUI ERROR] GUI:ItemBox_Create ID is exists", ID)
  4355. return nil
  4356. end
  4357. local setData = {}
  4358. setData.img = img
  4359. setData.boxindex = boxindex
  4360. setData.stdmode = stdmode
  4361. local widget = SItemBox:create(setData)
  4362. widget:setName(ID)
  4363. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4364. widget:setAnchorPoint(cc.p(0, 0))
  4365. if parent ~= NONEED_PARENT_CODE then
  4366. if CheckIsInvalidCObject(parent) then
  4367. return nil
  4368. end
  4369. parent:addChild(widget)
  4370. end
  4371. return widget
  4372. end
  4373. function GUI:ItemBox_GetItemData(widget, boxindex)
  4374. if CheckIsInvalidCObject(widget) then
  4375. return nil
  4376. end
  4377. local SSRUIManager = global.Facade:retrieveMediator("SSRUIManager")
  4378. return SSRUIManager:GetItemDataByboxIndex(boxindex)
  4379. end
  4380. function GUI:ItemBox_RemoveBoxData(widget, boxindex)
  4381. if CheckIsInvalidCObject(widget) then
  4382. return false
  4383. end
  4384. global.Facade:sendNotification(global.NoticeTable.SSR_ITEMBOXWidget_Remove, {boxindex = boxindex})
  4385. end
  4386. function GUI:ItemBox_UpdateBoxData(widget, boxindex, itemData)
  4387. if CheckIsInvalidCObject(widget) then
  4388. return false
  4389. end
  4390. local updateData = true
  4391. if itemData and next(itemData) then
  4392. updateData = false
  4393. end
  4394. global.Facade:sendNotification(global.NoticeTable.SSR_ITEMBOXWidget_Update, {boxindex = boxindex, updateData = updateData, itemData = itemData})
  4395. end
  4396. -------------------------------------------------------------
  4397. -- EquipShow
  4398. function GUI:EquipShow_Create(parent, ID, x, y, pos, isHero, data)
  4399. if not ID then
  4400. SL:Print("[GUI ERROR] GUI:EquipShow_Create can't find ID")
  4401. return nil
  4402. end
  4403. if not parent then
  4404. SL:Print("[GUI ERROR] GUI:EquipShow_Create can't find parent", ID)
  4405. return nil
  4406. end
  4407. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4408. SL:Print("[GUI ERROR] GUI:EquipShow_Create ID is exists", ID)
  4409. return nil
  4410. end
  4411. if not tonumber(pos) then
  4412. SL:Print("[GUI ERROR] GUI:EquipShow_Create pos is nil", ID)
  4413. return nil
  4414. end
  4415. local pos = tonumber(pos)
  4416. local isLookPlayer = data and data.lookPlayer
  4417. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4418. local EquipProxy = isHero and global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy) or global.Facade:retrieveProxy(global.ProxyTable.Equip)
  4419. local LookPlayerProxy = global.Facade:retrieveProxy(global.ProxyTable.LookPlayerProxy)
  4420. local size = cc.size(64, 64)
  4421. local equipData = nil
  4422. if isLookPlayer then
  4423. equipData = LookPlayerProxy:GetLookPlayerItemDataByPos(pos)
  4424. else
  4425. equipData = EquipProxy:GetEquipDataByPos(pos)
  4426. end
  4427. local widget = ccui.Widget:create()
  4428. widget:setContentSize(size)
  4429. widget:setName(ID)
  4430. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4431. widget:setAnchorPoint(cc.p(0, 0))
  4432. widget._EQUIP_POS = pos
  4433. widget._isHero = isHero
  4434. widget._param = data
  4435. if equipData then
  4436. local info = data or {}
  4437. info.index = equipData.Index
  4438. info.itemData = equipData
  4439. info.from = isHero and ItemMoveProxy.ItemFrom.HERO_EQUIP or ItemMoveProxy.ItemFrom.PALYER_EQUIP
  4440. local item = GoodsItem:create(info)
  4441. item:setPosition(cc.p(size.width / 2, size.height / 2))
  4442. widget:addChild(item)
  4443. if data.doubleTakeOff and not isLookPlayer then
  4444. if not (info.look) then
  4445. item:addLookItemInfoEvent(nil, 2)
  4446. end
  4447. item:addDoubleEventListener(function()
  4448. local takeOffEquipData = {
  4449. itemData = equipData,
  4450. pos = equipData.Where
  4451. }
  4452. if isHero then
  4453. ItemMoveProxy:TakeOffEquip_Hero(takeOffEquipData)
  4454. else
  4455. ItemMoveProxy:TakeOffEquip(takeOffEquipData)
  4456. end
  4457. end)
  4458. end
  4459. end
  4460. local function addItemIntoEquip(touchPos)
  4461. local state = ItemMoveProxy:GetMovingItemState()
  4462. local canMove = widget._param and widget._param.movable and not widget._param.lookPlayer
  4463. if state and canMove then
  4464. local goToName = isHero and ItemMoveProxy.ItemGoTo.HERO_EQUIP or ItemMoveProxy.ItemGoTo.PALYER_EQUIP
  4465. local data = {}
  4466. data.target = goToName
  4467. data.pos = touchPos
  4468. data.equipPos = pos
  4469. ItemMoveProxy:CheckAndCallBack(data)
  4470. else
  4471. return -1
  4472. end
  4473. end
  4474. local function setNoswallowMouse(touchPos)
  4475. return -1
  4476. end
  4477. global.mouseEventController:registerMouseButtonEvent(
  4478. widget,
  4479. {
  4480. down_r = setNoswallowMouse,
  4481. special_r = addItemIntoEquip,
  4482. checkIsVisible = true
  4483. }
  4484. )
  4485. if parent ~= NONEED_PARENT_CODE then
  4486. if CheckIsInvalidCObject(parent) then
  4487. return nil
  4488. end
  4489. if "ccui.ListView" == tolua.type(parent) then
  4490. parent:pushBackCustomItem(widget)
  4491. else
  4492. parent:addChild(widget)
  4493. end
  4494. end
  4495. return widget
  4496. end
  4497. function GUI:EquipShow_setAutoUpdate(widget)
  4498. if CheckIsInvalidCObject(widget) then
  4499. return false
  4500. end
  4501. local lookPlayer = widget._param and widget._param.lookPlayer
  4502. if not widget._EQUIP_POS or lookPlayer then
  4503. return false
  4504. end
  4505. global.Facade:sendNotification(global.NoticeTable.AutoEquipShowWidgetAdd, {widget = widget})
  4506. end
  4507. -------------------------------------------------------------
  4508. -- MoveWidget
  4509. function GUI:MoveWidget_Create(parent, ID, x, y, width, height, from, ext)
  4510. if not ID then
  4511. SL:Print("[GUI ERROR] GUI:MoveWidget_Create can't find ID")
  4512. return nil
  4513. end
  4514. if not parent then
  4515. SL:Print("[GUI ERROR] GUI:MoveWidget_Create can't find parent", ID)
  4516. return nil
  4517. end
  4518. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4519. SL:Print("[GUI ERROR] GUI:MoveWidget_Create ID is exists", ID)
  4520. return nil
  4521. end
  4522. ext = ext or {}
  4523. local widget = ccui.Layout:create()
  4524. if parent ~= NONEED_PARENT_CODE then
  4525. if CheckIsInvalidCObject(parent) then
  4526. return nil
  4527. end
  4528. if "ccui.ListView" == tolua.type(parent) then
  4529. parent:pushBackCustomItem(widget)
  4530. elseif "ccui.PageView" == tolua.type(parent) then
  4531. parent:addPage(widget)
  4532. else
  4533. parent:addChild(widget)
  4534. end
  4535. end
  4536. widget:setName(ID)
  4537. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4538. widget:setAnchorPoint(cc.p(0.5, 0.5))
  4539. widget:setContentSize(cc.size(width, height))
  4540. widget:setTouchEnabled(true)
  4541. local itemMoveState = {
  4542. begin = 1,
  4543. moving = 2,
  4544. end_move = 3,
  4545. }
  4546. local ITEMFROMUI = SL:GetMetaValue("ITEMFROMUI_ENUM")
  4547. local beginMoveCallBack = ext.beginMoveCB
  4548. local endMoveCallBack = ext.endMoveCB
  4549. local cancelMoveCallBack = ext.cancelMoveCB
  4550. local pressCallBack = ext.pressCB
  4551. local clickCallBack = ext.clickCB
  4552. local pcDoubleCallBack = ext.pcDoubleCB
  4553. local mouseScrollCallBack = ext.mouseScrollCB
  4554. local function resetMoveState(mySelf, bool, isCancel)
  4555. if mySelf and not tolua.isnull(mySelf) then
  4556. mySelf._movingState = bool
  4557. if bool then
  4558. if beginMoveCallBack then
  4559. beginMoveCallBack( mySelf, bool )
  4560. end
  4561. else
  4562. if isCancel then
  4563. if cancelMoveCallBack then
  4564. cancelMoveCallBack( mySelf, bool )
  4565. end
  4566. else
  4567. if endMoveCallBack then
  4568. endMoveCallBack( mySelf, bool )
  4569. end
  4570. end
  4571. end
  4572. end
  4573. end
  4574. local function SetGoodItemState(state, movePos)
  4575. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  4576. local itemData = nil
  4577. if from == ITEMFROMUI.PALYER_EQUIP and ext.equipPos then
  4578. itemData = EquipProxy:GetEquipDataByPos(ext.equipPos, ext.equipList == true)
  4579. elseif from == ITEMFROMUI.HERO_EQUIP and ext.equipPos then
  4580. local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  4581. itemData = HeroEquipProxy:GetEquipDataByPos(ext.equipPos, ext.equipList == true)
  4582. end
  4583. if (from == ITEMFROMUI.PALYER_EQUIP or from == ITEMFROMUI.HERO_EQUIP) and not itemData then
  4584. return
  4585. end
  4586. if itemMoveState.begin == state then
  4587. resetMoveState(widget, true)
  4588. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_Begin,{
  4589. pos = movePos,
  4590. itemData = itemData,
  4591. cancelCallBack = function()
  4592. resetMoveState(widget, false, true)
  4593. end,
  4594. from = from,
  4595. movingNode = not itemData and widget:clone()
  4596. })
  4597. elseif itemMoveState.moving == state then
  4598. elseif itemMoveState.end_move == state then
  4599. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_End, movePos)
  4600. resetMoveState(widget, false)
  4601. end
  4602. end
  4603. local function clickEventCallBack(node)
  4604. --不在道具移动
  4605. if node._movingState then
  4606. return
  4607. end
  4608. local panelPos = node:getWorldPosition()
  4609. if global.isWinPlayMode then
  4610. SetGoodItemState(itemMoveState.begin, panelPos)
  4611. end
  4612. if clickCallBack then
  4613. clickCallBack(node)
  4614. end
  4615. end
  4616. local function pressEventCallBack(node)
  4617. --不在道具移动
  4618. if node._movingState then
  4619. return
  4620. end
  4621. local panelPos = node:getWorldPosition()
  4622. if global.isWinPlayMode then
  4623. SetGoodItemState(itemMoveState.begin, panelPos)
  4624. end
  4625. if pressCallBack then
  4626. pressCallBack(node)
  4627. end
  4628. end
  4629. local isEventPress = false
  4630. local isMoved = true
  4631. local hasEventCallOnTouchBegin = false --只有在响应了touchbegin 时才会去响应延时方法 因为在延时后 鼠标事件的 状态已经被置掉
  4632. local isMobile = not global.isWinPlayMode
  4633. local clickTimes = 0
  4634. -- 延迟
  4635. local function delayCallback()
  4636. isEventPress = true
  4637. if pressEventCallBack then
  4638. if not pressEventCallBack then
  4639. return false
  4640. end
  4641. if not isMoved then
  4642. pressEventCallBack(widget)
  4643. return false
  4644. end
  4645. local movedPos = widget:getTouchMovePosition()
  4646. local beganPos = widget:getTouchBeganPosition()
  4647. local diff = cc.pSub(movedPos, beganPos)
  4648. local distSq = cc.pLengthSQ(diff)
  4649. if distSq <= 100 then
  4650. pressEventCallBack(widget)
  4651. end
  4652. end
  4653. end
  4654. local function touchEvent(touch, eventType)
  4655. if global.isWinPlayMode then
  4656. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4657. local itemMoving = ItemMoveProxy:GetMovingItemState()
  4658. if itemMoving then --在道具移动中
  4659. resetMoveState(widget, false)
  4660. return
  4661. else -- 辅助清理状态
  4662. if widget and not tolua.isnull(widget) and widget._movingState then
  4663. widget._movingState = false
  4664. end
  4665. end
  4666. end
  4667. if eventType == 0 then
  4668. isEventPress = false
  4669. isMoved = false
  4670. hasEventCallOnTouchBegin = true
  4671. if pressEventCallBack then
  4672. performWithDelay(widget, delayCallback, global.MMO.CLICK_DOUBLE_TIME)
  4673. end
  4674. elseif eventType == 1 then
  4675. local movedPos = widget:getTouchMovePosition()
  4676. local beganPos = widget:getTouchBeganPosition()
  4677. local diff = cc.pSub(movedPos, beganPos)
  4678. local distSq = cc.pLengthSQ(diff)
  4679. if not isMoved and distSq > 100 then
  4680. isMoved = true
  4681. if isMobile then
  4682. local beginMovePos = widget:getWorldPosition()
  4683. SetGoodItemState(itemMoveState.begin, beginMovePos)
  4684. end
  4685. end
  4686. if isMobile then
  4687. local movedPos = widget:getTouchMovePosition()
  4688. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_Moving, {pos = movedPos})
  4689. end
  4690. elseif eventType == 2 then
  4691. widget:stopAllActions()
  4692. if not isMoved then
  4693. if not isEventPress then
  4694. local stateOnbegin = hasEventCallOnTouchBegin
  4695. if clickEventCallBack and stateOnbegin then
  4696. clickEventCallBack(widget, eventType)
  4697. end
  4698. if global.isWinPlayMode and pcDoubleCallBack then
  4699. clickTimes = clickTimes + 1
  4700. if clickTimes >= 2 then
  4701. clickTimes = 0
  4702. if widget._clickDelayHandler then
  4703. UnSchedule(widget._clickDelayHandler)
  4704. widget._clickDelayHandler = nil
  4705. end
  4706. if pcDoubleCallBack then
  4707. pcDoubleCallBack()
  4708. end
  4709. return
  4710. end
  4711. widget._clickDelayHandler = PerformWithDelayGlobal(function()
  4712. clickTimes = 0
  4713. end, global.MMO.CLICK_DOUBLE_TIME)
  4714. end
  4715. end
  4716. else
  4717. if isMobile then
  4718. local endPos = widget:getTouchEndPosition()
  4719. SetGoodItemState(itemMoveState.end_move, endPos)
  4720. end
  4721. end
  4722. hasEventCallOnTouchBegin = false
  4723. elseif eventType == 3 then
  4724. if isMobile then
  4725. local endPos = widget:getTouchEndPosition()
  4726. SetGoodItemState(itemMoveState.end_move, endPos)
  4727. end
  4728. hasEventCallOnTouchBegin = false
  4729. end
  4730. end
  4731. widget:addTouchEventListener(touchEvent)
  4732. local function addIntoPanel(touchPos)
  4733. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4734. local state = ItemMoveProxy:GetMovingItemState()
  4735. if state then
  4736. local goToName = from
  4737. local data = {}
  4738. data.target = goToName
  4739. data.pos = touchPos
  4740. data.equipPos = ext.equipPos
  4741. ItemMoveProxy:CheckAndCallBack( data )
  4742. else
  4743. return -1
  4744. end
  4745. end
  4746. local function setNoswallowMouse(touchPos)
  4747. --不在道具移动
  4748. local itemData = SL:GetMetaValue("EQUIP_DATA", ext.equipPos)
  4749. if ((from == ITEMFROMUI.PALYER_EQUIP or from == ITEMFROMUI.HERO_EQUIP) and not itemData) or widget._movingState then
  4750. return
  4751. end
  4752. local panelPos = widget:getWorldPosition()
  4753. SetGoodItemState(itemMoveState.begin, panelPos)
  4754. end
  4755. global.mouseEventController:registerMouseButtonEvent(
  4756. widget,
  4757. {
  4758. down_r = setNoswallowMouse,
  4759. special_r = addIntoPanel,
  4760. scroll = mouseScrollCallBack,
  4761. checkIsVisible = true
  4762. }
  4763. )
  4764. return widget
  4765. end
  4766. function GUI:AddMoveWidgetTypeEvent(from, to, fromToEvent, toFromEvent)
  4767. if not from or not to then
  4768. SL:Print("[GUI ERROR] GUI:AddMoveWidgetTypeEvent can't find type")
  4769. return
  4770. end
  4771. if not fromToEvent and not toFromEvent then
  4772. SL:Print("[GUI ERROR] GUI:AddMoveWidgetTypeEvent can't find event")
  4773. return
  4774. end
  4775. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4776. ItemMoveProxy:AddMoveTypeAndFunc(from, to, fromToEvent, toFromEvent)
  4777. end
  4778. -------------------------------------------------------------
  4779. -- Frames
  4780. function GUI:Frames_Create(parent, ID, x, y, prefix, suffix, beginframe, finishframe, ext)
  4781. if not ID then
  4782. SL:Print("[GUI ERROR] GUI:Frames_Create can't find ID")
  4783. return nil
  4784. end
  4785. if not parent then
  4786. SL:Print("[GUI ERROR] GUI:Frames_Create can't find parent", ID)
  4787. return nil
  4788. end
  4789. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4790. SL:Print("[GUI ERROR] GUI:Frames_Create ID is exists", ID)
  4791. return nil
  4792. end
  4793. finishframe = tonumber(finishframe)
  4794. local speed = ext and tonumber(ext.speed) or 100
  4795. local count = ext and tonumber(ext.count) or 1
  4796. local loop = ext and tonumber(ext.loop) or -1
  4797. local finishhide = ext and tonumber(ext.finishhide)
  4798. local callback = ext and ext.callback
  4799. local fullPath = string.format("%s%s%s", prefix, beginframe or "1", suffix)
  4800. local widget = ccui.ImageView:create()
  4801. if parent ~= NONEED_PARENT_CODE then
  4802. if CheckIsInvalidCObject(parent) then
  4803. return nil
  4804. end
  4805. parent:addChild(widget)
  4806. end
  4807. widget:setName(ID)
  4808. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4809. widget:setAnchorPoint(cc.p(0, 0))
  4810. widget:loadTexture(FixPath(fullPath))
  4811. local function finishCB()
  4812. if finishframe then
  4813. fullPath = string.format("%s%s%s", prefix, finishframe, suffix)
  4814. widget:loadTexture(FixPath(fullPath))
  4815. end
  4816. if finishhide == 1 then
  4817. widget:setVisible(false)
  4818. end
  4819. if callback then
  4820. callback()
  4821. end
  4822. end
  4823. local index = beginframe and tonumber(beginframe) or 1
  4824. local counting = 0
  4825. local function delayCB()
  4826. fullPath = string.format("%s%s%s", prefix, index, suffix)
  4827. widget:loadTexture(FixPath(fullPath))
  4828. index = index + 1
  4829. if index > (count + beginframe) then
  4830. index = beginframe and tonumber(beginframe) or 1
  4831. counting = counting + 1
  4832. if loop ~= -1 and counting >= loop then
  4833. widget:stopAllActions()
  4834. finishCB()
  4835. end
  4836. elseif finishframe and index == finishframe then
  4837. if loop ~= -1 and counting + 1 == loop then
  4838. widget:stopAllActions()
  4839. performWithDelay(widget, finishCB, speed*0.001)
  4840. end
  4841. end
  4842. end
  4843. schedule(widget, delayCB, speed*0.001)
  4844. delayCB()
  4845. return widget
  4846. end
  4847. -------------------------------------------------------------
  4848. -- CircleBar
  4849. function GUI:CircleBar_Create(parent, ID, x, y, bgImg, barImg, startper, endper, time)
  4850. if not ID then
  4851. SL:Print("[GUI ERROR] GUI:CircleBar_Create can't find ID")
  4852. return nil
  4853. end
  4854. if not parent then
  4855. SL:Print("[GUI ERROR] GUI:CircleBar_Create can't find parent", ID)
  4856. return nil
  4857. end
  4858. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4859. SL:Print("[GUI ERROR] GUI:CircleBar_Create ID is exists", ID)
  4860. return nil
  4861. end
  4862. local widget = ccui.ImageView:create()
  4863. widget:setName(ID)
  4864. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4865. widget:setAnchorPoint(cc.p(0, 0))
  4866. widget:loadTexture(FixPath(bgImg))
  4867. if parent ~= NONEED_PARENT_CODE then
  4868. if CheckIsInvalidCObject(parent) then
  4869. return nil
  4870. end
  4871. parent:addChild(widget)
  4872. end
  4873. local contentSize = widget:getContentSize()
  4874. local progressTimer = cc.ProgressTimer:create(cc.Sprite:create(FixPath(barImg)))
  4875. widget:addChild(progressTimer)
  4876. progressTimer:setName("PROGRESS_TIMER")
  4877. progressTimer:setPosition(cc.p(contentSize.width / 2 , contentSize.height / 2 ))
  4878. progressTimer:setPercentage(startper)
  4879. local function loadCompleteCB()
  4880. progressTimer:stopAllActions()
  4881. -- event
  4882. local completeCB = widget.completeCB
  4883. if completeCB then
  4884. completeCB()
  4885. end
  4886. end
  4887. progressTimer:runAction(
  4888. cc.Sequence:create(
  4889. cc.ProgressFromTo:create(time, startper, endper),
  4890. cc.DelayTime:create(0.1),
  4891. cc.CallFunc:create(loadCompleteCB)
  4892. )
  4893. )
  4894. return widget
  4895. end
  4896. function GUI:CircleBar_setBarOffSet(widget, offsetX, offsetY)
  4897. if CheckIsInvalidCObject(widget) then
  4898. return false
  4899. end
  4900. if widget and widget:getChildByName("PROGRESS_TIMER") then
  4901. local bar = widget:getChildByName("PROGRESS_TIMER")
  4902. local contentSize = widget:getContentSize()
  4903. bar:setPosition(cc.p(contentSize.width / 2 + offsetX, contentSize.height / 2 + offsetY))
  4904. end
  4905. end
  4906. function GUI:CircleBar_addOnCompleteEvent(widget, value)
  4907. if CheckIsInvalidCObject(widget) then
  4908. return false
  4909. end
  4910. widget.completeCB = value
  4911. end
  4912. -------------------------------------------------------------
  4913. -- PercentImg
  4914. function GUI:PercentImg_Create(parent, ID, x, y, img, direction, minValue, maxValue)
  4915. if not ID then
  4916. SL:Print("[GUI ERROR] GUI:PercentImg_Create can't find ID")
  4917. return nil
  4918. end
  4919. if not parent then
  4920. SL:Print("[GUI ERROR] GUI:PercentImg_Create can't find parent", ID)
  4921. return nil
  4922. end
  4923. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4924. SL:Print("[GUI ERROR] GUI:PercentImg_Create ID is exists", ID)
  4925. return nil
  4926. end
  4927. local widget = ccui.LoadingBar:create()
  4928. widget:setName(ID)
  4929. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4930. widget:setAnchorPoint(cc.p(0, 0))
  4931. widget:loadTexture(FixPath(img))
  4932. if parent ~= NONEED_PARENT_CODE then
  4933. if CheckIsInvalidCObject(parent) then
  4934. return nil
  4935. end
  4936. parent:addChild(widget)
  4937. end
  4938. direction = tonumber(direction) or 0
  4939. local min = tonumber(minValue) or 100
  4940. local max = tonumber(maxValue) or 100
  4941. local percent = math.floor(min / max * 100) or 100
  4942. if direction == 0 or direction == 1 then
  4943. widget:setPercent(percent)
  4944. if direction == 1 then
  4945. widget:setDirection(1)
  4946. end
  4947. elseif direction == 2 or direction == 3 then
  4948. local barRenderer = widget:getVirtualRenderer()
  4949. local barRendererTextureSize = widget:getVirtualRendererSize()
  4950. local innerSprite = barRenderer:getSprite()
  4951. local contentSize = widget:getContentSize()
  4952. if direction == 2 then
  4953. barRenderer:setAnchorPoint(0, 0)
  4954. barRenderer:setPosition(0, 0)
  4955. else
  4956. barRenderer:setAnchorPoint(0, 1)
  4957. barRenderer:setPosition(0, contentSize.height)
  4958. end
  4959. if innerSprite then
  4960. local rect = innerSprite:getTextureRect()
  4961. rect.height = barRendererTextureSize.height * percent / 100
  4962. innerSprite:setTextureRect(rect, innerSprite:isTextureRectRotated(), cc.size(rect.width, rect.height))
  4963. if direction == 2 then
  4964. innerSprite:setFlippedY(true)
  4965. else
  4966. innerSprite:setFlippedY(false)
  4967. end
  4968. end
  4969. end
  4970. return widget
  4971. end
  4972. -------------------------------------------------------------
  4973. -- UIModel
  4974. function GUI:UIModel_Create(parent, ID, x, y, sex, feature, scale, useStaticScale, job, ext_param)
  4975. if not ID then
  4976. SL:Print("[GUI ERROR] GUI:UIModel_Create can't find ID")
  4977. return nil
  4978. end
  4979. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  4980. SL:Print("[GUI ERROR] GUI:UIModel_Create ID is exists", ID)
  4981. return nil
  4982. end
  4983. local param = not useStaticScale and {ignoreStaticScale = true} or nil
  4984. if job then
  4985. param = param or {}
  4986. param.job = job
  4987. end
  4988. if ext_param and next(ext_param) then
  4989. param = param or {}
  4990. for k, v in pairs(ext_param) do
  4991. param[k] = v
  4992. end
  4993. end
  4994. local widget = CreateStaticUIModel(sex, feature, scale, param)
  4995. widget:setName(ID)
  4996. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  4997. widget:setAnchorPoint(cc.p(0, 0))
  4998. if parent ~= NONEED_PARENT_CODE then
  4999. if CheckIsInvalidCObject(parent) then
  5000. return nil
  5001. end
  5002. parent:addChild(widget)
  5003. end
  5004. return widget
  5005. end
  5006. -------------------------------------------------------------
  5007. -- QuickCell
  5008. function GUI:QuickCell_Create(parent, ID, x, y, w, h, createCB, activeCheckCB, ext_param)
  5009. if not ID then
  5010. SL:Print("[GUI ERROR] GUI:QuickCell_Create can't find ID")
  5011. return nil
  5012. end
  5013. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5014. SL:Print("[GUI ERROR] GUI:QuickCell_Create ID is exists", ID)
  5015. return nil
  5016. end
  5017. local widget = GUIQuickCell:Create({
  5018. wid = w,
  5019. hei = h,
  5020. activeEvent = activeCheckCB,
  5021. eventX = ext_param and ext_param.event_x,
  5022. tick_interval = ext_param and ext_param.tick_interval
  5023. })
  5024. if parent ~= NONEED_PARENT_CODE then
  5025. if CheckIsInvalidCObject(parent) then
  5026. return nil
  5027. end
  5028. if "ccui.ListView" == tolua.type(parent) then
  5029. parent:pushBackCustomItem(widget)
  5030. else
  5031. parent:addChild(widget)
  5032. end
  5033. end
  5034. widget:Update({createCell = createCB})
  5035. widget:setName(ID)
  5036. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5037. widget:setAnchorPoint(cc.p(0, 0))
  5038. return widget
  5039. end
  5040. function GUI:QuickCell_Refresh(widget)
  5041. if CheckIsInvalidCObject(widget) then
  5042. return false
  5043. end
  5044. widget:Refresh()
  5045. end
  5046. function GUI:QuickCell_Exit(widget)
  5047. if CheckIsInvalidCObject(widget) then
  5048. return false
  5049. end
  5050. widget:Exit()
  5051. end
  5052. function GUI:QuickCell_Sleep(widget)
  5053. if CheckIsInvalidCObject(widget) then
  5054. return false
  5055. end
  5056. widget:Sleep()
  5057. end
  5058. function GUI:QuickCell_Active(widget)
  5059. if CheckIsInvalidCObject(widget) then
  5060. return false
  5061. end
  5062. widget:Active()
  5063. end
  5064. -------------------------------------------------------------
  5065. -- Animation
  5066. function GUI:Animation_Create()
  5067. local widget = cc.Animation:create()
  5068. return widget
  5069. end
  5070. function GUI:Animation_addSpriteFrame(widget, frame)
  5071. if CheckIsInvalidCObject(widget) then
  5072. return false
  5073. end
  5074. widget:addSpriteFrame(frame)
  5075. end
  5076. function GUI:Animation_setDelayPerUnit(widget, time)
  5077. if CheckIsInvalidCObject(widget) then
  5078. return false
  5079. end
  5080. widget:setDelayPerUnit(time)
  5081. end
  5082. function GUI:Animation_setLoops(widget, value)
  5083. if CheckIsInvalidCObject(widget) then
  5084. return false
  5085. end
  5086. widget:setLoops(value)
  5087. end
  5088. function GUI:Animation_setRestoreOriginalFrame(widget, bool)
  5089. if CheckIsInvalidCObject(widget) then
  5090. return false
  5091. end
  5092. widget:setRestoreOriginalFrame(bool)
  5093. end
  5094. ------------------------------------------------------------
  5095. -- Sprite
  5096. function GUI:Sprite_Create(parent, ID, x, y, path)
  5097. if not ID then
  5098. SL:Print("[GUI ERROR] GUI:Sprite_Create can't find ID")
  5099. return nil
  5100. end
  5101. if not parent then
  5102. SL:Print("[GUI ERROR] GUI:Sprite_Create can't find parent", ID)
  5103. return nil
  5104. end
  5105. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5106. SL:Print("[GUI ERROR] GUI:Sprite_Create ID is exists", ID)
  5107. return nil
  5108. end
  5109. local widget = nil
  5110. if path and SL:IsFileExist(path) then
  5111. widget = cc.Sprite:create(path)
  5112. else
  5113. widget = cc.Sprite:create()
  5114. end
  5115. widget:setName(ID)
  5116. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5117. widget:setAnchorPoint(cc.p(0, 0))
  5118. if parent ~= NONEED_PARENT_CODE then
  5119. if CheckIsInvalidCObject(parent) then
  5120. return nil
  5121. end
  5122. parent:addChild(widget)
  5123. end
  5124. return widget
  5125. end
  5126. function GUI:Sprite_getSpriteFrame(widget)
  5127. if CheckIsInvalidCObject(widget) then
  5128. return false
  5129. end
  5130. return widget:getSpriteFrame()
  5131. end
  5132. -----------------------------------------------------------
  5133. --- LineWidget
  5134. local LineWidget = class("LineWidget", function()
  5135. return ccui.Widget:create()
  5136. end)
  5137. function LineWidget:ctor()
  5138. self._size = cc.size(0, 0)
  5139. self._cells = {}
  5140. self._offset = {}
  5141. end
  5142. function LineWidget:pushCell(cell, offset, isadd)
  5143. if not cell then return end
  5144. if isadd then
  5145. self:addChild(cell)
  5146. end
  5147. local size = cell:getContentSize()
  5148. cell:setPositionX(self._size.width + size.width / 2 + offset.x)
  5149. table.insert(self._cells, cell)
  5150. self._offset[#self._cells] = offset
  5151. self._size.width = self._size.width + size.width
  5152. self._size.height = self._size.height + size.height
  5153. end
  5154. function LineWidget:getSize()
  5155. return self._size
  5156. end
  5157. function LineWidget:reSize()
  5158. self:setContentSize(self._size)
  5159. for i,cell in pairs(self._cells) do
  5160. local offset = self._offset[i] or cc.p(0, 0)
  5161. cell:setPositionY(self._size.height / 2 + offset.y)
  5162. end
  5163. end
  5164. function GUI:TipLineWidget_Create(parent, ID, x, y)
  5165. if not ID then
  5166. SL:Print("[GUI ERROR] GUI:TipLineWidget_Create can't find ID")
  5167. return nil
  5168. end
  5169. if not parent then
  5170. SL:Print("[GUI ERROR] GUI:TipLineWidget_Create can't find parent", ID)
  5171. return nil
  5172. end
  5173. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5174. SL:Print("[GUI ERROR] GUI:TipLineWidget_Create ID is exists", ID)
  5175. return nil
  5176. end
  5177. local widget = LineWidget.new()
  5178. widget:setTouchEnabled(false)
  5179. widget:setAnchorPoint(0,0)
  5180. widget:setName(ID)
  5181. widget:setPosition(cc.p(x, y))
  5182. if parent ~= NONEED_PARENT_CODE then
  5183. if CheckIsInvalidCObject(parent) then
  5184. return nil
  5185. end
  5186. parent:addChild(widget)
  5187. end
  5188. return widget
  5189. end
  5190. function GUI:TipLineWidget_updateSize( widget )
  5191. if CheckIsInvalidCObject(widget) then
  5192. return false
  5193. end
  5194. if widget.reSize then
  5195. widget:reSize()
  5196. end
  5197. end
  5198. function GUI:TipLineWidget_getSize( widget )
  5199. if CheckIsInvalidCObject(widget) then
  5200. return cc.size(0, 0)
  5201. end
  5202. return widget:getSize()
  5203. end
  5204. function GUI:TipLineWidget_pushCell( widget , cell, offset )
  5205. if CheckIsInvalidCObject(widget) then
  5206. return false
  5207. end
  5208. widget:pushCell(cell, offset)
  5209. end
  5210. function GUI:TipLineWidget_pushChildCell( widget , cell, offset )
  5211. if CheckIsInvalidCObject(widget) then
  5212. return false
  5213. end
  5214. widget:pushCell(cell, offset, true)
  5215. end
  5216. ------------------------------------------------------------
  5217. -- 粒子特效
  5218. function GUI:ParticleEffect_Create(parent, ID, x, y, res)
  5219. if not ID then
  5220. SL:Print("[GUI ERROR] GUI:ParticleEffect_Create can't find ID")
  5221. return nil
  5222. end
  5223. if not parent then
  5224. SL:Print("[GUI ERROR] GUI:ParticleEffect_Create can't find parent", ID)
  5225. return nil
  5226. end
  5227. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5228. SL:Print("[GUI ERROR] GUI:ParticleEffect_Create ID is exists", ID)
  5229. return nil
  5230. end
  5231. local widget = cc.ParticleSystemQuad:create(res)
  5232. widget:setName(ID)
  5233. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5234. if parent ~= NONEED_PARENT_CODE then
  5235. if CheckIsInvalidCObject(parent) then
  5236. return nil
  5237. end
  5238. parent:addChild(widget)
  5239. end
  5240. return widget
  5241. end
  5242. function GUI:ParticleEffect_setTotalParticles(widget, value)
  5243. if CheckIsInvalidCObject(widget) then
  5244. return false
  5245. end
  5246. widget:setTotalParticles(value)
  5247. end
  5248. function GUI:ParticleEffect_setSpeed(widget, value)
  5249. if CheckIsInvalidCObject(widget) then
  5250. return false
  5251. end
  5252. widget:setSpeed(value)
  5253. end
  5254. function GUI:ParticleEffect_setSpeedVar(widget, value)
  5255. if CheckIsInvalidCObject(widget) then
  5256. return false
  5257. end
  5258. widget:setSpeedVar(value)
  5259. end
  5260. function GUI:ParticleEffect_setAngle(widget, value)
  5261. if CheckIsInvalidCObject(widget) then
  5262. return false
  5263. end
  5264. widget:setAngle(widget, value)
  5265. end
  5266. function GUI:ParticleEffect_setAngleVar(widget, value)
  5267. if CheckIsInvalidCObject(widget) then
  5268. return false
  5269. end
  5270. widget:setAngleVar(widget, value)
  5271. end
  5272. -- 持续时间 -1 永久
  5273. function GUI:ParticleEffect_setDuration(widget, value)
  5274. if CheckIsInvalidCObject(widget) then
  5275. return false
  5276. end
  5277. widget:setDuration(value)
  5278. end
  5279. -- 开始大小
  5280. function GUI:ParticleEffect_setStartSize(widget, value)
  5281. if CheckIsInvalidCObject(widget) then
  5282. return false
  5283. end
  5284. widget:setStartSize(value)
  5285. end
  5286. function GUI:ParticleEffect_setStartSizeVar(widget, value)
  5287. if CheckIsInvalidCObject(widget) then
  5288. return false
  5289. end
  5290. widget:setStartSizeVar(value)
  5291. end
  5292. -- 结束大小
  5293. function GUI:ParticleEffect_setEndSize(widget, value)
  5294. if CheckIsInvalidCObject(widget) then
  5295. return false
  5296. end
  5297. widget:setEndSize(value)
  5298. end
  5299. function GUI:ParticleEffect_setEndSizeVar(widget, value)
  5300. if CheckIsInvalidCObject(widget) then
  5301. return false
  5302. end
  5303. widget:setEndSizeVar(value)
  5304. end
  5305. --------------------------------------------------------------
  5306. local function checkSpineVer(jsonPath, needVer)
  5307. if not global.FileUtilCtl:isFileExist(jsonPath) then
  5308. return false
  5309. end
  5310. local jsonStr = global.FileUtilCtl:getDataFromFileEx(jsonPath)
  5311. if not jsonStr or jsonStr == "" or jsonStr == jsonPath then
  5312. return false
  5313. end
  5314. local jsonData = cjson.decode(jsonStr)
  5315. if not jsonData then
  5316. return false
  5317. end
  5318. local ver = jsonData["skeleton"] and jsonData["skeleton"]["spine"] or ""
  5319. local t = string.split(ver, ".")
  5320. if tonumber(t[1]) and tonumber(t[2]) then
  5321. local curVer = tonumber(t[1]) * 10 + tonumber(t[2])
  5322. if curVer == needVer then
  5323. return true
  5324. end
  5325. end
  5326. return false
  5327. end
  5328. -- 骨骼动画
  5329. function GUI:SpineAnim_Create(parent, ID, x, y, jsonPath, atlasPath, trackIndex, name, loop)
  5330. if not ID then
  5331. SL:Print("[GUI ERROR] GUI:SpineAnim_Create can't find ID")
  5332. return nil
  5333. end
  5334. if not parent then
  5335. SL:Print("[GUI ERROR] GUI:SpineAnim_Create can't find parent", ID)
  5336. return nil
  5337. end
  5338. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5339. SL:Print("[GUI ERROR] GUI:SpineAnim_Create ID is exists", ID)
  5340. return nil
  5341. end
  5342. local widget = nil
  5343. if not (spine and spine.SkeletonAnimation) then
  5344. SL:release_print("Warning! The current version of exe does not support spine2.1 version!")
  5345. widget = ccui.Widget:create()
  5346. widget.notSpine = true
  5347. elseif not checkSpineVer(jsonPath, 21) then
  5348. SL:release_print("Warning! The current spine animation file is not spine2.1 version!")
  5349. widget = ccui.Widget:create()
  5350. widget.notSpine = true
  5351. else
  5352. widget = spine.SkeletonAnimation:createWithFile(jsonPath, atlasPath)
  5353. widget:setAnimation(trackIndex, name, loop)
  5354. end
  5355. widget:setName(ID)
  5356. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5357. if parent ~= NONEED_PARENT_CODE then
  5358. if CheckIsInvalidCObject(parent) then
  5359. return nil
  5360. end
  5361. parent:addChild(widget)
  5362. end
  5363. return widget
  5364. end
  5365. function GUI:Spine38Anim_Create(parent, ID, x, y, jsonPath, atlasPath, trackIndex, name, loop, scale)
  5366. if not ID then
  5367. SL:Print("[GUI ERROR] GUI:Spine38Anim_Create can't find ID")
  5368. return nil
  5369. end
  5370. if not parent then
  5371. SL:Print("[GUI ERROR] GUI:Spine38Anim_Create can't find parent", ID)
  5372. return nil
  5373. end
  5374. if SL._DEBUG and parent:getChildByName(ID) then
  5375. SL:Print("[GUI ERROR] GUI:Spine38Anim_Create ID is exists", ID)
  5376. return nil
  5377. end
  5378. if not (sp and sp.SkeletonAnimation) then
  5379. SL:release_print("Error! The current version of exe does not support spine3.8 version!")
  5380. return nil
  5381. end
  5382. local widget = sp.SkeletonAnimation:create(jsonPath, atlasPath, scale or 1)
  5383. widget:setAnimation(trackIndex, name, loop)
  5384. widget:setName(ID)
  5385. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5386. if parent ~= NONEED_PARENT_CODE then
  5387. if CheckIsInvalidCObject(parent) then
  5388. return nil
  5389. end
  5390. parent:addChild(widget)
  5391. end
  5392. return widget
  5393. end
  5394. -- trackIndex: 轨道索引 name: 动画名 loop: 是否循环
  5395. function GUI:SpineAnim_setAnimation(widget, trackIndex, name, loop)
  5396. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5397. return false
  5398. end
  5399. widget:setAnimation(trackIndex, name, loop)
  5400. end
  5401. function GUI:SpineAnim_addAnimation(widget, trackIndex, name, loop)
  5402. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5403. return false
  5404. end
  5405. widget:addAnimation(trackIndex, name, loop)
  5406. end
  5407. -- duration 过渡时间
  5408. function GUI:SpineAnim_setMix(widget, fromAnimName, toAnimName, duration)
  5409. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5410. return false
  5411. end
  5412. widget:setMix(fromAnimName, toAnimName, duration)
  5413. end
  5414. -------- spine 3.8 新增接口 begin -----------
  5415. -- 清除轨道所有动画
  5416. function GUI:SpineAnim_clearTracks(widget)
  5417. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5418. return false
  5419. end
  5420. widget:clearTracks()
  5421. end
  5422. -- 清除指定轨道动画 trackIndex: 轨道索引
  5423. function GUI:SpineAnim_clearTrack(widget, trackIndex)
  5424. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5425. return false
  5426. end
  5427. widget:clearTrack(trackIndex)
  5428. end
  5429. -- 播放时间缩放 / 播放速度 默认: 1, 数值越大 播放越快
  5430. function GUI:SpineAnim_getTimeScale(widget)
  5431. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5432. return false
  5433. end
  5434. return widget:getTimeScale()
  5435. end
  5436. function GUI:SpineAnim_setTimeScale(widget, scale)
  5437. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5438. return false
  5439. end
  5440. widget:setTimeScale(scale)
  5441. end
  5442. -- 重置到初始姿态, 主要用于处理切换动画时上个动画留下的残影
  5443. -- [setBonesToSetupPose 和 setSlotsToSetupPose]
  5444. function GUI:SpineAnim_setToSetupPose(widget)
  5445. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5446. return false
  5447. end
  5448. widget:setToSetupPose()
  5449. end
  5450. -- 重置插槽到初始设定
  5451. function GUI:SpineAnim_setSlotsToSetupPose(widget)
  5452. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5453. return false
  5454. end
  5455. widget:setSlotsToSetupPose()
  5456. end
  5457. -- 查找动画 name: 动画名称
  5458. function GUI:SpineAnim_findAnimation(widget, name)
  5459. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5460. return false
  5461. end
  5462. return widget:findAnimation(name)
  5463. end
  5464. -- 设置皮肤 skinName: 皮肤名称
  5465. function GUI:SpineAnim_setSkin(widget, skinName)
  5466. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5467. return false
  5468. end
  5469. widget:setSkin(skinName)
  5470. end
  5471. -- 绕X轴翻转
  5472. function GUI:SpineAnim_setFlipX(widget, bool)
  5473. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5474. return false
  5475. end
  5476. widget:setScaleX(bool and -1 or 1)
  5477. end
  5478. -- 绕Y轴翻转
  5479. function GUI:SpineAnim_setFlipY(widget, bool)
  5480. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5481. return false
  5482. end
  5483. widget:setScaleY(bool and -1 or 1)
  5484. end
  5485. -- 设置插槽内附件 slotName: 插槽名字 attachmentName: 附件名称 [此附件在本插槽内]
  5486. function GUI:SpineAnim_setAttachment(widget, slotName, attachmentName)
  5487. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5488. return false
  5489. end
  5490. widget:setAttachment(slotName, attachmentName)
  5491. end
  5492. -- 获取插槽内附件
  5493. -- return sp.Attachment 附件
  5494. function GUI:SpineAnim_getAttachment(widget, slotName, attachmentName)
  5495. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5496. return false
  5497. end
  5498. return widget:getAttachment(slotName, attachmentName)
  5499. end
  5500. -- 查找插槽对象 slotName: 插槽名字
  5501. -- return sp.Slot 插槽对象
  5502. function GUI:SpineAnim_findSlot(widget, slotName)
  5503. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5504. return false
  5505. end
  5506. return widget:findSlot(slotName)
  5507. end
  5508. -- 返回所有插槽对象列表
  5509. function GUI:SpineAnim_getSlots(widget)
  5510. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5511. return false
  5512. end
  5513. return widget:getSlots()
  5514. end
  5515. -- 注册监听事件回调
  5516. --[[
  5517. handler 回调参数:
  5518. {
  5519. animation: "xxanimation", -- 动画名
  5520. loopCount: 1, -- 循环次数
  5521. trackIndex: 0, -- 轨道索引
  5522. type: "xxx" -- 事件类型 "start" "interrupt" "end" "dispose" "complete" "event"
  5523. eventData: table -- 自定义事件数据 {name: "xx", floatValue: 0, intValue: 0, stringValue: ""}
  5524. }
  5525. ]]
  5526. -- handler: function eventType: sp.EventType
  5527. function GUI:SpineAnim_registerSpineEventHandler(widget, handler, eventType)
  5528. if CheckIsInvalidCObject(widget) or widget.notSpine then
  5529. return false
  5530. end
  5531. widget:registerSpineEventHandler(handler, eventType)
  5532. end
  5533. ------- [sp.Slot] 插槽对象
  5534. -- 获取插槽对象颜色table
  5535. -- {r = 1, g = 1, b = 1, a = 1} 数值0-1
  5536. function GUI:SpineSlot_getColor(widget)
  5537. if CheckIsInvalidCObject(widget) then
  5538. return false
  5539. end
  5540. return widget:getColor()
  5541. end
  5542. -- 设置插槽对象颜色 数值0-1
  5543. function GUI:SpineSlot_setColor(widget, r, g, b, a)
  5544. if CheckIsInvalidCObject(widget) then
  5545. return false
  5546. end
  5547. widget:setColor(r, g, b, a)
  5548. end
  5549. -- 设置插槽对象可见性
  5550. function GUI:SpineSlot_setVisible(widget, isVisible)
  5551. if CheckIsInvalidCObject(widget) then
  5552. return false
  5553. end
  5554. widget:setVisible(isVisible)
  5555. end
  5556. -- 设置插槽对象的附件 attachment: sp.Attachment附件对象
  5557. function GUI:SpineSlot_setAttachment(widget, attachment)
  5558. if CheckIsInvalidCObject(widget) then
  5559. return false
  5560. end
  5561. widget:setAttachment(attachment)
  5562. end
  5563. -------- spine 3.8 新增接口 end -----------
  5564. -------------------------------------------------------------
  5565. -- WebView
  5566. function GUI:WebView_Create(parent, ID, x, y, width, height, index)
  5567. if not ID then
  5568. SL:Print("[GUI ERROR] GUI:WebView_Create can't find ID")
  5569. return nil
  5570. end
  5571. if not parent then
  5572. SL:Print("[GUI ERROR] GUI:WebView_Create can't find parent", ID)
  5573. return nil
  5574. end
  5575. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5576. SL:Print("[GUI ERROR] GUI:WebView_Create ID is exists", ID)
  5577. return nil
  5578. end
  5579. local widget = ccexp.CustomView and ccexp.CustomView:create() or (ccexp.WebView and ccexp.WebView:create())
  5580. local envProxy = global.Facade:retrieveProxy(global.ProxyTable.GameEnvironment)
  5581. local URLList = envProxy:GetCustomDataByKey("useUrlList")
  5582. if widget then
  5583. widget:setName(ID)
  5584. widget:setContentSize(cc.size(width, height))
  5585. if URLList and URLList[index] then
  5586. widget:loadURL(URLList[index])
  5587. else
  5588. ShowSystemTips("链接未配置!")
  5589. end
  5590. if parent ~= NONEED_PARENT_CODE then
  5591. if CheckIsInvalidCObject(parent) then
  5592. return nil
  5593. end
  5594. parent:addChild(widget)
  5595. end
  5596. widget:setAnchorPoint(cc.p(0, 0))
  5597. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5598. end
  5599. return widget
  5600. end
  5601. -------------------------------------------------------------
  5602. -- ScrapePic
  5603. function GUI:ScrapePic_Create(parent, ID, x, y, bgImg, maskImg, clearHei, moveTime, beginTime, callback)
  5604. if not ID then
  5605. SL:Print("[GUI ERROR] GUI:ScrapePic_Create can't find ID")
  5606. return nil
  5607. end
  5608. if not parent then
  5609. SL:Print("[GUI ERROR] GUI:ScrapePic_Create can't find parent", ID)
  5610. return nil
  5611. end
  5612. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5613. SL:Print("[GUI ERROR] GUI:ScrapePic_Create ID is exists", ID)
  5614. return nil
  5615. end
  5616. if not bgImg or not global.FileUtilCtl:isFileExist(bgImg) then
  5617. SL:Print("[GUI ERROR] GUI:ScrapePic_Create showImg can't find res path! ")
  5618. return nil
  5619. end
  5620. local widget = ccui.Layout:create()
  5621. if parent ~= NONEED_PARENT_CODE then
  5622. if CheckIsInvalidCObject(parent) then
  5623. return nil
  5624. end
  5625. if "ccui.ListView" == tolua.type(parent) then
  5626. parent:pushBackCustomItem(widget)
  5627. else
  5628. parent:addChild(widget)
  5629. end
  5630. end
  5631. widget:setName(ID)
  5632. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5633. widget:setAnchorPoint(cc.p(0, 0))
  5634. local img = ccui.ImageView:create()
  5635. img:loadTexture(bgImg)
  5636. local imgSize = img:getContentSize()
  5637. widget:setContentSize(imgSize)
  5638. widget:addChild(img)
  5639. img:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
  5640. local radius = clearHei and math.floor(clearHei / 2) or 8
  5641. local drawNode = cc.DrawNode:create()
  5642. widget:addChild(drawNode)
  5643. drawNode:retain()
  5644. drawNode:drawSolidCircle(cc.p(0, 0), radius, 0, radius, 1, 1, cc.c4b(0, 0, 0, 0))
  5645. drawNode:setVisible(false)
  5646. local renderTexture = cc.RenderTexture:create(imgSize.width, imgSize.height)
  5647. renderTexture:retain()
  5648. renderTexture:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
  5649. widget:addChild(renderTexture, 10)
  5650. local mask = ccui.ImageView:create()
  5651. mask:loadTexture(maskImg)
  5652. mask:ignoreContentAdaptWithSize(false)
  5653. mask:setContentSize(imgSize)
  5654. mask:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
  5655. renderTexture:begin()
  5656. mask:visit()
  5657. renderTexture:endToLua()
  5658. local lastMovePos = nil
  5659. local moveBT = nil
  5660. local iMoveTime = 0
  5661. local iBeginAct = nil
  5662. local releaseCount = 0
  5663. local touchPosList = {}
  5664. local function timeCB()
  5665. if releaseCount == 0 then
  5666. releaseCount = releaseCount + 1
  5667. if drawNode then
  5668. drawNode:removeFromParent()
  5669. drawNode:autorelease()
  5670. drawNode = nil
  5671. end
  5672. if renderTexture then
  5673. renderTexture:removeFromParent()
  5674. renderTexture:autorelease()
  5675. renderTexture = nil
  5676. end
  5677. if callback and type(callback) == "function" then
  5678. callback()
  5679. end
  5680. end
  5681. end
  5682. local function getKey(x, y)
  5683. return x * 10000 + y
  5684. end
  5685. local function addTouchPoint(x, y)
  5686. local key = getKey(x, y)
  5687. if touchPosList[key] then
  5688. return
  5689. end
  5690. if x <= 0 or x >= imgSize.width then
  5691. return
  5692. end
  5693. if y <= 0 or y >= imgSize.height then
  5694. return
  5695. end
  5696. if not touchPosList[key] then
  5697. touchPosList[key] = true
  5698. end
  5699. end
  5700. widget:setTouchEnabled(true)
  5701. widget:addTouchEventListener(function (node, eventType)
  5702. if eventType == 0 then
  5703. local beganPos = node:getTouchBeganPosition()
  5704. lastMovePos = nil
  5705. moveBT = os.clock()
  5706. if tonumber(beginTime) and not iBeginAct then
  5707. iBeginAct = performWithDelay(widget, function()
  5708. timeCB()
  5709. end, tonumber(beginTime))
  5710. end
  5711. elseif eventType == 1 then
  5712. if releaseCount > 0 then
  5713. return
  5714. end
  5715. local movedPos = node:getTouchMovePosition()
  5716. local beganPos = node:getTouchBeganPosition()
  5717. local tt = GUI:convertToNodeSpace(widget, movedPos.x, movedPos.y)
  5718. tt = fixPosition(tt)
  5719. local key = getKey(tt.x, tt.y)
  5720. if touchPosList[key] then
  5721. return
  5722. end
  5723. drawNode:setPosition(tt)
  5724. drawNode:setBlendFunc({src = gl.ONE, dst = gl.ZERO})
  5725. drawNode:setVisible(true)
  5726. renderTexture:begin()
  5727. drawNode:visit()
  5728. renderTexture:endToLua()
  5729. drawNode:setVisible(false)
  5730. if lastMovePos then
  5731. local distance = math.abs(cc.pGetDistance(lastMovePos, movedPos))
  5732. local pos = cc.pSub(lastMovePos, movedPos)
  5733. local angle = 180 * (cc.pToAngleSelf(pos) / math.pi)
  5734. local height = radius * 2
  5735. local midPos = cc.pMidpoint(lastMovePos, movedPos)
  5736. local rectNode = cc.DrawNode:create()
  5737. local posList = {
  5738. cc.p(- distance / 2 , - height / 2),
  5739. cc.p(- distance / 2 , height / 2),
  5740. cc.p(distance / 2 , height / 2),
  5741. cc.p(distance / 2 , - height / 2)
  5742. }
  5743. rectNode:drawSolidPoly(posList, 4, cc.c4b(0,0,0,0))
  5744. midPos = fixPosition(GUI:convertToNodeSpace(widget, midPos.x, midPos.y))
  5745. rectNode:setPosition(midPos)
  5746. rectNode:setRotation(angle)
  5747. rectNode:setBlendFunc({src = gl.ONE, dst = gl.ZERO})
  5748. renderTexture:begin()
  5749. rectNode:visit()
  5750. renderTexture:endToLua()
  5751. end
  5752. -- pos
  5753. local mPos = GUI:convertToNodeSpace(widget, movedPos.x, movedPos.y)
  5754. mPos = fixPosition(mPos)
  5755. for i = mPos.x - radius, mPos.x + radius do
  5756. for j = mPos.y - radius, mPos.y + radius do
  5757. if math.pow(i - mPos.x, 2) + math.pow(j - mPos.y, 2) <= math.pow(radius, 2) then
  5758. addTouchPoint(i, j)
  5759. end
  5760. end
  5761. end
  5762. if moveBT then
  5763. iMoveTime = iMoveTime + (os.clock() - moveBT)
  5764. end
  5765. moveBT = os.clock()
  5766. if tonumber(moveTime) then
  5767. if iMoveTime >= tonumber(moveTime) then
  5768. timeCB()
  5769. end
  5770. end
  5771. lastMovePos = movedPos
  5772. elseif eventType == 2 or eventType == 3 then
  5773. local endPos = node:getTouchEndPosition()
  5774. lastMovePos = nil
  5775. moveBT = nil
  5776. end
  5777. end)
  5778. return widget
  5779. end
  5780. -------------------------------------------------------------
  5781. -- MotionStreak
  5782. function GUI:MotionStreak_Create(parent, ID, x, y, fadeTime, minSeg, width, path, color)
  5783. if not ID then
  5784. SL:Print("[GUI ERROR] GUI:MotionStreak_Create can't find ID")
  5785. return nil
  5786. end
  5787. if not parent then
  5788. SL:Print("[GUI ERROR] GUI:MotionStreak_Create can't find parent", ID)
  5789. return nil
  5790. end
  5791. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  5792. SL:Print("[GUI ERROR] GUI:MotionStreak_Create ID is exists", ID)
  5793. return nil
  5794. end
  5795. color = color or cc.c3b(255, 255, 255)
  5796. if type(color) == "string" and string.find(color, "#") then
  5797. color = SL:ConvertColorFromHexString(color)
  5798. end
  5799. local widget = cc.MotionStreak:create(fadeTime, minSeg, width, color, path)
  5800. widget:setName(ID)
  5801. widget:setPosition(cc.p(fixPosition(x), fixPosition(y)))
  5802. if parent ~= NONEED_PARENT_CODE then
  5803. if CheckIsInvalidCObject(parent) then
  5804. return nil
  5805. end
  5806. parent:addChild(widget)
  5807. end
  5808. return widget
  5809. end
  5810. -- 重置
  5811. function GUI:MotionStreak_reset(widget)
  5812. if CheckIsInvalidCObject(widget) then
  5813. return false
  5814. end
  5815. widget:reset()
  5816. end
  5817. -------------------------------------------------------------
  5818. -- MoveTo
  5819. function GUI:ActionMoveTo(time, x, y)
  5820. return cc.MoveTo:create(time, cc.p(x, y))
  5821. end
  5822. -- MoveBy
  5823. function GUI:ActionMoveBy(time, x, y)
  5824. return cc.MoveBy:create(time, cc.p(x, y))
  5825. end
  5826. -- ScaleTo
  5827. function GUI:ActionScaleTo(time, ratio, ...)
  5828. return cc.ScaleTo:create(time, ratio, ...)
  5829. end
  5830. -- ScaleBy
  5831. function GUI:ActionScaleBy(time, ratio, ...)
  5832. return cc.ScaleBy:create(time, ratio, ...)
  5833. end
  5834. function GUI:ActionScaleXTo(time, x)
  5835. return cc.ScaleTo:create(time, x, 1)
  5836. end
  5837. function GUI:ActionScaleYTo(time, y)
  5838. return cc.ScaleTo:create(time, 1, y)
  5839. end
  5840. function GUI:ActionScaleXBy(time, x)
  5841. return cc.ScaleBy:create(time, x, 1)
  5842. end
  5843. function GUI:ActionScaleYBy(time, y)
  5844. return cc.ScaleBy:create(time, 1, y)
  5845. end
  5846. -- RotateTo
  5847. function GUI:ActionRotateTo(time, angle)
  5848. return cc.RotateTo:create(time, angle)
  5849. end
  5850. -- RotateBy
  5851. function GUI:ActionRotateBy(time, angle)
  5852. return cc.RotateBy:create(time, angle)
  5853. end
  5854. -- FadeIn
  5855. function GUI:ActionFadeIn(time)
  5856. return cc.FadeIn:create(time)
  5857. end
  5858. -- FadeOut
  5859. function GUI:ActionFadeOut(time)
  5860. return cc.FadeOut:create(time)
  5861. end
  5862. -- FadeTo
  5863. function GUI:ActionFadeTo(time, opacity)
  5864. return cc.FadeTo:create(time, opacity)
  5865. end
  5866. -- Blink
  5867. function GUI:ActionBlink(time, num)
  5868. return cc.Blink:create(time, num)
  5869. end
  5870. -- CallFunc
  5871. function GUI:CallFunc(callback)
  5872. return cc.CallFunc:create(callback)
  5873. end
  5874. -- DelayTime
  5875. function GUI:DelayTime(time)
  5876. return cc.DelayTime:create(time)
  5877. end
  5878. function GUI:ActionShow()
  5879. return cc.Show:create()
  5880. end
  5881. function GUI:ActionHide()
  5882. return cc.Hide:create()
  5883. end
  5884. -- Sequence
  5885. function GUI:ActionSequence( ... )
  5886. return cc.Sequence:create( ... )
  5887. end
  5888. -- Spawn
  5889. function GUI:ActionSpawn( ... )
  5890. return cc.Spawn:create( ... )
  5891. end
  5892. -- Repeat
  5893. function GUI:ActionRepeat(action, time)
  5894. return cc.Repeat:create(action, time)
  5895. end
  5896. -- RepeatForever
  5897. function GUI:ActionRepeatForever(action)
  5898. return cc.RepeatForever:create(action)
  5899. end
  5900. -- RemoveSelf
  5901. function GUI:ActionRemoveSelf()
  5902. return cc.RemoveSelf:create()
  5903. end
  5904. -- EaseBounceIn
  5905. function GUI:ActionEaseBounceIn(action)
  5906. return cc.EaseBounceIn:create(action)
  5907. end
  5908. -- EaseBounceOut
  5909. function GUI:ActionEaseBounceOut(action)
  5910. return cc.EaseBounceOut:create(action)
  5911. end
  5912. -- EaseBounceInOut
  5913. function GUI:ActionEaseBounceInOut(action)
  5914. return cc.EaseBounceInOut:create(action)
  5915. end
  5916. -- EaseBackIn
  5917. function GUI:ActionEaseBackIn(action)
  5918. return cc.EaseBackIn:create(action)
  5919. end
  5920. -- EaseBackOut
  5921. function GUI:ActionEaseBackOut(action)
  5922. return cc.EaseBackOut:create(action)
  5923. end
  5924. -- EaseBackInOut
  5925. function GUI:ActionEaseBackInOut(action)
  5926. return cc.EaseBackInOut:create(action)
  5927. end
  5928. -- EaseBackInOut
  5929. function GUI:ActionEaseSineInOut(action)
  5930. return cc.EaseSineInOut:create(action)
  5931. end
  5932. --EaseElasticIn
  5933. function GUI:ActionEaseElasticIn(action)
  5934. return cc.EaseElasticIn:create(action)
  5935. end
  5936. --EaseElasticOut
  5937. function GUI:ActionEaseElasticOut(action)
  5938. return cc.EaseElasticOut:create(action)
  5939. end
  5940. --EaseElasticInOut
  5941. function GUI:ActionEaseElasticInOut(action)
  5942. return cc.EaseElasticInOut:create(action)
  5943. end
  5944. -- BezierTo
  5945. function GUI:ActionBezierTo(time, ...)
  5946. return cc.BezierTo:create(time, { ... })
  5947. end
  5948. -- Animate
  5949. function GUI:ActionAnimate(animation)
  5950. return cc.Animate:create(animation)
  5951. end
  5952. -- EaseExponentialIn
  5953. function GUI:ActionEaseExponentialIn(action)
  5954. return cc.EaseExponentialIn:create(action)
  5955. end
  5956. -- EaseExponentialOut
  5957. function GUI:ActionEaseExponentialOut(action)
  5958. return cc.EaseExponentialOut:create(action)
  5959. end
  5960. -- EaseExponentialOut
  5961. function GUI:ActionEaseExponentialInOut(action)
  5962. return cc.EaseExponentialInOut:create(action)
  5963. end
  5964. ------------------------------------------
  5965. -- timeline
  5966. function GUI:Timeline_Window1(widget, timelineCB)
  5967. if CheckIsInvalidCObject(widget) then
  5968. return false
  5969. end
  5970. local action = nil
  5971. if timelineCB then
  5972. action = cc.Sequence:create(
  5973. cc.ScaleTo:create(0, 0.8),
  5974. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
  5975. cc.CallFunc:create(timelineCB)
  5976. )
  5977. else
  5978. action = cc.Sequence:create(
  5979. cc.ScaleTo:create(0, 0.8),
  5980. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
  5981. )
  5982. end
  5983. widget:runAction(action)
  5984. end
  5985. function GUI:Timeline_Window2(widget, timelineCB)
  5986. if CheckIsInvalidCObject(widget) then
  5987. return false
  5988. end
  5989. local action = nil
  5990. if timelineCB then
  5991. action = cc.Sequence:create(
  5992. cc.ScaleTo:create(0, 0.5),
  5993. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
  5994. cc.CallFunc:create(timelineCB)
  5995. )
  5996. else
  5997. action = cc.Sequence:create(
  5998. cc.ScaleTo:create(0, 0.5),
  5999. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
  6000. )
  6001. end
  6002. widget:runAction(action)
  6003. end
  6004. function GUI:Timeline_Window3(widget, timelineCB)
  6005. if CheckIsInvalidCObject(widget) then
  6006. return false
  6007. end
  6008. local action = nil
  6009. if timelineCB then
  6010. action = cc.Sequence:create(
  6011. cc.ScaleTo:create(0, 0),
  6012. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
  6013. cc.CallFunc:create(timelineCB)
  6014. )
  6015. else
  6016. action = cc.Sequence:create(
  6017. cc.ScaleTo:create(0, 0),
  6018. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
  6019. )
  6020. end
  6021. widget:runAction(action)
  6022. end
  6023. function GUI:Timeline_Window4(widget, timelineCB)
  6024. if CheckIsInvalidCObject(widget) then
  6025. return false
  6026. end
  6027. local action = nil
  6028. if timelineCB then
  6029. action = cc.Sequence:create(
  6030. cc.ScaleTo:create(0, 1.2),
  6031. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
  6032. cc.CallFunc:create(timelineCB)
  6033. )
  6034. else
  6035. action = cc.Sequence:create(
  6036. cc.ScaleTo:create(0, 1.2),
  6037. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
  6038. )
  6039. end
  6040. widget:runAction(action)
  6041. end
  6042. function GUI:Timeline_Window5(widget, timelineCB)
  6043. if CheckIsInvalidCObject(widget) then
  6044. return false
  6045. end
  6046. local action = nil
  6047. if timelineCB then
  6048. action = cc.Sequence:create(
  6049. cc.ScaleTo:create(0, 1.5),
  6050. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
  6051. cc.CallFunc:create(timelineCB)
  6052. )
  6053. else
  6054. action = cc.Sequence:create(
  6055. cc.ScaleTo:create(0, 1.5),
  6056. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
  6057. )
  6058. end
  6059. widget:runAction(action)
  6060. end
  6061. function GUI:Timeline_Window6(widget, timelineCB)
  6062. if CheckIsInvalidCObject(widget) then
  6063. return false
  6064. end
  6065. local action = nil
  6066. if timelineCB then
  6067. action = cc.Sequence:create(
  6068. cc.ScaleTo:create(0, 2),
  6069. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1)),
  6070. cc.CallFunc:create(timelineCB)
  6071. )
  6072. else
  6073. action = cc.Sequence:create(
  6074. cc.ScaleTo:create(0, 2),
  6075. cc.EaseBackOut:create(cc.ScaleTo:create(0.3, 1))
  6076. )
  6077. end
  6078. widget:runAction(action)
  6079. end
  6080. function GUI:Timeline_StopAll(widget)
  6081. if CheckIsInvalidCObject(widget) then
  6082. return false
  6083. end
  6084. widget:stopAllActions()
  6085. end
  6086. function GUI:Timeline_SetTag(action, tag)
  6087. if CheckIsInvalidCObject(action) then
  6088. return false
  6089. end
  6090. action:setTag(tag)
  6091. end
  6092. function GUI:Timeline_StopByTag(widget, tag)
  6093. if CheckIsInvalidCObject(widget) then
  6094. return false
  6095. end
  6096. widget:stopActionByTag(tag)
  6097. end
  6098. function GUI:Timeline_FadeOut(widget, time, timelineCB)
  6099. if CheckIsInvalidCObject(widget) then
  6100. return false
  6101. end
  6102. time = time or 1
  6103. local action = nil
  6104. if timelineCB then
  6105. action = cc.Sequence:create(cc.FadeOut:create(time), cc.CallFunc:create(timelineCB))
  6106. else
  6107. action = cc.FadeOut:create(time)
  6108. end
  6109. widget:runAction(action)
  6110. return action
  6111. end
  6112. function GUI:Timeline_FadeIn(widget, time, timelineCB)
  6113. if CheckIsInvalidCObject(widget) then
  6114. return false
  6115. end
  6116. time = time or 1
  6117. local action = nil
  6118. if timelineCB then
  6119. action = cc.Sequence:create(cc.FadeIn:create(time), cc.CallFunc:create(timelineCB))
  6120. else
  6121. action = cc.FadeIn:create(time)
  6122. end
  6123. widget:runAction(action)
  6124. return action
  6125. end
  6126. function GUI:Timeline_FadeTo(widget, value, time, timelineCB)
  6127. if CheckIsInvalidCObject(widget) then
  6128. return false
  6129. end
  6130. value = value or 1
  6131. time = time or 1
  6132. local action = nil
  6133. if timelineCB then
  6134. action = cc.Sequence:create(cc.FadeTo:create(time, value), cc.CallFunc:create(timelineCB))
  6135. else
  6136. action = cc.FadeTo:create(time, value)
  6137. end
  6138. widget:runAction(action)
  6139. return action
  6140. end
  6141. function GUI:Timeline_ScaleTo(widget, value, time, timelineCB)
  6142. if CheckIsInvalidCObject(widget) then
  6143. return false
  6144. end
  6145. time = time or 1
  6146. value = value or 1
  6147. local action = nil
  6148. if timelineCB then
  6149. action = cc.Sequence:create(cc.ScaleTo:create(time, value), cc.CallFunc:create(timelineCB))
  6150. else
  6151. action = cc.ScaleTo:create(time, value)
  6152. end
  6153. widget:runAction(action)
  6154. return action
  6155. end
  6156. function GUI:Timeline_RotateTo(widget, value, time, timelineCB)
  6157. if CheckIsInvalidCObject(widget) then
  6158. return false
  6159. end
  6160. value = value or 1
  6161. time = time or 1
  6162. local action = nil
  6163. if timelineCB then
  6164. action = cc.Sequence:create(cc.RotateTo:create(time, value), cc.CallFunc:create(timelineCB))
  6165. else
  6166. action = cc.RotateTo:create(time, value)
  6167. end
  6168. widget:runAction(action)
  6169. return action
  6170. end
  6171. function GUI:Timeline_MoveTo(widget, value, time, timelineCB)
  6172. if CheckIsInvalidCObject(widget) then
  6173. return false
  6174. end
  6175. value = value or cc.p(0, 0)
  6176. time = time or 1
  6177. local action = nil
  6178. if timelineCB then
  6179. action = cc.Sequence:create(cc.MoveTo:create(time, value), cc.CallFunc:create(timelineCB))
  6180. else
  6181. action = cc.MoveTo:create(time, value)
  6182. end
  6183. widget:runAction(action)
  6184. return action
  6185. end
  6186. function GUI:Timeline_DelayTime(widget, time, timelineCB)
  6187. if CheckIsInvalidCObject(widget) then
  6188. return false
  6189. end
  6190. time = time or 1
  6191. local action = nil
  6192. if timelineCB then
  6193. action = cc.Sequence:create(cc.DelayTime:create(time), cc.CallFunc:create(timelineCB))
  6194. else
  6195. action = cc.DelayTime:create(time)
  6196. end
  6197. widget:runAction(action)
  6198. return action
  6199. end
  6200. function GUI:Timeline_Blink(widget, value, time, timelineCB)
  6201. if CheckIsInvalidCObject(widget) then
  6202. return false
  6203. end
  6204. value = value or 1
  6205. time = time or 1
  6206. local action = nil
  6207. if timelineCB then
  6208. action = cc.Sequence:create(cc.Blink:create(time, value), cc.CallFunc:create(timelineCB))
  6209. else
  6210. action = cc.Blink:create(time, value)
  6211. end
  6212. widget:runAction(action)
  6213. return action
  6214. end
  6215. function GUI:Timeline_MoveBy(widget, value, time, timelineCB)
  6216. if CheckIsInvalidCObject(widget) then
  6217. return false
  6218. end
  6219. value = value or cc.p(0, 0)
  6220. time = time or 1
  6221. local action = nil
  6222. if timelineCB then
  6223. action = cc.Sequence:create(cc.MoveBy:create(time, value), cc.CallFunc:create(timelineCB))
  6224. else
  6225. action = cc.MoveBy:create(time, value)
  6226. end
  6227. widget:runAction(action)
  6228. return action
  6229. end
  6230. function GUI:Timeline_ScaleBy(widget, value, time, timelineCB)
  6231. if CheckIsInvalidCObject(widget) then
  6232. return false
  6233. end
  6234. time = time or 1
  6235. value = value or 1
  6236. local action = nil
  6237. if timelineCB then
  6238. action = cc.Sequence:create(cc.ScaleBy:create(time, value), cc.CallFunc:create(timelineCB))
  6239. else
  6240. action = cc.ScaleBy:create(time, value)
  6241. end
  6242. widget:runAction(action)
  6243. return action
  6244. end
  6245. function GUI:Timeline_ScaleBy(widget, value, time, timelineCB)
  6246. if CheckIsInvalidCObject(widget) then
  6247. return false
  6248. end
  6249. time = time or 1
  6250. value = value or 1
  6251. local action = nil
  6252. if timelineCB then
  6253. action = cc.Sequence:create(cc.ScaleBy:create(time, value), cc.CallFunc:create(timelineCB))
  6254. else
  6255. action = cc.ScaleBy:create(time, value)
  6256. end
  6257. widget:runAction(action)
  6258. return action
  6259. end
  6260. function GUI:Timeline_RotateBy(widget, value, time, timelineCB)
  6261. if CheckIsInvalidCObject(widget) then
  6262. return false
  6263. end
  6264. value = value or 1
  6265. time = time or 1
  6266. local action = nil
  6267. if timelineCB then
  6268. action = cc.Sequence:create(cc.RotateBy:create(time, value), cc.CallFunc:create(timelineCB))
  6269. else
  6270. action = cc.RotateBy:create(time, value)
  6271. end
  6272. widget:runAction(action)
  6273. return action
  6274. end
  6275. function GUI:Timeline_CallFunc(widget, time, timelineCB)
  6276. if CheckIsInvalidCObject(widget) then
  6277. return false
  6278. end
  6279. time = time or 1
  6280. local action = nil
  6281. if timelineCB then
  6282. action = cc.Sequence:create(cc.DelayTime:create(time), cc.CallFunc:create(timelineCB))
  6283. else
  6284. action = cc.CallFunc:create(timelineCB)
  6285. end
  6286. widget:runAction(action)
  6287. return action
  6288. end
  6289. function GUI:Timeline_Show(widget, time)
  6290. if CheckIsInvalidCObject(widget) then
  6291. return false
  6292. end
  6293. time = time or 1
  6294. local action = nil
  6295. if time then
  6296. action = cc.Sequence:create(cc.DelayTime:create(time), cc.Show:create())
  6297. else
  6298. action = cc.Show:create()
  6299. end
  6300. widget:runAction(action)
  6301. return action
  6302. end
  6303. function GUI:Timeline_Hide(widget, time)
  6304. if CheckIsInvalidCObject(widget) then
  6305. return false
  6306. end
  6307. time = time or 1
  6308. local action = nil
  6309. if time then
  6310. action = cc.Sequence:create(cc.DelayTime:create(time), cc.Hide:create())
  6311. else
  6312. action = cc.Hide:create()
  6313. end
  6314. widget:runAction(action)
  6315. return action
  6316. end
  6317. function GUI:Timeline_Shake(widget, time, x, y, timelineCB)
  6318. if CheckIsInvalidCObject(widget) then
  6319. return false
  6320. end
  6321. time = time or 1
  6322. x = x or 10
  6323. y = y or 10
  6324. local action = nil
  6325. if timelineCB then
  6326. action = cc.Sequence:create(cc.ActionShake:create(time, x, y), cc.CallFunc:create(timelineCB))
  6327. else
  6328. action = cc.ActionShake:create(time, x, y)
  6329. end
  6330. widget:runAction(action)
  6331. return action
  6332. end
  6333. function GUI:Timeline_EaseSineIn_MoveTo(widget, value, time, timelineCB)
  6334. if CheckIsInvalidCObject(widget) then
  6335. return false
  6336. end
  6337. value = value or cc.p(0, 0)
  6338. time = time or 1
  6339. local action = nil
  6340. if timelineCB then
  6341. action = cc.Sequence:create(cc.EaseSineIn:create(cc.MoveTo:create(time, value)), cc.CallFunc:create(timelineCB))
  6342. else
  6343. action = cc.EaseSineIn:create(cc.MoveTo:create(time, value))
  6344. end
  6345. widget:runAction(action)
  6346. return action
  6347. end
  6348. function GUI:Timeline_EaseSineOut_MoveTo(widget, value, time, timelineCB)
  6349. if CheckIsInvalidCObject(widget) then
  6350. return false
  6351. end
  6352. value = value or cc.p(0, 0)
  6353. time = time or 1
  6354. local action = nil
  6355. if timelineCB then
  6356. action = cc.Sequence:create(cc.EaseSineOut:create(cc.MoveTo:create(time, value)), cc.CallFunc:create(timelineCB))
  6357. else
  6358. action = cc.EaseSineOut:create(cc.MoveTo:create(time, value))
  6359. end
  6360. widget:runAction(action)
  6361. return action
  6362. end
  6363. function GUI:TimeLine_BezierTo(time, ...)
  6364. if CheckIsInvalidCObject(widget) then
  6365. return false
  6366. end
  6367. return cc.BezierTo:create(time, { ... })
  6368. end
  6369. function GUI:Timeline_Waggle(widget, time, angle)
  6370. if CheckIsInvalidCObject(widget) then
  6371. return false
  6372. end
  6373. time = time or 0.05
  6374. angle = angle or 20
  6375. widget:runAction(
  6376. cc.RepeatForever:create(
  6377. cc.Sequence:create(
  6378. cc.RotateBy:create(time, angle),
  6379. cc.RotateBy:create(time, -angle),
  6380. cc.RotateBy:create(time, -angle),
  6381. cc.RotateBy:create(time, angle),
  6382. cc.RotateBy:create(time, angle),
  6383. cc.RotateBy:create(time, -angle),
  6384. cc.RotateBy:create(time, -angle),
  6385. cc.RotateBy:create(time, angle),
  6386. cc.RotateBy:create(time, angle),
  6387. cc.RotateBy:create(time, -angle),
  6388. cc.RotateBy:create(time, -angle),
  6389. cc.RotateBy:create(time, angle),
  6390. cc.DelayTime:create(3)
  6391. )
  6392. )
  6393. )
  6394. end
  6395. function GUI:Timeline_OrbitCamera(widget, time, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX, timelineCB)
  6396. if CheckIsInvalidCObject(widget) then
  6397. return false
  6398. end
  6399. local oribitAction = cc.OrbitCamera:create(time, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX)
  6400. if timelineCB then
  6401. widget:runAction(cc.Sequence:create(
  6402. oribitAction,
  6403. cc.CallFunc:create(timelineCB)
  6404. ))
  6405. else
  6406. widget:runAction(oribitAction)
  6407. end
  6408. end
  6409. -- 点击间隔
  6410. function GUI:setClickDelay(widget, time)
  6411. if CheckIsInvalidCObject(widget) then
  6412. return false
  6413. end
  6414. DelayTouchEnabled(widget, time or global.MMO.CLICK_DOUBLE_TIME)
  6415. end
  6416. function GUI:ui_delegate(nativeUI)
  6417. return ui_delegate(nativeUI)
  6418. end
  6419. -- 数字滚动动画
  6420. function GUI:Timeline_DigitChange(widget, cur, target, interval)
  6421. if CheckIsInvalidCObject(widget) then
  6422. return false
  6423. end
  6424. if tolua.isnull(widget) then
  6425. return false
  6426. end
  6427. local _SetText = {
  6428. ["Label"] = function (widget, value) widget:setString(value) end,
  6429. ["Button"] = function (widget, value) widget:setTitleText(value) end,
  6430. ["TextAtlas"] = function (widget, value) widget:setString(value) end,
  6431. }
  6432. local descript = widget:getDescription()
  6433. if not _SetText[descript] then
  6434. return false
  6435. end
  6436. -- 数字动态变化(val1 -> val2)
  6437. local function _ChangeNum(val1, val2)
  6438. local isUp = val2 > val1
  6439. local str = isUp and tostring(val2) or tostring(val1)
  6440. for i=1,string.len(str) do
  6441. if val1 % 10 ^ i ~= val2 % 10 ^ i then
  6442. if isUp then -- 递增
  6443. return val1 + 10 ^ (i-1)
  6444. else -- 递减
  6445. return val1 - 10 ^ (i-1)
  6446. end
  6447. end
  6448. end
  6449. end
  6450. local function _Stop()
  6451. if SL.DigitChangeTimerID then
  6452. SL:UnSchedule(SL.DigitChangeTimerID)
  6453. SL.DigitChangeTimerID = nil
  6454. end
  6455. end
  6456. _Stop()
  6457. local isUp = target > cur
  6458. SL.DigitChangeTimerID = SL:Schedule(function ()
  6459. if isUp then
  6460. if cur >= target then
  6461. return _Stop()
  6462. end
  6463. else
  6464. if cur <= target then
  6465. return _Stop()
  6466. end
  6467. end
  6468. cur = _ChangeNum(cur, target)
  6469. if widget and not tolua.isnull(widget) then
  6470. _SetText[descript](widget, cur)
  6471. else
  6472. _Stop()
  6473. end
  6474. end, interval or 0.01)
  6475. end
  6476. -- 进度条动画
  6477. -- widget:进度条
  6478. -- widgetBg:进度条变化时的底(背景是进度条的话 type传值1或者不传; 如果Layout的话 必须传一个值,这个值不能是1)
  6479. -- param = {
  6480. -- count: 重置次数
  6481. -- num: 当前剩余血条的数量
  6482. -- to: 目标进度值
  6483. -- step: 动画步长
  6484. -- interval: 增长的速度, 默认0.01
  6485. -- colors: 血条颜色变化顺序
  6486. -- callback: 回调函数
  6487. -- opacity: 血条透明度
  6488. -- type: 进度条类型
  6489. -- }
  6490. function GUI:Timeline_Progress(widget, widgetBg, param)
  6491. if CheckIsInvalidCObject(widget) then
  6492. return false
  6493. end
  6494. local count = param.count or 0
  6495. local num = param.num or 1
  6496. local to = param.to or 0
  6497. local step = param.step or 0
  6498. local interval = param.interval or 0.01
  6499. local colors = param.colors or nil
  6500. local callback = param.callback or nil
  6501. local opacity = param.opacity or 255
  6502. local type = param.type or 1
  6503. local from = widget:getPercent()
  6504. widget:setPercent(from)
  6505. local function _GetColor(n)
  6506. return colors[n] or colors[#colors]
  6507. end
  6508. local k = 0
  6509. local function _CallFunc()
  6510. from = from + step
  6511. if k == count then
  6512. if step > 0 and from > to then
  6513. from = to
  6514. elseif step < 0 and from < to then
  6515. from = to
  6516. end
  6517. end
  6518. local percent = from
  6519. if k < count then
  6520. if step < 0 then
  6521. if from <= 0 then
  6522. from = 100
  6523. k = k + 1
  6524. if colors then
  6525. local n = #colors
  6526. if type == 1 then
  6527. widget:loadTexture(_GetColor(k % n))
  6528. else
  6529. widget:setColor(SL:ConvertColorFromHexString(_GetColor(k % n)))
  6530. end
  6531. if widgetBg then
  6532. if num == 1 then
  6533. widgetBg:setOpacity(0)
  6534. else
  6535. if type == 1 then
  6536. widgetBg:loadTexture(_GetColor((k+1) % n))
  6537. widgetBg:setPercent(100)
  6538. else
  6539. widgetBg:setBackGroundColor(SL:ConvertColorFromHexString(_GetColor((k+1) % n)))
  6540. end
  6541. widgetBg:setOpacity(255)
  6542. end
  6543. end
  6544. end
  6545. if callback then
  6546. callback(k)
  6547. end
  6548. end
  6549. else
  6550. if from >= 100 then
  6551. from = 0
  6552. k = k + 1
  6553. if colors then
  6554. local n = #colors
  6555. if type == 1 then
  6556. widget:loadTexture(_GetColor(k % n))
  6557. else
  6558. widget:setColor(SL:ConvertColorFromHexString(_GetColor(k % n)))
  6559. end
  6560. if widgetBg then
  6561. if num == 1 then
  6562. widgetBg:setOpacity(0)
  6563. else
  6564. if type == 1 then
  6565. widgetBg:loadTexture(_GetColor((k+1) % n))
  6566. widgetBg:setPercent(100)
  6567. else
  6568. widgetBg:setBackGroundColor(SL:ConvertColorFromHexString(_GetColor((k+1) % n)))
  6569. end
  6570. widgetBg:setOpacity(255)
  6571. end
  6572. end
  6573. end
  6574. if callback then
  6575. callback(k)
  6576. end
  6577. end
  6578. end
  6579. else
  6580. local isStop = (step < 0 and from <= to) or (step >= 0 and from >= to)
  6581. if isStop then
  6582. from = to
  6583. widget:stopAllActions()
  6584. if callback then
  6585. callback(k, true)
  6586. end
  6587. end
  6588. if colors then
  6589. if type == 1 then
  6590. widget:loadTexture(_GetColor(1))
  6591. else
  6592. widget:setColor(SL:ConvertColorFromHexString(_GetColor(1)))
  6593. end
  6594. if widgetBg then
  6595. if num == 1 then
  6596. widgetBg:setOpacity(0)
  6597. else
  6598. if type == 1 then
  6599. widgetBg:loadTexture(_GetColor(2))
  6600. widgetBg:setPercent(100)
  6601. else
  6602. widgetBg:setBackGroundColor(SL:ConvertColorFromHexString(_GetColor(2)))
  6603. end
  6604. widgetBg:setOpacity(255)
  6605. end
  6606. end
  6607. end
  6608. end
  6609. widget:setPercent(percent)
  6610. end
  6611. schedule(widget, _CallFunc, interval)
  6612. end
  6613. -- 自适应布局
  6614. -- pNode: ScrollView(常用)、Panel(pNode 中的子控件不显示,则不参与排版)
  6615. -- param = {
  6616. -- dir: 1:垂直; 2: 水平; 3: 两者
  6617. -- gap: x: 左右间距; y: 上下间距; l: 左边距; t: 上边距
  6618. -- addDir: 动画增长方式 1: 从上到下(从左到右)(多行从左上角), 2:中间到两边(多行从右上角), 3:从下到上(从右到左)
  6619. -- colnum: 多行列数(dir必须是2)
  6620. -- autosize: 根据内容自适应容器
  6621. -- sortfunc: 排序函数
  6622. -- interval:增长方式动画播放时间间隔, 不传值则不播放动画
  6623. -- rownums : 每一行的数量table ; 例如:rownums = {3, 2} (第一行3个元素,第二行2个元素)
  6624. -- }
  6625. function GUI:UserUILayout(pNode, param)
  6626. if CheckIsInvalidCObject(pNode) then
  6627. return false
  6628. end
  6629. local isScrollView = tolua.type(pNode) == "ccui.ScrollView"
  6630. pNode:stopAllActions()
  6631. --初始化默认值
  6632. param = param or {}
  6633. local dir = param.dir and param.dir or (isScrollView and pNode:getDirection() or 3)
  6634. dir = math.min(dir, 3)
  6635. local gap = param.gap
  6636. local addDir = param.addDir or 1
  6637. local colnum = param.colnum or 0
  6638. local autosize = param.autosize or false
  6639. local sortfunc = param.sortfunc
  6640. local interval = param.play and 0.01 or param.interval
  6641. local rownums = param.rownums or {}
  6642. local loadStyle = param.loadStyle or 1
  6643. local xGap = (gap and gap.x) and gap.x or (param.x or 0) -- 控件左右间距
  6644. local yGap = (gap and gap.y) and gap.y or (param.y or 0) -- 控件上下间距
  6645. local xMar = (gap and gap.l) and gap.l or (param.l or 0) -- 左边距
  6646. local yMar = (gap and gap.t) and gap.t or (param.t or 0) -- 上边距
  6647. --水平和垂直方向只能有一个
  6648. local visibleChildren = {}
  6649. for i,v in ipairs(pNode:getChildren()) do
  6650. if v and v:isVisible() then
  6651. v:setAnchorPoint({x = 0.5, y = 0.5})
  6652. table.insert(visibleChildren, v)
  6653. end
  6654. end
  6655. local num = #visibleChildren
  6656. if num == 0 then
  6657. return cc.size(0, 0)
  6658. end
  6659. if isScrollView then
  6660. pNode:setDirection(dir)
  6661. end
  6662. local cSize = visibleChildren[1]:getContentSize()
  6663. local pSize = pNode:getContentSize()
  6664. local width = xMar * 2
  6665. local height = yMar * 2
  6666. local offX = 0
  6667. local offY = 0
  6668. if dir == 1 then -- 垂直
  6669. height = height + num * (cSize.height + yGap) - yGap
  6670. width = pSize.width
  6671. if width > cSize.width then
  6672. width = cSize.width
  6673. end
  6674. elseif dir == 2 then -- 水平
  6675. width = width + num * (cSize.width + xGap) - xGap
  6676. height = pSize.height
  6677. if height > cSize.height then
  6678. height = cSize.height
  6679. end
  6680. else -- 多行多列
  6681. local rownum = 0
  6682. for i,cnt in ipairs(rownums) do
  6683. if cnt and tonumber(cnt) then
  6684. colnum = math.max(colnum, cnt)
  6685. if autosize then
  6686. if cnt > 0 then
  6687. rownum = rownum + 1
  6688. end
  6689. else
  6690. rownum = rownum + 1
  6691. end
  6692. end
  6693. end
  6694. if colnum < 1 then
  6695. colnum = math.max(1, math.floor(pSize.width / cSize.width))
  6696. end
  6697. if rownum == 0 then
  6698. rownum = math.ceil(num / colnum)
  6699. end
  6700. width = width + colnum * (cSize.width + xGap) - xGap
  6701. height = height + rownum * (cSize.height + yGap) - yGap
  6702. end
  6703. -- 设置容器的尺寸
  6704. if autosize then
  6705. pNode:setContentSize({width = width, height = height})
  6706. if isScrollView then
  6707. pNode:setInnerContainerSize({width = width, height = height})
  6708. end
  6709. else
  6710. if pSize.width > width then
  6711. offX = (pSize.width - width) / 2
  6712. end
  6713. if pSize.height > height then
  6714. offY = (pSize.height - height) / 2
  6715. end
  6716. width = math.max(pSize.width, width)
  6717. height = math.max(pSize.height, height)
  6718. if isScrollView then
  6719. pNode:setInnerContainerSize({width = width, height = height})
  6720. else
  6721. pNode:setContentSize({width = width, height = height})
  6722. end
  6723. end
  6724. -- 自己排序
  6725. if sortfunc then
  6726. sortfunc(visibleChildren)
  6727. end
  6728. local scrollFunc = {
  6729. [1] = function ()
  6730. if addDir == 2 then
  6731. pNode:scrollToPercentVertical(50, 0.01, false)
  6732. elseif addDir == 3 then
  6733. pNode:scrollToPercentVertical(100, 0.01, false)
  6734. end
  6735. end,
  6736. [2] = function ()
  6737. if addDir == 2 then
  6738. pNode:scrollToPercentHorizontal(50, 0.01, false)
  6739. elseif addDir == 3 then
  6740. pNode:scrollToPercentHorizontal(100, 0.01, false)
  6741. end
  6742. end
  6743. }
  6744. -- 水平垂直滚动指定位置
  6745. if isScrollView and (dir == 1 or dir == 2) then
  6746. local func = scrollFunc[dir]
  6747. if func then
  6748. func()
  6749. end
  6750. end
  6751. if dir > 2 then -- 双方向
  6752. local rows = {}
  6753. local cnum = 0
  6754. for i,cnt in ipairs(rownums) do
  6755. if cnt and tonumber(cnt) then
  6756. cnum = cnum + cnt
  6757. if autosize then
  6758. if cnt > 0 then
  6759. rows[#rows+1] = cnum
  6760. end
  6761. else
  6762. rows[i] = cnum
  6763. end
  6764. end
  6765. end
  6766. for i,item in ipairs(visibleChildren) do
  6767. local hang = math.ceil(i / colnum)
  6768. local k = i
  6769. for r,v in ipairs(rows) do
  6770. if i <= v then
  6771. hang = r
  6772. if rows[r-1] then
  6773. k = i - rows[r-1]
  6774. end
  6775. break
  6776. end
  6777. end
  6778. local x = 0
  6779. local y = 0
  6780. local mod = k % colnum
  6781. if addDir == 2 then
  6782. if autosize then
  6783. x = mod == 0 and xMar + offX + cSize.width/2 or (xMar + (colnum - mod + 1-0.5) * (cSize.width + xGap) - xGap/2) + offX
  6784. else
  6785. x = mod == 0 and xMar + offX * 2 + cSize.width/2 or (xMar + (colnum - mod + 1-0.5) * (cSize.width + xGap) - xGap/2) + offX * 2
  6786. end
  6787. else
  6788. if autosize then
  6789. x = mod == 0 and (width - xMar - cSize.width/2) - offX or (xMar + (mod-0.5) * (cSize.width + xGap) - xGap/2) + offX
  6790. else
  6791. x = mod == 0 and (width - xMar - cSize.width/2) - offX * 2 or (xMar + (mod-0.5) * (cSize.width + xGap) - xGap/2)
  6792. end
  6793. end
  6794. if loadStyle == 3 then
  6795. y = yMar + (hang - 0.5) * cSize.height + (hang - 1) * yGap
  6796. elseif loadStyle == 2 then
  6797. y = height - yMar - (hang - 0.5) * cSize.height - (hang - 1) * yGap - offY
  6798. else
  6799. y = height - yMar - (hang - 0.5) * cSize.height - (hang - 1) * yGap
  6800. end
  6801. item:setPosition({x = x, y = y})
  6802. if interval then
  6803. item:setVisible(false)
  6804. item:runAction(cc.Sequence:create(cc.DelayTime:create(i*interval), cc.Show:create()))
  6805. else
  6806. item:setVisible(true)
  6807. end
  6808. end
  6809. else -- 水平、垂直
  6810. for i,item in ipairs(visibleChildren) do
  6811. local x = 0
  6812. local y = 0
  6813. if dir == 1 then
  6814. x = width / 2
  6815. if addDir == 1 then -- 上到下
  6816. y = height - yMar - cSize.height*(i-0.5) - (i-1) * yGap
  6817. elseif addDir == 3 then -- 下到上
  6818. y = yMar + cSize.height*(i-0.5) + (i-1) * yGap
  6819. else -- 居中
  6820. y = height - yMar - cSize.height*(i-0.5) - (i-1) * yGap - offY
  6821. item.__pos = clone({x = x, y = y})
  6822. y = height / 2
  6823. end
  6824. elseif dir == 2 then
  6825. y = height / 2
  6826. if addDir == 1 then -- 左到右
  6827. x = xMar + cSize.width*(i-0.5) + (i-1) * xGap
  6828. elseif addDir == 3 then -- 右到左
  6829. x = width - xMar - cSize.width*(i-0.5) - (i-1) * xGap
  6830. else -- 居中
  6831. x = width - xMar - cSize.width*(i-0.5) - (i-1) * xGap - offX
  6832. item.__pos = clone({x = x, y = y})
  6833. x = width / 2
  6834. end
  6835. end
  6836. item:setPosition({x = x, y = y})
  6837. if interval then
  6838. item:setVisible(false)
  6839. else
  6840. item:setVisible(true)
  6841. end
  6842. end
  6843. if interval then
  6844. if addDir == 2 then
  6845. local r = math.floor(num / 2)
  6846. local minR = num % 2 == 0 and r or r + 1
  6847. local maxR = r + 1
  6848. for i=1,num do
  6849. local item = visibleChildren[i]
  6850. if item then
  6851. local t = 1
  6852. t = i > maxR and i - maxR or t
  6853. t = i < minR and minR - i or t
  6854. item:setLocalZOrder(t)
  6855. item:setVisible(true)
  6856. item:setOpacity(0)
  6857. item:runAction(cc.Spawn:create(cc.FadeTo:create(interval * t, 255), cc.EaseExponentialOut:create(cc.MoveTo:create(interval * t, item.__pos))))
  6858. end
  6859. end
  6860. else
  6861. for i=1,num do
  6862. local item = visibleChildren[i]
  6863. if item then
  6864. item:runAction(cc.Sequence:create(cc.DelayTime:create(i*interval), cc.Show:create()))
  6865. end
  6866. end
  6867. end
  6868. end
  6869. end
  6870. return cc.size(width, height)
  6871. end
  6872. --[[
  6873. param = {
  6874. bgPic: 背景图
  6875. barPic: 滑动按钮图片
  6876. Arr1PicN: 上(正常图)
  6877. Arr1PicP: 上(按下图)可不传
  6878. Arr2PicN: 下(正常图)
  6879. Arr2PicP: 下(按下图)可不传
  6880. default: 进度条值(默认是0)
  6881. x: 进度条坐标 x
  6882. y: 进度条坐标 y
  6883. list: 滚动的容器 list
  6884. callFunc: 容器滚动的回调函数
  6885. }
  6886. ]]
  6887. function GUI:SetScrollViewVerticalBar(parent, param)
  6888. if CheckIsInvalidCObject(parent) then
  6889. return false
  6890. end
  6891. local bgPic = FixPath(param.bgPic)
  6892. local barPic = FixPath(param.barPic)
  6893. local Arr1PicN = FixPath(param.Arr1PicN)
  6894. local Arr1PicP = FixPath(param.Arr1PicP)
  6895. local Arr2PicN = FixPath(param.Arr2PicN)
  6896. local Arr2PicP = FixPath(param.Arr2PicP)
  6897. local default = param.default or 0
  6898. local x = param.x
  6899. local y = param.y
  6900. local list = param.list
  6901. local callFunc = param.callFunc
  6902. -- 背景
  6903. local bar_bg = GUI:Image_Create(parent, "bar_bg", x, y, bgPic)
  6904. local bgWidth = GUI:getContentSize(bar_bg).width
  6905. local bgHeight = GUI:getContentSize(list).height
  6906. GUI:setContentSize(bar_bg, bgWidth, bgHeight)
  6907. -- 上
  6908. local btnArr_1 = GUI:Button_Create(bar_bg, "btnArr_1", bgWidth/2, bgHeight, Arr1PicN)
  6909. if Arr1PicP then
  6910. GUI:Button_loadTexturePressed(btnArr_1, Arr1PicP)
  6911. end
  6912. GUI:setAnchorPoint(btnArr_1, 0.5, 1)
  6913. -- 下
  6914. local btnArr_2 = GUI:Button_Create(bar_bg, "btnArr_2", bgWidth/2, 0, Arr2PicN)
  6915. if Arr2PicP then
  6916. GUI:Button_loadTexturePressed(btnArr_2, Arr2PicP)
  6917. end
  6918. GUI:setAnchorPoint(btnArr_2, 0.5, 0)
  6919. --bar
  6920. local sliderBar = GUI:Slider_Create(bar_bg, "sliderBar", bgWidth/2, bgHeight/2, "res/public/0.png", "res/public/0.png", barPic)
  6921. local btnArr_1_hh = GUI:getContentSize(btnArr_1).height
  6922. local btnArr2Pichh = GUI:getContentSize(btnArr_2).height
  6923. local Image = ccui.ImageView:create(barPic)
  6924. local imageWidth = GUI:getContentSize(Image).width
  6925. local imageHeight = GUI:getContentSize(Image).height
  6926. GUI:setContentSize(sliderBar, bgHeight - btnArr_1_hh - btnArr2Pichh - imageHeight , imageWidth)
  6927. GUI:setAnchorPoint(sliderBar, 0.5, 0.5)
  6928. GUI:setRotation(sliderBar, 90)
  6929. GUI:Slider_setPercent(sliderBar, default)
  6930. -- 计算偏移
  6931. local function GetListOffY()
  6932. return list:getInnerContainerSize().height - list:getContentSize().height
  6933. end
  6934. -- list_cells
  6935. local function listCallback(sender, eventType)
  6936. if callFunc then
  6937. callFunc(sender, eventType)
  6938. end
  6939. local setBarPercent = function ()
  6940. local posY = list:getInnerContainerPosition().y
  6941. local offY = GetListOffY()
  6942. local percent = 100
  6943. if offY > 0 then
  6944. percent = math.min(math.max(0, (offY + posY) / offY * 100), 100)
  6945. end
  6946. sliderBar:setPercent(percent)
  6947. end
  6948. performWithDelay(sliderBar, setBarPercent, 0.01)
  6949. end
  6950. if tolua.type(list) == "ccui.ListView" then
  6951. list:addScrollViewEventListener(listCallback)
  6952. else
  6953. list:addEventListener(listCallback)
  6954. end
  6955. list:addMouseScrollPercent()
  6956. -- Slider_bar
  6957. sliderBar:addEventListener(function ()
  6958. local offY = GetListOffY()
  6959. if offY > 0 then
  6960. list:scrollToPercentVertical(sliderBar:getPercent(), 0.03, false)
  6961. else
  6962. sliderBar:setPercent(100)
  6963. end
  6964. end)
  6965. local function UpOrDown(percent)
  6966. sliderBar:setPercent(percent)
  6967. list:scrollToPercentVertical(percent, 0.03, false)
  6968. end
  6969. btnArr_1:addClickEventListener(function ()
  6970. local offY = GetListOffY()
  6971. if offY > 0 then
  6972. UpOrDown(0)
  6973. end
  6974. end)
  6975. btnArr_1:setTouchEnabled(true)
  6976. btnArr_2:addClickEventListener(function ()
  6977. local offY = GetListOffY()
  6978. if offY > 0 then
  6979. UpOrDown(100)
  6980. end
  6981. end)
  6982. btnArr_2:setTouchEnabled(true)
  6983. end
  6984. function GUI:ShowWorldTips(tips, worldPos, anchorPoint)
  6985. showWorldTips(tips, worldPos, anchorPoint)
  6986. end
  6987. function GUI:HideWorldTips()
  6988. hideMouseOverTips()
  6989. end
  6990. --创建技能item
  6991. function GUI:CreateSkillItem(parent, skillID)
  6992. if CheckIsInvalidCObject(parent) then
  6993. return false
  6994. end
  6995. local item = SkillItem:create(skillID)
  6996. parent:addChild(item)
  6997. return item
  6998. end
  6999. function GUI:Retain(widget)
  7000. if CheckIsInvalidCObject(widget) then
  7001. return false
  7002. end
  7003. widget:retain()
  7004. end
  7005. function GUI:addRef(widget)
  7006. if CheckIsInvalidCObject(widget) then
  7007. return false
  7008. end
  7009. widget:retain()
  7010. end
  7011. function GUI:Release(widget)
  7012. if CheckIsInvalidCObject(widget) then
  7013. return false
  7014. end
  7015. widget:release()
  7016. end
  7017. function GUI:decRef(widget)
  7018. if CheckIsInvalidCObject(widget) then
  7019. return false
  7020. end
  7021. widget:release()
  7022. end
  7023. -- FIXME: 写错了方法名,但是不能删
  7024. function GUI:defRef(widget)
  7025. if CheckIsInvalidCObject(widget) then
  7026. return false
  7027. end
  7028. widget:release()
  7029. end
  7030. function GUI:autoDecRef(widget)
  7031. if CheckIsInvalidCObject(widget) then
  7032. return false
  7033. end
  7034. widget:autorelease()
  7035. end
  7036. -- FIXME: 写错了方法名,但是不能删
  7037. function GUI:autoDefRef(widget)
  7038. if CheckIsInvalidCObject(widget) then
  7039. return false
  7040. end
  7041. widget:autorelease()
  7042. end
  7043. function GUI:Rect(x, y, width, height)
  7044. return cc.rect(x, y, width, height)
  7045. end
  7046. function GUI:RectContainsPoint(Rect, position)
  7047. return cc.rectContainsPoint(Rect, position)
  7048. end
  7049. function GUI:Size(width, height)
  7050. return cc.size(width, height)
  7051. end
  7052. function GUI:p(x, y)
  7053. return cc.p(x, y)
  7054. end
  7055. --获取图片尺寸
  7056. function GUI:getImageContentSize(path)
  7057. local img = ccui.ImageView:create(path)
  7058. return img:getContentSize()
  7059. end
  7060. --[[
  7061. 文本提示框
  7062. str文本
  7063. width文本宽度
  7064. ]]
  7065. function GUI:GetWordTips(str, width)
  7066. return GetWordTips({str = str,width = width})
  7067. end
  7068. function GUI:isClippingParentContainsPoint(widget, position)
  7069. if CheckIsInvalidCObject(widget) then
  7070. return false
  7071. end
  7072. return widget:isClippingParentContainsPoint(position)
  7073. end
  7074. function GUI:setEnabled(widget, enable)
  7075. if CheckIsInvalidCObject(widget) then
  7076. return false
  7077. end
  7078. widget:setEnabled(enable)
  7079. end
  7080. -- 刷坐标整数
  7081. function GUI:RefPosByParent(widget)
  7082. if CheckIsInvalidCObject(widget) then
  7083. return false
  7084. end
  7085. if widget then
  7086. refPositionByParent(widget)
  7087. end
  7088. end
  7089. -- 旋转滑动 容器
  7090. function GUI:RotateView_Create(parent, ID, x, y, width, height, scrollGap, param)
  7091. if not ID then
  7092. SL:Print("[GUI ERROR] GUI:RotateView_Create can't find ID")
  7093. return nil
  7094. end
  7095. if not parent then
  7096. SL:Print("[GUI ERROR] GUI:RotateView_Create can't find parent", ID)
  7097. return nil
  7098. end
  7099. if SL._DEBUG and parent ~= NONEED_PARENT_CODE and parent:getChildByName(ID) then
  7100. SL:Print("[GUI ERROR] GUI:RotateView_Create ID is exists", ID)
  7101. return nil
  7102. end
  7103. if CheckIsInvalidCObject(parent) then
  7104. return nil
  7105. end
  7106. SL:RequireFile(SLDefine.LUAFile.LUA_FILE_UI_ROTATEVIEW)
  7107. local rotateView = UIRotateView.main(parent, ID, x, y, width, height, scrollGap, param)
  7108. return rotateView
  7109. end
  7110. function GUI:RotateView_addChild(widget, value, index)
  7111. if CheckIsInvalidCObject(widget) then
  7112. return false
  7113. end
  7114. if CheckIsInvalidCObject(value) then
  7115. return false
  7116. end
  7117. if not index then
  7118. SL:Print("[GUI ERROR] GUI:RotateView_addChild index is nil")
  7119. return false
  7120. end
  7121. UIRotateView.addRotateViewChild(widget, value, index)
  7122. end
  7123. function GUI:RotateView_getChildByIndex(widget, index)
  7124. if CheckIsInvalidCObject(widget) then
  7125. return false
  7126. end
  7127. if not index then
  7128. SL:Print("[GUI ERROR] GUI:RotateView_getChildByIndex index is nil")
  7129. return false
  7130. end
  7131. return UIRotateView.getRotateViewChildByIndex(widget, index)
  7132. end
  7133. function GUI:RotateView_getItemByIndex(widget, index)
  7134. if CheckIsInvalidCObject(widget) then
  7135. return false
  7136. end
  7137. if not index then
  7138. SL:Print("[GUI ERROR] GUI:RotateView_getChildByIndex index is nil")
  7139. return false
  7140. end
  7141. return UIRotateView.getRotateViewItemByIndex(widget, index)
  7142. end
  7143. -- 不提供对外函数 --------------------------------------------------------------------------------------------------------------------------
  7144. function GUI:setChineseName(widget, value)
  7145. widget._chinesename = value
  7146. end
  7147. function GUI:getChineseName(widget)
  7148. return widget._chinesename or ""
  7149. end
  7150. function GUI:setID(widget, value)
  7151. widget._ID = value
  7152. end
  7153. function GUI:getID(widget)
  7154. return widget._ID or 0
  7155. end
  7156. function GUI:setChildID(widget, value)
  7157. widget._childID = value
  7158. end
  7159. function GUI:getChildID(widget)
  7160. return widget._childID or 0
  7161. end
  7162. function GUI:setJumpIndex(widget, value)
  7163. widget._jump_index = value
  7164. end
  7165. function GUI:getJumpIndex(widget)
  7166. return widget._jump_index or 0
  7167. end
  7168. function GUI:setClickStatus(widget, value)
  7169. widget._Click_Status = value
  7170. end
  7171. function GUI:setContainerIndexTable(widget, value)
  7172. widget._Container_table = value
  7173. end
  7174. function GUI:setButtonPage(widget, value)
  7175. widget._Button_page = value
  7176. end
  7177. function GUI:setButtonPressColor(widget, value)
  7178. widget._Button_press_C = value
  7179. end
  7180. function GUI:setUIIDs(widget, value)
  7181. widget._uiIDs = value
  7182. end
  7183. function GUI:getRedID(widget)
  7184. if tolua.isnull(widget) then
  7185. return false
  7186. end
  7187. if widget._uiIDs then
  7188. return false
  7189. end
  7190. return tonumber(widget._uiIDs.redID)
  7191. end
  7192. function GUI:getGuideID(widget)
  7193. if tolua.isnull(widget) then
  7194. return false
  7195. end
  7196. if widget._uiIDs then
  7197. return false
  7198. end
  7199. return tonumber(widget._uiIDs.guideID)
  7200. end
  7201. -----------------------------------------------------------------------------------------------------------------------------------------------