SUILoader.lua 223 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758
  1. --------------------------------------------------------
  2. --------------------------------------------------------
  3. --------------------------------------------------------
  4. local SUILoader = class("SUILoader")
  5. local Element = require("sui/Element")
  6. local SWidget = require("sui/SWidget")
  7. local SUIHelper = require("sui/SUIHelper")
  8. local LexicalHelper = require("sui/LexicalHelper")
  9. local RichTextHelp = require("util/RichTextHelp")
  10. local QuickCell = requireUtil("QuickCell")
  11. local cjson = require("cjson")
  12. local tinsert = table.insert
  13. local tremove = table.remove
  14. local ssplit = string.split
  15. local sfind = string.find
  16. local mfloor = math.floor
  17. local DEBUG_MODE = false
  18. ------------------------------------------ util
  19. SUILoader.convertToDesignPos = function(swidget, input_pos)
  20. local parent = swidget.render:getParent()
  21. local visibleSize = global.Director:getVisibleSize()
  22. local parentSize = parent and parent:getContentSize() or visibleSize
  23. local x = tonumber(input_pos.x) or 0
  24. local y = tonumber(input_pos.y) or 0
  25. local fixX = x
  26. local fixY = parentSize.height-y
  27. return cc.p(fixX, fixY)
  28. end
  29. SUILoader.convertToOpenGLPos = function(swidget, input_pos)
  30. local parent = swidget.render:getParent()
  31. local visibleSize = global.Director:getVisibleSize()
  32. local parentSize = parent and parent:getContentSize() or visibleSize
  33. local x = tonumber(input_pos.x) or 0
  34. local y = tonumber(input_pos.y) or 0
  35. local fixX = x
  36. local fixY = parentSize.height-y
  37. return cc.p(fixX, fixY)
  38. end
  39. SUILoader.compareSWidget = function(a, b)
  40. if not a or not b then
  41. return 0
  42. end
  43. if #a.branches ~= #b.branches then
  44. return -5
  45. end
  46. local eleA = a.element
  47. local eleB = b.element
  48. if not eleA or not eleB then
  49. return -1
  50. end
  51. -- 类型不同
  52. if eleA.type ~= eleB.type then
  53. return -2
  54. end
  55. -- 重新加载
  56. local reloadA = tonumber(eleA.attr.reload) or 0
  57. local reloadB = tonumber(eleB.attr.reload) or 0
  58. if reloadB == 1 then
  59. return -6
  60. end
  61. if eleA.type == "Frames" then
  62. return -6
  63. end
  64. if eleA.type == "Effect" and (eleA.attr.count == 1 or eleB.attr.count == 1) then
  65. return -6
  66. end
  67. if eleA.type == "CheckBox" then
  68. return -6
  69. end
  70. if eleA.type == "COUNTDOWN" then
  71. return -6
  72. end
  73. if eleA.type == "BAGITEMS" or eleA.type == "HEROBAGITEMS" or eleA.type == "DLINKITEMS" then
  74. return -6
  75. end
  76. if eleA.type == "EQUIPITEMS" or eleA.type == "HEROEQUIPITEMS" then
  77. return -6
  78. end
  79. if eleA.type == "DBItemShow" or eleA.type == "HERODBItemShow" or eleA.type == "MKItemShow" then
  80. return -6
  81. end
  82. if eleA.type == "Input" then
  83. return -6
  84. end
  85. if eleA.type == "TIMETIPS" then
  86. return -6
  87. end
  88. if eleA.type == "LoadingBar" then
  89. return -6
  90. end
  91. if eleA.type == "Slider" then
  92. return -6
  93. end
  94. if eleA.type == "MenuItem" then
  95. return -6
  96. end
  97. if eleA.type == "ScrapePic" then
  98. return -6
  99. end
  100. local ignored = {[1]="id", [2]="default", [3]="reload", [4]="loadCount", [5]="loadDelay", [6]="loadStep", [7]="tax", [8]="tay", [9]="tpercentx", [10]="tpercenty"}
  101. local attrA = clone(eleA.attr)
  102. local attrB = clone(eleB.attr)
  103. for _, v in ipairs(ignored) do
  104. attrA[v] = nil
  105. attrB[v] = nil
  106. end
  107. for key, value in pairs(attrA) do
  108. if not attrB[key] then
  109. -- 属性数量不同
  110. return -3
  111. end
  112. if value ~= attrB[key] then
  113. -- 属性值不同
  114. return -4
  115. end
  116. attrB[key] = nil
  117. end
  118. if next(attrB) then
  119. -- 属性数量不同
  120. return -3
  121. end
  122. -- 属性相同
  123. return 1
  124. end
  125. SUILoader.isBackground = function(swidget)
  126. if not swidget then
  127. return false
  128. end
  129. return tonumber(swidget.element.attr.bg) == 1
  130. end
  131. ------------------------------------------
  132. ------------------------------------------
  133. --
  134. local defaultOutline = 1
  135. local defaultOutlineC = 0
  136. local defaultColorID = 255
  137. local defaultFontSize = global.isWinPlayMode and 12 or 18
  138. local anchorPoints = {[0]={x=0,y=1}, [1]={x=1,y=1}, [2]={x=0,y=0}, [3]={x=1,y=0}, [4]={x=0.5,y=0.5}}
  139. local defaultTextX = 25
  140. local defaultTextY = 20
  141. local interval = 0.167
  142. local defaultFontPath = SL:GetMetaValue("GAME_DATA", "SUI_FONT_PATH") or global.MMO.PATH_FONT2
  143. SUILoader.getAnchorByIndex = function(index)
  144. return anchorPoints[index or 0]
  145. end
  146. SUILoader.modifySizeAble = function(swidget)
  147. local element = swidget.element
  148. if element.type == "Effect" then
  149. return false
  150. end
  151. if element.type == "Text" then
  152. return false
  153. end
  154. if element.type == "ItemShow" then
  155. return false
  156. end
  157. if element.type == "CostItem" then
  158. return false
  159. end
  160. if element.type == "COUNTDOWN" then
  161. return false
  162. end
  163. if element.type == "EquipShow" or element.type == "HEROEquipShow" or element.type == "PETEQUIPSHOW" then
  164. return false
  165. end
  166. if element.type == "TIMETIPS" then
  167. return false
  168. end
  169. if element.type == "TextAtlas" then
  170. return false
  171. end
  172. if element.type == "UIModel" then
  173. return false
  174. end
  175. if element.type == "ScrapePic" then
  176. return false
  177. end
  178. if element.type == "BmpText" then
  179. return false
  180. end
  181. return true
  182. end
  183. SUILoader.modifyAnchorAble = function(swidget)
  184. local element = swidget.element
  185. if element.type == "Effect" then
  186. return false
  187. end
  188. if element.type == "UIModel" then
  189. return false
  190. end
  191. return true
  192. end
  193. SUILoader.modifyRotateAble = function(swidget)
  194. return true
  195. end
  196. SUILoader.modifyVisible = function(swidget)
  197. return true
  198. end
  199. SUILoader.modifyOpacity = function(swidget)
  200. local element = swidget.element
  201. if element.type == "CostItem" then
  202. return false
  203. end
  204. if element.type == "QuickTextView" then
  205. return false
  206. end
  207. if element.type == "ItemShow" or element.type == "DBItemShow" or element.type == "HERODBItemShow" or element.type == "MKItemShow" then
  208. return false
  209. end
  210. if element.type == "EquipShow" or element.type == "HEROEquipShow" or element.type == "PETEQUIPSHOW" then
  211. return false
  212. end
  213. return true
  214. end
  215. SUILoader.fixAnchor = function(swidget)
  216. if tonumber(swidget.element.attr.bg) == 1 and (tonumber(swidget.element.attr.show) == 5 or tonumber(swidget.element.attr.show) == 6) then
  217. local ax = tonumber(swidget.element.attr.tax)
  218. local ay = tonumber(swidget.element.attr.tay)
  219. ax = ax or 0
  220. ay = ay or 1
  221. return cc.p(ax, ay)
  222. end
  223. if swidget.element.attr.ax or swidget.element.attr.ay then
  224. local ax = tonumber(swidget.element.attr.ax)
  225. local ay = tonumber(swidget.element.attr.ay)
  226. ax = ax or 0
  227. ay = ay or 1
  228. return cc.p(ax, ay)
  229. end
  230. local a = tonumber(swidget.element.attr.a) or 0
  231. return SUILoader.getAnchorByIndex(a)
  232. end
  233. SUILoader.fixPosition = function(swidget)
  234. local parent = swidget.render:getParent()
  235. local parentSize = parent:getContentSize()
  236. local defaultX = (swidget.element.type == "Text" or swidget.element.type == "RText" or swidget.element.type == "RTextX" or swidget.element.type == "BmpText") and defaultTextX or 0
  237. local defaultY = (swidget.element.type == "Text" or swidget.element.type == "RText" or swidget.element.type == "RTextX" or swidget.element.type == "BmpText") and defaultTextY or 0
  238. local x = tonumber(swidget.element.attr.x) or defaultX
  239. local y = parentSize.height - (tonumber(swidget.element.attr.y) or defaultY)
  240. local percentx = nil
  241. local percenty = nil
  242. if tonumber(swidget.element.attr.bg) == 1 and (tonumber(swidget.element.attr.show) == 5 or tonumber(swidget.element.attr.show) == 6) then
  243. percentx = tonumber(swidget.element.attr.tpercentx)
  244. percenty = tonumber(swidget.element.attr.tpercenty)
  245. else
  246. percentx = tonumber(swidget.element.attr.percentx)
  247. percenty = tonumber(swidget.element.attr.percenty)
  248. end
  249. if percentx then
  250. x = parentSize.width * (percentx/100)
  251. end
  252. if percenty then
  253. y = parentSize.height - parentSize.height * (percenty/100)
  254. end
  255. return cc.p(x, y)
  256. end
  257. SUILoader.fixSize = function(swidget)
  258. local parent = swidget.render:getParent()
  259. local parentSize = parent:getContentSize()
  260. local contentSize = swidget.render:getContentSize()
  261. local defaultWidth = contentSize.width
  262. local defaultHeight = contentSize.height
  263. local width = tonumber(swidget.element.attr.width) or defaultWidth
  264. local height = tonumber(swidget.element.attr.height) or defaultHeight
  265. local percentwidth = tonumber(swidget.element.attr.percentwidth)
  266. local percentheight = tonumber(swidget.element.attr.percentheight)
  267. if percentwidth then
  268. width = parentSize.width * (percentwidth/100)
  269. end
  270. if percentheight then
  271. height = parentSize.height * (percentheight/100)
  272. end
  273. return cc.size(width, height)
  274. end
  275. SUILoader.fixRotate = function(swidget)
  276. local rotate = tonumber(swidget.element.attr.rotate) or 0
  277. return rotate
  278. end
  279. SUILoader.fixVisible = function(swidget)
  280. -- 默认0可见 1不可见
  281. local visible = tonumber(swidget.element.attr.visible) or 0
  282. return visible == 0
  283. end
  284. SUILoader.fixOpacity = function(swidget)
  285. -- 默认不透明度 255
  286. local opacity = tonumber(swidget.element.attr.opacity) or 255
  287. return opacity
  288. end
  289. -- load attr
  290. SUILoader.loadSWidgetAttr = function(swidget)
  291. local render = swidget.render
  292. local element = swidget.element
  293. -- size
  294. if SUILoader.modifySizeAble(swidget) then
  295. local size = SUILoader.fixSize(swidget)
  296. render:ignoreContentAdaptWithSize(false)
  297. render:setContentSize(size)
  298. end
  299. -- anchor
  300. if SUILoader.modifyAnchorAble(swidget) then
  301. local anchor = SUILoader.fixAnchor(swidget)
  302. render:setAnchorPoint(anchor)
  303. end
  304. -- rotate
  305. if SUILoader.modifyRotateAble(swidget) then
  306. local rotate = SUILoader.fixRotate(swidget)
  307. render:setRotation(rotate)
  308. end
  309. -- x y
  310. local position = SUILoader.fixPosition(swidget)
  311. render:setPosition(position)
  312. local worldPos = render:convertToWorldSpace(cc.p(0, 0))
  313. local tranPos = cc.p(mfloor(worldPos.x), mfloor(worldPos.y))
  314. render:setPosition(cc.pAdd(position, cc.pSub(tranPos, worldPos)))
  315. if SUILoader.modifyVisible(swidget) then
  316. local visible = SUILoader.fixVisible(swidget)
  317. render:setVisible(visible)
  318. end
  319. if SUILoader.modifyOpacity(swidget) then
  320. local opacity = SUILoader.fixOpacity(swidget)
  321. if render.setOpacity then
  322. render:setOpacity(opacity)
  323. end
  324. end
  325. end
  326. ------------------------------------------
  327. --- SUILoad Core
  328. function SUILoader:ctor()
  329. defaultOutline = SL:GetMetaValue("GAME_DATA","defaultOutlineSize") or 0
  330. defaultOutlineC = SL:GetMetaValue("GAME_DATA","defaultOutlineColor") or 0
  331. end
  332. function SUILoader:getInputTable(fliter)
  333. local submitTable = {}
  334. if fliter == nil or fliter == "" or fliter == "0" then
  335. elseif fliter == "*" then
  336. for k, v in pairs(self._inputWidgets) do
  337. local input = v
  338. local inputID = k
  339. local inputValue = input.widget and input.widget:getString() or ""
  340. table.insert(submitTable, {id = inputID, value = inputValue, type = input.inputFlag, isChatInput = input.isChatInput, isNameInput = input.isNameInput})
  341. end
  342. else
  343. local slices = ssplit(fliter, ",")
  344. for i, v in ipairs(slices) do
  345. local inputID = v
  346. local input = self._inputWidgets[inputID]
  347. local inputValue = input.widget and input.widget:getString() or ""
  348. table.insert(submitTable, {id = inputID, value = inputValue, type = input.inputFlag, isChatInput = input.isChatInput, isNameInput = input.isNameInput})
  349. end
  350. end
  351. return submitTable
  352. end
  353. function SUILoader:getCheckBoxTable(fliter)
  354. local submitTable = {}
  355. if fliter == nil or fliter == "" or fliter == "0" then
  356. submitTable = {}
  357. else
  358. for k, v in pairs(self._checkboxWidgets) do
  359. local widget = v
  360. local widgetID = k
  361. local value = (widget:isSelected() and 1 or 0)
  362. table.insert(submitTable, {id = widgetID, value = value})
  363. end
  364. end
  365. return submitTable
  366. end
  367. function SUILoader:getCheckBoxTableByID(widgetID)
  368. local submitTable = {}
  369. local widget = self._checkboxWidgets[widgetID]
  370. if not widget then
  371. submitTable = {}
  372. else
  373. local value = (widget:isSelected() and 1 or 0)
  374. table.insert(submitTable, {id = widgetID, value = value})
  375. end
  376. return submitTable
  377. end
  378. function SUILoader:getSliderTableByID(widgetID)
  379. local submitTable = {}
  380. local param = self._sliderWidgets[widgetID]
  381. if not param or not param.widget then
  382. submitTable = {}
  383. else
  384. local value = param and param.value or 0
  385. table.insert(submitTable, {id = widgetID, value = value})
  386. end
  387. return submitTable
  388. end
  389. function SUILoader:getMenuItemTableByID(widgetID)
  390. local submitTable = {}
  391. local param = self._menuItemWidgets[widgetID]
  392. if not param or not param.widget then
  393. submitTable = {}
  394. else
  395. local value = param and param.value or ""
  396. value = param.widget:getString() or ""
  397. table.insert(submitTable, {id = widgetID, value = value})
  398. end
  399. return submitTable
  400. end
  401. function SUILoader:addMouseOverTips(widget, element)
  402. widget:setSwallowMouse(false)
  403. widget:setMouseEnabled(false)
  404. local tips = element.attr.tips
  405. local tipsx = tonumber(element.attr.tipsx) or 0
  406. local tipsy = tonumber(element.attr.tipsy) or 0
  407. if tips and string.len(tips) > 0 then
  408. -- 监听事件;
  409. tips = string.gsub(tips, "%^", "\\")
  410. widget:addMouseOverTips(tips, cc.p(tipsx, -tipsy), cc.p(0.5, 1))
  411. end
  412. end
  413. ------------------------------------------------------------------
  414. -- load
  415. function SUILoader:load(source, callback, closeCB, ext)
  416. local clock = os.clock()
  417. -- parse
  418. local elements = LexicalHelper:Parse(source)
  419. -- fix background
  420. self:fixBackground(elements, ext)
  421. -- content
  422. local visibleSize = global.Director:getVisibleSize()
  423. local _, rootRect = checkNotchPhone()
  424. rootRect.width = visibleSize.width
  425. rootRect.height = visibleSize.height
  426. local trunk, background = self:loadContent(elements, callback, closeCB, rootRect, ext)
  427. print("load cost", os.clock() - clock)
  428. return trunk, background
  429. end
  430. function SUILoader:fixBackground(elements, ext)
  431. -- 优先级 脚本中设置过bg字段 -> GM指定大背景框 -> 默认背景框
  432. -- dump(elements)
  433. -- find background
  434. local background = nil
  435. for k, v in ipairs(elements) do
  436. if v.attr["bg"] == "1" then
  437. if not background then
  438. background = v
  439. else
  440. v.attr["bg"] = nil
  441. end
  442. end
  443. end
  444. if nil == background then
  445. if ext and ext.background then
  446. -- GM指定大背景框
  447. -- OPENMERCHANTBIGDLG 路径 显示位置 X坐标 Y坐标 高度 宽度 是否显示关闭按钮 关闭按钮X坐标 关闭按钮Y坐标 固定NPC对话框
  448. if ext.background.Param7 and tonumber(ext.background.Param7) == 1 then
  449. local element = {}
  450. element.type = "Button"
  451. element.attr = {}
  452. element.attr.nimg = "public/1900000510.png"
  453. element.attr.pimg = "public/1900000511.png"
  454. element.attr.link = "@exit"
  455. element.attr.x = tonumber(ext.background.Param8)
  456. element.attr.y = tonumber(ext.background.Param9)
  457. table.insert(elements, 1, element)
  458. end
  459. local element = {}
  460. element.type = "Img"
  461. element.attr = {}
  462. element.attr.img = ext.background.Param1
  463. element.attr.bg = 1
  464. element.attr.move = tonumber(ext.background.Param10) and 1 or 0
  465. element.attr.reset = 1
  466. element.attr.show = tonumber(ext.background.Param2)
  467. element.attr.x = tonumber(ext.background.Param3)
  468. element.attr.y = tonumber(ext.background.Param4)
  469. element.attr.height = tonumber(ext.background.Param5) ~= 0 and tonumber(ext.background.Param5) or nil
  470. element.attr.width = tonumber(ext.background.Param6) ~= 0 and tonumber(ext.background.Param6) or nil
  471. element.attr.loadDelay = 1
  472. table.insert(elements, 1, element)
  473. else
  474. -- 默认背景框
  475. local element = {}
  476. element.type = "Button"
  477. element.attr = {}
  478. element.attr.nimg = "public/1900000510.png"
  479. element.attr.pimg = "public/1900000511.png"
  480. element.attr.link = "@exit"
  481. element.attr.x = 546
  482. element.attr.y = 0
  483. table.insert(elements, 1, element)
  484. local element = {}
  485. element.type = "Layout"
  486. element.attr = {}
  487. element.attr.width = 80
  488. element.attr.height = 80
  489. element.attr.x = 545
  490. element.attr.y = 0
  491. element.attr.link = "@exit"
  492. table.insert(elements, 1, element)
  493. local element = {}
  494. element.type = "Img"
  495. element.attr = {}
  496. element.attr.img = SL:GetMetaValue("WINPLAYMODE") and "public_win32/bg_npc_01.png" or "public/bg_npc_01.png"
  497. element.attr.bg = 1
  498. element.attr.move = 0
  499. element.attr.reset = 1
  500. element.attr.show = 0
  501. element.attr.loadDelay = 1
  502. table.insert(elements, 1, element)
  503. end
  504. end
  505. return background
  506. end
  507. function SUILoader:loadContent(elements, callback, closeCB, rootRect, ext)
  508. self._loaders =
  509. {
  510. ["Img"] = handler(self, self.load_render_Img),
  511. ["Text"] = handler(self, self.load_render_Text),
  512. ["RText"] = handler(self, self.load_render_RText),
  513. ["Input"] = handler(self, self.load_render_Input),
  514. ["Button"] = handler(self, self.load_render_Button),
  515. ["Effect"] = handler(self, self.load_render_Effect),
  516. ["Frames"] = handler(self, self.load_render_Frames),
  517. ["Layout"] = handler(self, self.load_render_Layout),
  518. ["CheckBox"] = handler(self, self.load_render_CheckBox),
  519. ["ListView"] = handler(self, self.load_render_ListView),
  520. ["ItemShow"] = handler(self, self.load_render_ItemShow),
  521. ["CostItem"] = handler(self, self.load_render_CostItem),
  522. ["COUNTDOWN"] = handler(self, self.load_render_COUNTDOWN),
  523. ["ITEMBOX"] = handler(self, self.load_render_ITEMBOX),
  524. ["EquipShow"] = handler(self, self.load_render_EquipShow),
  525. ["BAGITEMS"] = handler(self, self.load_render_BAGITEMS),
  526. ["EQUIPITEMS"] = handler(self, self.load_render_EQUIPITEMS),
  527. ["DBItemShow"] = handler(self, self.load_render_DBItemShow),
  528. ["TIMETIPS"] = handler(self, self.load_render_TIMETIPS),
  529. ["TextAtlas"] = handler(self, self.load_render_TextAtlas),
  530. ["LoadingBar"] = handler(self, self.load_render_LoadingBar),
  531. ["CircleBar"] = handler(self, self.load_render_CircleBar),
  532. ["PercentImg"] = handler(self, self.load_render_PercentImg),
  533. ["UIModel"] = handler(self, self.load_render_UIModel),
  534. ["HEROEquipShow"] = handler(self, self.load_render_HEROEquipShow),
  535. ["HEROEQUIPITEMS"] = handler(self, self.load_render_HEROEQUIPITEMS),
  536. ["HERODBItemShow"] = handler(self, self.load_render_HERODBItemShow),
  537. ["HEROBAGITEMS"] = handler(self, self.load_render_HEROBAGITEMS),
  538. ["QuickTextView"] = handler(self, self.load_render_QuickTextView),
  539. ["RTextX"] = handler(self, self.load_render_RTextX),
  540. ["DLINKITEMS"] = handler(self, self.load_render_DLINKITEMS),
  541. ["MKItemShow"] = handler(self, self.load_render_MKItemShow),
  542. ["PETEQUIPSHOW"] = handler(self, self.load_render_PETEQUIPSHOW),
  543. ["PageView"] = handler(self, self.load_render_PageView),
  544. ["Slider"] = handler(self, self.load_render_Slider),
  545. ["MenuItem"] = handler(self, self.load_render_MenuItem),
  546. ["ScrapePic"] = handler(self, self.load_render_ScrapePic),
  547. ["BmpText"] = handler(self, self.load_render_BmpText),
  548. ["ButtonKeFu"] = handler(self, self.load_render_ButtonKeFu),
  549. }
  550. --
  551. self._inputWidgets = {}
  552. self._checkboxWidgets = {}
  553. self._sliderWidgets = {}
  554. self._menuItemWidgets = {}
  555. local SUIComponentProxy = global.Facade:retrieveProxy(global.ProxyTable.SUIComponentProxy)
  556. -- 对比上次,差异化更改
  557. local lastTrunk = ext and ext.lastTrunk or nil
  558. local lastBackground = ext and ext.lastBackground or nil
  559. local loadCompleteCB = ext and ext.loadCompleteCB or nil
  560. local isImmediate = ext and ext.isImmediate or false
  561. local parentNode = ext and ext.parentNode or nil
  562. local npcLayer = ext and ext.npcLayer or nil --刷新npcLayer的background
  563. if npcLayer then
  564. SUIComponentProxy:ClearSUISlider()
  565. end
  566. -- load swidgets
  567. local background = nil
  568. local swidgets = {}
  569. for i, element in ipairs(elements) do
  570. -- exist loader
  571. if self._loaders[element.type] then
  572. element.attr.id = element.attr.id or string.format("default_%s", i)
  573. element.attr.x = (element.type == "Text" or element.type == "RText" or element.type == "RTextX" or element.type == "BmpText") and (element.attr.x or defaultTextX) or element.attr.x
  574. element.attr.y = (element.type == "Text" or element.type == "RText" or element.type == "RTextX" or element.type == "BmpText") and (element.attr.y or defaultTextY) or element.attr.y
  575. element.attr._mainIndex= ext and ext.mainIndex -- 主界面的按钮/图片点击需上报, 加的标识
  576. -- swidget
  577. local swidget = global.SWidgetCache:generateSWidget()
  578. swidget.element = element
  579. swidget.render = nil
  580. swidgets[element.attr.id] = swidget
  581. -- 记录背景图
  582. local isBG = tonumber(element.attr.bg) == 1
  583. if isBG and not background then
  584. background = swidget
  585. end
  586. end
  587. end
  588. -- tree mode
  589. for _, element in ipairs(elements) do
  590. if swidgets[element.attr.id] and swidgets[element.attr.id].element.attr.children then
  591. local swidget = swidgets[element.attr.id]
  592. local branches = swidget.element.attr.children
  593. local find_info = {sfind(branches, "{(.-)}")}
  594. local slices = ssplit(find_info[3] or branches, ",")
  595. if #slices > 0 then
  596. for _, branchID in ipairs(slices) do
  597. local branch = swidgets[branchID]
  598. if branch and not branch.render and branch.element.attr.id ~= swidget.element.attr.id then
  599. if branch.trunk then
  600. print("ERROR SUILoader: swidget can't be add aegin. swidgetID=" .. element.attr.id .. " branchID=" .. branchID)
  601. else
  602. swidget:addBranch(branch)
  603. end
  604. end
  605. end
  606. end
  607. end
  608. end
  609. -- trunk
  610. local trunk = global.SWidgetCache:generateSWidget()
  611. trunk.element = Element.new("Layout")
  612. trunk.depth = 0
  613. for _, element in ipairs(elements) do
  614. local swidget = swidgets[element.attr.id]
  615. if swidget and swidget.trunk == nil then
  616. trunk:addBranch(swidget)
  617. end
  618. end
  619. -- compare
  620. if lastTrunk then
  621. local backgroundR = SUILoader.compareSWidget(lastBackground, background)
  622. --
  623. local function fixBranches(trunkL, trunkC)
  624. if #trunkL.branches <= 0 then
  625. if #trunkC.branches > 0 then
  626. for index, branch in ipairs(trunkC.branches) do
  627. trunkL:addBranch(branch)
  628. end
  629. end
  630. return nil
  631. end
  632. -- 数量不同
  633. local additions = {}
  634. if #trunkL.branches < #trunkC.branches then
  635. for i = #trunkL.branches+1, #trunkC.branches do
  636. tinsert(additions, trunkC.branches[i])
  637. end
  638. end
  639. local rmvitemsL = {}
  640. local insertitemsL = {}
  641. for index, branch in ipairs(trunkL.branches) do
  642. local branchL = branch
  643. local branchC = trunkC.branches[index]
  644. local compareR = SUILoader.compareSWidget(branchL, branchC)
  645. if compareR == 0 then
  646. tinsert(rmvitemsL, branchL)
  647. elseif compareR == 1 and backgroundR == 1 then
  648. if SUILoader.isBackground(branchL) and SUILoader.isBackground(branchC) then
  649. background = branchL
  650. end
  651. local element = branchC.element
  652. if element.type == "ListView" and tonumber(element.attr.reload) == 2 then
  653. local default = tonumber(element.attr.default)
  654. if branchL.element then
  655. branchL.element.attr.default = default
  656. end
  657. end
  658. self:reload_render(branchL)
  659. fixBranches(branchL, branchC)
  660. elseif backgroundR ~= 1 or compareR == -1 or compareR == -2 or compareR == -3 or compareR == -4 or compareR == -5 or compareR == -6 then
  661. tinsert(rmvitemsL, branchL)
  662. tinsert(insertitemsL, {branch=branchC, index=index})
  663. end
  664. end
  665. for index, branch in ipairs(rmvitemsL) do
  666. trunkL:removeBranch(branch)
  667. end
  668. for index, item in ipairs(insertitemsL) do
  669. trunkL:insertBranch(item.branch, item.index)
  670. end
  671. for index, branch in ipairs(additions) do
  672. trunkL:addBranch(branch)
  673. end
  674. end
  675. fixBranches(lastTrunk, trunk)
  676. --
  677. trunk = lastTrunk
  678. end
  679. -- load trunk render
  680. if trunk and not trunk.render then
  681. trunk.render = self:load_render(trunk, callback, closeCB)
  682. end
  683. ---
  684. if parentNode and not trunk.render:getParent() then
  685. trunk.render:addTo(parentNode)
  686. end
  687. -- load background render
  688. if background and not background.render then
  689. background.render = self:load_render(background, callback, closeCB)
  690. trunk:addBranchRender(background)
  691. end
  692. -- size
  693. if background and background.render and SUILoader.modifySizeAble(background) then
  694. local size = SUILoader.fixSize(background)
  695. background.render:ignoreContentAdaptWithSize(false)
  696. background.render:setContentSize(size)
  697. end
  698. local root_anchor = cc.p(0, 0)
  699. local root_position = cc.p(mfloor(rootRect.x), 0)
  700. local root_size = cc.size(rootRect.width, rootRect.height)
  701. if background then
  702. local root_show = tonumber(background.element.attr.show) or 0
  703. if root_show == 0 then
  704. -- 左上
  705. root_anchor = cc.p(0, 1)
  706. root_position = cc.p(mfloor(rootRect.x), rootRect.height)
  707. root_size = background.render:getContentSize()
  708. elseif root_show == 1 then
  709. -- 右上
  710. root_anchor = cc.p(1, 1)
  711. root_position = cc.p(rootRect.width, rootRect.height)
  712. root_size = background.render:getContentSize()
  713. elseif root_show == 2 then
  714. -- 左下
  715. root_anchor = cc.p(0, 0)
  716. root_position = cc.p(mfloor(rootRect.x), 0)
  717. root_size = background.render:getContentSize()
  718. elseif root_show == 3 then
  719. -- 右下
  720. root_anchor = cc.p(1, 0)
  721. root_position = cc.p(rootRect.width, 0)
  722. root_size = background.render:getContentSize()
  723. elseif root_show == 4 then
  724. -- 中间
  725. root_anchor = cc.p(0.5, 0.5)
  726. root_position = cc.p(mfloor((rootRect.width)/2), mfloor(rootRect.height/2))
  727. root_size = background.render:getContentSize()
  728. -- 尺寸处理成偶数,防止特效抖动
  729. root_size = {width = ConvertToEven(root_size.width), height = ConvertToEven(root_size.height)}
  730. elseif root_show == 5 or root_show == 6 then
  731. -- 中间铺满
  732. local attr = background.element.attr
  733. root_size = (attr.width or attr.height) and background.render:getContentSize() or root_size
  734. root_anchor = cc.p(0.5, 0.5)
  735. root_position = cc.p(mfloor((rootRect.width)/2), mfloor(rootRect.height/2))
  736. background.element.attr.tax = 0.5
  737. background.element.attr.tay = 0.5
  738. background.element.attr.tpercentx = 50
  739. background.element.attr.tpercenty = 50
  740. -- 尺寸处理成偶数,防止特效抖动
  741. root_size = {width = ConvertToEven(root_size.width), height = ConvertToEven(root_size.height)}
  742. elseif root_show == 7 then
  743. -- 上下居中
  744. root_anchor.y = 0.5
  745. root_position.y = mfloor(rootRect.height / 2)
  746. root_size = background.render:getContentSize()
  747. -- 尺寸处理成偶数,防止特效抖动
  748. root_size.height = ConvertToEven(root_size.height)
  749. elseif root_show == 8 then
  750. -- 左右居中
  751. root_anchor.x = 0.5
  752. root_position.x = mfloor(rootRect.width / 2)
  753. root_size = background.render:getContentSize()
  754. -- 尺寸处理成偶数,防止特效抖动
  755. root_size.width = ConvertToEven(root_size.width)
  756. end
  757. end
  758. trunk.render:setContentSize(root_size)
  759. trunk.render:setAnchorPoint(root_anchor)
  760. trunk.render:setPosition(root_position)
  761. trunk.render:stopAllActions()
  762. -- load background attr
  763. if background and background.render then
  764. SUILoader.loadSWidgetAttr(background)
  765. end
  766. -- DEBUG
  767. if DEBUG_MODE then
  768. trunk.render:setBackGroundColor(cc.Color3B.RED)
  769. trunk.render:setBackGroundColorType(1)
  770. trunk.render:setBackGroundColorOpacity(80)
  771. end
  772. ---------------------------------------
  773. -- load renders
  774. local function loadBranchRenders(loadTrunk)
  775. if #loadTrunk.branches == 0 then
  776. return nil
  777. end
  778. for _, branch in ipairs(loadTrunk.branches) do
  779. if not branch.render then
  780. local render = self:load_render(branch, callback, closeCB)
  781. if render then
  782. branch.render = render
  783. -- add to trunk
  784. loadTrunk:addBranchRender(branch)
  785. -- load show attr
  786. SUILoader.loadSWidgetAttr(branch)
  787. if loadTrunk.element.type == "ListView" then
  788. if loadTrunk.element.attr.default and tonumber(loadTrunk.element.attr.default) then
  789. local default = tonumber(loadTrunk.element.attr.default) - 1
  790. local index = math.max(default, 0)
  791. loadTrunk.render:jumpToItem(index, cc.p(0, 0), cc.p(0, 0))
  792. end
  793. loadTrunk.render:doLayout()
  794. end
  795. if loadTrunk.element.type == "PageView" then
  796. if loadTrunk.element.attr.default and tonumber(loadTrunk.element.attr.default) then
  797. local default = tonumber(loadTrunk.element.attr.default) - 1
  798. local index = math.max(default, 0)
  799. loadTrunk.render:setCurrentPageIndex(index)
  800. end
  801. loadTrunk.render:doLayout()
  802. end
  803. end
  804. end
  805. end
  806. end
  807. -- load immediate flag, edit form background
  808. local loadCount = 1
  809. local loadStep = 50
  810. if background then
  811. if isImmediate == false then
  812. isImmediate = true
  813. --
  814. if tonumber(background.element.attr.loadDelay) == 1 then
  815. isImmediate = false
  816. end
  817. end
  818. loadCount = tonumber(background.element.attr.loadCount) or loadCount
  819. loadStep = tonumber(background.element.attr.loadStep) or loadStep
  820. if npcLayer then
  821. npcLayer.background = background
  822. end
  823. end
  824. if isImmediate then
  825. local function loadBranch(loadTrunk)
  826. if #loadTrunk.branches > 0 then
  827. loadBranchRenders(loadTrunk)
  828. for _, branch in ipairs(loadTrunk.branches) do
  829. loadBranch(branch)
  830. end
  831. end
  832. end
  833. loadBranch(trunk)
  834. -- 装载完成
  835. if loadCompleteCB then
  836. loadCompleteCB()
  837. end
  838. else
  839. local loadQueue = {}
  840. local loadTrunk = nil
  841. tinsert(loadQueue, trunk)
  842. local function scheduleCB(sender, loadInit)
  843. local step = loadInit and loadCount or loadStep
  844. for i=1, step do
  845. if #loadQueue == 0 then
  846. trunk.render:stopAllActions()
  847. -- 装载完成
  848. if loadCompleteCB then
  849. loadCompleteCB()
  850. end
  851. return
  852. end
  853. -- load render
  854. loadTrunk = tremove(loadQueue, 1)
  855. loadBranchRenders(loadTrunk)
  856. if #loadTrunk.branches > 0 then
  857. for _, branch in ipairs(loadTrunk.branches) do
  858. if #branch.branches > 0 then
  859. tinsert(loadQueue, branch)
  860. end
  861. end
  862. end
  863. end
  864. end
  865. schedule(trunk.render, scheduleCB, interval)
  866. scheduleCB(trunk.render, true)
  867. end
  868. return trunk, background
  869. end
  870. function SUILoader:load_action(source)
  871. if not source then
  872. return nil
  873. end
  874. local find_info = {sfind(source, "{(.+)}")}
  875. if not (find_info[1] and find_info[2] and string.len(find_info[3]) > 0) then
  876. return nil
  877. end
  878. local actions = {}
  879. local slices = ssplit(find_info[3], ";")
  880. for _, slice in ipairs(slices) do
  881. local slice_info = {sfind(slice, "(.+):(.+)")}
  882. local action_type = tonumber(slice_info[3])
  883. local params = ssplit(slice_info[4], "#")
  884. if action_type == 1 then
  885. table.insert(actions, cc.ScaleTo:create(tonumber(params[1]), tonumber(params[2]), tonumber(params[2])))
  886. elseif action_type == 2 then
  887. dump(params)
  888. table.insert(actions, cc.FadeTo:create(tonumber(params[1]), tonumber(params[2])))
  889. end
  890. end
  891. if not next(actions) then
  892. return nil
  893. end
  894. return cc.Sequence:create(actions)
  895. end
  896. function SUILoader:reload_render(swidget)
  897. local element = swidget.element
  898. if element.type == "ListView" then
  899. local default = tonumber(element.attr.default)
  900. if default and swidget.render then
  901. -- default
  902. local function callback()
  903. local index = math.max(default - 1, 0)
  904. swidget.render:jumpToItem(index, cc.p(0, 0), cc.p(0, 0))
  905. swidget.render:doLayout()
  906. end
  907. performWithDelay(swidget.render, callback, 1/60)
  908. end
  909. end
  910. if element.type == "PageView" then
  911. local default = tonumber(element.attr.default)
  912. if default and swidget.render then
  913. -- default
  914. local function callback()
  915. local index = math.max(default - 1, 0)
  916. swidget.render:setCurrentPageIndex(index)
  917. swidget.render:doLayout()
  918. end
  919. performWithDelay(swidget.render, callback, 1/60)
  920. end
  921. end
  922. end
  923. function SUILoader:load_render(swidget, callback, closeCB)
  924. local element = swidget.element
  925. local loader = self._loaders[element.type]
  926. if nil == loader then
  927. print("load render error")
  928. return nil
  929. end
  930. local render = loader(swidget, callback, closeCB)
  931. render:setCascadeOpacityEnabled(true)
  932. render:setName(element.attr.id)
  933. return render
  934. end
  935. function SUILoader:linkFuncWithCheckWords(callback, param)
  936. if not callback or not param then
  937. return
  938. end
  939. local fixInput = param.Input
  940. local function checkFunc(i)
  941. local v = fixInput[i]
  942. if v and (v.isChatInput or v.isNameInput) then
  943. local isNameCheck = v.isNameInput
  944. local isChatCheck = v.isChatInput
  945. if isNameCheck and IsForbidName(true) then
  946. return
  947. end
  948. if isChatCheck and IsForbidSay(true) then
  949. return
  950. end
  951. local SensitiveWordProxy = global.Facade:retrieveProxy(global.ProxyTable.SensitiveWordProxy)
  952. local function handle_Func(state, str, risk_param)
  953. if not str then
  954. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1006))
  955. return
  956. end
  957. v.value = str
  958. if i == #fixInput then
  959. param.Input = (#fixInput > 0 and fixInput or nil)
  960. callback(param)
  961. else
  962. checkFunc(i + 1)
  963. end
  964. end
  965. if isNameCheck then
  966. SensitiveWordProxy:IsHaveSensitiveAddFilter(v.value, handle_Func)
  967. else
  968. SensitiveWordProxy:fixSensitiveTalkAddFilter(v.value, handle_Func, nil)
  969. end
  970. else
  971. if i == #fixInput then
  972. param.Input = (#fixInput > 0 and fixInput or nil)
  973. callback(param)
  974. else
  975. checkFunc(i + 1)
  976. end
  977. end
  978. end
  979. if fixInput and #fixInput > 0 then
  980. checkFunc(1)
  981. else
  982. callback(param)
  983. end
  984. end
  985. function SUILoader:load_render_Text(swidget, callback)
  986. local element = swidget.element
  987. local text = element.attr.text or ""
  988. local size = tonumber(element.attr.size) or defaultFontSize
  989. local color = element.attr.color or defaultColorID
  990. local link = element.attr.link
  991. local width = tonumber(element.attr.width)
  992. local outline = tonumber(element.attr.outline) or defaultOutline
  993. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  994. local scrollWidth = tonumber(element.attr.scrollWidth)
  995. local submitInput = element.attr.submitInput
  996. local submitCheckBox = element.attr.submitCheckBox
  997. local auto = tonumber(element.attr.auto)
  998. local platform = tonumber(element.attr.platform)
  999. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  1000. local tips = element.attr.tips
  1001. local tipsx = tonumber(element.attr.tipsx) or 0
  1002. local tipsy = tonumber(element.attr.tipsy) or 0
  1003. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  1004. local simplenum = tonumber(element.attr.simplenum) or 0
  1005. local scrollWay = tonumber(element.attr.scrollWay) or 0 -- 0 从右到左 1 从下到上
  1006. local scrollTime = tonumber(element.attr.scrollTime) or 4
  1007. local scrollHeight = tonumber(element.attr.scrollHeight)
  1008. local thouFormat = tonumber(element.attr.thouFormat) or 0
  1009. local hexColor = element.attr.hexcolor
  1010. local bl = math.floor(tonumber(element.attr.bl) or 0)
  1011. text = string.gsub(text, "\\", "\r\n")
  1012. text = string.trim(text)
  1013. if tonumber(text) and bl >= 1 and bl <= 3 then
  1014. local unitFunc = function(num, pointBit)
  1015. pointBit = pointBit or 2
  1016. if pointBit == 0 then
  1017. return math.floor(num)
  1018. end
  1019. local iNum, fNum = math.modf(num)
  1020. local fDecimal = math.pow(10, tostring(pointBit))
  1021. local newFNum = math.floor(tostring(fNum * fDecimal))
  1022. local newINum = iNum + (newFNum / fDecimal)
  1023. return newINum
  1024. end
  1025. local blValue = 100
  1026. if bl == 2 then
  1027. blValue = 10000
  1028. elseif bl == 3 then
  1029. blValue = 1000
  1030. end
  1031. text = string.format("%s%%", unitFunc(text/blValue))
  1032. end
  1033. --
  1034. local colorTable = {}
  1035. if tonumber(color) then
  1036. table.insert(colorTable, tonumber(color))
  1037. else
  1038. local slices = ssplit(color, ",")
  1039. for _, v in ipairs(slices) do
  1040. table.insert(colorTable, tonumber(v))
  1041. end
  1042. end
  1043. --
  1044. local useHex = false
  1045. local hexColorTable = {}
  1046. if hexColor then
  1047. local slices = ssplit(hexColor, ",")
  1048. for _, v in ipairs(slices) do
  1049. if string.len(v) > 0 and string.find(v, "#") then
  1050. table.insert(hexColorTable, v)
  1051. end
  1052. end
  1053. if #hexColorTable > 0 then
  1054. useHex = true
  1055. end
  1056. end
  1057. local widget = global.SWidgetCache:generateRender("ccui.Text")
  1058. widget:setScale(1)
  1059. widget:setString(text)
  1060. widget:setFontSize(size)
  1061. widget:setFontName(defaultFontPath)
  1062. widget:setTextColor(useHex and GetColorFromHexString(hexColorTable[1]) or GET_COLOR_BYID_C3B(colorTable[1]))
  1063. widget:setTouchEnabled(false)
  1064. widget:stopAllActions()
  1065. widget:disableEffect(1)
  1066. widget:disableEffect(6)
  1067. widget:getVirtualRenderer():setMaxLineWidth(0)
  1068. widget:enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  1069. -- 加入元变量组件管理
  1070. local isMateValue = false
  1071. local metaValue = {}
  1072. local content = text
  1073. while content and string.len(content) > 0 do
  1074. local find_info = {sfind(content, "$STM%((.-)%)")}
  1075. local begin_pos = find_info[1]
  1076. local end_pos = find_info[2]
  1077. if begin_pos and end_pos then
  1078. isMateValue = true
  1079. -- prefix
  1080. if begin_pos ~= 1 then
  1081. local substr = string.sub(content, 1, begin_pos - 1)
  1082. table.insert(metaValue, substr)
  1083. end
  1084. -- metaValue
  1085. local slices = ssplit(find_info[3], "_")
  1086. table.insert(metaValue, {key = slices[1], param = slices[2]})
  1087. -- suffix
  1088. content = string.sub(content, end_pos+1, string.len(content))
  1089. else
  1090. table.insert(metaValue, content)
  1091. content = ""
  1092. end
  1093. end
  1094. if isMateValue then
  1095. widget.useMetaValue = true
  1096. global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget, simplenum = simplenum, thouFormat = thouFormat})
  1097. end
  1098. -- width
  1099. if width then
  1100. local contentSize = widget:getContentSize()
  1101. local renderer = widget:getVirtualRenderer()
  1102. renderer:setMaxLineWidth(width)
  1103. end
  1104. -- link
  1105. if link and string.len(link) > 0 or (tips and string.len(tips) > 0) then
  1106. widget:setTouchEnabled(true)
  1107. widget:addClickEventListener(function()
  1108. DelayTouchEnabled(widget, clickInterval)
  1109. widget:setScale(1 + 0.2)
  1110. local function reback()
  1111. widget:setScale(1)
  1112. end
  1113. performWithDelay(widget, reback, 0.03)
  1114. if callback and link then
  1115. local inputTable = self:getInputTable(submitInput)
  1116. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  1117. local jsonData = {}
  1118. jsonData.Act = link
  1119. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  1120. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  1121. self:linkFuncWithCheckWords(callback, jsonData)
  1122. end
  1123. if not global.isWinPlayMode then
  1124. if tips and string.len(tips) > 0 then
  1125. local offset = cc.p(tipsx, -tipsy)
  1126. local anchorPoint = cc.p(0.5, 1)
  1127. tips = string.gsub(tips, "%^", "\\")
  1128. SHOW_SUI_DESCTIP( widget ,tips, tipWidth, offset, anchorPoint)
  1129. end
  1130. end
  1131. end)
  1132. -- 下划线
  1133. widget:getVirtualRenderer():enableUnderline()
  1134. end
  1135. -- auto color
  1136. local tbl = useHex and hexColorTable or colorTable
  1137. if #tbl > 1 then
  1138. local index = 1
  1139. local function callback()
  1140. index = index + 1
  1141. if index > #tbl then
  1142. index = 1
  1143. end
  1144. local color = useHex and GetColorFromHexString(tbl[index]) or GET_COLOR_BYID_C3B(tbl[index])
  1145. widget:setTextColor(color)
  1146. if link and string.len(link) > 0 then
  1147. -- 下划线
  1148. widget:getVirtualRenderer():disableEffect(6)
  1149. widget:getVirtualRenderer():enableUnderline()
  1150. end
  1151. end
  1152. schedule(widget, callback, 1)
  1153. end
  1154. self:addMouseOverTips(widget, element)
  1155. -- auto scroll
  1156. if scrollWidth then
  1157. local widgetSize = widget:getContentSize()
  1158. local scrollH = scrollHeight or widgetSize.height
  1159. local scrollLayout = global.SWidgetCache:generateRender("ccui.Layout")
  1160. scrollLayout:setClippingType(0)
  1161. scrollLayout:setClippingEnabled(true)
  1162. scrollLayout:setContentSize(cc.size(scrollWidth, scrollH))
  1163. scrollLayout:addChild(widget)
  1164. widget:setAnchorPoint(cc.p(0, 0))
  1165. widget:setPosition(cc.p(0, 0))
  1166. if scrollWay == 0 then
  1167. widget:runAction(cc.RepeatForever:create(cc.Sequence:create(
  1168. cc.MoveBy:create(scrollTime, cc.p(-widgetSize.width, 0)),
  1169. cc.MoveBy:create(0, cc.p(widgetSize.width, 0)))
  1170. ))
  1171. elseif scrollWay == 1 then
  1172. widget:setAnchorPoint(cc.p(0,1))
  1173. widget:setPosition(cc.p(0, scrollH))
  1174. widget:runAction(cc.RepeatForever:create(cc.Sequence:create(
  1175. cc.MoveBy:create(scrollTime, cc.p(0, widgetSize.height)),
  1176. cc.MoveBy:create(0, cc.p(0, -widgetSize.height))
  1177. )))
  1178. end
  1179. return scrollLayout
  1180. end
  1181. -- auto event
  1182. if widget:getChildByName("textAuto") then
  1183. widget:removeChildByName("textAuto")
  1184. end
  1185. if platform == global.OperatingMode and auto and link and string.len(link) > 0 then
  1186. local textAuto = ccui.Text:create()
  1187. widget:addChild(textAuto)
  1188. textAuto:setName("textAuto")
  1189. textAuto:setString(string.format("(%s)", auto))
  1190. textAuto:setFontSize(size)
  1191. textAuto:setFontName(defaultFontPath)
  1192. textAuto:setColor(cc.Color3B.WHITE)
  1193. textAuto:setAnchorPoint(cc.p(0, 0.5))
  1194. textAuto:setPosition(cc.p(widget:getContentSize().width + 3, widget:getContentSize().height/2))
  1195. widget:disableEffect(6)
  1196. local function autoCB()
  1197. auto = auto - 1
  1198. auto = math.max(auto, 0)
  1199. textAuto:setString(string.format("(%s)", auto))
  1200. if auto == 0 then
  1201. textAuto:stopAllActions()
  1202. textAuto:removeFromParent()
  1203. if callback then
  1204. local inputTable = self:getInputTable(submitInput)
  1205. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  1206. local jsonData = {}
  1207. jsonData.Act = link
  1208. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  1209. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  1210. self:linkFuncWithCheckWords(callback, jsonData)
  1211. end
  1212. end
  1213. end
  1214. schedule(textAuto, autoCB, 1)
  1215. end
  1216. if simplenum == 1 then
  1217. local text = widget:getString()
  1218. if text and tonumber(text) then
  1219. text = GetSimpleNumber(tonumber(text))
  1220. widget:setString(text)
  1221. end
  1222. end
  1223. if thouFormat == 1 then
  1224. local text = widget:getString()
  1225. if text and tonumber(text) then
  1226. text = string.formatnumberthousands(tonumber(text))
  1227. widget:setString(text)
  1228. end
  1229. end
  1230. return widget
  1231. end
  1232. function SUILoader:load_render_TextAtlas(swidget, callback)
  1233. local element = swidget.element
  1234. local img = element.attr.img or "public/word_tywz_01.png"
  1235. local iwidth = tonumber(element.attr.iwidth) or 18
  1236. local iheight = tonumber(element.attr.iheight) or 28
  1237. local schar = element.attr.schar or "0"
  1238. local text = element.attr.text or ""
  1239. local img = SUIHelper.fixImageFileName(img)
  1240. local fullPath = (img and img ~= "") and string.format(getResFullPath("res/%s"), img) or ""
  1241. if not fullPath or fullPath == "" or not global.FileUtilCtl:isFileExist(fullPath) then
  1242. img = SUIHelper.fixImageFileName("public/word_tywz_01.png")
  1243. fullPath = string.format(getResFullPath("res/%s"), img)
  1244. end
  1245. local widget = ccui.TextAtlas:create()
  1246. widget:setProperty( "", fullPath, iwidth, iheight, schar )
  1247. widget:setScale(1)
  1248. -- 加入元变量组件管理
  1249. local isMateValue = false
  1250. local metaValue = {}
  1251. local content = text
  1252. while content and string.len(content) > 0 do
  1253. local find_info = {sfind(content, "$STM%((.-)%)")}
  1254. local begin_pos = find_info[1]
  1255. local end_pos = find_info[2]
  1256. if begin_pos and end_pos then
  1257. isMateValue = true
  1258. -- prefix
  1259. if begin_pos ~= 1 then
  1260. local substr = string.sub(content, 1, begin_pos - 1)
  1261. table.insert(metaValue, substr)
  1262. end
  1263. -- metaValue
  1264. local slices = ssplit(find_info[3], "_")
  1265. table.insert(metaValue, {key = slices[1], param = slices[2]})
  1266. -- suffix
  1267. content = string.sub(content, end_pos+1, string.len(content))
  1268. else
  1269. table.insert(metaValue, content)
  1270. content = ""
  1271. end
  1272. end
  1273. if isMateValue then
  1274. widget.useMetaValue = true
  1275. global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget})
  1276. else
  1277. widget:setString(text)
  1278. end
  1279. return widget
  1280. end
  1281. function SUILoader:load_render_RText(swidget, callback)
  1282. local element = swidget.element
  1283. local text = element.attr.text or ""
  1284. local size = tonumber(element.attr.size) or defaultFontSize
  1285. local color = tonumber(element.attr.color) or defaultColorID
  1286. local width = tonumber(element.attr.width) or 1136
  1287. local link = element.attr.link
  1288. local submitInput = element.attr.submitInput
  1289. local submitCheckBox = element.attr.submitCheckBox
  1290. local outline = tonumber(element.attr.outline) or defaultOutline
  1291. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  1292. local scrollWidth = tonumber(element.attr.scrollWidth)
  1293. local scrollWay = tonumber(element.attr.scrollWay) or 0 -- 0 从右到左 1 从下到上
  1294. local scrollTime = tonumber(element.attr.scrollTime) or 4
  1295. local scrollHeight = tonumber(element.attr.scrollHeight)
  1296. local function textCB(str)
  1297. if callback then
  1298. local jsonData = {}
  1299. jsonData.Act = str
  1300. callback(jsonData)
  1301. end
  1302. end
  1303. local ttfConfig = {
  1304. outlineSize = outline,
  1305. outlineColor = GET_COLOR_BYID_C3B(outlinecolor)
  1306. }
  1307. local SUI_RTEXT_FONT_PATH = SL:GetMetaValue("WINPLAYMODE") and SL:GetMetaValue("GAME_DATA","SUI_RTEXT_FONT_PATH") or nil
  1308. local fontPath = SUI_RTEXT_FONT_PATH or defaultFontPath
  1309. local widget = RichTextHelp:CreateRichTextWithFCOLOR(text, width, size, color, ttfConfig, textCB, SL:GetMetaValue("GAME_DATA","DEFAULT_VSPACE"), fontPath)
  1310. self:addMouseOverTips(widget, element)
  1311. -- auto scroll
  1312. if scrollWidth then
  1313. local widgetSize = widget:getContentSize()
  1314. local scrollH = scrollHeight or widgetSize.height
  1315. local scrollLayout = global.SWidgetCache:generateRender("ccui.Layout")
  1316. scrollLayout:setClippingEnabled(true)
  1317. scrollLayout:setClippingType(0)
  1318. scrollLayout:setContentSize(cc.size(scrollWidth, scrollH))
  1319. scrollLayout:addChild(widget)
  1320. widget:setAnchorPoint(cc.p(0, 0))
  1321. widget:setPosition(cc.p(0, 0))
  1322. if scrollWay == 0 then
  1323. widget:runAction(cc.RepeatForever:create(cc.Sequence:create(
  1324. cc.MoveBy:create(scrollTime, cc.p(-widgetSize.width, 0)),
  1325. cc.MoveBy:create(0, cc.p(widgetSize.width, 0)))
  1326. ))
  1327. elseif scrollWay == 1 then
  1328. widget:setAnchorPoint(cc.p(0, 1))
  1329. widget:setPosition(cc.p(0, scrollH))
  1330. widget:runAction(cc.RepeatForever:create(cc.Sequence:create(
  1331. cc.MoveBy:create(scrollTime, cc.p(0, widgetSize.height)),
  1332. cc.MoveBy:create(0, cc.p(0, -widgetSize.height))
  1333. )))
  1334. end
  1335. return scrollLayout
  1336. end
  1337. return widget
  1338. end
  1339. function SUILoader:load_render_Img(swidget, callback)
  1340. local element = swidget.element
  1341. local bg = tonumber(element.attr.bg)
  1342. local img = element.attr.img or ""
  1343. local link = element.attr.link
  1344. local width = tonumber(element.attr.width)
  1345. local height = tonumber(element.attr.height)
  1346. local scale9l = tonumber(element.attr.scale9l)
  1347. local scale9r = tonumber(element.attr.scale9r)
  1348. local scale9t = tonumber(element.attr.scale9t)
  1349. local scale9b = tonumber(element.attr.scale9b)
  1350. local submitInput = element.attr.submitInput
  1351. local submitCheckBox = element.attr.submitCheckBox
  1352. local grey = tonumber(element.attr.grey) or 0
  1353. local flip = tonumber(element.attr.flip) or 0
  1354. local tips = element.attr.tips
  1355. local tipsx = tonumber(element.attr.tipsx) or 0
  1356. local tipsy = tonumber(element.attr.tipsy) or 0
  1357. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  1358. local mainIndex = element.attr._mainIndex
  1359. local widget = nil
  1360. local img = SUIHelper.fixImageFileName(img)
  1361. local fullPath = (img and img ~= "") and string.format(getResFullPath("res/%s"), img) or ""
  1362. if not fullPath or fullPath == "" or not global.FileUtilCtl:isFileExist(fullPath) then
  1363. widget = global.SWidgetCache:generateEmptyImageRender("ccui.ImageView")
  1364. else
  1365. widget = global.SWidgetCache:generateRender("ccui.ImageView")
  1366. end
  1367. widget:loadTexture(fullPath)
  1368. widget:ignoreContentAdaptWithSize(false)
  1369. widget:setContentSize(widget:getVirtualRendererSize())
  1370. widget:setCapInsets(cc.rect(0, 0, 0, 0))
  1371. widget:setScale9Enabled(false)
  1372. widget:setTouchEnabled(false)
  1373. if scale9l and scale9r and scale9t and scale9b then
  1374. local contentSize = widget:getContentSize()
  1375. local x = scale9l
  1376. local y = scale9t
  1377. local width = contentSize.width-scale9l-scale9r
  1378. local height = contentSize.height-scale9t-scale9b
  1379. widget:setScale9Enabled(true)
  1380. widget:setCapInsets({x = x, y = y, width = width, height = height})
  1381. end
  1382. -- link
  1383. widget._linkClick = false
  1384. if link and string.len(link) > 0 then
  1385. widget:setTouchEnabled(true)
  1386. widget:addClickEventListener(function()
  1387. if mainIndex then
  1388. -- 数据上报
  1389. local NativeBridgeProxy = global.Facade:retrieveProxy(global.ProxyTable.NativeBridgeProxy)
  1390. NativeBridgeProxy:GN_MainUIClickEvent({
  1391. index = mainIndex,
  1392. id = element.attr.id,
  1393. link = link
  1394. })
  1395. end
  1396. if callback and link then
  1397. local inputTable = self:getInputTable(submitInput)
  1398. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  1399. local jsonData = {}
  1400. jsonData.Act = link
  1401. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  1402. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  1403. self:linkFuncWithCheckWords(callback, jsonData)
  1404. end
  1405. if not global.isWinPlayMode then
  1406. if tips and string.len(tips) > 0 then
  1407. local offset = cc.p(tipsx, -tipsy)
  1408. local anchorPoint = cc.p(0.5, 1)
  1409. tips = string.gsub(tips, "%^", "\\")
  1410. SHOW_SUI_DESCTIP( widget ,tips, tipWidth, offset, anchorPoint)
  1411. end
  1412. end
  1413. end)
  1414. if bg == 1 then
  1415. widget._linkClick = true
  1416. end
  1417. end
  1418. if bg == 1 then
  1419. widget:setTouchEnabled(true)
  1420. if global.isWinPlayMode then
  1421. widget:setMouseEnabled(true)
  1422. global.mouseEventController:registerMouseMoveEvent(widget)
  1423. end
  1424. end
  1425. self:addMouseOverTips(widget, element)
  1426. -- grey
  1427. if grey == 1 then
  1428. Shader_Grey(widget)
  1429. else
  1430. Shader_Normal(widget)
  1431. end
  1432. if flip == 1 then
  1433. widget:setFlippedX(true)
  1434. elseif flip == 2 then
  1435. widget:setFlippedY(true)
  1436. end
  1437. return widget
  1438. end
  1439. function SUILoader:load_render_Button(swidget, callback, closeCB)
  1440. local element = swidget.element
  1441. local nimg = element.attr.nimg
  1442. local pimg = element.attr.pimg
  1443. local mimg = element.attr.mimg
  1444. local text = element.attr.text or ""
  1445. local color = tonumber(element.attr.color) or defaultColorID
  1446. local size = tonumber(element.attr.size) or defaultFontSize
  1447. local width = tonumber(element.attr.width)
  1448. local height = tonumber(element.attr.height)
  1449. local link = element.attr.link
  1450. local submitInput = element.attr.submitInput
  1451. local submitCheckBox = element.attr.submitCheckBox
  1452. local tips = element.attr.tips
  1453. local tipsx = tonumber(element.attr.tipsx) or 0
  1454. local tipsy = tonumber(element.attr.tipsy) or 0
  1455. local textWidth = tonumber(element.attr.textwidth)
  1456. local grey = tonumber(element.attr.grey) or 0
  1457. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  1458. local outline = tonumber(element.attr.outline) or defaultOutline
  1459. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  1460. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  1461. local mainIndex = element.attr._mainIndex
  1462. text = string.gsub(text, "\\", "\r\n")
  1463. text = string.trim(text)
  1464. local nimg = SUIHelper.fixImageFileName(nimg)
  1465. local pimg = SUIHelper.fixImageFileName(pimg)
  1466. local mimg = SUIHelper.fixImageFileName(mimg)
  1467. local fullPathN = (nimg and string.len(nimg) > 0 and string.format(getResFullPath( "res/%s" ), nimg) or "")
  1468. local fullPathP = (pimg and string.len(pimg) > 0 and string.format(getResFullPath( "res/%s" ), pimg) or "")
  1469. local fullPathM = (mimg and string.len(mimg) > 0 and string.format(getResFullPath( "res/%s" ), mimg) or "")
  1470. local widget = nil
  1471. local isNormalExist = fullPathN ~= "" and global.FileUtilCtl:isFileExist(fullPathN)
  1472. local isPressExist = fullPathP ~= "" and global.FileUtilCtl:isFileExist(fullPathP)
  1473. local isMouseExist = fullPathM ~= "" and global.FileUtilCtl:isFileExist(fullPathM)
  1474. local Button_Type = 1
  1475. --1-normalAndPress 2-Normal 3-Press 4-nil
  1476. if isNormalExist and isPressExist then
  1477. Button_Type = 1
  1478. elseif isNormalExist then
  1479. Button_Type = 2
  1480. elseif isPressExist then
  1481. Button_Type = 3
  1482. else
  1483. Button_Type = 4
  1484. end
  1485. widget = global.SWidgetCache:generateButtonRender(Button_Type)
  1486. widget:resetNormalRender()
  1487. widget:resetPressedRender()
  1488. widget:setTitleText(text)
  1489. widget:setTitleColor(GET_COLOR_BYID_C3B(color))
  1490. widget:setTitleFontName(defaultFontPath)
  1491. widget:setTitleFontSize(size)
  1492. widget:setTouchEnabled(false)
  1493. widget:getTitleRenderer():setMaxLineWidth(0)
  1494. widget:getTitleRenderer():enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  1495. if isNormalExist then
  1496. widget:loadTextureNormal(fullPathN)
  1497. end
  1498. if isPressExist then
  1499. widget:loadTexturePressed(fullPathP)
  1500. end
  1501. --
  1502. widget:ignoreContentAdaptWithSize(false)
  1503. widget:setContentSize(widget:getVirtualRendererSize())
  1504. local showTips = tips and string.len(tips) > 0
  1505. if isNormalExist and (isMouseExist or showTips) then
  1506. if global.isWinPlayMode then
  1507. local function checkResType(path)
  1508. if global.SpriteFrameCache:getSpriteFrame(path) then
  1509. return 1
  1510. end
  1511. if global.FileUtilCtl:isFileExist(path) then
  1512. return 0
  1513. end
  1514. return 0
  1515. end
  1516. local function checkRes(path)
  1517. local resType = checkResType(path)
  1518. if isMouseExist and isNormalExist then
  1519. widget:loadTextureNormal(path, resType)
  1520. end
  1521. end
  1522. local offset = cc.p(tipsx, -tipsy)
  1523. local anchor = cc.p(0.5, 1)
  1524. local function enterCB(touchPos)
  1525. if global.userInputController:isTouching() or not widget:isVisible() then
  1526. return false
  1527. end
  1528. if not CheckNodeCanCallBack(widget, touchPos) then
  1529. return false
  1530. end
  1531. checkRes(fullPathM)
  1532. if showTips then
  1533. tips = string.gsub(tips, "%^", "\\")
  1534. showMouseOverTips(widget, tips, offset, anchor)
  1535. end
  1536. end
  1537. local function leaveCB()
  1538. checkRes(fullPathN)
  1539. hideMouseOverTips()
  1540. end
  1541. -- widget:loadTextureMouseOver(fullPathN, fullPathM, enterCB, leaveCB)
  1542. global.mouseEventController:registerMouseMoveEvent(
  1543. widget,
  1544. {
  1545. enter = enterCB,
  1546. leave = leaveCB,
  1547. checkIsVisible = true
  1548. }
  1549. )
  1550. end
  1551. end
  1552. -- 加入元变量组件管理
  1553. local isMateValue = false
  1554. local metaValue = {}
  1555. local content = text
  1556. while content and string.len(content) > 0 do
  1557. local find_info = {sfind(content, "$STM%((.-)%)")}
  1558. local begin_pos = find_info[1]
  1559. local end_pos = find_info[2]
  1560. if begin_pos and end_pos then
  1561. isMateValue = true
  1562. -- prefix
  1563. if begin_pos ~= 1 then
  1564. local substr = string.sub(content, 1, begin_pos - 1)
  1565. table.insert(metaValue, substr)
  1566. end
  1567. -- metaValue
  1568. local slices = ssplit(find_info[3], "_")
  1569. table.insert(metaValue, {key = slices[1], param = slices[2]})
  1570. -- suffix
  1571. content = string.sub(content, end_pos+1, string.len(content))
  1572. else
  1573. table.insert(metaValue, content)
  1574. content = ""
  1575. end
  1576. end
  1577. if isMateValue then
  1578. widget.useMetaValue = true
  1579. global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget})
  1580. end
  1581. if textWidth then
  1582. local renderer = widget:getTitleRenderer()
  1583. renderer:setMaxLineWidth(textWidth)
  1584. end
  1585. -- link
  1586. if link and string.len(link) > 0 or (tips and string.len(tips) > 0) then
  1587. widget:setTouchEnabled(true)
  1588. widget:addClickEventListener(function()
  1589. DelayTouchEnabled(widget, clickInterval)
  1590. if mainIndex then
  1591. -- 数据上报
  1592. local NativeBridgeProxy = global.Facade:retrieveProxy(global.ProxyTable.NativeBridgeProxy)
  1593. NativeBridgeProxy:GN_MainUIClickEvent({
  1594. index = mainIndex,
  1595. id = element.attr.id,
  1596. link = link
  1597. })
  1598. end
  1599. if link == "@DEFAULT_CLOSE" then
  1600. if closeCB then
  1601. closeCB()
  1602. end
  1603. elseif callback and link then
  1604. local inputTable = self:getInputTable(submitInput)
  1605. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  1606. local jsonData = {}
  1607. jsonData.Act = link
  1608. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  1609. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  1610. self:linkFuncWithCheckWords(callback, jsonData)
  1611. end
  1612. if not global.isWinPlayMode then
  1613. if tips and string.len(tips) > 0 then
  1614. local offset = cc.p(tipsx, -tipsy)
  1615. local anchorPoint = cc.p(0.5, 1)
  1616. tips = string.gsub(tips, "%^", "\\")
  1617. SHOW_SUI_DESCTIP( widget ,tips, tipWidth, offset, anchorPoint)
  1618. end
  1619. end
  1620. end)
  1621. end
  1622. -- if nil == mimg then
  1623. -- self:addMouseOverTips(widget, element)
  1624. -- end
  1625. -- grey
  1626. if grey == 1 then
  1627. Shader_Grey(widget)
  1628. else
  1629. Shader_Normal(widget)
  1630. end
  1631. return widget
  1632. end
  1633. function SUILoader:load_render_CheckBox(swidget, callback)
  1634. local element = swidget.element
  1635. local checkboxid = element.attr.checkboxid
  1636. local nimg = element.attr.nimg
  1637. local pimg = element.attr.pimg
  1638. local default = tonumber(element.attr.default) or 0
  1639. local submit = tonumber(element.attr.submit) or 0
  1640. local delay = math.max(tonumber(element.attr.delay) or 0, 1/60)
  1641. local count = tonumber(element.attr.count) or 0
  1642. local link = element.attr.link
  1643. local nimg = SUIHelper.fixImageFileName(nimg)
  1644. local pimg = SUIHelper.fixImageFileName(pimg)
  1645. local widget = ccui.CheckBox:create()
  1646. widget:loadTextureBackGround(string.format(getResFullPath("res/%s"), nimg))
  1647. widget:loadTextureFrontCross(string.format(getResFullPath("res/%s"), pimg))
  1648. widget:setSelected(default == 1)
  1649. widget:setTouchEnabled(true)
  1650. widget:ignoreContentAdaptWithSize(false)
  1651. widget:stopAllActions()
  1652. -- link
  1653. if link and string.len(link) > 0 then
  1654. widget:addEventListener(function()
  1655. local counting = 0
  1656. local function delayCB()
  1657. if callback then
  1658. local checkBoxTable = self:getCheckBoxTableByID(checkboxid)
  1659. local jsonData = {}
  1660. jsonData.Act = link
  1661. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  1662. callback(jsonData)
  1663. end
  1664. counting = counting + 1
  1665. if count ~= -1 and counting >= count then
  1666. widget:stopAllActions()
  1667. end
  1668. end
  1669. widget:stopAllActions()
  1670. schedule(widget, delayCB, delay)
  1671. end)
  1672. end
  1673. if checkboxid and self._checkboxWidgets then
  1674. self._checkboxWidgets[checkboxid] = widget
  1675. end
  1676. return widget
  1677. end
  1678. function SUILoader:load_render_ListView(swidget, callback)
  1679. local element = swidget.element
  1680. local width = element.attr.width or 200
  1681. local height = element.attr.height or 200
  1682. local color = tonumber(element.attr.color)
  1683. local direction = tonumber(element.attr.direction) or 1
  1684. local bounce = tonumber(element.attr.bounce) or 1
  1685. local margin = tonumber(element.attr.margin) or 0
  1686. local default = tonumber(element.attr.default)
  1687. local cantouch = tonumber(element.attr.cantouch) or 1
  1688. local widget = global.SWidgetCache:generateRender("ccui.ListView")
  1689. widget:ignoreContentAdaptWithSize(false)
  1690. widget:setClippingEnabled(true)
  1691. widget:setClippingType(0)
  1692. widget:setTouchEnabled(true)
  1693. widget:setDirection(direction)
  1694. widget:setGravity(0)
  1695. widget:setItemsMargin(margin)
  1696. widget:setBounceEnabled(bounce == 1)
  1697. widget:setBackGroundColorType(0)
  1698. widget:stopAllActions()
  1699. if DEBUG_MODE then
  1700. widget:setBackGroundColorType(1)
  1701. widget:setBackGroundColorOpacity(100)
  1702. widget:setBackGroundColor(cc.Color3B.GREEN)
  1703. end
  1704. -- color
  1705. if color then
  1706. widget:setBackGroundColorType(1)
  1707. widget:setBackGroundColorOpacity(255)
  1708. widget:setBackGroundColor(GET_COLOR_BYID_C3B(color))
  1709. end
  1710. -- default
  1711. if default then
  1712. -- default
  1713. local function callback()
  1714. default = default - 1
  1715. local index = math.max(default, 0)
  1716. widget:jumpToItem(index, cc.p(0, 0), cc.p(0, 0))
  1717. widget:doLayout()
  1718. end
  1719. performWithDelay(widget, callback, 1/60)
  1720. end
  1721. if cantouch == 0 then
  1722. widget:setTouchEnabled(false)
  1723. else
  1724. widget._unRefPos = true
  1725. end
  1726. return widget
  1727. end
  1728. function SUILoader:load_render_Effect(swidget, callback)
  1729. local element = swidget.element
  1730. local effecttype = tonumber(element.attr.effecttype) or 0
  1731. local effectid = tonumber(element.attr.effectid) or 9999
  1732. local sex = tonumber(element.attr.sex) or 0
  1733. local act = tonumber(element.attr.act) or 0
  1734. local dir = tonumber(element.attr.dir) or 5
  1735. local speed = tonumber(element.attr.speed) or 1
  1736. local scale = tonumber(element.attr.scale) or 1
  1737. local count = tonumber(element.attr.count) or 0
  1738. local grey = tonumber(element.attr.grey) or 0
  1739. local link = element.attr.link
  1740. local scalex = tonumber(element.attr.scalex)
  1741. local scaley = tonumber(element.attr.scaley)
  1742. -- 0.普通特效 1.npc模型 2.怪物模型 3.技能特效 4.人物 5.武器 6.翅膀 7.发型 8.盾牌
  1743. local widget = nil
  1744. if effecttype == 0 then
  1745. -- 特效
  1746. widget = global.FrameAnimManager:CreateSFXAnim(effectid)
  1747. widget:Play(0, 0, true, speed)
  1748. elseif effecttype == 1 then
  1749. -- NPC
  1750. widget = global.FrameAnimManager:CreateActorNpcAnim(effectid)
  1751. widget:Play(act, dir, true, speed)
  1752. elseif effecttype == 2 then
  1753. -- 怪物
  1754. widget = global.FrameAnimManager:CreateActorMonsterAnim(effectid, act)
  1755. widget:Play(act, dir, true, speed)
  1756. elseif effecttype == 3 then
  1757. -- 技能
  1758. widget = global.FrameAnimManager:CreateSkillEffAnim(effectid, dir)
  1759. widget:Play(act, dir, true, speed)
  1760. elseif effecttype == 4 then
  1761. -- 人物
  1762. widget = global.FrameAnimManager:CreateActorPlayerAnim(effectid, sex, act)
  1763. widget:Play(act, dir, true, speed)
  1764. elseif effecttype == 5 then
  1765. -- 武器
  1766. widget = global.FrameAnimManager:CreateActorPlayerWeaponAnim(effectid, sex, act)
  1767. widget:Play(act, dir, true, speed)
  1768. elseif effecttype == 6 then
  1769. -- 翅膀
  1770. widget = global.FrameAnimManager:CreateActorPlayerWingsAnim(effectid, sex, act)
  1771. widget:Play(act, dir, true, speed)
  1772. elseif effecttype == 7 then
  1773. -- 发型
  1774. widget = global.FrameAnimManager:CreateActorPlayerHairAnim(effectid, sex, act)
  1775. widget:Play(act, dir, true, speed)
  1776. elseif effecttype == 8 then
  1777. -- 盾牌
  1778. widget = global.FrameAnimManager:CreateActorPlayerShieldAnim(effectid, sex, act)
  1779. widget:Play(act, dir, true, speed)
  1780. else
  1781. widget = global.FrameAnimManager:CreateSFXAnim(1)
  1782. widget:Play(0, 0, true, speed)
  1783. end
  1784. if widget then
  1785. widget:setScale(scale)
  1786. if not tonumber(element.attr.scale) and scalex then
  1787. widget:setScaleX(scalex)
  1788. end
  1789. if not tonumber(element.attr.scale) and scaley then
  1790. widget:setScaleY(scaley)
  1791. end
  1792. -- 播放次数
  1793. local counting = 0
  1794. widget:SetAnimEventCallback(
  1795. function(_, eventType)
  1796. counting = counting + 1
  1797. if counting == count then
  1798. if link then
  1799. if callback then
  1800. local jsonData = {}
  1801. jsonData.Act = link
  1802. callback(jsonData)
  1803. end
  1804. end
  1805. widget:Stop()
  1806. widget:setVisible(false)
  1807. end
  1808. end
  1809. )
  1810. -- 灰化处理
  1811. if grey == 1 then
  1812. Shader_Grey(widget)
  1813. else
  1814. Shader_Normal(widget)
  1815. end
  1816. end
  1817. return widget
  1818. end
  1819. function SUILoader:load_render_Frames(swidget, callback)
  1820. local element = swidget.element
  1821. local prefix = element.attr.prefix
  1822. local suffix = element.attr.suffix
  1823. local speed = tonumber(element.attr.speed) or 100
  1824. local count = tonumber(element.attr.count) or 1
  1825. local loop = tonumber(element.attr.loop) or -1
  1826. local finishframe = tonumber(element.attr.finishframe)
  1827. local finishhide = tonumber(element.attr.finishhide)
  1828. local link = element.attr.link
  1829. local submitInput = element.attr.submitInput
  1830. local submitCheckBox = element.attr.submitCheckBox
  1831. local img = SUIHelper.fixImageFileName(prefix .. "1" .. suffix)
  1832. local fullPath = string.format(getResFullPath("res/%s"), img)
  1833. local widget = nil
  1834. if global.FileUtilCtl:isFileExist(fullPath) then
  1835. widget = global.SWidgetCache:generateRender("ccui.ImageView")
  1836. else
  1837. widget = ccui.ImageView:create()
  1838. end
  1839. widget:loadTexture(fullPath)
  1840. widget:ignoreContentAdaptWithSize(false)
  1841. widget:setContentSize(widget:getVirtualRendererSize())
  1842. widget:setTouchEnabled(false)
  1843. widget:setCapInsets(cc.rect(0, 0, 0, 0))
  1844. widget:setScale9Enabled(false)
  1845. widget:stopAllActions()
  1846. local function finishCB()
  1847. if finishframe then
  1848. fullPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(prefix .. finishframe .. suffix))
  1849. widget:loadTexture(fullPath)
  1850. end
  1851. if finishhide == 1 then
  1852. widget:setVisible(false)
  1853. end
  1854. end
  1855. local index = 1
  1856. local counting = 0
  1857. local function delayCB()
  1858. fullPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(prefix .. index .. suffix))
  1859. widget:loadTexture(fullPath)
  1860. index = index + 1
  1861. if index > count then
  1862. index = 1
  1863. counting = counting + 1
  1864. if loop ~= -1 and counting >= loop then
  1865. widget:stopAllActions()
  1866. finishCB()
  1867. end
  1868. end
  1869. end
  1870. schedule(widget, delayCB, speed*0.01)
  1871. delayCB()
  1872. -- link
  1873. if link and string.len(link) > 0 then
  1874. widget:setTouchEnabled(true)
  1875. widget:addClickEventListener(function()
  1876. if callback then
  1877. local inputTable = self:getInputTable(submitInput)
  1878. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  1879. local jsonData = {}
  1880. jsonData.Act = link
  1881. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  1882. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  1883. self:linkFuncWithCheckWords(callback, jsonData)
  1884. end
  1885. end)
  1886. end
  1887. return widget
  1888. end
  1889. function SUILoader:load_render_Input(swidget, callback)
  1890. local element = swidget.element
  1891. local inputid = element.attr.inputid
  1892. local inputtype = tonumber(element.attr.type) or 0
  1893. local text = element.attr.text or ""
  1894. local place = element.attr.place
  1895. local placecolor = element.attr.placecolor or defaultColorID
  1896. local width = element.attr.width
  1897. local height = element.attr.height
  1898. local color = element.attr.color or defaultColorID
  1899. local size = tonumber(element.attr.size) or defaultFontSize
  1900. local mincount = element.attr.mincount
  1901. local maxcount = tonumber(element.attr.maxcount) or 10000
  1902. local errortips = element.attr.errortips
  1903. local submitInput = element.attr.submitInput
  1904. local submitCheckBox = element.attr.submitCheckBox
  1905. local linkType = tonumber(element.attr.linkType) or 1
  1906. local link = element.attr.link
  1907. local onlyCh = tonumber(element.attr.onlyCh) and tonumber(element.attr.onlyCh) == 1
  1908. local isChatInput = (tonumber(element.attr.isChatInput) or 1) == 1
  1909. local isNameInput = tonumber(element.attr.isNameInput) == 1
  1910. local fontPath = defaultFontPath
  1911. local widget = ccui.EditBox:create({width=width, height=height}, global.MMO.PATH_RES_ALPHA)
  1912. widget:setFontColor(GET_COLOR_BYID_C3B(tonumber(color)))
  1913. widget:setColor(GET_COLOR_BYID_C3B(tonumber(color)))
  1914. if global.isMobile then
  1915. widget:setFontName(fontPath)
  1916. end
  1917. widget:setFontSize(size)
  1918. widget:setString(text)
  1919. widget:setPlaceHolder(place)
  1920. widget:setPlaceholderFontColor(GET_COLOR_BYID_C3B(tonumber(placecolor)))
  1921. widget:setPlaceholderFontSize(size)
  1922. widget:setTextHorizontalAlignment(0)
  1923. widget:setMaxLength(maxcount)
  1924. -- native offset
  1925. if global.Platform == cc.PLATFORM_OS_WINDOWS then
  1926. elseif global.Platform == cc.PLATFORM_OS_ANDROID then
  1927. widget:setNativeOffset( cc.p( 0, -15 ) )
  1928. else
  1929. end
  1930. -- 输入类型
  1931. if inputtype == 1 or inputtype == 3 then
  1932. widget:setInputMode(2)
  1933. elseif inputtype == 2 then
  1934. widget:setInputFlag(0)
  1935. end
  1936. if inputid and self._inputWidgets then
  1937. self._inputWidgets[inputid] = {widget = widget, inputFlag = (inputtype ~= 1 and "INPUTTEXT" or ""), isChatInput = isChatInput, isNameInput = isNameInput}
  1938. end
  1939. local function eventCB(sender, eventType)
  1940. if eventType == 2 and onlyCh then
  1941. local str = sender:getString()
  1942. sender:setString(CheckInputOnlyChinese(str))
  1943. end
  1944. if eventType == 2 and (inputtype == 1 or inputtype == 3) then
  1945. local str = sender:getString()
  1946. if string.find(str,"[^%d]+") then
  1947. local s, d = string.find(str,"[^%d]+")
  1948. local str1 = string.sub(str, 1, s-1)
  1949. local str2 = string.sub(str, d+1)
  1950. sender:setString(str1..str2)
  1951. end
  1952. if inputtype == 3 then
  1953. local str = sender:getString()
  1954. local num = tonumber(str)
  1955. if num and tostring(num) ~= str then
  1956. sender:setString(num)
  1957. end
  1958. end
  1959. end
  1960. end
  1961. if link then
  1962. widget:addEventListener(function(sender, eventType)
  1963. eventCB(sender, eventType)
  1964. if linkType == eventType then
  1965. if callback then
  1966. local inputTable = self:getInputTable(submitInput)
  1967. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  1968. local jsonData = {}
  1969. jsonData.Act = link
  1970. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  1971. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  1972. self:linkFuncWithCheckWords(callback, jsonData)
  1973. end
  1974. end
  1975. end)
  1976. else
  1977. widget:addEventListener(eventCB)
  1978. end
  1979. return widget
  1980. end
  1981. function SUILoader:load_render_COUNTDOWN(swidget, callback)
  1982. local element = swidget.element
  1983. local time = tonumber(element.attr.time) or 10
  1984. local count = tonumber(element.attr.count) or 1
  1985. local color = tonumber(element.attr.color) or defaultColorID
  1986. local size = tonumber(element.attr.size) or defaultFontSize
  1987. local showWay = tonumber(element.attr.showWay) or 0
  1988. local outline = tonumber(element.attr.outline) or defaultOutline
  1989. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  1990. local link = element.attr.link
  1991. local widget = global.SWidgetCache:generateRender("ccui.Text")
  1992. if showWay == 1 then
  1993. widget:setString(TimeFormatToString(time))
  1994. else
  1995. widget:setString(string.format(GET_STRING(2006), time))
  1996. end
  1997. widget:setFontSize(size)
  1998. widget:setFontName(defaultFontPath)
  1999. widget:setTextColor(GET_COLOR_BYID_C3B(color))
  2000. widget:enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  2001. widget:setTouchEnabled(false)
  2002. widget:stopAllActions()
  2003. local counting = 0
  2004. local remaining = time
  2005. local function scheduleCallback()
  2006. if showWay == 1 then
  2007. widget:setString(TimeFormatToString(remaining))
  2008. else
  2009. widget:setString(string.format(GET_STRING(2006), remaining))
  2010. end
  2011. remaining = remaining - 1
  2012. if remaining < 0 then
  2013. -- link
  2014. if link and string.len(link) > 0 then
  2015. if callback then
  2016. local jsonData = {}
  2017. jsonData.Act = link
  2018. callback(jsonData)
  2019. end
  2020. end
  2021. remaining = time
  2022. counting = counting + 1
  2023. if count > 0 and counting >= count then
  2024. widget:stopAllActions()
  2025. end
  2026. end
  2027. end
  2028. schedule(widget, scheduleCallback, 1)
  2029. scheduleCallback()
  2030. return widget
  2031. end
  2032. function SUILoader:load_render_ItemShow(swidget, callback)
  2033. local element = swidget.element
  2034. local itemid = tonumber(element.attr.itemid) or 1
  2035. local itemcount = tonumber(element.attr.itemcount) or 1
  2036. local showtips = tonumber(element.attr.showtips) or 1
  2037. local bgtype = tonumber(element.attr.bgtype)
  2038. local scale = tonumber(element.attr.scale) or 1
  2039. local grey = tonumber(element.attr.grey) or 0
  2040. local lock = tonumber(element.attr.lock) or 0
  2041. local link = element.attr.link
  2042. local submitInput = element.attr.submitInput
  2043. local submitCheckBox = element.attr.submitCheckBox
  2044. local countColor = tonumber(element.attr.color) or defaultColorID
  2045. local dblink = element.attr.dblink
  2046. local effectshow = tonumber(element.attr.effectshow) or 1
  2047. local itemDataStr = element.attr.itemdata
  2048. local itemName = element.attr.itemname
  2049. local itemData = nil
  2050. if itemDataStr and string.len(tostring(itemDataStr)) > 0 then
  2051. local json = cjson.decode(itemDataStr)
  2052. if json and next(json) then
  2053. itemData = ChangeItemServersSendDatas(json)
  2054. end
  2055. end
  2056. if itemName and string.len(itemName) > 0 then
  2057. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  2058. local index = ItemConfigProxy:GetItemIndexByName(itemName)
  2059. if index and not tonumber(element.attr.itemid) then
  2060. itemid = index
  2061. end
  2062. end
  2063. local contentSize = cc.size(66,66)
  2064. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  2065. widget:setContentSize(contentSize)
  2066. local info = {}
  2067. info.index = itemid
  2068. info.look = showtips == 1
  2069. info.count = itemcount
  2070. info.bgVisible = bgtype == 1
  2071. info.color = countColor
  2072. info.itemData = itemData
  2073. if not info.look and global.isWinPlayMode then
  2074. info.noMouseTips = true
  2075. end
  2076. if effectshow == 2 then
  2077. info.showModelEffect = true
  2078. elseif effectshow == 0 then
  2079. info.isShowEff = false
  2080. end
  2081. local goodsItem = GoodsItem:create(info)
  2082. widget:addChild(goodsItem)
  2083. goodsItem:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  2084. goodsItem:setScale(scale)
  2085. goodsItem:setIconGrey(grey == 1)
  2086. if dblink and string.len(dblink) > 0 then
  2087. if not (showtips == 1) then
  2088. goodsItem:addLookItemInfoEvent(nil, 2)
  2089. end
  2090. goodsItem:addDoubleEventListener(function()
  2091. if callback then
  2092. local inputTable = self:getInputTable(submitInput)
  2093. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2094. local jsonData = {}
  2095. jsonData.Act = dblink
  2096. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2097. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2098. self:linkFuncWithCheckWords(callback, jsonData)
  2099. end
  2100. end)
  2101. end
  2102. if lock == 1 then
  2103. local imageLock = ccui.ImageView:create()
  2104. imageLock:setAnchorPoint(cc.p(0, 1))
  2105. goodsItem:addChild(imageLock)
  2106. if global.isWinPlayMode then
  2107. imageLock:setScale(0.7)
  2108. end
  2109. imageLock:loadTexture(global.MMO.PATH_RES_PUBLIC .. "lock.png")
  2110. imageLock:setPosition(cc.p(0, goodsItem:getContentSize().height))
  2111. end
  2112. if link and not dblink then
  2113. local linkWidget = global.SWidgetCache:generateRender("ccui.Widget")
  2114. widget:addChild(linkWidget)
  2115. linkWidget:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  2116. linkWidget:setContentSize(contentSize)
  2117. linkWidget:setTouchEnabled(true)
  2118. linkWidget:setSwallowTouches(false)
  2119. linkWidget:addClickEventListener(function()
  2120. if callback then
  2121. local inputTable = self:getInputTable(submitInput)
  2122. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2123. local jsonData = {}
  2124. jsonData.Act = link
  2125. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2126. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2127. self:linkFuncWithCheckWords(callback, jsonData)
  2128. end
  2129. end)
  2130. end
  2131. return widget
  2132. end
  2133. function SUILoader:load_render_DBItemShow(swidget, callback)
  2134. local element = swidget.element
  2135. local makeindex = tonumber(element.attr.makeindex) or 1
  2136. local showtips = tonumber(element.attr.showtips) or 1
  2137. local bgtype = tonumber(element.attr.bgtype)
  2138. local scale = tonumber(element.attr.scale) or 1
  2139. local grey = tonumber(element.attr.grey) or 0
  2140. local showstar = tonumber(element.attr.showstar) == 1
  2141. local count = tonumber(element.attr.count)
  2142. local link = element.attr.link
  2143. local submitInput = element.attr.submitInput
  2144. local submitCheckBox = element.attr.submitCheckBox
  2145. local dblink = element.attr.dblink
  2146. local effectshow = tonumber(element.attr.effectshow) or 1 -- 1只显示背包 2只显示内观 0不显示
  2147. local itemData = nil
  2148. if not itemData then
  2149. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  2150. itemData = EquipProxy:GetEquipDataByMakeIndex(makeindex)
  2151. end
  2152. if not itemData then
  2153. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  2154. itemData = BagProxy:GetItemDataByMakeIndex(makeindex)
  2155. end
  2156. if not itemData then
  2157. local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
  2158. itemData = QuickUseProxy:GetQucikUseDataByMakeIndex(makeindex)
  2159. end
  2160. if not itemData then
  2161. local LookPlayerProxy = global.Facade:retrieveProxy(global.ProxyTable.LookPlayerProxy)
  2162. itemData = LookPlayerProxy:GetLookPlayerItemDataByMakeIndex(makeindex)
  2163. end
  2164. local contentSize = cc.size(66,66)
  2165. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  2166. widget:setContentSize(contentSize)
  2167. if itemData then
  2168. local info = {}
  2169. info.index = itemData.Index
  2170. info.itemData = itemData
  2171. info.look = showtips == 1
  2172. info.bgVisible = bgtype == 1
  2173. info.starLv = showstar
  2174. if not info.look and global.isWinPlayMode then
  2175. info.noMouseTips = true
  2176. end
  2177. if effectshow == 2 then
  2178. info.showModelEffect = true
  2179. elseif effectshow == 0 then
  2180. info.isShowEff = false
  2181. end
  2182. local goodsItem = GoodsItem:create(info)
  2183. widget:addChild(goodsItem)
  2184. goodsItem:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  2185. goodsItem:setScale(scale)
  2186. goodsItem:setIconGrey(grey == 1)
  2187. if count then
  2188. goodsItem:setCount(count)
  2189. end
  2190. if dblink and string.len(dblink) then
  2191. if not (showtips == 1) then
  2192. goodsItem:addLookItemInfoEvent(nil, 2)
  2193. end
  2194. goodsItem:addDoubleEventListener(function()
  2195. if callback then
  2196. local inputTable = self:getInputTable(submitInput)
  2197. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2198. local jsonData = {}
  2199. jsonData.Act = dblink
  2200. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2201. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2202. self:linkFuncWithCheckWords(callback, jsonData)
  2203. end
  2204. end)
  2205. end
  2206. end
  2207. if link and string.len(link) > 0 and not dblink then
  2208. local linkWidget = global.SWidgetCache:generateRender("ccui.Widget")
  2209. widget:addChild(linkWidget)
  2210. linkWidget:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  2211. linkWidget:setContentSize(contentSize)
  2212. linkWidget:setTouchEnabled(true)
  2213. linkWidget:setSwallowTouches(false)
  2214. linkWidget:addClickEventListener(function()
  2215. if callback then
  2216. local inputTable = self:getInputTable(submitInput)
  2217. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2218. local jsonData = {}
  2219. jsonData.Act = link
  2220. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2221. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2222. self:linkFuncWithCheckWords(callback, jsonData)
  2223. end
  2224. end)
  2225. end
  2226. return widget
  2227. end
  2228. function SUILoader:load_render_CostItem(swidget, callback)
  2229. local element = swidget.element
  2230. local itemid = tonumber(element.attr.itemid) or 1
  2231. local itemcount = tonumber(element.attr.itemcount) or 1
  2232. local itemScale = tonumber(element.attr.itemscale)
  2233. local fontSize = tonumber(element.attr.fontsize)
  2234. local titleText = element.attr.title
  2235. local simplenum = tonumber(element.attr.simplenum) or 0
  2236. local CostItemCell = requireLayerUI("extra_layer/CostItemCell")
  2237. local widget = CostItemCell:create(string.format("%s#%s", itemid, itemcount), {itemScale = itemScale, titleText = titleText, fontSize = fontSize, simplenum = simplenum})
  2238. return widget
  2239. end
  2240. function SUILoader:load_render_Layout(swidget, callback)
  2241. local element = swidget.element
  2242. local width = tonumber(element.attr.width) or 1
  2243. local height = tonumber(element.attr.height) or 1
  2244. local color = tonumber(element.attr.color)
  2245. local link = element.attr.link
  2246. local submitInput = element.attr.submitInput
  2247. local submitCheckBox = element.attr.submitCheckBox
  2248. local clipEnable = (tonumber(element.attr.clip) or 0) == 1
  2249. local widget = global.SWidgetCache:generateRender("ccui.Layout")
  2250. widget:setContentSize(cc.size(width, height))
  2251. widget:setBackGroundColorType(0)
  2252. widget:setTouchEnabled(false)
  2253. if DEBUG_MODE then
  2254. widget:setBackGroundColorType(1)
  2255. widget:setBackGroundColorOpacity(100)
  2256. widget:setBackGroundColor(cc.Color3B.BLUE)
  2257. end
  2258. -- color
  2259. if color then
  2260. widget:setBackGroundColorType(1)
  2261. widget:setBackGroundColorOpacity(255)
  2262. widget:setBackGroundColor(GET_COLOR_BYID_C3B(color))
  2263. end
  2264. -- clip
  2265. if clipEnable then
  2266. widget:setClippingEnabled(true)
  2267. widget:setClippingType(0)
  2268. end
  2269. -- link
  2270. if link and string.len(link) > 0 then
  2271. widget:setTouchEnabled(true)
  2272. widget:addClickEventListener(function()
  2273. if callback then
  2274. local inputTable = self:getInputTable(submitInput)
  2275. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2276. local jsonData = {}
  2277. jsonData.Act = link
  2278. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2279. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2280. self:linkFuncWithCheckWords(callback, jsonData)
  2281. end
  2282. end)
  2283. end
  2284. return widget
  2285. end
  2286. function SUILoader:load_render_ITEMBOX(swidget, callback)
  2287. local element = swidget.element
  2288. local width = tonumber(element.attr.width) or 1
  2289. local height = tonumber(element.attr.height) or 1
  2290. local boxindex = tonumber(element.attr.boxindex)
  2291. local img = element.attr.img
  2292. local stdmode = element.attr.stdmode
  2293. local img = SUIHelper.fixImageFileName(img)
  2294. local fullPath = string.format(getResFullPath("res/%s"), img)
  2295. local widget = nil
  2296. if img and img ~= "" and global.FileUtilCtl:isFileExist(fullPath) then
  2297. widget = global.SWidgetCache:generateRender("ccui.ImageView")
  2298. else
  2299. widget = ccui.ImageView:create()
  2300. end
  2301. widget:loadTexture(fullPath)
  2302. widget:ignoreContentAdaptWithSize(false)
  2303. widget:setContentSize(widget:getVirtualRendererSize())
  2304. widget:setCapInsets(cc.rect(0, 0, 0, 0))
  2305. widget:setScale9Enabled(false)
  2306. widget:setTouchEnabled(true)
  2307. --
  2308. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  2309. local function addItemToITEMBOX(touchPos)
  2310. local state = ItemMoveProxy:GetMovingItemState()
  2311. if state then
  2312. local goToName = ItemMoveProxy.ItemGoTo.ITEMBOX
  2313. local data = {}
  2314. data.target = goToName
  2315. data.stdmode = stdmode
  2316. data.widget = widget
  2317. data.boxindex = boxindex
  2318. ItemMoveProxy:CheckAndCallBack( data )
  2319. else
  2320. return -1
  2321. end
  2322. end
  2323. local function setNoswallowMouse()
  2324. return -1
  2325. end
  2326. global.mouseEventController:registerMouseButtonEvent(
  2327. widget,
  2328. {
  2329. down_r = setNoswallowMouse,
  2330. special_r = addItemToITEMBOX
  2331. }
  2332. )
  2333. --
  2334. self:addMouseOverTips(widget, element)
  2335. -- 加入管理
  2336. global.Facade:sendNotification(global.NoticeTable.SUIITEMBOXWidgetAdd, {boxindex = boxindex, widget = widget})
  2337. return widget
  2338. end
  2339. function SUILoader:load_render_EquipShow(swidget, callback)
  2340. local element = swidget.element
  2341. local index = tonumber(element.attr.index) or 0
  2342. local showtips = tonumber(element.attr.showtips) or 1
  2343. local bgtype = tonumber(element.attr.bgtype)
  2344. local scale = tonumber(element.attr.scale) or 1
  2345. local grey = tonumber(element.attr.grey) or 0
  2346. local showstar = tonumber(element.attr.showstar) == 1
  2347. local link = element.attr.link
  2348. local submitInput = element.attr.submitInput
  2349. local submitCheckBox = element.attr.submitCheckBox
  2350. local dblink = element.attr.dblink
  2351. local effectshow = tonumber(element.attr.effectshow) or 1 -- 1只显示背包 2只显示内观 0不显示
  2352. local contentSize = cc.size(66,66)
  2353. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  2354. widget:setContentSize(contentSize)
  2355. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  2356. local equipData = EquipProxy:GetEquipDataByPos(index)
  2357. if equipData then
  2358. local info = {}
  2359. info.index = equipData.Index
  2360. info.itemData = equipData
  2361. info.look = showtips == 1
  2362. info.bgVisible = bgtype == 1
  2363. info.starLv = showstar
  2364. if not info.look and global.isWinPlayMode then
  2365. info.noMouseTips = true
  2366. end
  2367. if effectshow == 2 then
  2368. info.showModelEffect = true
  2369. elseif effectshow == 0 then
  2370. info.isShowEff = false
  2371. end
  2372. local goodsItem = GoodsItem:create(info)
  2373. widget:addChild(goodsItem)
  2374. goodsItem:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  2375. goodsItem:setScale(scale)
  2376. goodsItem:setIconGrey(grey == 1)
  2377. if dblink and string.len(dblink) then
  2378. if not (showtips == 1) then
  2379. goodsItem:addLookItemInfoEvent(nil, 2)
  2380. end
  2381. goodsItem:addDoubleEventListener(function()
  2382. if callback then
  2383. local inputTable = self:getInputTable(submitInput)
  2384. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2385. local jsonData = {}
  2386. jsonData.Act = dblink
  2387. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2388. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2389. self:linkFuncWithCheckWords(callback, jsonData)
  2390. end
  2391. end)
  2392. end
  2393. end
  2394. if link and not dblink then
  2395. local linkWidget = global.SWidgetCache:generateRender("ccui.Widget")
  2396. widget:addChild(linkWidget)
  2397. linkWidget:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  2398. linkWidget:setContentSize(contentSize)
  2399. linkWidget:setTouchEnabled(true)
  2400. linkWidget:setSwallowTouches(false)
  2401. linkWidget:addClickEventListener(function()
  2402. if callback then
  2403. local inputTable = self:getInputTable(submitInput)
  2404. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2405. local jsonData = {}
  2406. jsonData.Act = link
  2407. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2408. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2409. self:linkFuncWithCheckWords(callback, jsonData)
  2410. end
  2411. end)
  2412. end
  2413. return widget
  2414. end
  2415. function SUILoader:load_render_BAGITEMS(swidget, callback)
  2416. local element = swidget.element
  2417. local condition = element.attr.condition or ""
  2418. local exclude = element.attr.exclude or ""
  2419. local select = element.attr.select or ""
  2420. local count = tonumber(element.attr.count) or 12
  2421. local row = tonumber(element.attr.row) or 2
  2422. local selecttype = tonumber(element.attr.selecttype) or 0
  2423. local showstar = tonumber(element.attr.showstar) == 1
  2424. local iwidth = tonumber(element.attr.iwidth) or 70
  2425. local iheight = tonumber(element.attr.iheight) or 70
  2426. local iimg = element.attr.iimg
  2427. local filter1 = element.attr.fliter1 or element.attr.filter1 or ""
  2428. local filter2 = element.attr.fliter2 or element.attr.filter2 or ""
  2429. local filter3 = element.attr.fliter3 or element.attr.filter3 or ""
  2430. local link = element.attr.link
  2431. local conditionEx = element.attr.conditionEx
  2432. local conditionParam = element.attr.conditionParam
  2433. local conditionOnOff = tonumber(element.attr.conditionOnOff) or 0
  2434. local condition2 = element.attr.condition2
  2435. local dblink = element.attr.dblink
  2436. local effectshow = tonumber(element.attr.effectshow) or 1
  2437. local exBind = tonumber(element.attr.exbind) == 1
  2438. local showtips = (tonumber(element.attr.showtips) or 0) == 1
  2439. local includeQuick = (tonumber(element.attr.includequick) or 0) == 1
  2440. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  2441. local itemscaleX = iwidth / 70
  2442. local itemscaleY = iheight / 70
  2443. -- 是否满足显示条件
  2444. local conditionT = {}
  2445. local slices1 = ssplit(condition, ",")
  2446. local slices2 = {}
  2447. for _, v in pairs(slices1) do
  2448. slices2 = ssplit(v, "#")
  2449. tinsert(conditionT, {StdMode = tonumber(slices2[1]), Shape = tonumber(slices2[2])})
  2450. end
  2451. -- 唯一ID过滤
  2452. local excludeT = {}
  2453. local slices = ssplit(exclude, ",")
  2454. for _, v in pairs(slices) do
  2455. tinsert(excludeT, tonumber(v))
  2456. end
  2457. -- 道具ID过滤,存在不显示
  2458. local filter1T = {}
  2459. local slices = ssplit(filter1, ",")
  2460. for _, v in pairs(slices) do
  2461. tinsert(filter1T, tonumber(v))
  2462. end
  2463. -- 道具名过滤,存在不显示
  2464. local filter2T = {}
  2465. local slices = ssplit(filter2, ",")
  2466. for _, v in pairs(slices) do
  2467. if v ~= "" then
  2468. tinsert(filter2T, v)
  2469. end
  2470. end
  2471. -- 道具ID过滤,存在才显示
  2472. local filter3T = {}
  2473. local slices = ssplit(filter3, ",")
  2474. for _, v in pairs(slices) do
  2475. if v ~= "" then
  2476. tinsert(filter3T, v)
  2477. end
  2478. end
  2479. local function conditionAble(item)
  2480. if conditionEx and tonumber(conditionEx) == 1 then
  2481. local starLv = item.Star or 0
  2482. if conditionOnOff and conditionOnOff == 0 then
  2483. if conditionParam and starLv < tonumber(conditionParam) then
  2484. return false
  2485. end
  2486. elseif conditionOnOff == 1 then
  2487. if conditionParam and starLv > tonumber(conditionParam) then
  2488. return false
  2489. end
  2490. end
  2491. end
  2492. -- 被排除
  2493. for _, v in ipairs(excludeT) do
  2494. if v == item.MakeIndex then
  2495. return false
  2496. end
  2497. end
  2498. -- 道具ID过滤
  2499. for _, v in ipairs(filter1T) do
  2500. if v == item.Index then
  2501. return false
  2502. end
  2503. end
  2504. -- 道具名过滤
  2505. for _, v in ipairs(filter2T) do
  2506. if v == item.Name then
  2507. return false
  2508. end
  2509. end
  2510. -- 绑定过滤
  2511. if exBind and CheckItemisBind(item) then
  2512. return false
  2513. end
  2514. -- 道具ID/道具名过滤
  2515. if #filter3T > 0 then
  2516. for _, v in ipairs(filter3T) do
  2517. if tonumber(v) == item.Index or v == item.Name then
  2518. return true
  2519. end
  2520. end
  2521. return false
  2522. end
  2523. -- 筛选
  2524. if condition == "*" then
  2525. return true
  2526. end
  2527. for _, v in pairs(conditionT) do
  2528. if v.StdMode == item.StdMode and (not v.Shape or v.Shape == item.Shape) then
  2529. return true
  2530. end
  2531. end
  2532. if condition2 then
  2533. if tonumber(item.sDivParam2) and tonumber(item.sDivParam2) == tonumber(condition2) then
  2534. return true
  2535. elseif string.find(tostring(condition2), "#") then
  2536. local paramList = string.split(tostring(condition2), "#")
  2537. for _, param in ipairs(paramList) do
  2538. if tonumber(param) == tonumber(item.sDivParam2) then
  2539. return true
  2540. end
  2541. end
  2542. end
  2543. end
  2544. return false
  2545. end
  2546. -- 是否选中
  2547. local selects = {}
  2548. local slices = ssplit(select, ",")
  2549. for _, v in pairs(slices) do
  2550. tinsert(selects, tonumber(v))
  2551. end
  2552. local function selectAble(item)
  2553. for _, v in pairs(selects) do
  2554. if v == item.MakeIndex then
  2555. return true
  2556. end
  2557. end
  2558. return false
  2559. end
  2560. local itemWid = iwidth
  2561. local itemHei = iheight
  2562. local col = math.ceil(count / row)
  2563. local contentSize = cc.size(col * itemWid, row * itemHei)
  2564. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  2565. widget:setContentSize(contentSize)
  2566. --
  2567. local boxes = {}
  2568. for i = 1, count do
  2569. local x = ((i - 1) % col + 0.5) * itemWid
  2570. local y = contentSize.height - (mfloor((i - 1) / col) + 0.5) * itemHei
  2571. local iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  2572. local fullPath = string.format(getResFullPath("res/%s"), iimg)
  2573. local imageBG = ccui.ImageView:create()
  2574. widget:addChild(imageBG)
  2575. imageBG:loadTexture(fullPath)
  2576. GUI:Image_setScale9Slice(imageBG, 21, 22, 21, 22)
  2577. GUI:setContentSize(imageBG, itemWid, itemHei)
  2578. imageBG:setTouchEnabled(false)
  2579. imageBG:setAnchorPoint(cc.p(0.5, 0.5))
  2580. imageBG:setPosition(cc.p(x, y))
  2581. tinsert(boxes, imageBG)
  2582. end
  2583. -- bag items
  2584. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  2585. local items = {}
  2586. local BagMaxNum = BagProxy:GetMaxBag()
  2587. for i = 1, BagMaxNum do
  2588. local itemMakeIndex = BagProxy:GetMakeIndexByBagPos(i)
  2589. if itemMakeIndex then
  2590. local itemData = BagProxy:GetItemDataByMakeIndex(itemMakeIndex)
  2591. if itemData and conditionAble(itemData) then
  2592. tinsert(items, itemData)
  2593. end
  2594. end
  2595. end
  2596. if includeQuick then
  2597. local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
  2598. local quickUseData = QuickUseProxy:GetQuickUseData()
  2599. for _, itemData in pairs(quickUseData) do
  2600. if itemData and conditionAble(itemData) then
  2601. tinsert(items, itemData)
  2602. end
  2603. end
  2604. end
  2605. --
  2606. -- show
  2607. for index, item in ipairs(items) do
  2608. local imageBG = boxes[index]
  2609. if imageBG then
  2610. local size = imageBG:getContentSize()
  2611. -- 道具图标
  2612. local info = {index = item.Index, itemData = item, starLv = showstar}
  2613. if effectshow == 2 then
  2614. info.showModelEffect = true
  2615. elseif effectshow == 0 then
  2616. info.isShowEff = false
  2617. end
  2618. info.look = showtips
  2619. if not info.look and global.isWinPlayMode then
  2620. info.noMouseTips = true
  2621. end
  2622. local goodsItem = GoodsItem:create(info)
  2623. imageBG:addChild(goodsItem)
  2624. goodsItem:setPosition(cc.p(size.width/2, size.height/2))
  2625. goodsItem._canLooks = true
  2626. goodsItem:addLookItemInfoEvent(nil, 1)
  2627. goodsItem:setScaleX(itemscaleX)
  2628. goodsItem:setScaleY(itemscaleY)
  2629. -- link
  2630. if link and string.len(link) > 0 then
  2631. goodsItem:addTouchEventListener(function()
  2632. if clickInterval > 0 then
  2633. goodsItem:DelayTouchEnabled(clickInterval)
  2634. end
  2635. local selected = clone(selects)
  2636. if selecttype == 0 then
  2637. -- 多选
  2638. if selectAble(item) then
  2639. for key, value in pairs(selected) do
  2640. if item.MakeIndex == value then
  2641. table.remove(selected, key)
  2642. break
  2643. end
  2644. end
  2645. else
  2646. tinsert(selected, item.MakeIndex)
  2647. end
  2648. else
  2649. -- 单选
  2650. if selectAble(item) then
  2651. selected = {}
  2652. else
  2653. selected = {item.MakeIndex}
  2654. end
  2655. end
  2656. local jsonData = {}
  2657. jsonData.Act = link
  2658. jsonData.SelectItemID = table.concat(selected, ",")
  2659. callback(jsonData)
  2660. end, 2)
  2661. end
  2662. -- 选中
  2663. if selectAble(item) then
  2664. local imageS = ccui.ImageView:create()
  2665. imageBG:addChild(imageS)
  2666. imageS:loadTexture(global.MMO.PATH_RES_PUBLIC .. "1900000678_2.png")
  2667. imageS:ignoreContentAdaptWithSize(true)
  2668. imageS:setCapInsets(cc.rect(0, 0, 0, 0))
  2669. imageS:setScale9Enabled(false)
  2670. imageS:setTouchEnabled(false)
  2671. imageS:setAnchorPoint(cc.p(0.5,0.5))
  2672. imageS:setPosition(cc.p(size.width/2, size.height/2))
  2673. imageS:setScaleX(itemscaleX)
  2674. imageS:setScaleY(itemscaleY)
  2675. end
  2676. if dblink and string.len(dblink) then
  2677. goodsItem:addDoubleEventListener(function()
  2678. local jsonData = {}
  2679. jsonData.Act = dblink
  2680. jsonData.SelectItemID = item.MakeIndex
  2681. callback(jsonData)
  2682. end)
  2683. end
  2684. end
  2685. end
  2686. return widget
  2687. end
  2688. function SUILoader:load_render_EQUIPITEMS(swidget, callback)
  2689. local element = swidget.element
  2690. local positions = element.attr.positions or "*"
  2691. local select = element.attr.select or ""
  2692. local count = tonumber(element.attr.count) or 12
  2693. local row = tonumber(element.attr.row) or 2
  2694. local selecttype = tonumber(element.attr.selecttype) or 0
  2695. local showstar = tonumber(element.attr.showstar) == 1
  2696. local iwidth = tonumber(element.attr.iwidth) or 70
  2697. local iheight = tonumber(element.attr.iheight) or 70
  2698. local iimg = element.attr.iimg
  2699. local link = element.attr.link
  2700. local effectshow = tonumber(element.attr.effectshow) or 1 -- 1只显示背包 2只显示内观 0不显示
  2701. local itemscaleX = iwidth / 70
  2702. local itemscaleY = iheight / 70
  2703. -- 装备位
  2704. local equipPositions = {}
  2705. local slices = ssplit(positions, ",")
  2706. for _, v in ipairs(slices) do
  2707. tinsert(equipPositions, tonumber(v))
  2708. end
  2709. -- 是否选中
  2710. local selects = {}
  2711. local slices = ssplit(select, ",")
  2712. for _, v in pairs(slices) do
  2713. tinsert(selects, tonumber(v))
  2714. end
  2715. local function selectAble(item)
  2716. for _, v in pairs(selects) do
  2717. if v == item.MakeIndex then
  2718. return true
  2719. end
  2720. end
  2721. return false
  2722. end
  2723. local itemWid = iwidth
  2724. local itemHei = iheight
  2725. local col = math.ceil(count / row)
  2726. local contentSize = cc.size(col * itemWid, row * itemHei)
  2727. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  2728. widget:setContentSize(contentSize)
  2729. --
  2730. local boxes = {}
  2731. for i = 1, count do
  2732. local x = ((i - 1) % col + 0.5) * itemWid
  2733. local y = contentSize.height - (mfloor((i - 1) / col) + 0.5) * itemHei
  2734. local iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  2735. local fullPath = string.format(getResFullPath("res/%s"), iimg)
  2736. local imageBG = ccui.ImageView:create()
  2737. widget:addChild(imageBG)
  2738. imageBG:loadTexture(fullPath)
  2739. GUI:Image_setScale9Slice(imageBG, 21, 22, 21, 22)
  2740. GUI:setContentSize(imageBG, itemWid, itemHei)
  2741. imageBG:setTouchEnabled(false)
  2742. imageBG:setAnchorPoint(cc.p(0.5, 0.5))
  2743. imageBG:setPosition(cc.p(x, y))
  2744. tinsert(boxes, imageBG)
  2745. end
  2746. -- items
  2747. local items = {}
  2748. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  2749. if positions == "*" then
  2750. local equipTypeConfig = EquipProxy:GetEquipTypeConfig()
  2751. for equipPos = equipTypeConfig.Equip_Type_Dress, equipTypeConfig.Equip_Type_Shield do
  2752. local equipData = EquipProxy:GetEquipDataByPos(equipPos)
  2753. if equipData then
  2754. tinsert(items, equipData)
  2755. end
  2756. end
  2757. else
  2758. for _, equipPos in ipairs(equipPositions) do
  2759. local equipData = EquipProxy:GetEquipDataByPos(equipPos)
  2760. if equipData then
  2761. tinsert(items, equipData)
  2762. end
  2763. end
  2764. end
  2765. -- show
  2766. for index, item in ipairs(items) do
  2767. local imageBG = boxes[index]
  2768. if imageBG then
  2769. local size = imageBG:getContentSize()
  2770. -- 道具图标
  2771. local info = {index = item.Index, itemData = item, starLv = showstar}
  2772. if effectshow == 2 then
  2773. info.showModelEffect = true
  2774. elseif effectshow == 0 then
  2775. info.isShowEff = false
  2776. end
  2777. local goodsItem = GoodsItem:create(info)
  2778. imageBG:addChild(goodsItem)
  2779. goodsItem:setPosition(cc.p(size.width/2, size.height/2))
  2780. goodsItem._canLooks = true
  2781. goodsItem:addLookItemInfoEvent(nil, 1)
  2782. goodsItem:setScaleX(itemscaleX)
  2783. goodsItem:setScaleY(itemscaleY)
  2784. -- link
  2785. if link and string.len(link) > 0 then
  2786. goodsItem:addTouchEventListener(function()
  2787. local selected = clone(selects)
  2788. if selecttype == 0 then
  2789. -- 多选
  2790. if selectAble(item) then
  2791. for key, value in pairs(selected) do
  2792. if item.MakeIndex == value then
  2793. table.remove(selected, key)
  2794. break
  2795. end
  2796. end
  2797. else
  2798. tinsert(selected, item.MakeIndex)
  2799. end
  2800. else
  2801. -- 单选
  2802. if selectAble(item) then
  2803. selected = {}
  2804. else
  2805. selected = {item.MakeIndex}
  2806. end
  2807. end
  2808. local jsonData = {}
  2809. jsonData.Act = link
  2810. jsonData.SelectItemID = table.concat(selected, ",")
  2811. callback(jsonData)
  2812. end, 2)
  2813. end
  2814. -- 选中
  2815. if selectAble(item) then
  2816. local imageS = ccui.ImageView:create()
  2817. imageBG:addChild(imageS)
  2818. imageS:loadTexture(global.MMO.PATH_RES_PUBLIC .. "1900000678_2.png")
  2819. imageS:ignoreContentAdaptWithSize(true)
  2820. imageS:setCapInsets(cc.rect(0, 0, 0, 0))
  2821. imageS:setScale9Enabled(false)
  2822. imageS:setTouchEnabled(false)
  2823. imageS:setAnchorPoint(cc.p(0.5,0.5))
  2824. imageS:setPosition(cc.p(size.width/2, size.height/2))
  2825. imageS:setScaleX(itemscaleX)
  2826. imageS:setScaleY(itemscaleY)
  2827. end
  2828. end
  2829. end
  2830. return widget
  2831. end
  2832. function SUILoader:load_render_TIMETIPS(swidget, callback)
  2833. local element = swidget.element
  2834. local size = tonumber(element.attr.size) or defaultFontSize
  2835. local color = tonumber(element.attr.color) or defaultColorID
  2836. local time = tonumber(element.attr.time) or 0
  2837. local outline = tonumber(element.attr.outline) or defaultOutline
  2838. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  2839. local link = element.attr.link
  2840. local widget = ccui.Text:create()
  2841. widget:setString("")
  2842. widget:setFontSize(size)
  2843. widget:setFontName(defaultFontPath)
  2844. widget:setTextColor(GET_COLOR_BYID_C3B(color))
  2845. widget:enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  2846. local endTime = time + GetServerTime()
  2847. local function scheduleCB()
  2848. local remaining = math.max(endTime - GetServerTime(), 0)
  2849. widget:setString(SecondToHMS(remaining, true))
  2850. if remaining <= 0 then
  2851. -- link
  2852. if link and string.len(link) > 0 then
  2853. if callback then
  2854. local jsonData = {}
  2855. jsonData.Act = link
  2856. callback(jsonData)
  2857. end
  2858. end
  2859. widget:stopAllActions()
  2860. end
  2861. end
  2862. schedule(widget, scheduleCB, 1)
  2863. scheduleCB()
  2864. return widget
  2865. end
  2866. function SUILoader:load_render_LoadingBar(swidget, callback)
  2867. local element = swidget.element
  2868. local size = tonumber(element.attr.size) or defaultFontSize
  2869. local color = tonumber(element.attr.color) or defaultColorID
  2870. local outline = tonumber(element.attr.outline) or defaultOutline
  2871. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  2872. local direction = tonumber(element.attr.direction) or 0 -- 0从左至右 1从右到左
  2873. local loadBgImg = element.attr.loadingbg or "public/bg_szjm_03_1.png"
  2874. local loadBarImg = element.attr.loadingbar or "public/bg_szjm_03_2.png"
  2875. local startPercent = tonumber(element.attr.startper) or 0
  2876. local interval = tonumber(element.attr.interval) or 0.05
  2877. local loadValue = tonumber(element.attr.loadvalue) or 10
  2878. local link = element.attr.link
  2879. local submitInput = element.attr.submitInput
  2880. local submitCheckBox = element.attr.submitCheckBox
  2881. local offsetX = element.attr.offsetX or 0
  2882. local offsetY = element.attr.offsetY or 0
  2883. local endPercent = tonumber(element.attr.endper) or 100
  2884. local imgBg = SUIHelper.fixImageFileName(loadBgImg)
  2885. local imgBar = SUIHelper.fixImageFileName(loadBarImg)
  2886. local fullPathBG = (imgBg and imgBg ~= "") and string.format(getResFullPath("res/%s"), imgBg) or ""
  2887. local fullPathBAR = (imgBar and imgBar ~= "") and string.format(getResFullPath("res/%s"), imgBar) or ""
  2888. local widget = ccui.ImageView:create()
  2889. widget:ignoreContentAdaptWithSize(false)
  2890. if fullPathBG and fullPathBG ~= "" and global.FileUtilCtl:isFileExist(fullPathBG) then
  2891. widget:loadTexture(fullPathBG)
  2892. end
  2893. local LoadingBar = ccui.LoadingBar:create()
  2894. if fullPathBAR and fullPathBAR ~= "" and global.FileUtilCtl:isFileExist(fullPathBAR) then
  2895. LoadingBar:loadTexture(fullPathBAR)
  2896. end
  2897. LoadingBar:ignoreContentAdaptWithSize(false)
  2898. LoadingBar:setPercent(startPercent)
  2899. if direction == 1 then
  2900. LoadingBar:setDirection(1)
  2901. end
  2902. LoadingBar:setPosition(cc.p(widget:getContentSize().width/2 + offsetX, widget:getContentSize().height/2 + offsetY))
  2903. widget:addChild(LoadingBar)
  2904. local percentText = ccui.Text:create()
  2905. percentText:setString(string.format(GET_STRING(1053), startPercent, 100))
  2906. percentText:setAnchorPoint(0.5, 0.5)
  2907. percentText:setPosition(cc.p(widget:getContentSize().width/2, widget:getContentSize().height/2))
  2908. percentText:setFontSize(size)
  2909. percentText:setFontName(defaultFontPath)
  2910. percentText:setTextColor(GET_COLOR_BYID_C3B(color))
  2911. percentText:enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  2912. widget:addChild(percentText)
  2913. LoadingBar:stopAllActions()
  2914. local percent = startPercent
  2915. local function scheduleCB()
  2916. percent = percent + loadValue
  2917. percent = math.min(percent, endPercent)
  2918. LoadingBar:setPercent(percent)
  2919. local curPercent = mfloor(percent/100 * 100)
  2920. percentText:setString(string.format(GET_STRING(1053), curPercent, 100))
  2921. --
  2922. if percent >= endPercent then
  2923. LoadingBar:stopAllActions()
  2924. if link and string.len(link) > 0 then
  2925. if callback then
  2926. local inputTable = self:getInputTable(submitInput)
  2927. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2928. local jsonData = {}
  2929. jsonData.Act = link
  2930. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2931. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2932. self:linkFuncWithCheckWords(callback, jsonData)
  2933. end
  2934. end
  2935. end
  2936. end
  2937. schedule(LoadingBar, scheduleCB, interval)
  2938. scheduleCB()
  2939. return widget
  2940. end
  2941. function SUILoader:load_render_CircleBar(swidget, callback)
  2942. local element = swidget.element
  2943. local loadBgImg = element.attr.loadingbg or "private/sui/bg_xbzy_02.png"
  2944. local loadBarImg = element.attr.loadingbar or "private/sui/bg_xbzy_03.png"
  2945. local startPercent = tonumber(element.attr.startper) or 0
  2946. local endPercent = tonumber(element.attr.endper) or 100
  2947. local time = tonumber(element.attr.time) or 1
  2948. local link = element.attr.link
  2949. local submitInput = element.attr.submitInput
  2950. local submitCheckBox = element.attr.submitCheckBox
  2951. local offsetX = element.attr.offsetX or 0
  2952. local offsetY = element.attr.offsetY or 0
  2953. local imgBg = SUIHelper.fixImageFileName(loadBgImg)
  2954. local imgBar = SUIHelper.fixImageFileName(loadBarImg)
  2955. local fullPathBG = (imgBg and imgBg ~= "") and string.format(getResFullPath("res/%s"), imgBg) or ""
  2956. local fullPathBAR = (imgBar and imgBar ~= "") and string.format(getResFullPath("res/%s"), imgBar) or ""
  2957. local widget = ccui.ImageView:create()
  2958. widget:ignoreContentAdaptWithSize(false)
  2959. if fullPathBG and fullPathBG ~= "" and global.FileUtilCtl:isFileExist(fullPathBG) then
  2960. widget:loadTexture(fullPathBG)
  2961. end
  2962. local contentSize = widget:getContentSize()
  2963. if fullPathBAR and fullPathBAR ~= "" and global.FileUtilCtl:isFileExist(fullPathBAR) then
  2964. local loadingBar = cc.ProgressTimer:create(cc.Sprite:create(fullPathBAR))
  2965. widget:addChild(loadingBar)
  2966. loadingBar:setPosition(cc.p(contentSize.width / 2 + offsetX, contentSize.height / 2 + offsetY))
  2967. loadingBar:setPercentage(startPercent)
  2968. local function loadEndCallBack()
  2969. loadingBar:stopAllActions()
  2970. if link and string.len(link) > 0 then
  2971. if callback then
  2972. local inputTable = self:getInputTable(submitInput)
  2973. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  2974. local jsonData = {}
  2975. jsonData.Act = link
  2976. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  2977. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  2978. self:linkFuncWithCheckWords(callback, jsonData)
  2979. end
  2980. end
  2981. end
  2982. loadingBar:runAction(
  2983. cc.Sequence:create(
  2984. cc.ProgressFromTo:create(time, startPercent, endPercent),
  2985. cc.DelayTime:create(0.1),
  2986. cc.CallFunc:create(loadEndCallBack)
  2987. )
  2988. )
  2989. end
  2990. return widget
  2991. end
  2992. function SUILoader:load_render_PercentImg(swidget, callback)
  2993. local element = swidget.element
  2994. local direction = tonumber(element.attr.direction) or 0 -- 0 从左到右 1从右到左 2从上往下 3从下往上
  2995. local loadImg = element.attr.img or "public/bg_szjm_03_2.png"
  2996. local minValue = tonumber(element.attr.minValue) or 100
  2997. local maxValue = tonumber(element.attr.maxValue) or 100
  2998. local percent = mfloor( minValue/maxValue * 100) or 100
  2999. local img = SUIHelper.fixImageFileName(loadImg)
  3000. local fullPath = (img and img ~= "") and string.format(getResFullPath("res/%s"), img) or ""
  3001. local widget = ccui.LoadingBar:create()
  3002. if fullPath and fullPath ~= "" and global.FileUtilCtl:isFileExist(fullPath) then
  3003. widget:loadTexture(fullPath)
  3004. end
  3005. widget:ignoreContentAdaptWithSize(false)
  3006. if direction == 0 or direction == 1 then
  3007. widget:setPercent(percent)
  3008. if direction == 1 then
  3009. widget:setDirection(1)
  3010. end
  3011. elseif direction == 2 or direction == 3 then
  3012. local barRenderer = widget:getVirtualRenderer()
  3013. local barRendererTextureSize = widget:getVirtualRendererSize()
  3014. local innerSprite = barRenderer:getSprite()
  3015. local contentSize = widget:getContentSize()
  3016. widget:setDirection(direction)
  3017. if direction == 2 then
  3018. barRenderer:setAnchorPoint(0, 0)
  3019. barRenderer:setPosition(0, 0)
  3020. else
  3021. barRenderer:setAnchorPoint(0, 1)
  3022. barRenderer:setPosition(0, contentSize.height)
  3023. end
  3024. if innerSprite then
  3025. local rect = innerSprite:getTextureRect()
  3026. rect.height = barRendererTextureSize.height * percent / 100
  3027. innerSprite:setTextureRect(rect, innerSprite:isTextureRectRotated(), cc.size(rect.width, rect.height))
  3028. if direction == 2 then
  3029. innerSprite:setFlippedY(true)
  3030. else
  3031. innerSprite:setFlippedY(false)
  3032. end
  3033. end
  3034. end
  3035. -- 加入元变量组件管理
  3036. local isMateValue = false
  3037. if not tonumber(element.attr.minValue) or not tonumber(element.attr.maxValue) then
  3038. local metaValue = {}
  3039. local content = element.attr.minValue
  3040. while content and string.len(content) > 0 do
  3041. local find_info = {sfind(content, "$STM%((.-)%)")}
  3042. local begin_pos = find_info[1]
  3043. local end_pos = find_info[2]
  3044. if begin_pos and end_pos then
  3045. isMateValue = true
  3046. -- prefix
  3047. if begin_pos ~= 1 then
  3048. local substr = string.sub(content, 1, begin_pos - 1)
  3049. table.insert(metaValue, substr)
  3050. end
  3051. -- metaValue
  3052. local slices = ssplit(find_info[3], "_")
  3053. table.insert(metaValue, {key = slices[1], param = slices[2]})
  3054. -- suffix
  3055. content = string.sub(content, end_pos+1, string.len(content))
  3056. else
  3057. table.insert(metaValue, content)
  3058. content = ""
  3059. end
  3060. end
  3061. local metaValue2 = {}
  3062. local content2 = element.attr.maxValue
  3063. while content2 and string.len(content2) > 0 do
  3064. local find_info = {sfind(content2, "$STM%((.-)%)")}
  3065. local begin_pos = find_info[1]
  3066. local end_pos = find_info[2]
  3067. if begin_pos and end_pos then
  3068. isMateValue = true
  3069. -- prefix
  3070. if begin_pos ~= 1 then
  3071. local substr = string.sub(content2, 1, begin_pos - 1)
  3072. table.insert(metaValue2, substr)
  3073. end
  3074. -- metaValue
  3075. local slices = ssplit(find_info[3], "_")
  3076. table.insert(metaValue2, {key = slices[1], param = slices[2]})
  3077. -- suffix
  3078. content2 = string.sub(content2, end_pos+1, string.len(content))
  3079. else
  3080. table.insert(metaValue2, content2)
  3081. content2 = ""
  3082. end
  3083. end
  3084. if isMateValue then
  3085. widget.useMetaValue = true
  3086. global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, metaValue2 = metaValue2, widget = widget, lifewidget = widget})
  3087. end
  3088. end
  3089. return widget
  3090. end
  3091. function SUILoader:load_render_UIModel(swidget,callback)
  3092. local element = swidget.element
  3093. local sex = tonumber(element.attr.sex) or 0
  3094. local scale = tonumber(element.attr.scale) or 1
  3095. local function parseEffectStr(str)
  3096. if not str then
  3097. return nil
  3098. end
  3099. return string.gsub(str, "&", "|")
  3100. end
  3101. local feature = {}
  3102. feature.clothID = tonumber(element.attr.clothID)
  3103. feature.weaponID = tonumber(element.attr.weaponID)
  3104. feature.headID = tonumber(element.attr.headID)
  3105. feature.headEffectID = parseEffectStr(element.attr.headEffectID)
  3106. feature.weaponEffectID = parseEffectStr(element.attr.weaponEffectID)
  3107. feature.clothEffectID = parseEffectStr(element.attr.clothEffectID)
  3108. feature.capID = tonumber(element.attr.capID)
  3109. feature.shieldID = tonumber(element.attr.shieldID)
  3110. feature.shieldEffectID = parseEffectStr(element.attr.shieldEffectID)
  3111. feature.tDressID = tonumber(element.attr.tDressID)
  3112. feature.tDressEffectID = parseEffectStr(element.attr.tDressEffectID)
  3113. feature.tWeaponID = tonumber(element.attr.tWeaponID)
  3114. feature.tWeaponEffectID = parseEffectStr(element.attr.tWeaponEffectID)
  3115. feature.capEffectID = parseEffectStr(element.attr.capEffectID)
  3116. feature.veilID = tonumber(element.attr.veilID)
  3117. feature.veilEffectID = parseEffectStr(element.attr.veilEffectID)
  3118. feature.hairID = tonumber(element.attr.hairID)
  3119. feature.notShowMold = element.attr.notShowMold
  3120. feature.notShowHair = element.attr.notShowHair
  3121. local UIModel = CreateStaticUIModel(sex, feature, scale, {ignoreStaticScale = true})
  3122. if UIModel then
  3123. return UIModel
  3124. end
  3125. end
  3126. ---- 英雄相关
  3127. function SUILoader:load_render_HEROEquipShow(swidget, callback)
  3128. local element = swidget.element
  3129. local index = tonumber(element.attr.index) or 0
  3130. local showtips = tonumber(element.attr.showtips) or 1
  3131. local bgtype = tonumber(element.attr.bgtype)
  3132. local scale = tonumber(element.attr.scale) or 1
  3133. local grey = tonumber(element.attr.grey) or 0
  3134. local showstar = tonumber(element.attr.showstar) == 1
  3135. local link = element.attr.link
  3136. local submitInput = element.attr.submitInput
  3137. local submitCheckBox = element.attr.submitCheckBox
  3138. local dblink = element.attr.dblink
  3139. local effectshow = tonumber(element.attr.effectshow) or 1
  3140. local contentSize = cc.size(66,66)
  3141. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  3142. widget:setContentSize(contentSize)
  3143. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  3144. local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  3145. local equipData = HeroEquipProxy:GetEquipDataByPos(index)
  3146. if equipData then
  3147. local info = {}
  3148. info.index = equipData.Index
  3149. info.itemData = equipData
  3150. info.look = showtips == 1
  3151. info.bgVisible = bgtype == 1
  3152. info.starLv = showstar
  3153. if not info.look and global.isWinPlayMode then
  3154. info.noMouseTips = true
  3155. end
  3156. if effectshow == 2 then
  3157. info.showModelEffect = true
  3158. elseif effectshow == 0 then
  3159. info.isShowEff = false
  3160. end
  3161. info.from = ItemMoveProxy.ItemFrom.HERO_EQUIP
  3162. local goodsItem = GoodsItem:create(info)
  3163. widget:addChild(goodsItem)
  3164. goodsItem:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  3165. goodsItem:setScale(scale)
  3166. goodsItem:setIconGrey(grey == 1)
  3167. if dblink and string.len(dblink) then
  3168. if not (showtips == 1) then
  3169. goodsItem:addLookItemInfoEvent(nil, 2)
  3170. end
  3171. goodsItem:addDoubleEventListener(function()
  3172. if callback then
  3173. local inputTable = self:getInputTable(submitInput)
  3174. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  3175. local jsonData = {}
  3176. jsonData.Act = dblink
  3177. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  3178. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  3179. callback(jsonData)
  3180. end
  3181. end)
  3182. end
  3183. end
  3184. if link and not dblink then
  3185. local linkWidget = global.SWidgetCache:generateRender("ccui.Widget")
  3186. widget:addChild(linkWidget)
  3187. linkWidget:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  3188. linkWidget:setContentSize(contentSize)
  3189. linkWidget:setTouchEnabled(true)
  3190. linkWidget:setSwallowTouches(false)
  3191. linkWidget:addClickEventListener(function()
  3192. if callback then
  3193. local inputTable = self:getInputTable(submitInput)
  3194. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  3195. local jsonData = {}
  3196. jsonData.Act = link
  3197. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  3198. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  3199. self:linkFuncWithCheckWords(callback, jsonData)
  3200. end
  3201. end)
  3202. end
  3203. return widget
  3204. end
  3205. function SUILoader:load_render_HEROEQUIPITEMS(swidget, callback)
  3206. local element = swidget.element
  3207. local positions = element.attr.positions or "*"
  3208. local select = element.attr.select or ""
  3209. local count = tonumber(element.attr.count) or 12
  3210. local row = tonumber(element.attr.row) or 2
  3211. local selecttype = tonumber(element.attr.selecttype) or 0
  3212. local showstar = tonumber(element.attr.showstar) == 1
  3213. local iwidth = tonumber(element.attr.iwidth) or 70
  3214. local iheight = tonumber(element.attr.iheight) or 70
  3215. local iimg = element.attr.iimg
  3216. local link = element.attr.link
  3217. local effectshow = tonumber(element.attr.effectshow) or 1
  3218. local itemscaleX = iwidth / 70
  3219. local itemscaleY = iheight / 70
  3220. -- 装备位
  3221. local equipPositions = {}
  3222. local slices = ssplit(positions, ",")
  3223. for _, v in ipairs(slices) do
  3224. tinsert(equipPositions, tonumber(v))
  3225. end
  3226. -- 是否选中
  3227. local selects = {}
  3228. local slices = ssplit(select, ",")
  3229. for _, v in pairs(slices) do
  3230. tinsert(selects, tonumber(v))
  3231. end
  3232. local function selectAble(item)
  3233. for _, v in pairs(selects) do
  3234. if v == item.MakeIndex then
  3235. return true
  3236. end
  3237. end
  3238. return false
  3239. end
  3240. local itemWid = iwidth
  3241. local itemHei = iheight
  3242. local col = math.ceil(count / row)
  3243. local contentSize = cc.size(col * itemWid, row * itemHei)
  3244. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  3245. widget:setContentSize(contentSize)
  3246. --
  3247. local boxes = {}
  3248. for i = 1, count do
  3249. local x = ((i - 1) % col + 0.5) * itemWid
  3250. local y = contentSize.height - (mfloor((i - 1) / col) + 0.5) * itemHei
  3251. local iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  3252. local fullPath = string.format(getResFullPath("res/%s"), iimg)
  3253. local imageBG = ccui.ImageView:create()
  3254. widget:addChild(imageBG)
  3255. imageBG:loadTexture(fullPath)
  3256. GUI:Image_setScale9Slice(imageBG, 21, 22, 21, 22)
  3257. GUI:setContentSize(imageBG, itemWid, itemHei)
  3258. imageBG:setTouchEnabled(false)
  3259. imageBG:setAnchorPoint(cc.p(0.5, 0.5))
  3260. imageBG:setPosition(cc.p(x, y))
  3261. tinsert(boxes, imageBG)
  3262. end
  3263. -- items
  3264. local items = {}
  3265. local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  3266. if positions == "*" then
  3267. local equipTypeConfig = HeroEquipProxy:GetEquipTypeConfig()
  3268. for equipPos = equipTypeConfig.Equip_Type_Dress, equipTypeConfig.Equip_Type_Shield do
  3269. local equipData = HeroEquipProxy:GetEquipDataByPos(equipPos)
  3270. if equipData then
  3271. tinsert(items, equipData)
  3272. end
  3273. end
  3274. else
  3275. for _, equipPos in ipairs(equipPositions) do
  3276. local equipData = HeroEquipProxy:GetEquipDataByPos(equipPos)
  3277. if equipData then
  3278. tinsert(items, equipData)
  3279. end
  3280. end
  3281. end
  3282. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  3283. -- show
  3284. for index, item in ipairs(items) do
  3285. local imageBG = boxes[index]
  3286. if imageBG then
  3287. local size = imageBG:getContentSize()
  3288. -- 道具图标
  3289. local info = {index = item.Index, itemData = item, starLv = showstar}
  3290. if effectshow == 2 then
  3291. info.showModelEffect = true
  3292. elseif effectshow == 0 then
  3293. info.isShowEff = false
  3294. end
  3295. info.from = ItemMoveProxy.ItemFrom.HERO_EQUIP
  3296. local goodsItem = GoodsItem:create(info)
  3297. imageBG:addChild(goodsItem)
  3298. goodsItem:setPosition(cc.p(size.width/2, size.height/2))
  3299. goodsItem._canLooks = true
  3300. goodsItem:addLookItemInfoEvent(nil, 1)
  3301. goodsItem:setScaleX(itemscaleX)
  3302. goodsItem:setScaleY(itemscaleY)
  3303. -- link
  3304. if link and string.len(link) > 0 then
  3305. goodsItem:addTouchEventListener(function()
  3306. local selected = clone(selects)
  3307. if selecttype == 0 then
  3308. -- 多选
  3309. if selectAble(item) then
  3310. for key, value in pairs(selected) do
  3311. if item.MakeIndex == value then
  3312. table.remove(selected, key)
  3313. break
  3314. end
  3315. end
  3316. else
  3317. tinsert(selected, item.MakeIndex)
  3318. end
  3319. else
  3320. -- 单选
  3321. if selectAble(item) then
  3322. selected = {}
  3323. else
  3324. selected = {item.MakeIndex}
  3325. end
  3326. end
  3327. local jsonData = {}
  3328. jsonData.Act = link
  3329. jsonData.SelectItemID = table.concat(selected, ",")
  3330. callback(jsonData)
  3331. end, 2)
  3332. end
  3333. -- 选中
  3334. if selectAble(item) then
  3335. local imageS = ccui.ImageView:create()
  3336. imageBG:addChild(imageS)
  3337. imageS:loadTexture(global.MMO.PATH_RES_PUBLIC .. "1900000678_2.png")
  3338. imageS:ignoreContentAdaptWithSize(true)
  3339. imageS:setCapInsets(cc.rect(0, 0, 0, 0))
  3340. imageS:setScale9Enabled(false)
  3341. imageS:setTouchEnabled(false)
  3342. imageS:setAnchorPoint(cc.p(0.5,0.5))
  3343. imageS:setPosition(cc.p(size.width/2, size.height/2))
  3344. imageS:setScaleX(itemscaleX)
  3345. imageS:setScaleY(itemscaleY)
  3346. end
  3347. end
  3348. end
  3349. return widget
  3350. end
  3351. function SUILoader:load_render_HERODBItemShow(swidget, callback)
  3352. local element = swidget.element
  3353. local makeindex = tonumber(element.attr.makeindex) or 1
  3354. local showtips = tonumber(element.attr.showtips) or 1
  3355. local bgtype = tonumber(element.attr.bgtype)
  3356. local scale = tonumber(element.attr.scale) or 1
  3357. local grey = tonumber(element.attr.grey) or 0
  3358. local showstar = tonumber(element.attr.showstar) == 1
  3359. local count = tonumber(element.attr.count)
  3360. local link = element.attr.link
  3361. local submitInput = element.attr.submitInput
  3362. local submitCheckBox = element.attr.submitCheckBox
  3363. local dblink = element.attr.dblink
  3364. local effectshow = tonumber(element.attr.effectshow) or 1
  3365. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  3366. local itemData = nil
  3367. local from = nil
  3368. if not itemData then
  3369. local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  3370. itemData = HeroEquipProxy:GetEquipDataByMakeIndex(makeindex)
  3371. if itemData then
  3372. from = ItemMoveProxy.ItemFrom.HERO_EQUIP
  3373. end
  3374. end
  3375. if not itemData then
  3376. local HeroBagProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroBagProxy)
  3377. itemData = HeroBagProxy:GetItemDataByMakeIndex(makeindex)
  3378. if itemData then
  3379. from = ItemMoveProxy.ItemFrom.HERO_BAG
  3380. end
  3381. end
  3382. if not itemData then
  3383. local LookPlayerProxy = global.Facade:retrieveProxy(global.ProxyTable.LookPlayerProxy)
  3384. itemData = LookPlayerProxy:GetLookPlayerItemDataByMakeIndex(makeindex)
  3385. end
  3386. local contentSize = cc.size(66,66)
  3387. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  3388. widget:setContentSize(contentSize)
  3389. if itemData then
  3390. local info = {}
  3391. info.index = itemData.Index
  3392. info.itemData = itemData
  3393. info.look = showtips == 1
  3394. info.bgVisible = bgtype == 1
  3395. info.starLv = showstar
  3396. if not info.look and global.isWinPlayMode then
  3397. info.noMouseTips = true
  3398. end
  3399. if effectshow == 2 then
  3400. info.showModelEffect = true
  3401. elseif effectshow == 0 then
  3402. info.isShowEff = false
  3403. end
  3404. info.from = from
  3405. local goodsItem = GoodsItem:create(info)
  3406. widget:addChild(goodsItem)
  3407. goodsItem:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  3408. goodsItem:setScale(scale)
  3409. goodsItem:setIconGrey(grey == 1)
  3410. if count then
  3411. goodsItem:setCount(count)
  3412. end
  3413. if dblink and string.len(dblink) then
  3414. if not (showtips == 1) then
  3415. goodsItem:addLookItemInfoEvent(nil, 2)
  3416. end
  3417. goodsItem:addDoubleEventListener(function()
  3418. if callback then
  3419. local inputTable = self:getInputTable(submitInput)
  3420. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  3421. local jsonData = {}
  3422. jsonData.Act = dblink
  3423. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  3424. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  3425. self:linkFuncWithCheckWords(callback, jsonData)
  3426. end
  3427. end)
  3428. end
  3429. end
  3430. if link and string.len(link) > 0 and not dblink then
  3431. local linkWidget = global.SWidgetCache:generateRender("ccui.Widget")
  3432. widget:addChild(linkWidget)
  3433. linkWidget:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  3434. linkWidget:setContentSize(contentSize)
  3435. linkWidget:setTouchEnabled(true)
  3436. linkWidget:setSwallowTouches(false)
  3437. linkWidget:addClickEventListener(function()
  3438. if callback then
  3439. local inputTable = self:getInputTable(submitInput)
  3440. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  3441. local jsonData = {}
  3442. jsonData.Act = link
  3443. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  3444. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  3445. self:linkFuncWithCheckWords(callback, jsonData)
  3446. end
  3447. end)
  3448. end
  3449. return widget
  3450. end
  3451. function SUILoader:load_render_HEROBAGITEMS(swidget, callback)
  3452. local element = swidget.element
  3453. local condition = element.attr.condition or ""
  3454. local exclude = element.attr.exclude or ""
  3455. local select = element.attr.select or ""
  3456. local count = tonumber(element.attr.count) or 12
  3457. local row = tonumber(element.attr.row) or 2
  3458. local selecttype = tonumber(element.attr.selecttype) or 0
  3459. local showstar = tonumber(element.attr.showstar) == 1
  3460. local iwidth = tonumber(element.attr.iwidth) or 70
  3461. local iheight = tonumber(element.attr.iheight) or 70
  3462. local iimg = element.attr.iimg
  3463. local filter1 = element.attr.fliter1 or element.attr.filter1 or ""
  3464. local filter2 = element.attr.fliter2 or element.attr.filter2 or ""
  3465. local filter3 = element.attr.fliter3 or element.attr.filter3 or ""
  3466. local link = element.attr.link
  3467. local conditionEx = element.attr.conditionEx
  3468. local conditionParam = element.attr.conditionParam
  3469. local conditionOnOff = tonumber(element.attr.conditionOnOff) or 0
  3470. local condition2 = element.attr.condition2
  3471. local dblink = element.attr.dblink
  3472. local effectshow = tonumber(element.attr.effectshow) or 1
  3473. local itemscaleX = iwidth / 70
  3474. local itemscaleY = iheight / 70
  3475. -- 是否满足显示条件
  3476. local conditionT = {}
  3477. local slices1 = ssplit(condition, ",")
  3478. local slices2 = {}
  3479. for _, v in pairs(slices1) do
  3480. slices2 = ssplit(v, "#")
  3481. tinsert(conditionT, {StdMode = tonumber(slices2[1]), Shape = tonumber(slices2[2])})
  3482. end
  3483. -- 唯一ID过滤
  3484. local excludeT = {}
  3485. local slices = ssplit(exclude, ",")
  3486. for _, v in pairs(slices) do
  3487. tinsert(excludeT, tonumber(v))
  3488. end
  3489. -- 道具ID过滤,存在不显示
  3490. local filter1T = {}
  3491. local slices = ssplit(filter1, ",")
  3492. for _, v in pairs(slices) do
  3493. tinsert(filter1T, tonumber(v))
  3494. end
  3495. -- 道具名过滤,存在不显示
  3496. local filter2T = {}
  3497. local slices = ssplit(filter2, ",")
  3498. for _, v in pairs(slices) do
  3499. if v ~= "" then
  3500. tinsert(filter2T, v)
  3501. end
  3502. end
  3503. -- 道具ID过滤,存在才显示
  3504. local filter3T = {}
  3505. local slices = ssplit(filter3, ",")
  3506. for _, v in pairs(slices) do
  3507. if v ~= "" then
  3508. tinsert(filter3T, v)
  3509. end
  3510. end
  3511. local function conditionAble(item)
  3512. if conditionEx and tonumber(conditionEx) == 1 then
  3513. local starLv = item.Star or 0
  3514. if conditionOnOff and conditionOnOff == 0 then
  3515. if conditionParam and starLv < tonumber(conditionParam) then
  3516. return false
  3517. end
  3518. elseif conditionOnOff == 1 then
  3519. if conditionParam and starLv > tonumber(conditionParam) then
  3520. return false
  3521. end
  3522. end
  3523. end
  3524. -- 被排除
  3525. for _, v in ipairs(excludeT) do
  3526. if v == item.MakeIndex then
  3527. return false
  3528. end
  3529. end
  3530. -- 道具ID过滤
  3531. for _, v in ipairs(filter1T) do
  3532. if v == item.Index then
  3533. return false
  3534. end
  3535. end
  3536. -- 道具名过滤
  3537. for _, v in ipairs(filter2T) do
  3538. if v == item.Name then
  3539. return false
  3540. end
  3541. end
  3542. -- 道具ID/道具名过滤
  3543. if #filter3T > 0 then
  3544. for _, v in ipairs(filter3T) do
  3545. if tonumber(v) == item.Index or v == item.Name then
  3546. return true
  3547. end
  3548. end
  3549. return false
  3550. end
  3551. -- 筛选
  3552. if condition == "*" then
  3553. return true
  3554. end
  3555. for _, v in pairs(conditionT) do
  3556. if v.StdMode == item.StdMode and (not v.Shape or v.Shape == item.Shape) then
  3557. return true
  3558. end
  3559. end
  3560. if condition2 then
  3561. if tonumber(item.sDivParam2) and tonumber(item.sDivParam2) == tonumber(condition2) then
  3562. return true
  3563. elseif string.find(tostring(condition2), "#") then
  3564. local paramList = string.split(tostring(condition2), "#")
  3565. for _, param in ipairs(paramList) do
  3566. if tonumber(param) == tonumber(item.sDivParam2) then
  3567. return true
  3568. end
  3569. end
  3570. end
  3571. end
  3572. return false
  3573. end
  3574. -- 是否选中
  3575. local selects = {}
  3576. local slices = ssplit(select, ",")
  3577. for _, v in pairs(slices) do
  3578. tinsert(selects, tonumber(v))
  3579. end
  3580. local function selectAble(item)
  3581. for _, v in pairs(selects) do
  3582. if v == item.MakeIndex then
  3583. return true
  3584. end
  3585. end
  3586. return false
  3587. end
  3588. local itemWid = iwidth
  3589. local itemHei = iheight
  3590. local col = math.ceil(count / row)
  3591. local contentSize = cc.size(col * itemWid, row * itemHei)
  3592. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  3593. widget:setContentSize(contentSize)
  3594. --
  3595. local boxes = {}
  3596. for i = 1, count do
  3597. local x = ((i - 1) % col + 0.5) * itemWid
  3598. local y = contentSize.height - (mfloor((i - 1) / col) + 0.5) * itemHei
  3599. local iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  3600. local fullPath = string.format(getResFullPath("res/%s"), iimg)
  3601. local imageBG = ccui.ImageView:create()
  3602. widget:addChild(imageBG)
  3603. imageBG:loadTexture(fullPath)
  3604. GUI:Image_setScale9Slice(imageBG, 21, 22, 21, 22)
  3605. GUI:setContentSize(imageBG, itemWid, itemHei)
  3606. imageBG:setTouchEnabled(false)
  3607. imageBG:setAnchorPoint(cc.p(0.5, 0.5))
  3608. imageBG:setPosition(cc.p(x, y))
  3609. tinsert(boxes, imageBG)
  3610. end
  3611. -- bag items
  3612. local HeroBagProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroBagProxy)
  3613. local items = {}
  3614. for i = 1, global.MMO.MAX_ITEM_NUMBER do
  3615. local itemMakeIndex = HeroBagProxy:GetMakeIndexByBagPos(i)
  3616. if itemMakeIndex then
  3617. local itemData = HeroBagProxy:GetItemDataByMakeIndex(itemMakeIndex)
  3618. if itemData and conditionAble(itemData) then
  3619. tinsert(items, itemData)
  3620. end
  3621. end
  3622. end
  3623. --
  3624. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  3625. -- show
  3626. for index, item in ipairs(items) do
  3627. local imageBG = boxes[index]
  3628. if imageBG then
  3629. local size = imageBG:getContentSize()
  3630. -- 道具图标
  3631. local info = {index = item.Index, itemData = item, starLv = showstar}
  3632. if effectshow == 2 then
  3633. info.showModelEffect = true
  3634. elseif effectshow == 0 then
  3635. info.isShowEff = false
  3636. end
  3637. info.from = ItemMoveProxy.ItemFrom.HERO_BAG
  3638. local goodsItem = GoodsItem:create(info)
  3639. imageBG:addChild(goodsItem)
  3640. goodsItem:setPosition(cc.p(size.width/2, size.height/2))
  3641. goodsItem._canLooks = true
  3642. goodsItem:addLookItemInfoEvent(nil, 1)
  3643. goodsItem:setScaleX(itemscaleX)
  3644. goodsItem:setScaleY(itemscaleY)
  3645. -- link
  3646. if link and string.len(link) > 0 then
  3647. goodsItem:addTouchEventListener(function()
  3648. local selected = clone(selects)
  3649. if selecttype == 0 then
  3650. -- 多选
  3651. if selectAble(item) then
  3652. for key, value in pairs(selected) do
  3653. if item.MakeIndex == value then
  3654. table.remove(selected, key)
  3655. break
  3656. end
  3657. end
  3658. else
  3659. tinsert(selected, item.MakeIndex)
  3660. end
  3661. else
  3662. -- 单选
  3663. if selectAble(item) then
  3664. selected = {}
  3665. else
  3666. selected = {item.MakeIndex}
  3667. end
  3668. end
  3669. local jsonData = {}
  3670. jsonData.Act = link
  3671. jsonData.SelectItemID = table.concat(selected, ",")
  3672. callback(jsonData)
  3673. end, 2)
  3674. end
  3675. -- 选中
  3676. if selectAble(item) then
  3677. local imageS = ccui.ImageView:create()
  3678. imageBG:addChild(imageS)
  3679. imageS:loadTexture(global.MMO.PATH_RES_PUBLIC .. "1900000678_2.png")
  3680. imageS:ignoreContentAdaptWithSize(true)
  3681. imageS:setCapInsets(cc.rect(0, 0, 0, 0))
  3682. imageS:setScale9Enabled(false)
  3683. imageS:setTouchEnabled(false)
  3684. imageS:setAnchorPoint(cc.p(0.5,0.5))
  3685. imageS:setPosition(cc.p(size.width/2, size.height/2))
  3686. imageS:setScaleX(itemscaleX)
  3687. imageS:setScaleY(itemscaleY)
  3688. end
  3689. if dblink and string.len(dblink) then
  3690. goodsItem:addDoubleEventListener(function()
  3691. local jsonData = {}
  3692. jsonData.Act = dblink
  3693. jsonData.SelectItemID = item.MakeIndex
  3694. callback(jsonData)
  3695. end)
  3696. end
  3697. end
  3698. end
  3699. return widget
  3700. end
  3701. ---
  3702. function SUILoader:load_render_QuickTextView(swidget, callback)
  3703. local element = swidget.element
  3704. local text = element.attr.text or ""
  3705. local size = tonumber(element.attr.size) or defaultFontSize
  3706. local color = element.attr.color or defaultColorID
  3707. local outline = tonumber(element.attr.outline) or defaultOutline
  3708. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  3709. local direction = tonumber(element.attr.direction) or 1
  3710. local bounce = tonumber(element.attr.bounce) or 1
  3711. local margin = tonumber(element.attr.margin) or 0
  3712. local width = tonumber(element.attr.width) or 800
  3713. local height = tonumber(element.attr.height) or global.Director:getVisibleSize().height
  3714. local count = tonumber(element.attr.count) or 1
  3715. local function createText( str )
  3716. local item = global.SWidgetCache:generateRender("ccui.Text")
  3717. item:setScale(1)
  3718. item:setString(str)
  3719. item:setFontSize(size)
  3720. item:setFontName(defaultFontPath)
  3721. item:setTextColor(GET_COLOR_BYID_C3B(color))
  3722. item:setTouchEnabled(false)
  3723. item:stopAllActions()
  3724. item:disableEffect(1)
  3725. item:disableEffect(6)
  3726. item:getVirtualRenderer():setMaxLineWidth(0)
  3727. item:enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  3728. return item
  3729. end
  3730. local function createItem(loadText, wid, hei)
  3731. local panel = global.SWidgetCache:generateRender("ccui.Layout")
  3732. panel:setClippingEnabled(true)
  3733. panel:setContentSize(cc.size(wid, hei))
  3734. for i = 1, count do
  3735. if loadText and next(loadText) and loadText[i] then
  3736. local str = loadText[i]
  3737. local item = global.SWidgetCache:generateRender("ccui.Text")
  3738. item:setScale(1)
  3739. item:setString(str)
  3740. item:setFontSize(size)
  3741. item:setFontName(global.MMO.PATH_FONT)
  3742. item:setTextColor(GET_COLOR_BYID_C3B(color))
  3743. item:setTouchEnabled(false)
  3744. item:stopAllActions()
  3745. item:disableEffect(1)
  3746. item:disableEffect(6)
  3747. item:getVirtualRenderer():setMaxLineWidth(0)
  3748. item:enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  3749. item:setAnchorPoint(cc.p(0,0))
  3750. item:setPosition(cc.p(wid/count*(i-1), 0))
  3751. panel:addChild(item)
  3752. end
  3753. end
  3754. return panel
  3755. end
  3756. local widget = global.SWidgetCache:generateRender("ccui.ListView")
  3757. widget:ignoreContentAdaptWithSize(false)
  3758. widget:setClippingEnabled(true)
  3759. widget:setClippingType(0)
  3760. widget:setTouchEnabled(true)
  3761. widget:setDirection(direction)
  3762. widget:setGravity(0)
  3763. widget:setItemsMargin(margin)
  3764. widget:setBounceEnabled(bounce == 1)
  3765. widget:setBackGroundColorType(0)
  3766. widget:stopAllActions()
  3767. local textList = string.split(text, "\\")
  3768. local itemHei = 10
  3769. if textList and textList[1] then
  3770. itemHei = createText(textList[1]):getContentSize().height
  3771. end
  3772. local screenHeight = height-- global.Director:getVisibleSize().height
  3773. local limitSize = math.ceil(screenHeight/itemHei)
  3774. local loadText = clone(textList)
  3775. local loadNum = 0
  3776. local function loadItem( ... )
  3777. local lastIndex = #widget:getItems() - 1
  3778. while next(loadText) and loadNum < limitSize do
  3779. loadNum = loadNum + 1
  3780. local cell_data = {}
  3781. cell_data.wid = width
  3782. cell_data.hei = itemHei
  3783. local strList = {}
  3784. for i = 1, count do
  3785. if loadText and next(loadText) then
  3786. table.insert( strList, table.remove( loadText,1 ))
  3787. end
  3788. end
  3789. cell_data.createCell = function ()
  3790. local cell = createItem(strList, cell_data.wid, cell_data.hei)
  3791. return cell
  3792. end
  3793. local quickCell = QuickCell:Create(cell_data)
  3794. widget:pushBackCustomItem(quickCell)
  3795. end
  3796. if lastIndex >= 0 then
  3797. widget:jumpToItem(lastIndex, cc.p(0, 0), cc.p(0, 0))
  3798. end
  3799. end
  3800. loadItem()
  3801. local loadForce = true
  3802. widget:addScrollViewEventListener(function(sender, eventType)
  3803. local itemNum = #sender:getItems()
  3804. local BottomItem = sender:getBottommostItemInCurrentView()
  3805. local innerPos = widget:getInnerContainerPosition()
  3806. if (eventType == 1 or ((eventType == 10 or eventType == 9) and innerPos.y == 0)) and next(loadText) then
  3807. loadNum = 0
  3808. if loadForce then
  3809. loadForce = false
  3810. PerformWithDelayGlobal( function()
  3811. loadForce = true
  3812. end, 0.5 )
  3813. loadItem()
  3814. end
  3815. end
  3816. end)
  3817. widget:addMouseScrollPercent()
  3818. return widget
  3819. end
  3820. function SUILoader:load_render_RTextX(swidget, callback)
  3821. local element = swidget.element
  3822. local text = element.attr.text or ""
  3823. local size = tonumber(element.attr.size) or defaultFontSize
  3824. local color = tonumber(element.attr.color) or defaultColorID
  3825. local width = tonumber(element.attr.width) or 1136
  3826. local link = element.attr.link
  3827. local submitInput = element.attr.submitInput
  3828. local submitCheckBox = element.attr.submitCheckBox
  3829. local outline = tonumber(element.attr.outline) or defaultOutline
  3830. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  3831. local scrollWidth = tonumber(element.attr.scrollWidth)
  3832. local scrollWay = tonumber(element.attr.scrollWay) or 0 -- 0 从右到左 1 从下到上
  3833. local scrollTime = tonumber(element.attr.scrollTime) or 4
  3834. local scrollHeight = tonumber(element.attr.scrollHeight)
  3835. local function textCB(str)
  3836. if callback then
  3837. local jsonData = {}
  3838. jsonData.Act = str
  3839. callback(jsonData)
  3840. end
  3841. end
  3842. local ttfConfig = {
  3843. outlineSize = outline,
  3844. outlineColor = GET_COLOR_BYID_C3B(outlinecolor)
  3845. }
  3846. local SUI_RTEXT_FONT_PATH = SL:GetMetaValue("WINPLAYMODE") and SL:GetMetaValue("GAME_DATA","SUI_RTEXT_FONT_PATH") or nil
  3847. local fontPath = SUI_RTEXT_FONT_PATH or defaultFontPath
  3848. local widget = RichTextHelp:CreateRichTextWithXML(text, width, size, GET_COLOR_BYID(color), fontPath, textCB, SL:GetMetaValue("GAME_DATA","DEFAULT_VSPACE"))
  3849. self:addMouseOverTips(widget, element)
  3850. -- auto scroll
  3851. if scrollWidth then
  3852. local widgetSize = widget:getContentSize()
  3853. local scrollH = scrollHeight or widgetSize.height
  3854. local scrollLayout = global.SWidgetCache:generateRender("ccui.Layout")
  3855. scrollLayout:setClippingEnabled(true)
  3856. scrollLayout:setClippingType(0)
  3857. scrollLayout:setContentSize(cc.size(scrollWidth, scrollH))
  3858. scrollLayout:addChild(widget)
  3859. widget:setAnchorPoint(cc.p(0, 0))
  3860. widget:setPosition(cc.p(0, 0))
  3861. if scrollWay == 0 then
  3862. widget:runAction(cc.RepeatForever:create(cc.Sequence:create(
  3863. cc.MoveBy:create(scrollTime, cc.p(-widgetSize.width, 0)),
  3864. cc.MoveBy:create(0, cc.p(widgetSize.width, 0)))
  3865. ))
  3866. elseif scrollWay == 1 then
  3867. widget:setAnchorPoint(cc.p(0, 1))
  3868. widget:setPosition(cc.p(0, scrollH))
  3869. widget:runAction(cc.RepeatForever:create(cc.Sequence:create(
  3870. cc.MoveBy:create(scrollTime, cc.p(0, widgetSize.height)),
  3871. cc.MoveBy:create(0, cc.p(0, -widgetSize.height))
  3872. )))
  3873. end
  3874. return scrollLayout
  3875. end
  3876. return widget
  3877. end
  3878. function SUILoader:load_render_DLINKITEMS(swidget, callback)
  3879. local element = swidget.element
  3880. local condition = element.attr.condition or ""
  3881. local exclude = element.attr.exclude or ""
  3882. local select = element.attr.select or ""
  3883. local count = tonumber(element.attr.count) or 12
  3884. local row = tonumber(element.attr.row) or 2
  3885. local selecttype = tonumber(element.attr.selecttype) or 0
  3886. local showstar = tonumber(element.attr.showstar) == 1
  3887. local iwidth = tonumber(element.attr.iwidth) or 70
  3888. local iheight = tonumber(element.attr.iheight) or 70
  3889. local iimg = element.attr.iimg
  3890. local filter1 = element.attr.fliter1 or element.attr.filter1 or ""
  3891. local filter2 = element.attr.fliter2 or element.attr.filter2 or ""
  3892. local filter3 = element.attr.fliter3 or element.attr.filter3 or ""
  3893. local link = element.attr.link
  3894. local conditionEx = element.attr.conditionEx
  3895. local conditionParam = element.attr.conditionParam
  3896. local conditionOnOff = tonumber(element.attr.conditionOnOff) or 0
  3897. local itemscaleX = iwidth / 70
  3898. local itemscaleY = iheight / 70
  3899. -- 是否满足显示条件
  3900. local conditionT = {}
  3901. local slices1 = ssplit(condition, ",")
  3902. local slices2 = {}
  3903. for _, v in pairs(slices1) do
  3904. slices2 = ssplit(v, "#")
  3905. tinsert(conditionT, {StdMode = tonumber(slices2[1]), Shape = tonumber(slices2[2])})
  3906. end
  3907. -- 唯一ID过滤
  3908. local excludeT = {}
  3909. local slices = ssplit(exclude, ",")
  3910. for _, v in pairs(slices) do
  3911. tinsert(excludeT, tonumber(v))
  3912. end
  3913. -- 道具ID过滤,存在不显示
  3914. local filter1T = {}
  3915. local slices = ssplit(filter1, ",")
  3916. for _, v in pairs(slices) do
  3917. tinsert(filter1T, tonumber(v))
  3918. end
  3919. -- 道具名过滤,存在不显示
  3920. local filter2T = {}
  3921. local slices = ssplit(filter2, ",")
  3922. for _, v in pairs(slices) do
  3923. if v ~= "" then
  3924. tinsert(filter2T, v)
  3925. end
  3926. end
  3927. -- 道具ID过滤,存在才显示
  3928. local filter3T = {}
  3929. local slices = ssplit(filter3, ",")
  3930. for _, v in pairs(slices) do
  3931. if v ~= "" then
  3932. tinsert(filter3T, v)
  3933. end
  3934. end
  3935. local function conditionAble(item)
  3936. if conditionEx and tonumber(conditionEx) == 1 then
  3937. local starLv = item.Star or 0
  3938. if conditionOnOff and conditionOnOff == 0 then
  3939. if conditionParam and starLv < tonumber(conditionParam) then
  3940. return false
  3941. end
  3942. elseif conditionOnOff == 1 then
  3943. if conditionParam and starLv > tonumber(conditionParam) then
  3944. return false
  3945. end
  3946. end
  3947. end
  3948. -- 被排除
  3949. for _, v in ipairs(excludeT) do
  3950. if v == item.MakeIndex then
  3951. return false
  3952. end
  3953. end
  3954. -- 道具ID过滤
  3955. for _, v in ipairs(filter1T) do
  3956. if v == item.Index then
  3957. return false
  3958. end
  3959. end
  3960. -- 道具名过滤
  3961. for _, v in ipairs(filter2T) do
  3962. if v == item.Name then
  3963. return false
  3964. end
  3965. end
  3966. -- 道具ID/道具名过滤
  3967. if #filter3T > 0 then
  3968. for _, v in ipairs(filter3T) do
  3969. if tonumber(v) == item.Index or v == item.Name then
  3970. return true
  3971. end
  3972. end
  3973. return false
  3974. end
  3975. -- 筛选
  3976. if condition == "*" then
  3977. return true
  3978. end
  3979. for _, v in pairs(conditionT) do
  3980. if v.StdMode == item.StdMode and (not v.Shape or v.Shape == item.Shape) then
  3981. return true
  3982. end
  3983. end
  3984. return false
  3985. end
  3986. local itemWid = iwidth
  3987. local itemHei = iheight
  3988. local col = math.ceil(count / row)
  3989. local contentSize = cc.size(col * itemWid, row * itemHei)
  3990. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  3991. widget:setContentSize(contentSize)
  3992. --
  3993. local boxes = {}
  3994. for i = 1, count do
  3995. local x = ((i - 1) % col + 0.5) * itemWid
  3996. local y = contentSize.height - (mfloor((i - 1) / col) + 0.5) * itemHei
  3997. local iimg = (iimg and iimg ~= "") and SUIHelper.fixImageFileName(iimg) or "public/1900000664.png"
  3998. local fullPath = string.format(getResFullPath("res/%s"), iimg)
  3999. local imageBG = ccui.ImageView:create()
  4000. widget:addChild(imageBG)
  4001. imageBG:loadTexture(fullPath)
  4002. GUI:Image_setScale9Slice(imageBG, 21, 22, 21, 22)
  4003. GUI:setContentSize(imageBG, itemWid, itemHei)
  4004. imageBG:setTouchEnabled(false)
  4005. imageBG:setAnchorPoint(cc.p(0.5, 0.5))
  4006. imageBG:setPosition(cc.p(x, y))
  4007. tinsert(boxes, imageBG)
  4008. end
  4009. -- bag items
  4010. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  4011. local items = {}
  4012. local BagMaxNum = BagProxy:GetMaxBag()
  4013. for i = 1, BagMaxNum do
  4014. local itemMakeIndex = BagProxy:GetMakeIndexByBagPos(i)
  4015. if itemMakeIndex then
  4016. local itemData = BagProxy:GetItemDataByMakeIndex(itemMakeIndex)
  4017. if itemData and conditionAble(itemData) then
  4018. tinsert(items, itemData)
  4019. end
  4020. end
  4021. end
  4022. --
  4023. -- show
  4024. for index, item in ipairs(items) do
  4025. local imageBG = boxes[index]
  4026. if imageBG then
  4027. local size = imageBG:getContentSize()
  4028. -- 道具图标
  4029. local goodsItem = GoodsItem:create({index = item.Index, itemData = item, starLv = showstar,look = true})
  4030. imageBG:addChild(goodsItem)
  4031. goodsItem:setPosition(cc.p(size.width/2, size.height/2))
  4032. goodsItem:setScaleX(itemscaleX)
  4033. goodsItem:setScaleY(itemscaleY)
  4034. -- link
  4035. if link and string.len(link) > 0 then
  4036. goodsItem:addDoubleEventListener(function()
  4037. local jsonData = {}
  4038. jsonData.Act = link
  4039. jsonData.SelectItemID = item.MakeIndex
  4040. callback(jsonData)
  4041. end)
  4042. end
  4043. end
  4044. end
  4045. return widget
  4046. end
  4047. function SUILoader:load_render_MKItemShow(swidget, callback)
  4048. local element = swidget.element
  4049. local makeindex = tonumber(element.attr.makeindex) or 1
  4050. local showtips = tonumber(element.attr.showtips) or 1
  4051. local bgtype = tonumber(element.attr.bgtype)
  4052. local scale = tonumber(element.attr.scale) or 1
  4053. local grey = tonumber(element.attr.grey) or 0
  4054. local showstar = tonumber(element.attr.showstar) == 1
  4055. local count = tonumber(element.attr.count)
  4056. local link = element.attr.link
  4057. local submitInput = element.attr.submitInput
  4058. local submitCheckBox = element.attr.submitCheckBox
  4059. local canmove = tonumber(element.attr.canmove) or 0
  4060. local effectshow = tonumber(element.attr.effectshow) or 1 -- 1只显示背包 2只显示内观 0不显示
  4061. local itemData = nil
  4062. if not itemData then
  4063. local PetsEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.PetsEquipProxy)
  4064. itemData = PetsEquipProxy:GetEquipDataByMakeIndex(makeindex)
  4065. end
  4066. -- 人物
  4067. if not itemData then
  4068. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  4069. itemData = EquipProxy:GetEquipDataByMakeIndex(makeindex)
  4070. end
  4071. if not itemData then
  4072. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  4073. itemData = BagProxy:GetItemDataByMakeIndex(makeindex)
  4074. end
  4075. -- 英雄
  4076. if not itemData then
  4077. local HeroEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  4078. itemData = HeroEquipProxy:GetEquipDataByMakeIndex(makeindex)
  4079. end
  4080. if not itemData then
  4081. local HeroBagProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroBagProxy)
  4082. itemData = HeroBagProxy:GetItemDataByMakeIndex(makeindex)
  4083. end
  4084. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4085. local contentSize = cc.size(66,66)
  4086. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  4087. widget:setContentSize(contentSize)
  4088. if itemData then
  4089. local info = {}
  4090. info.index = itemData.Index
  4091. info.itemData = itemData
  4092. -- info.look = showtips == 1
  4093. info.bgVisible = bgtype == 1
  4094. info.starLv = showstar
  4095. info.from = ItemMoveProxy.ItemFrom.PETS_EQUIP
  4096. info.movable = false
  4097. if effectshow == 2 then
  4098. info.showModelEffect = true
  4099. elseif effectshow == 0 then
  4100. info.isShowEff = false
  4101. end
  4102. local goodsItem = GoodsItem:create(info)
  4103. widget:addChild(goodsItem)
  4104. goodsItem:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  4105. goodsItem:setScale(scale)
  4106. goodsItem:setIconGrey(grey == 1)
  4107. if count then
  4108. goodsItem:setCount(count)
  4109. end
  4110. local function linkFunc()
  4111. if link and string.len(link) > 0 then
  4112. local jsonData = {}
  4113. jsonData.Act = link
  4114. jsonData.SelectItemID = itemData.MakeIndex
  4115. if callback then
  4116. callback(jsonData)
  4117. end
  4118. end
  4119. end
  4120. local itemMoveState = {
  4121. begin = 1,
  4122. moving = 2,
  4123. end_move = 3,
  4124. }
  4125. local function SetGoodItemState(state, movePos)
  4126. if not itemData then
  4127. return
  4128. end
  4129. if itemMoveState.begin == state then
  4130. if widget and not tolua.isnull(widget) then
  4131. widget._movingState = true
  4132. widget:setVisible(false)
  4133. end
  4134. global.Facade:sendNotification(global.NoticeTable.Layer_ItemTips_Close)
  4135. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_Begin,{
  4136. pos = movePos,
  4137. itemData = itemData,
  4138. linkFunc = linkFunc,
  4139. cancelCallBack = function()
  4140. if widget and not tolua.isnull(widget) then
  4141. widget._movingState = false
  4142. widget:setVisible(true)
  4143. end
  4144. end,
  4145. from = ItemMoveProxy.ItemFrom.PETS_EQUIP
  4146. })
  4147. elseif itemMoveState.moving == state then
  4148. elseif itemMoveState.end_move == state then
  4149. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_End, movePos)
  4150. end
  4151. end
  4152. local function doubleEventCallBack()
  4153. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4154. local itemMoving = ItemMoveProxy:GetMovingItemState()
  4155. if itemMoving then --在道具移动中
  4156. return
  4157. end
  4158. if itemData then
  4159. linkFunc()
  4160. end
  4161. end
  4162. local function clickEventCallBack(widget, eventtype)
  4163. if tolua.isnull(widget) then
  4164. return
  4165. end
  4166. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4167. if not itemData or widget._movingState then
  4168. return
  4169. end
  4170. local panelPos = widget:getWorldPosition()
  4171. if global.isWinPlayMode and canmove == 1 then
  4172. SetGoodItemState(itemMoveState.begin, panelPos)
  4173. else
  4174. if showtips == 1 then
  4175. local data = {}
  4176. data.itemData = itemData
  4177. data.pos = panelPos
  4178. data.from = ItemMoveProxy.ItemFrom.PETS_EQUIP
  4179. global.Facade:sendNotification(global.NoticeTable.Layer_ItemTips_Open, data)
  4180. end
  4181. end
  4182. end
  4183. local pressEventCallBack = clickEventCallBack
  4184. local isEventPress = false
  4185. local isMoved = true
  4186. local hasEventCallOnTouchBegin = false --只有在响应了touchbegin 时才会去响应延时方法 因为在延时后 鼠标事件的 状态已经被置掉
  4187. local isMobile = not global.isWinPlayMode
  4188. local function delayCallback()
  4189. isEventPress = true
  4190. if pressEventCallBack then
  4191. if not pressEventCallBack then
  4192. return false
  4193. end
  4194. if not isMoved then
  4195. pressEventCallBack()
  4196. return false
  4197. end
  4198. local movedPos = widget:getTouchMovePosition()
  4199. local beganPos = widget:getTouchBeganPosition()
  4200. local diff = cc.pSub(movedPos, beganPos)
  4201. local distSq = cc.pLengthSQ(diff)
  4202. if distSq <= 100 then
  4203. pressEventCallBack()
  4204. end
  4205. end
  4206. end
  4207. local function touchEvent( touch, eventType )
  4208. if global.OperatingMode == global.MMO.OPERATING_MODE_WINDOWS then
  4209. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  4210. local itemMoving = ItemMoveProxy:GetMovingItemState()
  4211. if itemMoving then --在道具移动中
  4212. return
  4213. end
  4214. end
  4215. if eventType == 0 then
  4216. isEventPress = false
  4217. isMoved = false
  4218. hasEventCallOnTouchBegin = true
  4219. if pressEventCallBack then
  4220. performWithDelay(widget, delayCallback, global.MMO.CLICK_DOUBLE_TIME)
  4221. end
  4222. elseif eventType == 1 then
  4223. local movedPos = widget:getTouchMovePosition()
  4224. local beganPos = widget:getTouchBeganPosition()
  4225. local diff = cc.pSub(movedPos, beganPos)
  4226. local distSq = cc.pLengthSQ(diff)
  4227. if not isMoved and distSq > 100 then
  4228. isMoved = true
  4229. if isMobile and canmove == 1 then
  4230. local beginMovePos = widget:getWorldPosition()
  4231. SetGoodItemState(itemMoveState.begin, beginMovePos)
  4232. end
  4233. end
  4234. if isMobile then
  4235. local movedPos = widget:getTouchMovePosition()
  4236. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_Moving,{pos = movedPos})
  4237. end
  4238. elseif eventType == 2 then
  4239. widget:stopAllActions()
  4240. if not isMoved then
  4241. if not isEventPress then
  4242. -- 判断是否有双击事件
  4243. if doubleEventCallBack then
  4244. -- 记录上一次点击时间
  4245. if not widget._lastClickTime then
  4246. widget._lastClickTime = true
  4247. -- 记录单击触发
  4248. -- 记录进入此处时的状态,避免在延时操作后状态被改变
  4249. local stateOnbegin = hasEventCallOnTouchBegin
  4250. widget._clickDelayHandler =
  4251. PerformWithDelayGlobal(
  4252. function()
  4253. if clickEventCallBack and stateOnbegin then
  4254. clickEventCallBack(widget, eventType)
  4255. end
  4256. widget._lastClickTime = nil
  4257. end,
  4258. global.MMO.CLICK_DOUBLE_TIME
  4259. )
  4260. else
  4261. if widget._clickDelayHandler then
  4262. UnSchedule(widget._clickDelayHandler)
  4263. widget._clickDelayHandler = nil
  4264. end
  4265. if doubleEventCallBack then
  4266. doubleEventCallBack()
  4267. end
  4268. widget._lastClickTime = nil
  4269. end
  4270. else
  4271. if clickEventCallBack then
  4272. clickEventCallBack(widget, eventType)
  4273. end
  4274. end
  4275. end
  4276. else
  4277. if isMobile and canmove == 1 then
  4278. local endPos = widget:getTouchEndPosition()
  4279. SetGoodItemState(itemMoveState.end_move, endPos)
  4280. end
  4281. end
  4282. hasEventCallOnTouchBegin = false
  4283. elseif eventType == 3 then
  4284. if isMobile and canmove == 1 then
  4285. local endPos = widget:getTouchEndPosition()
  4286. SetGoodItemState(itemMoveState.end_move, endPos)
  4287. end
  4288. hasEventCallOnTouchBegin = false
  4289. end
  4290. end
  4291. widget:setTouchEnabled(true)
  4292. widget:addTouchEventListener( touchEvent )
  4293. end
  4294. return widget
  4295. end
  4296. function SUILoader:load_render_PETEQUIPSHOW(swidget, callback)
  4297. local element = swidget.element
  4298. local index = tonumber(element.attr.index) or 0
  4299. local showtips = tonumber(element.attr.showtips) or 1
  4300. local bgtype = tonumber(element.attr.bgtype)
  4301. local scale = tonumber(element.attr.scale) or 1
  4302. local grey = tonumber(element.attr.grey) or 0
  4303. local showstar = tonumber(element.attr.showstar) == 1
  4304. local link = element.attr.link
  4305. local submitInput = element.attr.submitInput
  4306. local submitCheckBox = element.attr.submitCheckBox
  4307. local dblink = element.attr.dblink
  4308. local contentSize = cc.size(66,66)
  4309. local widget = global.SWidgetCache:generateRender("ccui.Widget")
  4310. widget:setContentSize(contentSize)
  4311. local PetsEquipProxy = global.Facade:retrieveProxy(global.ProxyTable.PetsEquipProxy)
  4312. local curSelectPetIdx = PetsEquipProxy:GetSelectPetIdx()
  4313. local equipData = PetsEquipProxy:GetEquipDataByPos(curSelectPetIdx, index)
  4314. if equipData then
  4315. local info = {}
  4316. info.index = equipData.Index
  4317. info.itemData = equipData
  4318. info.look = showtips == 1
  4319. info.bgVisible = bgtype == 1
  4320. info.starLv = showstar
  4321. if not info.look and global.isWinPlayMode then
  4322. info.noMouseTips = true
  4323. end
  4324. local goodsItem = GoodsItem:create(info)
  4325. widget:addChild(goodsItem)
  4326. goodsItem:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  4327. goodsItem:setScale(scale)
  4328. goodsItem:setIconGrey(grey == 1)
  4329. if dblink and string.len(dblink) then
  4330. if not (showtips == 1) then
  4331. goodsItem:addLookItemInfoEvent(nil, 2)
  4332. end
  4333. goodsItem:addDoubleEventListener(function()
  4334. if callback then
  4335. local inputTable = self:getInputTable(submitInput)
  4336. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  4337. local jsonData = {}
  4338. jsonData.Act = dblink
  4339. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  4340. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  4341. self:linkFuncWithCheckWords(callback, jsonData)
  4342. end
  4343. end)
  4344. end
  4345. end
  4346. if link and not dblink then
  4347. local linkWidget = global.SWidgetCache:generateRender("ccui.Widget")
  4348. widget:addChild(linkWidget)
  4349. linkWidget:setPosition(cc.p(contentSize.width/2, contentSize.height/2))
  4350. linkWidget:setContentSize(contentSize)
  4351. linkWidget:setTouchEnabled(true)
  4352. linkWidget:setSwallowTouches(false)
  4353. linkWidget:addClickEventListener(function()
  4354. if callback then
  4355. local inputTable = self:getInputTable(submitInput)
  4356. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  4357. local jsonData = {}
  4358. jsonData.Act = link
  4359. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  4360. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  4361. self:linkFuncWithCheckWords(callback, jsonData)
  4362. end
  4363. end)
  4364. end
  4365. return widget
  4366. end
  4367. function SUILoader:load_render_PageView(swidget, callback)
  4368. local element = swidget.element
  4369. local width = element.attr.width or 200
  4370. local height = element.attr.height or 200
  4371. local color = tonumber(element.attr.color)
  4372. -- local direction = tonumber(element.attr.direction) or 2
  4373. local default = tonumber(element.attr.default)
  4374. local cantouch = tonumber(element.attr.cantouch) or 1
  4375. local widget = ccui.PageView:create()
  4376. widget:ignoreContentAdaptWithSize(false)
  4377. widget:setClippingEnabled(true)
  4378. widget:setClippingType(0)
  4379. widget:setTouchEnabled(true)
  4380. -- widget:setDirection(direction)
  4381. widget:setBackGroundColorType(0)
  4382. widget:stopAllActions()
  4383. if DEBUG_MODE then
  4384. widget:setBackGroundColorType(1)
  4385. widget:setBackGroundColorOpacity(100)
  4386. widget:setBackGroundColor(cc.Color3B.GREEN)
  4387. end
  4388. -- color
  4389. if color then
  4390. widget:setBackGroundColorType(1)
  4391. widget:setBackGroundColorOpacity(255)
  4392. widget:setBackGroundColor(GET_COLOR_BYID_C3B(color))
  4393. end
  4394. -- default
  4395. if default then
  4396. -- default
  4397. local function callback()
  4398. default = default - 1
  4399. local index = math.max(default, 0)
  4400. widget:setCurrentPageIndex(index)
  4401. widget:doLayout()
  4402. end
  4403. performWithDelay(widget, callback, 1/60)
  4404. end
  4405. if cantouch == 0 then
  4406. widget:setTouchEnabled(false)
  4407. end
  4408. return widget
  4409. end
  4410. function SUILoader:load_render_Slider(swidget, callback)
  4411. local element = swidget.element
  4412. local sliderid = element.attr.sliderid
  4413. local ballPath = element.attr.ballimg or "public/bg_szjm_02_1.png"
  4414. local barPath = element.attr.barimg or "public/bg_szjm_02.png"
  4415. local bgPath = element.attr.bgimg or "public/bg_szjm_01.png"
  4416. local default = tonumber(element.attr.defvalue) or 0
  4417. local maxValue = tonumber(element.attr.maxvalue) or 100
  4418. local link = element.attr.link
  4419. local SUIComponentProxy = global.Facade:retrieveProxy(global.ProxyTable.SUIComponentProxy)
  4420. local defaultPer = mfloor(default)
  4421. ballPath = SUIHelper.fixImageFileName(ballPath)
  4422. barPath = SUIHelper.fixImageFileName(barPath)
  4423. bgPath = SUIHelper.fixImageFileName(bgPath)
  4424. local widget = ccui.Slider:create()
  4425. widget:loadBarTexture(string.format(getResFullPath("res/%s"), bgPath), 0)
  4426. widget:loadProgressBarTexture(string.format(getResFullPath("res/%s"), barPath), 0)
  4427. widget:loadSlidBallTextureNormal(string.format(getResFullPath("res/%s"), ballPath), 0)
  4428. widget:ignoreContentAdaptWithSize(false)
  4429. widget:setTouchEnabled(true)
  4430. widget:setMaxPercent(maxValue)
  4431. widget:setPercent(defaultPer)
  4432. widget:addEventListener(function(_, eventType)
  4433. if eventType == 0 then
  4434. local per = widget:getPercent()
  4435. local curValue = mfloor(per)
  4436. if self._sliderWidgets[sliderid] then
  4437. self._sliderWidgets[sliderid].value = curValue
  4438. end
  4439. SUIComponentProxy:SetSUISliderValueById(sliderid, curValue)
  4440. global.Facade:sendNotification(global.NoticeTable.SUISlider_Value_Change)
  4441. elseif eventType == 2 then
  4442. if callback then
  4443. local sliderTable = self:getSliderTableByID(sliderid)
  4444. local jsonData = {}
  4445. jsonData.Act = link
  4446. jsonData.Slider = (#sliderTable > 0 and sliderTable or nil)
  4447. callback(jsonData)
  4448. end
  4449. end
  4450. end)
  4451. if sliderid and self._sliderWidgets then
  4452. self._sliderWidgets[sliderid] = {
  4453. widget = widget,
  4454. value = default
  4455. }
  4456. SUIComponentProxy:SetSUISliderValueById(sliderid, default)
  4457. global.Facade:sendNotification(global.NoticeTable.SUISlider_Value_Change)
  4458. end
  4459. return widget
  4460. end
  4461. local function fixPosition(p)
  4462. if not p then
  4463. return nil
  4464. end
  4465. if tonumber(p) then
  4466. return mfloor(p)
  4467. end
  4468. return cc.p(mfloor(p.x), mfloor(p.y))
  4469. end
  4470. function SUILoader:load_render_MenuItem(swidget, callback)
  4471. local element = swidget.element
  4472. local menuid = element.attr.menuid
  4473. local imgPath = element.attr.img or "public/1900000668.png"
  4474. local arrowPath = element.attr.arrowimg or "public/btn_szjm_01.png"
  4475. local listPath = element.attr.listimg or "public/1900000677.png"
  4476. local itemname = element.attr.itemname
  4477. local select = element.attr.select or ""
  4478. local selectimg = element.attr.selectimg or "public/1900000678.png"
  4479. local direction = tonumber(element.attr.direction) or 0 -- 默认0下拉 1上拉
  4480. local width = tonumber(element.attr.width)
  4481. local height = tonumber(element.attr.height)
  4482. local itemHei = tonumber(element.attr.itemhei) or 16
  4483. local fontSize = tonumber(element.attr.fontsize) or 14
  4484. local fontColor = tonumber(element.attr.fontcolor) or 255
  4485. local selectColor = tonumber(element.attr.selectcolor)
  4486. local maxHei = tonumber(element.attr.maxhei)
  4487. local link = element.attr.link
  4488. local itemList = {}
  4489. if itemname and string.len(itemname) > 0 then
  4490. itemList = string.split(itemname, "#")
  4491. end
  4492. local selectPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(selectimg))
  4493. imgPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(imgPath))
  4494. arrowPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(arrowPath))
  4495. listPath = string.format(getResFullPath("res/%s"), SUIHelper.fixImageFileName(listPath))
  4496. -- 默认显示选项
  4497. local widget = ccui.ImageView:create()
  4498. widget:loadTexture(imgPath)
  4499. widget:ignoreContentAdaptWithSize(false)
  4500. if not width then
  4501. width = widget:getVirtualRendererSize().width
  4502. end
  4503. if not height then
  4504. height = widget:getVirtualRendererSize().height
  4505. end
  4506. widget:setContentSize(cc.size(width, height))
  4507. local arrow = ccui.ImageView:create()
  4508. arrow:loadTexture(arrowPath)
  4509. arrow:setAnchorPoint(cc.p(1, 0.5))
  4510. arrow:setPosition(fixPosition(cc.p(width - 6, height / 2)))
  4511. arrow:setFlippedY(direction == 0)
  4512. arrow:addTo(widget)
  4513. local showText = ccui.Text:create()
  4514. showText:setAnchorPoint(cc.p(0.5, 0.5))
  4515. showText:setPosition(fixPosition(cc.p(width / 2, height / 2)))
  4516. showText:setFontName(global.MMO.PATH_FONT)
  4517. showText:setFontSize(fontSize)
  4518. showText:setTextColor(GET_COLOR_BYID_C3B(fontColor))
  4519. showText:setString(select)
  4520. showText:addTo(widget)
  4521. if not next(itemList) then
  4522. return widget
  4523. end
  4524. local menuListView = nil
  4525. local itemCells = {}
  4526. local isOpen = false
  4527. local function onRefreshSelect()
  4528. for _, cell in ipairs(itemCells) do
  4529. local titleText = cell.title
  4530. local selectImg = cell.selectImg
  4531. if titleText and selectImg then
  4532. local name = titleText:getString()
  4533. if select and name == select then
  4534. selectImg:setVisible(true)
  4535. if selectColor then
  4536. titleText:setTextColor(GET_COLOR_BYID_C3B(selectColor))
  4537. end
  4538. else
  4539. selectImg:setVisible(false)
  4540. titleText:setTextColor(GET_COLOR_BYID_C3B(fontColor))
  4541. end
  4542. end
  4543. end
  4544. showText:setString(select)
  4545. arrow:setFlippedY(direction == 0)
  4546. if widget:getChildByTag(777) then
  4547. widget:removeChildByTag(777)
  4548. isOpen = false
  4549. end
  4550. end
  4551. local function showItemList()
  4552. isOpen = not isOpen
  4553. if widget:getChildByTag(777) then
  4554. widget:removeChildByTag(777)
  4555. end
  4556. if not isOpen then
  4557. arrow:setFlippedY(direction == 0)
  4558. return
  4559. end
  4560. arrow:setFlippedY(direction ~= 0)
  4561. local num = #itemList
  4562. local menuListBg = ccui.ImageView:create()
  4563. menuListBg:loadTexture(listPath)
  4564. menuListBg:ignoreContentAdaptWithSize(false)
  4565. menuListBg:setScale9Enabled(true)
  4566. menuListBg:setCapInsets({x = 21, y = 33, width = 23, height = 34})
  4567. local aPoint = direction == 0 and cc.p(0, 1) or cc.p(0, 0)
  4568. menuListBg:setAnchorPoint(aPoint)
  4569. local posX = width * (0 - widget:getAnchorPoint().x)
  4570. local posY = direction == 0 and height * (0 - widget:getAnchorPoint().y) or height * (1 - widget:getAnchorPoint().y)
  4571. local posY = direction == 0 and 0 or height
  4572. menuListBg:setPosition(fixPosition(cc.p(0, posY)))
  4573. menuListBg:setTag(777)
  4574. widget:addChild(menuListBg)
  4575. menuListView = ccui.ListView:create()
  4576. menuListBg:addChild(menuListView)
  4577. menuListView:setPosition(fixPosition(cc.p(width/2, 3)))
  4578. menuListView:setAnchorPoint(cc.p(0.5, 0))
  4579. menuListView:setContentSize(cc.size(width, 0))
  4580. menuListView:setClippingEnabled(true)
  4581. menuListView:setClippingType(0)
  4582. menuListView:setTouchEnabled(true)
  4583. menuListView:setDirection(1)
  4584. for id, name in ipairs(itemList) do
  4585. if string.len(name) > 0 then
  4586. local channel_cell = ccui.Layout:create()
  4587. channel_cell:setContentSize(cc.size(width, itemHei))
  4588. local selectImg = ccui.ImageView:create()
  4589. selectImg:setPosition(fixPosition(cc.p(width/2, itemHei/2)))
  4590. selectImg:loadTexture(selectPath)
  4591. selectImg:ignoreContentAdaptWithSize(false)
  4592. selectImg:setContentSize(cc.size(width, itemHei))
  4593. selectImg:addTo(channel_cell)
  4594. local titleText = ccui.Text:create()
  4595. titleText:setAnchorPoint(cc.p(0.5, 0.5))
  4596. titleText:setPosition(fixPosition(cc.p(width/2, itemHei/2)))
  4597. titleText:setFontName(global.MMO.PATH_FONT)
  4598. titleText:setFontSize(fontSize)
  4599. titleText:setString(name)
  4600. titleText:addTo(channel_cell)
  4601. if select and name == select then
  4602. selectImg:setVisible(true)
  4603. if selectColor then
  4604. titleText:setTextColor(GET_COLOR_BYID_C3B(selectColor))
  4605. end
  4606. else
  4607. selectImg:setVisible(false)
  4608. titleText:setTextColor(GET_COLOR_BYID_C3B(fontColor))
  4609. end
  4610. channel_cell:setTouchEnabled(true)
  4611. channel_cell:addClickEventListener(function()
  4612. select = name
  4613. onRefreshSelect()
  4614. if callback then
  4615. local menuTable = self:getMenuItemTableByID(menuid)
  4616. local jsonData = {}
  4617. jsonData.Act = link
  4618. jsonData.MenuItem = (#menuTable > 0 and menuTable or nil)
  4619. callback(jsonData)
  4620. end
  4621. end)
  4622. menuListView:pushBackCustomItem(channel_cell)
  4623. itemCells[id] = {cell = channel_cell, title = titleText, selectImg = selectImg}
  4624. end
  4625. end
  4626. local count = #menuListView:getChildren()
  4627. local listWid = menuListView:getContentSize().width
  4628. local rHei = count * itemHei
  4629. local listHei = maxHei and math.min(rHei, maxHei) or rHei
  4630. menuListView:setContentSize(cc.size(listWid, listHei))
  4631. menuListBg:setContentSize(cc.size(listWid + 4, listHei + 6))
  4632. end
  4633. widget:setTouchEnabled(true)
  4634. widget:addClickEventListener(function ()
  4635. DelayTouchEnabled(widget)
  4636. showItemList()
  4637. end)
  4638. if menuid and self._menuItemWidgets then
  4639. self._menuItemWidgets[menuid] = {
  4640. widget = showText,
  4641. value = select
  4642. }
  4643. end
  4644. return widget
  4645. end
  4646. function SUILoader:load_render_ScrapePic(swidget, callback)
  4647. local element = swidget.element
  4648. local showImg = element.attr.showimg -- 展示图片
  4649. local maskImg = element.attr.maskimg or "public/mask_1.png" -- 遮罩图片
  4650. local clearHei = element.attr.clearhei -- 刮除高度
  4651. local moveTime = tonumber(element.attr.movetime) or 5 -- 移动时间
  4652. local beginTime = tonumber(element.attr.begintime) -- 开始按下时间
  4653. local link = element.attr.link
  4654. local submitInput = element.attr.submitInput
  4655. local submitCheckBox = element.attr.submitCheckBox
  4656. local widget = global.SWidgetCache:generateRender("ccui.Layout")
  4657. widget:setBackGroundColorType(0)
  4658. widget:setTouchEnabled(false)
  4659. local path = SUIHelper.fixImageFileName(showImg)
  4660. local img = nil
  4661. local fullPath = (path and path ~= "") and string.format(getResFullPath("res/%s"), path) or ""
  4662. if not fullPath or fullPath == "" or not global.FileUtilCtl:isFileExist(fullPath) then
  4663. img = global.SWidgetCache:generateEmptyImageRender("ccui.ImageView")
  4664. else
  4665. img = global.SWidgetCache:generateRender("ccui.ImageView")
  4666. end
  4667. img:loadTexture(fullPath)
  4668. img:ignoreContentAdaptWithSize(false)
  4669. img:setContentSize(img:getVirtualRendererSize())
  4670. widget:addChild(img)
  4671. local imgSize = img:getContentSize()
  4672. widget:setContentSize(imgSize)
  4673. img:setAnchorPoint(cc.p(0.5, 0.5))
  4674. img:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
  4675. if imgSize.width == 0 or imgSize.height == 0 then
  4676. return widget
  4677. end
  4678. local radius = clearHei and mfloor(clearHei / 2) or 8
  4679. local drawNode = cc.DrawNode:create()
  4680. widget:addChild(drawNode)
  4681. drawNode:retain()
  4682. drawNode:drawSolidCircle(cc.p(0, 0), radius, 0, radius, 1, 1, cc.c4b(0, 0, 0, 0))
  4683. drawNode:setVisible(false)
  4684. local renderTexture = cc.RenderTexture:create(imgSize.width, imgSize.height)
  4685. widget:addChild(renderTexture, 10)
  4686. renderTexture:retain()
  4687. renderTexture:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
  4688. local mask = nil
  4689. local path = SUIHelper.fixImageFileName(maskImg)
  4690. local fullPath = (path and path ~= "") and string.format(getResFullPath("res/%s"), path)
  4691. if not fullPath or fullPath == "" or not global.FileUtilCtl:isFileExist(fullPath) then
  4692. mask = global.SWidgetCache:generateEmptyImageRender("ccui.ImageView")
  4693. else
  4694. mask = global.SWidgetCache:generateRender("ccui.ImageView")
  4695. end
  4696. mask:loadTexture(fullPath)
  4697. mask:ignoreContentAdaptWithSize(false)
  4698. mask:setContentSize(imgSize)
  4699. mask:setAnchorPoint(cc.p(0.5, 0.5))
  4700. mask:setPosition(cc.p(fixPosition(imgSize.width / 2), fixPosition(imgSize.height / 2)))
  4701. renderTexture:begin()
  4702. mask:visit()
  4703. renderTexture:endToLua()
  4704. local lastMovePos = nil
  4705. local moveBT = nil
  4706. local iMoveTime = 0
  4707. local iBeginAct = nil
  4708. local releaseCount = 0
  4709. local touchPosList = {}
  4710. local function timeCB()
  4711. if releaseCount == 0 then
  4712. releaseCount = releaseCount + 1
  4713. if drawNode then
  4714. drawNode:removeFromParent()
  4715. drawNode:autorelease()
  4716. drawNode = nil
  4717. end
  4718. if renderTexture then
  4719. renderTexture:removeFromParent()
  4720. renderTexture:autorelease()
  4721. renderTexture = nil
  4722. end
  4723. if callback and link and string.len(link) > 0 then
  4724. local inputTable = self:getInputTable(submitInput)
  4725. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  4726. local jsonData = {}
  4727. jsonData.Act = link
  4728. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  4729. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  4730. self:linkFuncWithCheckWords(callback, jsonData)
  4731. end
  4732. end
  4733. end
  4734. local function getKey(x, y)
  4735. return x * 10000 + y
  4736. end
  4737. local function addTouchPoint(x, y)
  4738. local key = getKey(x, y)
  4739. if touchPosList[key] then
  4740. return
  4741. end
  4742. if x <= 0 or x >= imgSize.width then
  4743. return
  4744. end
  4745. if y <= 0 or y >= imgSize.height then
  4746. return
  4747. end
  4748. if not touchPosList[key] then
  4749. touchPosList[key] = true
  4750. end
  4751. end
  4752. widget:setTouchEnabled(true)
  4753. widget:addTouchEventListener(function (node, eventType)
  4754. if eventType == 0 then
  4755. lastMovePos = nil
  4756. moveBT = os.clock()
  4757. if tonumber(beginTime) and not iBeginAct then
  4758. iBeginAct = performWithDelay(widget, function()
  4759. timeCB()
  4760. end, tonumber(beginTime))
  4761. end
  4762. elseif eventType == 1 then
  4763. if releaseCount > 0 then
  4764. return
  4765. end
  4766. local movedPos = node:getTouchMovePosition()
  4767. local tt = GUI:convertToNodeSpace(widget, movedPos.x, movedPos.y)
  4768. tt = fixPosition(tt)
  4769. local key = getKey(tt.x, tt.y)
  4770. if touchPosList[key] then
  4771. return
  4772. end
  4773. drawNode:setPosition(tt)
  4774. drawNode:setBlendFunc({src = gl.ONE, dst = gl.ZERO})
  4775. drawNode:setVisible(true)
  4776. renderTexture:begin()
  4777. drawNode:visit()
  4778. renderTexture:endToLua()
  4779. drawNode:setVisible(false)
  4780. if lastMovePos then
  4781. local distance = math.abs(cc.pGetDistance(lastMovePos, movedPos))
  4782. local pos = cc.pSub(lastMovePos, movedPos)
  4783. local angle = 180 * (cc.pToAngleSelf(pos) / math.pi)
  4784. local height = radius * 2
  4785. local midPos = cc.pMidpoint(lastMovePos, movedPos)
  4786. midPos = fixPosition(GUI:convertToNodeSpace(widget, midPos.x, midPos.y))
  4787. local rectNode = cc.DrawNode:create()
  4788. local posList = {
  4789. cc.p(- distance / 2 , - height / 2),
  4790. cc.p(- distance / 2 , height / 2),
  4791. cc.p(distance / 2 , height / 2),
  4792. cc.p(distance / 2 , - height / 2)
  4793. }
  4794. rectNode:drawSolidPoly(posList, 4, cc.c4b(0,0,0,0))
  4795. rectNode:setPosition(midPos)
  4796. rectNode:setRotation(angle)
  4797. rectNode:setBlendFunc({src = gl.ONE, dst = gl.ZERO})
  4798. renderTexture:begin()
  4799. rectNode:visit()
  4800. renderTexture:endToLua()
  4801. end
  4802. -- pos
  4803. local mPos = GUI:convertToNodeSpace(widget, movedPos.x, movedPos.y)
  4804. mPos = fixPosition(mPos)
  4805. for i = mPos.x - radius, mPos.x + radius do
  4806. for j = mPos.y - radius, mPos.y + radius do
  4807. if math.pow(i - mPos.x, 2) + math.pow(j - mPos.y, 2) <= math.pow(radius, 2) then
  4808. addTouchPoint(i, j)
  4809. end
  4810. end
  4811. end
  4812. if moveBT then
  4813. iMoveTime = iMoveTime + (os.clock() - moveBT)
  4814. end
  4815. moveBT = os.clock()
  4816. if tonumber(moveTime) then
  4817. if iMoveTime >= tonumber(moveTime) then
  4818. timeCB()
  4819. end
  4820. end
  4821. lastMovePos = movedPos
  4822. elseif eventType == 2 or eventType == 3 then
  4823. lastMovePos = nil
  4824. moveBT = nil
  4825. end
  4826. end)
  4827. return widget
  4828. end
  4829. function SUILoader:load_render_BmpText(swidget, callback)
  4830. local element = swidget.element
  4831. local text = element.attr.text or ""
  4832. local size = tonumber(element.attr.size) or defaultFontSize
  4833. local color = tonumber(element.attr.color) or defaultColorID
  4834. local link = element.attr.link
  4835. local submitInput = element.attr.submitInput
  4836. local submitCheckBox = element.attr.submitCheckBox
  4837. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  4838. local tips = element.attr.tips
  4839. local tipsx = tonumber(element.attr.tipsx) or 0
  4840. local tipsy = tonumber(element.attr.tipsy) or 0
  4841. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  4842. text = string.gsub(text, "\\", "\r\n")
  4843. text = string.trim(text)
  4844. local widget = ccui.Text:create()
  4845. GUI:SetBmpTextProperties(widget)
  4846. widget:setBMFontFilePath()
  4847. widget:setFontSize(size)
  4848. widget:setTextColor(GET_COLOR_BYID_C3B(color))
  4849. widget:setString(text)
  4850. if link and string.len(link) > 0 or (tips and string.len(tips) > 0) then
  4851. widget:setTouchEnabled(true)
  4852. widget:addClickEventListener(function()
  4853. DelayTouchEnabled(widget, clickInterval)
  4854. widget:setScale(1 + 0.2)
  4855. local function reback()
  4856. widget:setScale(1)
  4857. end
  4858. performWithDelay(widget, reback, 0.03)
  4859. if callback and link then
  4860. local inputTable = self:getInputTable(submitInput)
  4861. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  4862. local jsonData = {}
  4863. jsonData.Act = link
  4864. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  4865. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  4866. callback(jsonData)
  4867. end
  4868. if not global.isWinPlayMode then
  4869. if tips and string.len(tips) > 0 then
  4870. local offset = cc.p(tipsx, -tipsy)
  4871. local anchorPoint = cc.p(0.5, 1)
  4872. tips = string.gsub(tips, "%^", "\\")
  4873. SHOW_SUI_DESCTIP( widget ,tips, tipWidth, offset, anchorPoint)
  4874. end
  4875. end
  4876. end)
  4877. -- 下划线
  4878. widget:getVirtualRenderer():enableUnderline()
  4879. end
  4880. self:addMouseOverTips(widget, element)
  4881. return widget
  4882. end
  4883. function SUILoader:load_render_ButtonKeFu(swidget, callback, closeCB)
  4884. local element = swidget.element
  4885. local nimg = element.attr.nimg
  4886. local pimg = element.attr.pimg
  4887. local mimg = element.attr.mimg
  4888. local text = element.attr.text or ""
  4889. local color = tonumber(element.attr.color) or defaultColorID
  4890. local size = tonumber(element.attr.size) or defaultFontSize
  4891. local width = tonumber(element.attr.width)
  4892. local height = tonumber(element.attr.height)
  4893. local link = element.attr.o_link or element.attr.link or "&701" -- 没有配置强制默认打开
  4894. local submitInput = element.attr.submitInput
  4895. local submitCheckBox = element.attr.submitCheckBox
  4896. local tips = element.attr.tips
  4897. local tipsx = tonumber(element.attr.o_tipsx) or tonumber(element.attr.tipsx) or 0
  4898. local tipsy = tonumber(element.attr.o_tipsy) or tonumber(element.attr.tipsy) or 0
  4899. local textWidth = tonumber(element.attr.textwidth)
  4900. local grey = tonumber(element.attr.grey) or 0
  4901. local clickInterval = (tonumber(element.attr.clickInterval) or 0) * 0.001
  4902. local outline = tonumber(element.attr.outline) or defaultOutline
  4903. local outlinecolor = tonumber(element.attr.outlinecolor) or defaultOutlineC
  4904. local tipWidth = tonumber(element.attr.tipWidth) or 1136
  4905. local redPointTx = tonumber(element.attr.effectid) or 0
  4906. local redPointPath = element.attr.redimg
  4907. local redx = tonumber(element.attr.redx) or 0
  4908. local redy = tonumber(element.attr.redy) or 0
  4909. local mainIndex = element.attr._mainIndex
  4910. local widgetID = element.attr.id
  4911. text = string.gsub(text, "\\", "\r\n")
  4912. text = string.trim(text)
  4913. local nimg = SUIHelper.fixImageFileName(nimg)
  4914. local pimg = SUIHelper.fixImageFileName(pimg)
  4915. local mimg = SUIHelper.fixImageFileName(mimg)
  4916. local fullPathN = (nimg and string.len(nimg) > 0 and string.format(getResFullPath( "res/%s" ), nimg) or "")
  4917. local fullPathP = (pimg and string.len(pimg) > 0 and string.format(getResFullPath( "res/%s" ), pimg) or "")
  4918. local fullPathM = (mimg and string.len(mimg) > 0 and string.format(getResFullPath( "res/%s" ), mimg) or "")
  4919. local widget = nil
  4920. local isNormalExist = fullPathN ~= "" and global.FileUtilCtl:isFileExist(fullPathN)
  4921. local isPressExist = fullPathP ~= "" and global.FileUtilCtl:isFileExist(fullPathP)
  4922. local isMouseExist = fullPathM ~= "" and global.FileUtilCtl:isFileExist(fullPathM)
  4923. local Button_Type = 1
  4924. --1-normalAndPress 2-Normal 3-Press 4-nil
  4925. if isNormalExist and isPressExist then
  4926. Button_Type = 1
  4927. elseif isNormalExist then
  4928. Button_Type = 2
  4929. elseif isPressExist then
  4930. Button_Type = 3
  4931. else
  4932. Button_Type = 4
  4933. end
  4934. widget = global.SWidgetCache:generateButtonRender(Button_Type)
  4935. widget:resetNormalRender()
  4936. widget:resetPressedRender()
  4937. widget:setTitleText(text)
  4938. widget:setTitleColor(GET_COLOR_BYID_C3B(color))
  4939. widget:setTitleFontName(defaultFontPath)
  4940. widget:setTitleFontSize(size)
  4941. widget:setTouchEnabled(false)
  4942. widget:getTitleRenderer():setMaxLineWidth(0)
  4943. widget:getTitleRenderer():enableOutline(GET_COLOR_BYID_C3B(outlinecolor), outline)
  4944. if isNormalExist then
  4945. widget:loadTextureNormal(fullPathN)
  4946. end
  4947. if isPressExist then
  4948. widget:loadTexturePressed(fullPathP)
  4949. end
  4950. --
  4951. widget:ignoreContentAdaptWithSize(false)
  4952. widget:setContentSize(widget:getVirtualRendererSize())
  4953. swidget.element.attr.o_link = element.attr.link
  4954. swidget.element.attr.link = nil
  4955. swidget.element.attr.bg = nil
  4956. local redPointWidget = nil
  4957. if redPointTx > 0 then
  4958. -- redPointWidget = self:load_render_Effect(swidget)
  4959. redPointWidget = global.FrameAnimManager:CreateSFXAnim(redPointTx)
  4960. redPointWidget:Play(0, 0, true, 1)
  4961. else
  4962. redPointWidget = ccui.ImageView:create()
  4963. local fullPath = (redPointPath and redPointPath ~= "") and string.format(getResFullPath("res/%s"), redPointPath) or ""
  4964. if global.FileUtilCtl:isFileExist(fullPath) then
  4965. redPointWidget:loadTexture(fullPath)
  4966. end
  4967. -- redPointWidget = self:load_render_Img(swidget)
  4968. end
  4969. SL:UnRegisterLUAEvent(LUA_EVENT_MANUAL_SERVICE_MESSAGE_UN_READ, "MABUAL_SERVICE_996_RED__"..(widgetID or ""))
  4970. if redPointWidget then
  4971. redPointWidget:setPosition(redx, redy)
  4972. widget:addChild(redPointWidget)
  4973. -- 监听客服红点
  4974. local ManualService996Proxy = global.Facade:retrieveProxy(global.ProxyTable.ManualService996Proxy)
  4975. local unReadNums = tonumber(ManualService996Proxy:GetUnReadNums()) or 0
  4976. redPointWidget:setVisible(unReadNums > 0)
  4977. SL:RegisterLUAEvent(LUA_EVENT_MANUAL_SERVICE_MESSAGE_UN_READ, "MABUAL_SERVICE_996_RED__"..(widgetID or ""), function(data)
  4978. if not redPointWidget or tolua.isnull(redPointWidget) then
  4979. SL:UnRegisterLUAEvent(LUA_EVENT_MANUAL_SERVICE_MESSAGE_UN_READ, "MABUAL_SERVICE_996_RED__"..(widgetID or ""))
  4980. return
  4981. end
  4982. local unReadNums = data and tonumber(data.unReadNums) or 0
  4983. redPointWidget:setVisible(unReadNums > 0)
  4984. end)
  4985. end
  4986. local showTips = tips and string.len(tips) > 0
  4987. if isNormalExist and (isMouseExist or showTips) then
  4988. if global.isWinPlayMode then
  4989. local function checkResType(path)
  4990. if global.SpriteFrameCache:getSpriteFrame(path) then
  4991. return 1
  4992. end
  4993. if global.FileUtilCtl:isFileExist(path) then
  4994. return 0
  4995. end
  4996. return 0
  4997. end
  4998. local function checkRes(path)
  4999. local resType = checkResType(path)
  5000. if isMouseExist and isNormalExist then
  5001. widget:loadTextureNormal(path, resType)
  5002. end
  5003. end
  5004. local offset = cc.p(tipsx, -tipsy)
  5005. local anchor = cc.p(0.5, 1)
  5006. local function enterCB(touchPos)
  5007. if global.userInputController:isTouching() or not widget:isVisible() then
  5008. return false
  5009. end
  5010. if not CheckNodeCanCallBack(widget, touchPos) then
  5011. return false
  5012. end
  5013. checkRes(fullPathM)
  5014. if showTips then
  5015. tips = string.gsub(tips, "%^", "\\")
  5016. showMouseOverTips(widget, tips, offset, anchor)
  5017. end
  5018. end
  5019. local function leaveCB()
  5020. checkRes(fullPathN)
  5021. hideMouseOverTips()
  5022. end
  5023. -- widget:loadTextureMouseOver(fullPathN, fullPathM, enterCB, leaveCB)
  5024. global.mouseEventController:registerMouseMoveEvent(
  5025. widget,
  5026. {
  5027. enter = enterCB,
  5028. leave = leaveCB,
  5029. checkIsVisible = true
  5030. }
  5031. )
  5032. end
  5033. end
  5034. -- 加入元变量组件管理
  5035. local isMateValue = false
  5036. local metaValue = {}
  5037. local content = text
  5038. while content and string.len(content) > 0 do
  5039. local find_info = {sfind(content, "$STM%((.-)%)")}
  5040. local begin_pos = find_info[1]
  5041. local end_pos = find_info[2]
  5042. if begin_pos and end_pos then
  5043. isMateValue = true
  5044. -- prefix
  5045. if begin_pos ~= 1 then
  5046. local substr = string.sub(content, 1, begin_pos - 1)
  5047. table.insert(metaValue, substr)
  5048. end
  5049. -- metaValue
  5050. local slices = ssplit(find_info[3], "_")
  5051. table.insert(metaValue, {key = slices[1], param = slices[2]})
  5052. -- suffix
  5053. content = string.sub(content, end_pos+1, string.len(content))
  5054. else
  5055. table.insert(metaValue, content)
  5056. content = ""
  5057. end
  5058. end
  5059. if isMateValue then
  5060. widget.useMetaValue = true
  5061. global.Facade:sendNotification(global.NoticeTable.SUIMetaWidgetAdd, {metaValue = metaValue, widget = widget, lifewidget = widget})
  5062. end
  5063. if textWidth then
  5064. local renderer = widget:getTitleRenderer()
  5065. renderer:setMaxLineWidth(textWidth)
  5066. end
  5067. -- link
  5068. if link and string.len(link) > 0 or (tips and string.len(tips) > 0) then
  5069. widget:setTouchEnabled(true)
  5070. widget:addClickEventListener(function()
  5071. DelayTouchEnabled(widget, clickInterval)
  5072. if mainIndex then
  5073. -- 数据上报
  5074. local NativeBridgeProxy = global.Facade:retrieveProxy(global.ProxyTable.NativeBridgeProxy)
  5075. NativeBridgeProxy:GN_MainUIClickEvent({
  5076. index = mainIndex,
  5077. id = element.attr.id,
  5078. link = link
  5079. })
  5080. end
  5081. if link == "@DEFAULT_CLOSE" then
  5082. if closeCB then
  5083. closeCB()
  5084. end
  5085. elseif callback and link then
  5086. local inputTable = self:getInputTable(submitInput)
  5087. local checkBoxTable = self:getCheckBoxTable(submitCheckBox)
  5088. local jsonData = {}
  5089. jsonData.Act = link
  5090. jsonData.Input = (#inputTable > 0 and inputTable or nil)
  5091. jsonData.CheckBox = (#checkBoxTable > 0 and checkBoxTable or nil)
  5092. self:linkFuncWithCheckWords(callback, jsonData)
  5093. end
  5094. if not global.isWinPlayMode then
  5095. if tips and string.len(tips) > 0 then
  5096. local offset = cc.p(tipsx, -tipsy)
  5097. local anchorPoint = cc.p(0.5, 1)
  5098. tips = string.gsub(tips, "%^", "\\")
  5099. SHOW_SUI_DESCTIP( widget ,tips, tipWidth, offset, anchorPoint)
  5100. end
  5101. end
  5102. end)
  5103. end
  5104. -- if nil == mimg then
  5105. -- self:addMouseOverTips(widget, element)
  5106. -- end
  5107. -- grey
  5108. if grey == 1 then
  5109. Shader_Grey(widget)
  5110. else
  5111. Shader_Normal(widget)
  5112. end
  5113. return widget
  5114. end
  5115. return SUILoader