Utils.ts 156 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380
  1. import AdManager from "./AdManager";
  2. import CommonConfig, { YzRedBagInfo } from "./CommonConfig";
  3. import WechatTool from "./WechatTool";
  4. import PlatUtils from "./PlatUtils";
  5. import OppoTool from "./YZ_Tool_Oppo";
  6. import YZ_Tool_Baidu from "./YZ_Tool_Baidu";
  7. import YZ_Tool_Native from "./YZ_Tool_Native";
  8. import YZ_Tool_Vivo from "./YZ_Tool_Vivo";
  9. import YZ_Tool_Douyin from "./YZ_Tool_Douyin";
  10. import YZ_Constant, { BannerLocation, LevelStatus, VibrateType, ViewLocation } from "./YZ_Constant";
  11. import YZ_Tool_QQ from "./YZ_Tool_QQ";
  12. import YZ_ShortcutWidget from "./YZ_ShortcutWidget";
  13. import YZ_Tool_QTT from "./YZ_Tool_QTT";
  14. import YZ_Tool_Xiaomi from "./YZ_Tool_Xiaomi";
  15. import AldUtils from "./AldUtils";
  16. import YZ_Tool_UC from "./YZ_Tool_UC";
  17. import YZ_Tool_Cocosplay from "./YZ_Tool_Cocosplay";
  18. import YZ_Tool_4399 from "./YZ_Tool_4399";
  19. import YZ_Tool_IOS from "./YZ_Tool_IOS";
  20. import YZ_Tool_Bili from "./YZ_Tool_Bili";
  21. import YZ_Tool_Kwai from "./YZ_Tool_Kwai";
  22. import YZ_Tool_Broswer from "./YZ_Tool_Broswer";
  23. import YZ_Tool_WiFi from "./YZ_Tool_Wifi";
  24. import YZ_Tool_Hago from "./YZ_Tool_Hago";
  25. import RedBagProgressWidget from "./RedBagProgressWidget";
  26. import CompatibleTool from "./CompatibleTool";
  27. import YZ_Tool_HuaWei from "./YZ_Tool_HuaWei";
  28. import OpenRedBagPanel from "./OpenRedBagPanel";
  29. import YZ_Tool_FaceBook from "./YZ_Tool_FaceBook";
  30. import YzRealNameAuthPanel from "./YzRealNameAuthPanel";
  31. import YzUserPrivacyPanel from "./YzUserPrivacyPanel";
  32. import YZ_LocalStorage from "./YZ_LocalStorage";
  33. import YzLoginPanel from "./YzLoginPanel";
  34. import YZ_Tool_GoogleWeb from "./YZ_Tool_GoogleWeb";
  35. //@ts-ignore
  36. const CryptoJS = require("./Encrypt/CryptoJS");
  37. const secretKey = "youzhixx12345678"
  38. //@ts-ignore
  39. // var uma = require('./UMengSDK/uma.js');
  40. const { ccclass, property } = cc._decorator;
  41. export let utils: Utils = null;
  42. const UTILSVERSION: string = "1.6.6";
  43. @ccclass
  44. export default class Utils extends cc.Component {
  45. @property({ displayName: "组件版本", readonly: true })
  46. public get utilsVersion() {
  47. return UTILSVERSION;
  48. }
  49. @property({ displayName: "测试本地数据", tooltip: "勾选此选项则使用本地配置,否则会请求服务器配置!" })
  50. DebugLoacalConfig: boolean = false;
  51. @property({ displayName: "显示日志框", tooltip: "勾选此选项则会显示日志框,用于调试!" })
  52. showLogView: boolean = false;
  53. @property({ type: CommonConfig, displayName: "配置信息" })
  54. config: CommonConfig = null;
  55. /**
  56. * 红包信息
  57. */
  58. yzRedBagInfo: YzRedBagInfo = null;
  59. public adManager: AdManager = null;
  60. _wechatTool: WechatTool = null;
  61. /**
  62. * 当前关卡
  63. */
  64. public currentLevel: number = 0;
  65. /**
  66. * 当前是否胜利
  67. */
  68. public isSuccess: boolean;
  69. /**
  70. * 是否在录屏中
  71. */
  72. public isRecording: boolean = false;
  73. /**
  74. * 激励组件成功回调
  75. */
  76. public rewardCallFunc: Function = null;
  77. /**
  78. * 激励组件关闭回调
  79. */
  80. public rewardCloseFunc: Function = null;
  81. /**
  82. * 激励组件原始奖励
  83. */
  84. public rewardValue: number = 0;
  85. /**
  86. *
  87. * 幸运宝箱显示次数
  88. */
  89. public luckBoxShowCount: number = -1;
  90. /**
  91. * 原生插屏展示的次数
  92. */
  93. public nativeInsertShowCount: number = 0;
  94. /**
  95. *
  96. * 原生插屏满足关闭按钮设置大小条件后显示的次数,用来判断间隔多少次使用服务器大小
  97. */
  98. public nativeInsertResizeCloseBtnShowCount: number = 0;
  99. /**
  100. * 原生Banner展示的次数
  101. */
  102. public nativeBannerShowCount: number = 0;
  103. /**
  104. *
  105. * 原生banner满足关闭按钮设置大小条件后显示的次数,用来判断间隔多少次使用服务器大小
  106. */
  107. public nativeBannerResizeCloseBtnShowCount: number = 0;
  108. /**
  109. * 转盘抽奖关闭回调
  110. */
  111. public turnTablePanelCloseFunc: Function = null;
  112. /**
  113. * 分享录屏组件关闭回调
  114. */
  115. public shareRecordPanelCloseFunc: Function = null;
  116. /**
  117. * 宝箱关闭回调
  118. */
  119. public rewardBoxPanelCloseFunc: Function = null;
  120. /**
  121. * 添加快捷桌面组件关闭回调
  122. */
  123. public rewardShortCutPanelCloseFunc: Function = null;
  124. /**
  125. * 推荐游戏组件关闭回调
  126. */
  127. public rewardRecGamePanelCloseFunc: Function = null;
  128. /**
  129. * 幸运宝箱组件关闭回调
  130. */
  131. public rewardLuckBoxPanelCloseFunc: Function = null;
  132. //Banner广告关闭的时间
  133. public _bannerCloseTime: number = 0;
  134. /**
  135. * 其他配置:包含分组的信息
  136. */
  137. private _other_config: any = null;
  138. public get wechatTool() {
  139. if (!this._wechatTool) {
  140. utils.showLog("wechat tool is null");
  141. }
  142. return this._wechatTool;
  143. }
  144. _oppoTool: OppoTool = null;
  145. public get oppoTool() {
  146. if (!this._oppoTool) {
  147. utils.showLog("oppo tool is null");
  148. }
  149. return this._oppoTool;
  150. }
  151. _tool_Kwai: YZ_Tool_Kwai = null;
  152. public get kwaiTool() {
  153. if (!this._tool_Kwai) {
  154. utils.showLog("Kwai tool is null");
  155. }
  156. return this._tool_Kwai;
  157. }
  158. _tool_Wifi: YZ_Tool_WiFi = null;
  159. public get wifiTool() {
  160. if (!this._tool_Wifi) {
  161. utils.showLog("Wifi tool is null");
  162. }
  163. return this._tool_Wifi;
  164. }
  165. _tool_Hago: YZ_Tool_Hago = null;
  166. public get hagoTool() {
  167. if (!this._tool_Hago) {
  168. utils.showLog("Hago tool is null");
  169. }
  170. return this._tool_Hago;
  171. }
  172. _tool_Baidu: YZ_Tool_Baidu = null;
  173. public get Tool_Baidu() {
  174. if (!this._tool_Baidu) {
  175. utils.showLog("tool baidu is null");
  176. }
  177. return this._tool_Baidu;
  178. }
  179. _tool_Native: YZ_Tool_Native = null;
  180. public get Tool_Native() {
  181. if (!this._tool_Native) {
  182. utils.showLog("tool native is null");
  183. }
  184. return this._tool_Native;
  185. }
  186. _tool_Vivo: YZ_Tool_Vivo = null;
  187. public get Tool_Vivo() {
  188. if (!this._tool_Vivo) {
  189. utils.showLog("tool vivo is null");
  190. }
  191. return this._tool_Vivo;
  192. }
  193. _tool_Douyin: YZ_Tool_Douyin = null;
  194. public get Tool_Douyin() {
  195. if (!this._tool_Douyin) {
  196. utils.showLog("tool douyin is null");
  197. }
  198. return this._tool_Douyin;
  199. }
  200. _tool_QQ: YZ_Tool_QQ = null;
  201. public get Tool_QQ() {
  202. if (!this._tool_QQ) {
  203. utils.showLog("tool qq is null");
  204. }
  205. return this._tool_QQ;
  206. }
  207. _tool_XiaoMi: YZ_Tool_Xiaomi = null;
  208. public get Tool_XiaoMi() {
  209. if (!this._tool_XiaoMi) {
  210. utils.showLog("tool xiaomi is null");
  211. }
  212. return this._tool_XiaoMi;
  213. }
  214. _tool_QTT: YZ_Tool_QTT = null;
  215. public get Tool_QTT() {
  216. if (!this._tool_QTT) {
  217. utils.showLog("tool qtt is null");
  218. }
  219. return this._tool_QTT;
  220. }
  221. _tool_UC: YZ_Tool_UC = null;
  222. public get Tool_UC() {
  223. if (!this._tool_UC) {
  224. utils.showLog("tool uc is null");
  225. }
  226. return this._tool_UC;
  227. }
  228. _tool_Cocosplay: YZ_Tool_Cocosplay = null;
  229. public get Tool_Cocosplay() {
  230. if (!this._tool_Cocosplay) {
  231. utils.showLog("tool cocos is null");
  232. }
  233. return this._tool_Cocosplay;
  234. }
  235. _tool_4399: YZ_Tool_4399 = null;
  236. public get Tool_4399() {
  237. if (!this._tool_4399) {
  238. utils.showLog("tool 4399 is null");
  239. }
  240. return this._tool_4399;
  241. }
  242. _tool_Ios: YZ_Tool_IOS = null;
  243. public get Tool_IOS() {
  244. if (!this._tool_Ios) {
  245. utils.showLog("tool ios is null");
  246. }
  247. return this._tool_Ios;
  248. }
  249. _tool_bili: YZ_Tool_Bili = null;
  250. public get Tool_Bili() {
  251. if (!this._tool_Ios) {
  252. utils.showLog("tool ios is null");
  253. }
  254. return this._tool_bili;
  255. }
  256. _tool_Broswer: YZ_Tool_Broswer = null;
  257. public get Tool_Broswer(): YZ_Tool_Broswer {
  258. if (!this._tool_Broswer) {
  259. // cc.log("tool qtt is null");
  260. }
  261. return this._tool_Broswer;
  262. }
  263. _tool_Huawei: YZ_Tool_HuaWei = null;
  264. public get Tool_Huawei(): YZ_Tool_HuaWei {
  265. if (!this._tool_Huawei) {
  266. utils.showLog("huawei tool is null");
  267. }
  268. return this._tool_Huawei;
  269. }
  270. _tool_Facebook: YZ_Tool_FaceBook = null;
  271. public get Tool_Facebook(): YZ_Tool_FaceBook {
  272. if (!this._tool_Facebook) {
  273. utils.showLog("facebook tool is null");
  274. }
  275. return this._tool_Facebook;
  276. }
  277. _tool_GoogleWeb: YZ_Tool_GoogleWeb = null;
  278. public get Tool_GoogleWeb(): YZ_Tool_GoogleWeb {
  279. if (!this._tool_GoogleWeb) {
  280. utils.showLog("googleWeb tool is null");
  281. }
  282. return this._tool_GoogleWeb;
  283. }
  284. // 本地配置是否初始化
  285. _isConfigInit: boolean = false;
  286. // 服务器配置是否初始化
  287. _isServerInit: boolean = false;
  288. /**
  289. * 游戏进入时间
  290. */
  291. _gameEntryTime: number = 0;
  292. /**
  293. * 初始化配置数据
  294. * @param data 配置数据
  295. */
  296. private _initConfig() {
  297. if (this._isConfigInit) {
  298. utils.showLog("warn:" + "配置数据已经初始化,请勿重复初始化!");
  299. return;
  300. }
  301. if (this.config.otherconfig.localConfig) {
  302. let data = JSON.stringify(this.config.otherconfig.localConfig.json);
  303. utils.showLog("本地数据:" + data);
  304. if (data) {
  305. if (PlatUtils.IsNativeAndroid) {
  306. // 安卓需要先获取JNI,再取本地数据
  307. this.initTools(data);
  308. this._isConfigInit = this._initLoacalConfig(data);
  309. if (this._isConfigInit) {
  310. utils.Tool_Native.init();
  311. }
  312. } else {
  313. this._isConfigInit = this._initLoacalConfig(data);
  314. // 这个必须在广告组件之前初始化
  315. this.initTools(data);
  316. }
  317. this._other_config = this.config.otherconfig.localConfig.json.other;
  318. this.adManager = new AdManager();
  319. this.adManager.Init();
  320. if (this._oppoTool) {
  321. this._oppoTool.hideDefaultLoadingPage();
  322. }
  323. if (PlatUtils.IsKwai) {
  324. //@ts-ignore
  325. kwaigame.readyGo();
  326. }
  327. utils.yzRedBagInfo = new YzRedBagInfo();
  328. utils.registerServerInitEvent(() => {
  329. if (utils.ServerConfig) {
  330. this.serverShowLog = this.getConfigByKey("is_show_log_view") == "true";
  331. this.showLogToConsole = this.getConfigByKey("show_log_to_console") == "true";
  332. if (this.getConfigByKey("red_bag_total_progress")) {
  333. utils.yzRedBagInfo.totalProgress = this.getConfigByKey("red_bag_total_progress");
  334. }
  335. if (this.getConfigByKey("red_bag_progress_infos")) {
  336. utils.yzRedBagInfo.progressInfos = this.getConfigByKey("red_bag_progress_infos");
  337. }
  338. if (this.getConfigByKey("red_bag_moneys")) {
  339. utils.yzRedBagInfo.withdrawaMoneys = this.getConfigByKey("red_bag_moneys");
  340. }
  341. }
  342. if (PlatUtils.IsHago) {
  343. //@ts-ignore
  344. hg.gameLoadResult && hg.gameLoadResult({ code: 0 })
  345. }
  346. // if (PlatUtils.IsHuaWei) {
  347. // utils.showMsg("华为小游戏要用华为单独的组件对接!!!!!!!!!")
  348. // }
  349. }, this)
  350. } else {
  351. utils.showLog("warn:" + "本地配置文件不是合法的json文件!");
  352. }
  353. } else {
  354. utils.showLog("warn:" + "本地配置文件未找到,请检查 CommonUtils 组件上是否存在!");
  355. }
  356. }
  357. private _initLoacalConfig(data: string) {
  358. if (this.config) {
  359. return this.config.init(data);
  360. } else {
  361. return false;
  362. }
  363. }
  364. onLoad() {
  365. cc.game.addPersistRootNode(this.node);
  366. utils = this;
  367. utils.showLog("广告组件版本:" + this.utilsVersion);
  368. if (!CC_DEBUG) {
  369. // 正式包关闭此选项
  370. this.DebugLoacalConfig = false;
  371. }
  372. this._gameEntryTime = new Date().getTime();
  373. // 初始化本地配置
  374. this._initConfig();
  375. }
  376. update(dt: number) {
  377. if (this._isConfigInit) {
  378. if (this.adManager) {
  379. this.adManager.OnUpdate(dt);
  380. }
  381. }
  382. }
  383. private initTools(data: string) {
  384. if (!this._isConfigInit && !PlatUtils.IsNativeAndroid) {
  385. utils.showLog("warn:" + "本地数据未初始化!");
  386. return;
  387. }
  388. if (PlatUtils.IsNativeAndroid) {
  389. this._tool_Native = new YZ_Tool_Native();
  390. // this._tool_Native.init(data);
  391. } else if (PlatUtils.IsWechat) {
  392. this._wechatTool = new WechatTool();
  393. this._wechatTool.init(data);
  394. } else if (PlatUtils.IsOPPO) {
  395. this._oppoTool = new OppoTool();
  396. this._oppoTool.init(data);
  397. } else if (PlatUtils.IsBaidu) {
  398. this._tool_Baidu = new YZ_Tool_Baidu();
  399. this._tool_Baidu.init(data);
  400. } else if (PlatUtils.IsVIVO) {
  401. this._tool_Vivo = new YZ_Tool_Vivo();
  402. this._tool_Vivo.init(data);
  403. } else if (PlatUtils.IsDouyin) {
  404. this._tool_Douyin = new YZ_Tool_Douyin();
  405. this._tool_Douyin.init(data);
  406. } else if (PlatUtils.IsQQ) {
  407. this._tool_QQ = new YZ_Tool_QQ();
  408. this._tool_QQ.init(data);
  409. } else if (PlatUtils.IsQTT) {
  410. this._tool_QTT = new YZ_Tool_QTT();
  411. this._tool_QTT.init(data);
  412. } else if (PlatUtils.IsXiaoMi) {
  413. this._tool_XiaoMi = new YZ_Tool_Xiaomi();
  414. this._tool_XiaoMi.init(data);
  415. } else if (PlatUtils.ISUC) {
  416. this._tool_UC = new YZ_Tool_UC();
  417. this._tool_UC.init(data);
  418. } else if (PlatUtils.ISCocos) {
  419. this._tool_Cocosplay = new YZ_Tool_Cocosplay();
  420. this._tool_Cocosplay.init(data);
  421. } else if (PlatUtils.Is4399) {
  422. this._tool_4399 = new YZ_Tool_4399();
  423. this._tool_4399.init(data);
  424. } else if (PlatUtils.IsNativeIOS) {
  425. this._tool_Ios = new YZ_Tool_IOS();
  426. this._tool_Ios.init(data);
  427. } else if (PlatUtils.IsBili) {
  428. this._tool_bili = new YZ_Tool_Bili();
  429. this._tool_bili.init(data);
  430. } else if (PlatUtils.IsKwai) {
  431. this._tool_Kwai = new YZ_Tool_Kwai();
  432. this._tool_Kwai.init(data);
  433. } else if (PlatUtils.IsWiFi) {
  434. this._tool_Wifi = new YZ_Tool_WiFi();
  435. this._tool_Wifi.init(data);
  436. } else if (PlatUtils.IsHago) {
  437. this._tool_Hago = new YZ_Tool_Hago();
  438. this._tool_Hago.init(data);
  439. } else if (PlatUtils.IsHuaWei) {
  440. this._tool_Huawei = new YZ_Tool_HuaWei();
  441. this._tool_Huawei.init(data);
  442. } else if (PlatUtils.IsFaceBook) {
  443. this._tool_Facebook = new YZ_Tool_FaceBook();
  444. this._tool_Facebook.init(data);
  445. } else if (PlatUtils.IsGoogleWeb) {
  446. this._tool_GoogleWeb = new YZ_Tool_GoogleWeb();
  447. this._tool_GoogleWeb.init(data);
  448. } else if (PlatUtils.IsTest) {
  449. this._tool_Broswer = new YZ_Tool_Broswer();
  450. this._tool_Broswer.init(data);
  451. }
  452. }
  453. /**
  454. * 延时调用函数
  455. * @param callback 回调函数
  456. * @param delay 延时时间
  457. */
  458. public delayCall(callback: Function, delay: number) {
  459. this.scheduleOnce(() => {
  460. if (callback) {
  461. callback();
  462. }
  463. }, delay);
  464. }
  465. /**
  466. *
  467. * @param callback Function<ret:boolean, msg:string> 分享回调
  468. */
  469. public share(callback: Function = null) {
  470. if (!this._isConfigInit) {
  471. utils.showLog("warn:" + "本地数据未初始化!");
  472. return;
  473. }
  474. this.cur_tool && this.cur_tool.share && this.cur_tool.share(callback)
  475. }
  476. /**
  477. * 注销游戏退出回调
  478. */
  479. public gameExitOff() {
  480. if (!this._isConfigInit) {
  481. utils.showLog("warn:" + "本地数据未初始化!");
  482. return;
  483. }
  484. if (PlatUtils.IsNativeAndroid) {
  485. cc.systemEvent.targetOff(this);
  486. }
  487. }
  488. /**
  489. * 开始录屏
  490. */
  491. public recordStart() {
  492. if (!this._isConfigInit) {
  493. utils.showLog("warn:" + "本地数据未初始化!");
  494. return;
  495. }
  496. this.cur_tool && this.cur_tool.recordStart && this.cur_tool.recordStart();
  497. }
  498. /**
  499. * 结束录屏
  500. */
  501. public recordEnd() {
  502. if (!this._isConfigInit) {
  503. utils.showLog("warn:" + "本地数据未初始化!");
  504. return;
  505. }
  506. this.cur_tool && this.cur_tool.recordEnd && this.cur_tool.recordEnd();
  507. }
  508. /**
  509. * 获取分享信息
  510. */
  511. public getShareInfo() {
  512. if (!this._isConfigInit) {
  513. utils.showLog("warn:" + "本地数据未初始化!");
  514. return null;
  515. }
  516. if (this.config.otherconfig.shareTitle && this.config.otherconfig.shareImgUrl) {
  517. return {
  518. title: this.config.otherconfig.shareTitle,
  519. imageUrl: this.config.otherconfig.shareImgUrl
  520. }
  521. } else {
  522. utils.showLog("分享配置出错!");
  523. return null;
  524. }
  525. }
  526. /**
  527. * 获取游戏内交叉推广信息, 游戏内跳转组件使用
  528. * @returns object or null
  529. */
  530. public getInnerRecommendData() {
  531. if (!this._isConfigInit) {
  532. utils.showLog("warn:" + "本地数据未初始化!");
  533. return null;
  534. }
  535. if (this.ServerConfig && this.ServerConfig.jump_list && this.ServerConfig.jump_list.length > 0) {
  536. return {
  537. "jump_refresh_time": this.ServerConfig.icon_jump,
  538. "jump_list": this.ServerConfig.jump_list
  539. };
  540. }
  541. return null;
  542. }
  543. /**
  544. * 跳转到其他小游戏
  545. * @param data
  546. * { // 交叉推广挂件内容信息
  547. "icon": "http://xcx.youletd.com/img/icon/fgdxc.png",
  548. "name": "翻滚的香肠大冒险",
  549. "path": "",
  550. "js_jump": "true",
  551. "qr_code": "http://xcx.youletd.com/img/qrcode/q_fgdxc.jpg",
  552. "appid": "wx2c4ed4218224b042"
  553. }
  554. @param callback Function(ret) 跳转回调
  555. */
  556. public navigateToMiniGame(data: any, callback: Function = null) {
  557. if (!this._isConfigInit) {
  558. utils.showLog("warn:" + "本地数据未初始化!");
  559. return;
  560. }
  561. if (PlatUtils.IsWechat) {
  562. if (data) {
  563. if (data.is_jump && data.is_jump == "true" && data.appid) {
  564. this.wechatTool.navigateToMiniProgram(data.appid, callback, data.path);
  565. return;
  566. }
  567. if (data.is_jump && data.is_jump == "false" && data.qr_code) {
  568. this.wechatTool.previewImage(data.qr_code);
  569. if (callback) {
  570. callback(true);
  571. }
  572. return;
  573. }
  574. }
  575. } else if (PlatUtils.IsOPPO) {
  576. if (data && data.appid) {
  577. this.oppoTool.navigateToMiniGame(data.appid, callback);
  578. } else {
  579. utils.showLog("data 或者 appid 为null!");
  580. if (callback) {
  581. callback(false);
  582. }
  583. }
  584. } else if (PlatUtils.IsBaidu) {
  585. if (data && data.appid) {
  586. utils.Tool_Baidu.navigateToMiniGame(data.appid, callback);
  587. } else {
  588. utils.showLog("data 或者 appid 为null!");
  589. if (callback) {
  590. callback(false);
  591. }
  592. }
  593. } else if (PlatUtils.IsNativeAndroid) {
  594. if (data) {
  595. utils.Tool_Native.navigateToGame(JSON.stringify(data), callback);
  596. } else {
  597. utils.showLog("data 或者 appid 为null!");
  598. if (callback) {
  599. callback(false);
  600. }
  601. }
  602. } else if (PlatUtils.IsNativeIOS) {
  603. if (data && data.appid) {
  604. this.Tool_IOS.navigateToGame(data.appid, callback);
  605. } else {
  606. utils.showLog("data 或者 appid 为null!");
  607. if (callback) {
  608. callback(false);
  609. }
  610. }
  611. }
  612. }
  613. /**
  614. * 当前版本是否支持跳转到其他小游戏
  615. */
  616. public isSupportnavigateToMiniGame() {
  617. if (!this._isConfigInit) {
  618. utils.showLog("warn:" + "本地数据未初始化!");
  619. return false;
  620. }
  621. if (PlatUtils.IsWechat || PlatUtils.IsNativeAndroid || PlatUtils.IsNativeIOS || PlatUtils.IsBaidu) {
  622. return true;
  623. } else if (PlatUtils.IsOPPO) {
  624. return this.oppoTool.isOverMiniVersion("1044");
  625. } else if (PlatUtils.IsDouyin) {
  626. return this.Tool_Douyin.isShowMoreGamesModal() && this.Tool_Douyin._sysInfo.appName != "live_stream";
  627. } else if (PlatUtils.IsQQ) {
  628. return this._tool_QQ.isOverMinVersion("1.7.1");
  629. }
  630. return false;
  631. }
  632. /**
  633. * 显示消息提示
  634. * @param msg 消息提示
  635. */
  636. public showMsg(msg: string) {
  637. if (utils.Tool_Broswer) {
  638. console.log(msg);
  639. return;
  640. }
  641. this.cur_tool && this.cur_tool.showToast && this.cur_tool.showToast(msg);
  642. }
  643. /**
  644. * 是否已经创建过快捷方式
  645. */
  646. public hasShortcutInstalled() {
  647. if (!this._isConfigInit) {
  648. utils.showLog("warn:" + "本地数据未初始化!");
  649. return true;
  650. }
  651. if (PlatUtils.IsVIVO && this.Tool_Vivo) {
  652. return this.Tool_Vivo.ShortcutCreated;
  653. } else if (PlatUtils.IsOPPO && this.oppoTool) {
  654. return this.oppoTool.ShortcutCreated;
  655. }
  656. return false;
  657. }
  658. /**
  659. * 是否可以创建桌面快捷方式,平台是否支持
  660. */
  661. public canCreateShortcut() {
  662. if (!this._isConfigInit) {
  663. utils.showLog("warn:" + "本地数据未初始化!");
  664. return false;
  665. }
  666. if (this.cur_tool && this.cur_tool.canCreateShortcut) {
  667. return this.cur_tool.canCreateShortcut();
  668. }
  669. return false;
  670. }
  671. /**
  672. * 创建桌面快捷方式
  673. */
  674. public createShortcut(callback: Function) {
  675. if (!this._isConfigInit) {
  676. utils.showLog("warn:" + "本地数据未初始化!");
  677. return;
  678. }
  679. this.cur_tool && this.cur_tool.createShortcut && this.cur_tool.createShortcut(callback);
  680. }
  681. /**
  682. * 通用http请求,只封装了GET请求
  683. * @param url 请求的url地址
  684. * @param callback Function(ret:boolean, data:string)
  685. * 请求结束回调,成功ret为true, data为返回的数据string。 失败为ret为false, data为空
  686. */
  687. public commomHttpRequest(url: string, callback: Function) {
  688. if (!this._isConfigInit) {
  689. utils.showLog("warn:" + "本地数据未初始化!");
  690. return;
  691. }
  692. let completeCallback = callback;
  693. let xhr = new XMLHttpRequest();
  694. xhr.timeout = 6000; // 单位毫秒
  695. let requestUrl: string = this._buildServerUrl(url) + `&time_stamp=${(new Date()).getTime()}&reqv=${YZ_Constant.SERVER_VERSION}`
  696. utils.showLog("服务器地址:" + requestUrl);
  697. xhr.open('GET', requestUrl);
  698. xhr.send();
  699. xhr.onreadystatechange = () => {
  700. utils.showLog("请求状态改变, reaedyState=", xhr.readyState, "; status=", xhr.status);
  701. if (xhr.readyState == 4) {
  702. if (xhr.status == 200) {
  703. if (completeCallback) {
  704. if (requestUrl.indexOf("m=g") > -1 || requestUrl.indexOf("m=rlevelv3") > -1) {
  705. completeCallback(true, this.aesDecrypt(xhr.responseText));
  706. } else {
  707. completeCallback(true, xhr.responseText);
  708. }
  709. }
  710. } else {
  711. if (completeCallback) {
  712. completeCallback(false, "");
  713. }
  714. }
  715. }
  716. }
  717. xhr.ontimeout = function () {
  718. utils.showLog("请求超时!");
  719. if (completeCallback) {
  720. completeCallback(false, "");
  721. }
  722. }
  723. xhr.onerror = function (err) {
  724. utils.showLog("请求出错! err=", JSON.stringify(err));
  725. if (completeCallback) {
  726. completeCallback(false, "");
  727. }
  728. }
  729. }
  730. aesEncrypt(content) {
  731. let key = CryptoJS.enc.Utf8.parse(secretKey);
  732. let srcs = CryptoJS.enc.Utf8.parse(content);
  733. let encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
  734. return encrypted.toString();
  735. }
  736. /**
  737. * 解密方法
  738. * @param encryptStr 密文
  739. * @returns {string} 明文
  740. */
  741. aesDecrypt(encryptStr) {
  742. let key = CryptoJS.enc.Utf8.parse(secretKey);
  743. let decrypt = CryptoJS.AES.decrypt(encryptStr, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
  744. return CryptoJS.enc.Utf8.stringify(decrypt).toString();
  745. }
  746. /**
  747. * 增加常用字段
  748. */
  749. _buildServerUrl(url: string) {
  750. // utils.showLog(" _buildServerUrl >>>>>.");
  751. if (PlatUtils.IsOPPO) {
  752. //@ts-ignore
  753. url = url + `&kyx=true&app_id=${utils.config.oppoconfig.packageName}&channel=oppo&device_uid=${utils.oppoTool.uid}&uid=${utils.oppoTool.serviceId}&source=${this.oppoTool._source}&game_version=${utils.config.oppoconfig.version}&device_id=${utils.oppoTool._device_id}`;
  754. } else if (PlatUtils.IsXiaoMi) {
  755. url = url + `&kyx=true&app_id=${utils.config.xiaomiConfig.appID}&channel=xiaomi&device_uid=${utils._tool_XiaoMi.uid}&uid=${utils._tool_XiaoMi.serviceId}`;
  756. } else if (PlatUtils.IsWechat) {
  757. url = url + `&kyx=true&app_id=${utils.config.wechatconfig.appID}&channel=wechat&device_uid=${utils.wechatTool.uid}&uid=${utils.wechatTool.serviceId}&source=${this.wechatTool._source_app_id}&soure_type=${this.wechatTool._luanchType}&game_version=${utils.config.wechatconfig.version}`;
  758. } else if (PlatUtils.IsVIVO) {
  759. url = url + `&kyx=true&app_id=${utils.config.vivoconfig.appID}&channel=vivo&device_uid=${utils._tool_Vivo.uid}&uid=${utils._tool_Vivo.serviceId}&source=${this._tool_Vivo._source}&game_version=${utils.config.vivoconfig.version}`
  760. } else if (PlatUtils.IsQTT) {
  761. url = url + `&kyx=true&app_id=${utils.config.qttconfig.appID}&channel=qutoutiao&device_uid=${utils._tool_QTT.uid}&uid=${utils._tool_QTT.serviceId}`
  762. } else if (PlatUtils.IsDouyin) {
  763. url = url + `&kyx=true&app_id=${utils.config.douyinconfig.appID}&channel=toutiao&device_uid=${utils.Tool_Douyin.uid}&uid=${utils.Tool_Douyin.serviceId}&game_version=${utils.config.douyinconfig.version}`
  764. } else if (PlatUtils.IsQQ) {
  765. url = url + `&kyx=true&app_id=${utils.config.qqconfig.appID}&channel=qq&device_uid=${utils._tool_QQ.uid}&uid=${utils._tool_QQ.serviceId}&game_version=${utils.config.qqconfig.version}`
  766. } else if (PlatUtils.IsBaidu) {
  767. url = url + `&kyx=true&app_id=${utils.config.baiduconfig.appID}&channel=baidu&device_uid=${utils._tool_Baidu.uid}&uid=${utils._tool_Baidu.serviceId}&game_version=${utils.config.baiduconfig.version}`
  768. } else if (PlatUtils.ISUC) {
  769. url = url + `&kyx=true&app_id=${utils.config.ucConfig.appID}&channel=uc&device_uid=${utils._tool_UC.uid}&uid=${utils._tool_UC.serviceId}&game_version=${utils.config.ucConfig.version}`
  770. } else if (PlatUtils.ISCocos) {
  771. url = url + `&kyx=true&app_id=${utils.config.cocosConfig.appID}&channel=cocos&device_uid=${utils._tool_Cocosplay.uid}&uid=${utils._tool_Cocosplay.serviceId}`
  772. } else if (PlatUtils.IsNativeAndroid) {
  773. url = url + `&kyx=false&app_id=${utils.config.nativeAndroidConfig.appID}&channel=${utils.config.nativeAndroidConfig.channel}&device_uid=${utils.Tool_Native.uid}&uid=${utils.Tool_Native.serviceId}&game_type=2&game_version=${utils.config.nativeAndroidConfig.version}`
  774. } else if (PlatUtils.IsKwai) {
  775. url = url + `&kyx=true&app_id=${utils.config.kwaiConfig.appID}&channel=kuaishou&device_uid=${utils._tool_Kwai.uid}&uid=${utils._tool_Kwai.serviceId}&game_version=${utils.config.kwaiConfig.version}`
  776. } else if (PlatUtils.IsNativeIOS) {
  777. url = url + `&kyx=false&app_id=${utils.config.nativeIoSConfig.appID}&channel=ios&device_uid=${utils.Tool_IOS.uid}&uid=${utils.Tool_IOS.serviceId}&game_type=2&game_version=${utils.config.nativeIoSConfig.version}`
  778. } else if (PlatUtils.IsWiFi) {
  779. url = url + `&kyx=true&app_id=${utils.config.wifiConfig.appID}&channel=wifi&device_uid=${utils._tool_Wifi.uid}&uid=${utils._tool_Wifi.serviceId}&game_version=${utils.config.wifiConfig.version}`
  780. } else if (PlatUtils.IsHago) {
  781. url = url + `&kyx=true&app_id=${utils.config.hagoConfig.appID}&channel=hago&device_uid=${utils._tool_Hago.uid}&uid=${utils._tool_Hago.serviceId}&game_version=${utils.config.hagoConfig.version}`
  782. } else if (PlatUtils.IsHuaWei) {
  783. url = url + `&kyx=true&app_id=${utils.config.huaweiConfig.appID}&channel=huawei&device_uid=${utils.Tool_Huawei.uid}&uid=${utils.Tool_Huawei.serviceId}&game_version=${utils.config.huaweiConfig.version}`
  784. } else if (PlatUtils.IsFaceBook) {
  785. url = url + `&kyx=true&app_id=${utils.config.faceBookConfig.appID}&channel=facebookxyx&device_uid=${utils.Tool_Facebook.uid}&uid=${utils.Tool_Facebook.serviceId}&game_version=${utils.config.faceBookConfig.version}`
  786. }
  787. return url;
  788. }
  789. /**
  790. * 上报小游戏跳转点击数据
  791. */
  792. public postData(otherGameAppId: string) {
  793. if (!this._isConfigInit) {
  794. utils.showLog("warn:" + "本地数据未初始化!");
  795. return;
  796. }
  797. this.cur_tool && this.cur_tool.postData && this.cur_tool.postData(otherGameAppId);
  798. }
  799. /**
  800. * 注册服务器初始化完成事件
  801. * @param callback
  802. * @param target
  803. */
  804. public registerServerInitEvent(callback: Function, target: any) {
  805. if (!this._isConfigInit) {
  806. utils.showLog("warn:" + "本地数据未初始化!");
  807. return;
  808. }
  809. if (this._isServerInit) {
  810. if (callback) {
  811. callback();
  812. }
  813. } else {
  814. cc.game.on(YZ_Constant.EC_ServerInit, callback, target);
  815. }
  816. }
  817. /**
  818. * 注册服务器初始化完成事件
  819. * @param callback
  820. * @param target
  821. */
  822. public registerServerDataLoadSuccessEvent(callback: Function, target: any) {
  823. if (this._isServerLoadSuccess) {
  824. if (callback) {
  825. callback();
  826. }
  827. } else {
  828. cc.game.on(YZ_Constant.EC_ServerDataLoadSuccess, callback, target);
  829. }
  830. }
  831. /**
  832. * 注册隐私弹窗关闭事件
  833. * @param callback
  834. * @param target
  835. */
  836. public registerPrivacyCloseEvent(callback: Function, target: any) {
  837. let ysxy = YZ_LocalStorage.getItem(YZ_Constant.YZ_GAME_YSXY);
  838. if (ysxy) {
  839. if (callback) {
  840. callback();
  841. }
  842. } else {
  843. cc.game.on(YZ_Constant.YZ_PrivacyClose, callback, target);
  844. }
  845. }
  846. /**
  847. * 上报互推组件数据
  848. * @param otherGameAppId 跳转的ID
  849. * @param location 当前位置
  850. * @param status 0:点击,1:跳转成功
  851. */
  852. public postDataByLocation(otherGameAppId: string, location: string, status: number = 0) {
  853. if (!this._isConfigInit) {
  854. utils.showLog("warn:" + "本地数据未初始化!");
  855. return;
  856. }
  857. if (PlatUtils.IsBaidu) {
  858. if (this.Tool_Baidu) {
  859. this.Tool_Baidu.postData(otherGameAppId);
  860. }
  861. } else {
  862. this.cur_tool && this.cur_tool.postDataByLocation && this.cur_tool.postDataByLocation(otherGameAppId, location, status)
  863. }
  864. }
  865. /**
  866. * 上报互推组件数据
  867. * @param otherGameAppId 跳转的ID
  868. * @param location 当前位置
  869. * @param status 0:点击,1:跳转成功
  870. */
  871. public postRecommentShowData(location: string) {
  872. if (!this._isConfigInit) {
  873. utils.showLog("warn:" + "本地数据未初始化!");
  874. return;
  875. }
  876. this.cur_tool && this.cur_tool.postRecommentShowData && this.cur_tool.postRecommentShowData(location);
  877. }
  878. /**
  879. * 注销服务器初始化完成事件
  880. * @param target
  881. */
  882. public unregisterServerInitEvent(target: any) {
  883. cc.game.targetOff(target);
  884. }
  885. _isServerLoadSuccess: boolean = false;
  886. /**
  887. * 发送服务器初始化完毕事件
  888. */
  889. public emitServerInitEvent() {
  890. // if (PlatUtils.IsTest) {
  891. // this.getConfigByKey("is_privacy_panel = "true";
  892. // }
  893. if (this.isShowPrivacyPanel()) {
  894. this._isServerLoadSuccess = true;
  895. cc.game.emit(YZ_Constant.EC_ServerDataLoadSuccess);
  896. utils.registerPrivacyCloseEvent(() => {
  897. this._isServerInit = true;
  898. cc.game.emit(YZ_Constant.EC_ServerInit);
  899. cc.game.targetOff(YZ_Constant.EC_ServerDataLoadSuccess);
  900. cc.game.targetOff(YZ_Constant.YZ_PrivacyClose);
  901. }, this);
  902. return;
  903. }
  904. this._isServerInit = true;
  905. cc.game.emit(YZ_Constant.EC_ServerInit);
  906. }
  907. /**
  908. * 注册实名制认证关闭事件
  909. * @param callback
  910. * @param target
  911. */
  912. public registerRealNameAuthCloseEvent(callback: Function, target: any) {
  913. if (this._isServerLoadSuccess) {
  914. if (callback) {
  915. callback();
  916. }
  917. } else {
  918. cc.game.on(YZ_Constant.EC_RealNameAuthPanelClose, callback, target);
  919. }
  920. }
  921. public emitRealNameAuthCloseEvent() {
  922. cc.game.emit(YZ_Constant.EC_RealNameAuthPanelClose);
  923. }
  924. /**
  925. * 发送隐私确认弹窗关闭事件
  926. */
  927. public emitPrivacyCloseEvent() {
  928. this._isServerInit = true;
  929. cc.game.emit(YZ_Constant.YZ_PrivacyClose);
  930. }
  931. /**
  932. * 获取交叉推广数据
  933. */
  934. public getRecommondGameList() {
  935. if (!this._isConfigInit) {
  936. utils.showLog("warn:" + "本地数据未初始化!");
  937. return null;
  938. }
  939. // if (this.cur_tool && this.cur_tool.getRecommondGameList) {
  940. // return this.cur_tool.getRecommondGameList();
  941. // }
  942. if (PlatUtils.IsWechat) {
  943. return this.wechatTool.getRecommondGameList();
  944. } else if (PlatUtils.IsOPPO) {
  945. return this.oppoTool.getRecommondGameList();
  946. } else if (PlatUtils.IsBaidu) {
  947. return this.Tool_Baidu.getRecommondGameList();
  948. } else if (PlatUtils.IsNativeAndroid) {
  949. return this.Tool_Native.getRecommondGameList();
  950. } else if (PlatUtils.IsDouyin) {
  951. return this.Tool_Douyin.getRecommondGameList();
  952. } else if (this.Tool_Broswer) {
  953. return this.Tool_Broswer.getRecommondGameList();
  954. } else if (PlatUtils.IsNativeIOS) {
  955. return this.Tool_IOS.getRecommondGameList();
  956. }
  957. return null;
  958. }
  959. /**
  960. * 是否显示底部更多游戏banner列表
  961. */
  962. public isShowRecommondGamesBanner() {
  963. if (!this._isConfigInit) {
  964. utils.showLog("本地数据未初始化!");
  965. return false;
  966. }
  967. if (this.Tool_Broswer) return true;
  968. if (utils.isSupportnavigateToMiniGame()) {
  969. if (this.ServerConfig
  970. && this.ServerConfig.is_bottom_banner_list) {
  971. if (this.ServerConfig.is_bottom_banner_list == "true") {
  972. return true;
  973. } else {
  974. utils.showLog("is_bottom_banner_list 参数为false,底部更多游戏横幅组件不显示!");
  975. }
  976. } else {
  977. utils.showLog("配置中没有 is_bottom_banner_list 参数,底部更多游戏横幅组件不显示!");
  978. }
  979. } else {
  980. utils.showLog("当前平台不支持游戏内跳转,底部更多游戏横幅组件不显示!");
  981. }
  982. return false;
  983. }
  984. _recommendGamesBanner: cc.Node = null;
  985. /**
  986. * 显示底部推荐游戏Banner
  987. * @param params
  988. * 参数是一个对象.
  989. * {
  990. * group:string //组件所在的组。
  991. * scale:number //组件的缩放值。
  992. * }
  993. */
  994. public showRecommendGamesBanner(params: any = null): boolean {
  995. if (!this._isConfigInit) {
  996. utils.showLog("warn:" + "组件配置未初始化!");
  997. return false;
  998. }
  999. if (this.isShowRecommondGamesBanner()) {
  1000. utils.showLog("显示自定义banner!");
  1001. if (this.config.otherconfig.recommendGamesBanner) {
  1002. let bannerNode: cc.Node = cc.instantiate(this.config.otherconfig.recommendGamesBanner);
  1003. if (bannerNode) {
  1004. if (this._recommendGamesBanner && cc.isValid(this._recommendGamesBanner)) {
  1005. this._recommendGamesBanner.destroy();
  1006. }
  1007. this._recommendGamesBanner = bannerNode;
  1008. this._recommendGamesBanner.zIndex = 9999;
  1009. if (params) {
  1010. if (params.group) {
  1011. bannerNode.group = params.group;
  1012. }
  1013. if (params.scale) {
  1014. bannerNode.scale = params.scale;
  1015. }
  1016. }
  1017. cc.director.getScene().addChild(bannerNode, 1000);
  1018. return true;
  1019. }
  1020. } else {
  1021. utils.showLog("warn:" + "未找到预制体 RecommendGamesBanner, 请查看CommonUtils组件上是否赋值!");
  1022. }
  1023. }
  1024. return false;
  1025. }
  1026. /**
  1027. * 隐藏底部推荐游戏Banner
  1028. */
  1029. public hideRecommendGamesBanner() {
  1030. let banner: cc.Node = cc.find("RecommendGamesBanner");
  1031. if (banner) {
  1032. banner.active = false;
  1033. }
  1034. }
  1035. /**
  1036. * 是否显示推荐游戏列表
  1037. */
  1038. public isShowRecommondGamesList() {
  1039. if (!this._isConfigInit) {
  1040. utils.showLog("warn:" + "组件配置未初始化!");
  1041. return false;
  1042. }
  1043. if (this.Tool_Broswer) return true;
  1044. if (utils.isSupportnavigateToMiniGame()) {
  1045. if (this.ServerConfig.is_banner_list
  1046. && this.ServerConfig.is_banner_list == "true"
  1047. && this.ServerConfig.jump_list
  1048. && this.ServerConfig.jump_list.length > 0) {
  1049. return true;
  1050. } else {
  1051. utils.showLog("请确认字段:is_banner_list、jump_list 是否达到显示自定义banner的要求!");
  1052. return false;
  1053. }
  1054. } else {
  1055. utils.showLog("当前平台不支持游戏内跳转,更多游戏列表组件不显示!");
  1056. }
  1057. return false;
  1058. }
  1059. _recommendGamesList: cc.Node = null;
  1060. /**
  1061. * 显示互推滚动条
  1062. * @param params
  1063. * ```
  1064. * {
  1065. * group:string // 组件所在的组
  1066. * bottom:number // 组件距离屏幕下边的距离
  1067. * left:number // 组件距离屏幕左边的距离
  1068. * scale:number // 组件的缩放比例
  1069. * parent:cc.Node // 父节点,注意:如果不传此参数,则必须接收返回值,并将其加入到父节点中,否则组件不会显示。
  1070. * }
  1071. * ```
  1072. */
  1073. public showRecommendGamesList(params: any = null): cc.Node {
  1074. if (!this._isConfigInit) {
  1075. utils.showLog("warn:" + "组件配置未初始化!");
  1076. return null;
  1077. }
  1078. if (this.config.otherconfig.recommendGamesBar) {
  1079. let barNode: cc.Node = cc.instantiate(this.config.otherconfig.recommendGamesBar);
  1080. if (barNode) {
  1081. if (this._recommendGamesList && cc.isValid(this._recommendGamesList)) {
  1082. this._recommendGamesList.destroy();
  1083. }
  1084. this._recommendGamesList = barNode;
  1085. this._recommendGamesList.zIndex = 9999;
  1086. let widget: cc.Widget = barNode.getComponent(cc.Widget);
  1087. if (params) {
  1088. if (params.group) {
  1089. barNode.group = params.group;
  1090. }
  1091. if (params.scale != null) {
  1092. barNode.scale = params.scale;
  1093. }
  1094. if (params.top != null) {
  1095. widget.isAlignTop = true;
  1096. widget.isAlignBottom = false;
  1097. widget.top = params.top;
  1098. } else if (params.bottom != null) {
  1099. widget.isAlignTop = false;
  1100. widget.isAlignBottom = true;
  1101. widget.bottom = params.bottom;
  1102. }
  1103. if (params.left != null) {
  1104. widget.isAlignLeft = true;
  1105. widget.isAlignRight = false;
  1106. widget.left = params.left;
  1107. } else if (params.right != null) {
  1108. widget.isAlignLeft = false;
  1109. widget.isAlignRight = true;
  1110. widget.right = params.right;
  1111. }
  1112. if (params.parent != null) {
  1113. barNode.parent = params.parent;
  1114. }
  1115. }
  1116. widget.updateAlignment();
  1117. return barNode;
  1118. }
  1119. } else {
  1120. utils.showLog("warn:" + "未找到预制体 RecommendGamesBar, 请查看CommonUtils组件上是否赋值 !");
  1121. }
  1122. return null;
  1123. }
  1124. /**
  1125. * 隐藏互推滚动条
  1126. * @param _tryGamesWidget 更多游戏挂件
  1127. */
  1128. public hideRecommendGamesList() {
  1129. if (this._recommendGamesList && cc.isValid(this._recommendGamesList)) {
  1130. this._recommendGamesList.destroy();
  1131. }
  1132. }
  1133. /**
  1134. * 是否显示试玩挂件
  1135. */
  1136. public isShowTryGamesWidget() {
  1137. if (!this._isConfigInit) {
  1138. utils.showLog("warn:" + "组件配置未初始化!");
  1139. return false;
  1140. }
  1141. if (this.Tool_Broswer) return true;
  1142. if (PlatUtils.IsWechat) {
  1143. if (utils.isSupportnavigateToMiniGame()) {
  1144. if (utils.wechatTool
  1145. && utils.wechatTool.ServerConfig
  1146. && utils.wechatTool.ServerConfig.icon_jump) {
  1147. if (utils.wechatTool.ServerConfig.icon_jump > 0) {
  1148. return true;
  1149. } else {
  1150. utils.showLog("warn:" + "icon_jump参数为false,试玩游戏挂件不显示!");
  1151. }
  1152. } else {
  1153. utils.showLog("warn:" + "配置中没有icon_jump参数,试玩游戏挂件不显示!");
  1154. }
  1155. } else {
  1156. utils.showLog("warn:" + "当前平台不支持游戏内跳转,试玩游戏挂件不显示!");
  1157. }
  1158. } else if (PlatUtils.IsOPPO) {
  1159. if (utils.isSupportnavigateToMiniGame()) {
  1160. if (utils.oppoTool
  1161. && utils.oppoTool.ServerConfig
  1162. && utils.oppoTool.ServerConfig.icon_jump) {
  1163. if (parseInt(utils.oppoTool.ServerConfig.icon_jump) > 0) {
  1164. return true;
  1165. } else {
  1166. utils.showLog("warn:" + "icon_jump参数为false,试玩戏挂件不显示!");
  1167. }
  1168. } else {
  1169. utils.showLog("warn:" + "配置中没有icon_jump参数,试玩游戏挂件不显示!");
  1170. }
  1171. } else {
  1172. utils.showLog("warn:" + "当前平台不支持游戏内跳转,试玩游戏挂件不显示!");
  1173. }
  1174. } else if (PlatUtils.IsBaidu) {
  1175. if (utils.isSupportnavigateToMiniGame()) {
  1176. if (utils.Tool_Baidu
  1177. && utils.Tool_Baidu.ServerConfig
  1178. && utils.Tool_Baidu.ServerConfig.icon_jump) {
  1179. if (utils.Tool_Baidu.ServerConfig.icon_jump > 0) {
  1180. return true;
  1181. } else {
  1182. utils.showLog("warn:" + "icon_jump参数为false,更多游戏挂件不显示!");
  1183. }
  1184. } else {
  1185. utils.showLog("warn:" + "配置中没有icon_jump参数,试玩游戏挂件不显示!");
  1186. }
  1187. } else {
  1188. utils.showLog("warn:" + "当前平台不支持游戏内跳转,试玩游戏挂件不显示!");
  1189. }
  1190. } else if (PlatUtils.IsNativeAndroid) {
  1191. if (utils.Tool_Native
  1192. && utils.Tool_Native.ServerConfig
  1193. && utils.Tool_Native.ServerConfig.icon_jump) {
  1194. if (parseInt(utils.Tool_Native.ServerConfig.icon_jump) > 0) {
  1195. return true;
  1196. }
  1197. } else {
  1198. utils.showLog("warn:" + "配置中没有jumpList参数,试玩游戏挂件不显示!");
  1199. }
  1200. } else if (PlatUtils.IsDouyin) {
  1201. if (utils.isSupportnavigateToMiniGame()) {
  1202. if (utils.Tool_Douyin && utils.Tool_Douyin.isShowMoreGamesModal()
  1203. && utils.Tool_Douyin.ServerConfig
  1204. && utils.Tool_Douyin.ServerConfig.icon_jump) {
  1205. if (utils.Tool_Douyin.ServerConfig.icon_jump > 0) {
  1206. return true;
  1207. } else {
  1208. utils.showLog("warn:" + "icon_jump参数为false,试玩游戏挂件不显示!");
  1209. }
  1210. } else {
  1211. utils.showLog("warn:" + "配置中没有icon_jump参数,试玩游戏挂件不显示!");
  1212. }
  1213. } else {
  1214. utils.showLog("warn:" + "当前平台不支持游戏内跳转,试玩游戏挂件不显示!");
  1215. }
  1216. } else if (PlatUtils.IsQQ) {
  1217. if (utils.isSupportnavigateToMiniGame()) {
  1218. if (utils.Tool_QQ
  1219. && utils.Tool_QQ.ServerConfig
  1220. && utils.Tool_QQ.ServerConfig.icon_jump) {
  1221. if (utils.Tool_QQ.ServerConfig.icon_jump > 0) {
  1222. return true;
  1223. } else {
  1224. utils.showLog("warn:" + "icon_jump参数为false,试玩游戏挂件不显示!");
  1225. }
  1226. } else {
  1227. utils.showLog("warn:" + "配置中没有icon_jump参数,试玩游戏挂件不显示!");
  1228. }
  1229. } else {
  1230. utils.showLog("warn:" + "当前平台不支持游戏内跳转,试玩游戏挂件不显示!");
  1231. }
  1232. } else if (PlatUtils.IsNativeIOS) {
  1233. if (utils.Tool_IOS
  1234. && utils.Tool_IOS.ServerConfig
  1235. && utils.Tool_IOS.ServerConfig.icon_jump) {
  1236. if (utils.Tool_IOS.ServerConfig.icon_jump > 0) {
  1237. return true;
  1238. } else {
  1239. utils.showLog("warn:" + "icon_jump参数为false,试玩游戏挂件不显示!");
  1240. }
  1241. } else {
  1242. utils.showLog("warn:" + "配置中没有icon_jump参数,试玩游戏挂件不显示!");
  1243. }
  1244. }
  1245. return false;
  1246. }
  1247. _tryGamesWidget: cc.Node = null;
  1248. /**
  1249. * 显示试玩挂件
  1250. * @param params
  1251. * ```
  1252. * {
  1253. * group:string
  1254. * left:number
  1255. * bottom:number
  1256. * scale:number
  1257. * parent:cc.Node
  1258. * }
  1259. * ```
  1260. * @returns 生成的组件
  1261. */
  1262. public showTryGamesWidget(params: any = null): cc.Node {
  1263. if (!this._isConfigInit) {
  1264. utils.showLog("warn:" + "组件配置未初始化!");
  1265. return null;
  1266. }
  1267. if (utils.isShowTryGamesWidget()) {
  1268. if (params.location && (this.getConfigByKey("try_game_widget_locations").indexOf(params.location) < 0)) {
  1269. utils.showLog("当前位置服务器未配置显示试玩挂件!");
  1270. if (this._tryGamesWidget && cc.isValid(this._tryGamesWidget)) {
  1271. this._tryGamesWidget.destroy();
  1272. }
  1273. return null;
  1274. }
  1275. if (this.config.otherconfig.tryGamesWidget) {
  1276. let node: cc.Node = cc.instantiate(this.config.otherconfig.tryGamesWidget);
  1277. if (node) {
  1278. if (this._tryGamesWidget && cc.isValid(this._tryGamesWidget)) {
  1279. this._tryGamesWidget.destroy();
  1280. }
  1281. this._tryGamesWidget = node;
  1282. this._tryGamesWidget.zIndex = 9999;
  1283. let widget: cc.Widget = node.getComponent(cc.Widget);
  1284. if (params) {
  1285. if (params.group) {
  1286. node.group = params.group;
  1287. }
  1288. if (params.scale != null) {
  1289. node.scale = params.scale;
  1290. }
  1291. if (params.top != null) {
  1292. widget.isAlignTop = true;
  1293. widget.isAlignBottom = false;
  1294. widget.top = params.top;
  1295. } else if (params.bottom != null) {
  1296. widget.isAlignTop = false;
  1297. widget.isAlignBottom = true;
  1298. widget.bottom = params.bottom;
  1299. }
  1300. if (params.left != null) {
  1301. widget.isAlignLeft = true;
  1302. widget.isAlignRight = false;
  1303. widget.left = params.left;
  1304. } else if (params.right != null) {
  1305. widget.isAlignLeft = false;
  1306. widget.isAlignRight = true;
  1307. widget.right = params.right;
  1308. }
  1309. if (params.parent != null) {
  1310. node.parent = params.parent;
  1311. }
  1312. }
  1313. widget.updateAlignment();
  1314. return node;
  1315. }
  1316. } else {
  1317. utils.showLog("warn:" + "未找到预制体 TryGamesWidget, 请查看CommonUtils组件上是否赋值 !");
  1318. }
  1319. } else {
  1320. utils.showLog("warn:" + "不支持跳转组件");
  1321. }
  1322. return null;
  1323. }
  1324. /**
  1325. * 隐藏更多游戏挂件
  1326. * @param _tryGamesWidget 更多游戏挂件
  1327. */
  1328. public hideTryGamesWidget() {
  1329. if (this._tryGamesWidget && cc.isValid(this._tryGamesWidget)) {
  1330. this._tryGamesWidget.destroy();
  1331. }
  1332. }
  1333. /**
  1334. * 是否显示更多游戏侧边栏
  1335. */
  1336. public isShowMoreGamesWidget() {
  1337. if (!this._isConfigInit) {
  1338. utils.showLog("warn:" + "组件配置未初始化!");
  1339. return false;
  1340. }
  1341. if (this.Tool_Broswer || CC_DEBUG) return true;
  1342. if (PlatUtils.IsWechat) {
  1343. if (utils.isSupportnavigateToMiniGame()) {
  1344. if (this.getConfigByKey("is_more_game") == "true") {
  1345. return true;
  1346. } else {
  1347. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1348. }
  1349. } else {
  1350. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  1351. }
  1352. } else if (PlatUtils.IsOPPO) {
  1353. if (utils.isSupportnavigateToMiniGame()) {
  1354. if (this.getConfigByKey("is_more_game") == "true") {
  1355. if (utils.oppoTool.ServerConfig.show_oppo_rec == "true") {
  1356. if (!utils.oppoTool.canShowRecommend()) {
  1357. utils.showLog("warn:" + "当前平台不支持官方互推,更多游戏侧边栏组件不显示!");
  1358. return false;
  1359. }
  1360. }
  1361. return true;
  1362. } else {
  1363. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1364. }
  1365. } else {
  1366. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  1367. }
  1368. } else if (PlatUtils.IsDouyin) {
  1369. if (PlatUtils.IsAndroid
  1370. && utils.isSupportnavigateToMiniGame()) {
  1371. if (this.getConfigByKey("is_more_game") == "true") {
  1372. return true;
  1373. } else {
  1374. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1375. }
  1376. } else {
  1377. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  1378. }
  1379. } else if (PlatUtils.IsBaidu) {
  1380. if (utils.isSupportnavigateToMiniGame()) {
  1381. if (this.getConfigByKey("is_more_game") == "true") {
  1382. return true;
  1383. } else {
  1384. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1385. }
  1386. } else {
  1387. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  1388. }
  1389. } else if (PlatUtils.IsQQ) {
  1390. if (utils.isSupportnavigateToMiniGame()) {
  1391. if (this.getConfigByKey("is_more_game") == "true") {
  1392. return true;
  1393. } else {
  1394. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1395. }
  1396. } else {
  1397. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  1398. }
  1399. } else if (PlatUtils.Is4399) {
  1400. return true;
  1401. } else if (PlatUtils.IsNativeAndroid) {
  1402. if (this.getConfigByKey("is_more_game") == "true") {
  1403. return true;
  1404. } else {
  1405. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1406. }
  1407. } else if (PlatUtils.IsNativeIOS) {
  1408. if (this.getConfigByKey("is_more_game") == "true") {
  1409. return true;
  1410. } else {
  1411. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1412. }
  1413. } else if (PlatUtils.IsVIVO) {
  1414. if (this.getConfigByKey("is_more_game") == "true") {
  1415. return true;
  1416. } else {
  1417. utils.showLog("warn:" + "配置中没有is_more_game参数,更多游戏侧边栏组件不显示!");
  1418. }
  1419. }
  1420. return false;
  1421. }
  1422. _moreGamesSidePanel: any = null;
  1423. /**
  1424. * 显示更多游戏侧边栏
  1425. * @param params
  1426. * ```
  1427. * {
  1428. * group:string // 组件所在的组
  1429. * left:number // 组件距离屏幕左边的距离
  1430. * right:number // 组件距离屏幕右边的距离
  1431. * top:number // 距离屏幕顶部的距离
  1432. * bottom:number // 距离屏幕底部的距离
  1433. * scale:number // 缩放比例
  1434. * parent:cc.Node // 父节点
  1435. * }
  1436. * ```
  1437. */
  1438. public showMoreGamesWidget(params: any = null): cc.Node {
  1439. if (!this._isConfigInit) {
  1440. utils.showLog("warn:" + "组件配置未初始化!");
  1441. return null;
  1442. }
  1443. if (params.location && (this.getConfigByKey("more_game_widget_locations").indexOf(params.location) < 0)) {
  1444. utils.showLog("当前位置服务器未配置显示更多游戏挂件!");
  1445. if (this._moreGamesSidePanel && cc.isValid(this._moreGamesSidePanel)) {
  1446. this._moreGamesSidePanel.destroy();
  1447. }
  1448. return null;
  1449. }
  1450. if (PlatUtils.IsDouyin) {
  1451. if (utils.Tool_Douyin) {
  1452. if (utils.isShowMoreGamesWidget()) {
  1453. if (utils.Tool_Douyin.isShowMoreGamesModal()) {
  1454. if (this.config.otherconfig.moreGamesWidget) {
  1455. let node: cc.Node = cc.instantiate(this.config.otherconfig.moreGamesWidget);
  1456. if (node) {
  1457. if (this._moreGamesSidePanel && cc.isValid(this._moreGamesSidePanel)) {
  1458. this._moreGamesSidePanel.destroy();
  1459. }
  1460. this._moreGamesSidePanel = node;
  1461. this._moreGamesSidePanel.zIndex = 9999;
  1462. let widget: cc.Widget = node.getComponent(cc.Widget);
  1463. if (params) {
  1464. if (params.group) {
  1465. node.group = params.group;
  1466. }
  1467. if (params.scale != null) {
  1468. node.scale = params.scale;
  1469. }
  1470. if (params.top != null) {
  1471. widget.isAlignTop = true;
  1472. widget.isAlignBottom = false;
  1473. widget.top = params.top;
  1474. } else if (params.bottom != null) {
  1475. widget.isAlignTop = false;
  1476. widget.isAlignBottom = true;
  1477. widget.bottom = params.bottom;
  1478. }
  1479. if (params.left != null) {
  1480. widget.isAlignLeft = true;
  1481. widget.isAlignRight = false;
  1482. widget.left = params.left;
  1483. } else if (params.right != null) {
  1484. widget.isAlignLeft = false;
  1485. widget.isAlignRight = true;
  1486. widget.right = params.right;
  1487. }
  1488. if (params.parent != null) {
  1489. node.parent = params.parent;
  1490. }
  1491. }
  1492. widget.updateAlignment();
  1493. return node;
  1494. }
  1495. } else {
  1496. utils.showLog("warn:" + "未找到预制体 MoreGamesWidget, 请查看CommonUtils组件上是否赋值!");
  1497. }
  1498. } else {
  1499. let btn = utils.Tool_Douyin.showMoreGamesButton(params);
  1500. if (btn) {
  1501. if (this._moreGamesSidePanel) {
  1502. this._moreGamesSidePanel.destroy();
  1503. }
  1504. this._moreGamesSidePanel = btn;
  1505. if (params) {
  1506. if (params.group) {
  1507. btn.group = params.group;
  1508. }
  1509. if (params.parent != null) {
  1510. btn.parent = params.parent;
  1511. }
  1512. }
  1513. return this._moreGamesSidePanel;
  1514. } else {
  1515. return null;
  1516. }
  1517. }
  1518. } else {
  1519. utils.showLog("当前平台版本不支持交叉推广, 更多游戏按钮不显示!");
  1520. return null;
  1521. }
  1522. }
  1523. } else {
  1524. if (utils.isShowMoreGamesWidget()) {
  1525. if (this.config.otherconfig.moreGamesWidget) {
  1526. let node: cc.Node = cc.instantiate(this.config.otherconfig.moreGamesWidget);
  1527. if (node) {
  1528. if (this._moreGamesSidePanel && cc.isValid(this._moreGamesSidePanel)) {
  1529. this._moreGamesSidePanel.destroy();
  1530. }
  1531. this._moreGamesSidePanel = node;
  1532. this._moreGamesSidePanel.zIndex = 9999;
  1533. let widget: cc.Widget = node.getComponent(cc.Widget);
  1534. if (params) {
  1535. if (params.group) {
  1536. node.group = params.group;
  1537. }
  1538. if (params.scale != null) {
  1539. node.scale = params.scale;
  1540. }
  1541. if (params.top != null) {
  1542. widget.isAlignTop = true;
  1543. widget.isAlignBottom = false;
  1544. widget.top = params.top;
  1545. } else if (params.bottom != null) {
  1546. widget.isAlignTop = false;
  1547. widget.isAlignBottom = true;
  1548. widget.bottom = params.bottom;
  1549. }
  1550. if (params.left != null) {
  1551. widget.isAlignLeft = true;
  1552. widget.isAlignRight = false;
  1553. widget.left = params.left;
  1554. } else if (params.right != null) {
  1555. widget.isAlignLeft = false;
  1556. widget.isAlignRight = true;
  1557. widget.right = params.right;
  1558. }
  1559. if (params.parent != null) {
  1560. node.parent = params.parent;
  1561. }
  1562. }
  1563. widget.updateAlignment();
  1564. return node;
  1565. }
  1566. } else {
  1567. utils.showLog("warn:" + "未找到预制体 MoreGamesWidget, 请查看CommonUtils组件上是否赋值!");
  1568. }
  1569. } else {
  1570. utils.showLog("warn:" + "不可显示更多游戏侧边栏")
  1571. }
  1572. }
  1573. return null;
  1574. }
  1575. /**
  1576. * 隐藏侧边栏按钮
  1577. * @param moreGameBtn 更多游戏侧边栏按钮
  1578. */
  1579. public hideMoreGamesWidget(moreGameBtn?: any) {
  1580. if (PlatUtils.IsDouyin) {
  1581. if (moreGameBtn && cc.isValid(moreGameBtn)) {
  1582. moreGameBtn.destroy();
  1583. }
  1584. if (this._moreGamesSidePanel) {
  1585. this._moreGamesSidePanel.destroy();
  1586. }
  1587. } else {
  1588. if (moreGameBtn && cc.isValid(moreGameBtn)) {
  1589. moreGameBtn.destroy();
  1590. }
  1591. if (this._moreGamesSidePanel && cc.isValid(this._moreGamesSidePanel)) {
  1592. this._moreGamesSidePanel.destroy();
  1593. }
  1594. }
  1595. if (PlatUtils.IsVIVO) {
  1596. this.Tool_Vivo && this.Tool_Vivo.hideGamePortal();
  1597. }
  1598. }
  1599. _moreGamesSidePanelBaidu: any = null;
  1600. public showBaiduMoreGamesBtn(params: any = null) {
  1601. if (!this._isConfigInit) {
  1602. utils.showLog("warn:" + "组件配置未初始化!");
  1603. return null;
  1604. }
  1605. let isShow: boolean = false;
  1606. if (PlatUtils.IsBaidu) {
  1607. if (utils.Tool_Baidu
  1608. && utils.Tool_Baidu.canShowRecommendButton()) {
  1609. isShow = true;
  1610. } else {
  1611. utils.showLog("warn:" + "当前平台不支持游戏内跳转,百度更多游戏侧边栏组件不显示!");
  1612. }
  1613. }
  1614. if (PlatUtils.IsBaidu) {
  1615. if (utils.Tool_Baidu) {
  1616. if (isShow) {
  1617. let btn = utils.Tool_Baidu.showRecommendationButton(params);
  1618. if (btn) {
  1619. if (this._moreGamesSidePanelBaidu) {
  1620. this._moreGamesSidePanelBaidu.destroy();
  1621. }
  1622. this._moreGamesSidePanelBaidu = btn;
  1623. return this._moreGamesSidePanelBaidu;
  1624. } else {
  1625. return null;
  1626. }
  1627. } else {
  1628. utils.showLog("当前平台版本不支持交叉推广, 百度更多游戏按钮不显示!");
  1629. return null;
  1630. }
  1631. }
  1632. }
  1633. }
  1634. public hideBaiduMoreGamesBtn(moreGameBtn: any) {
  1635. if (PlatUtils.IsBaidu && moreGameBtn) {
  1636. if (moreGameBtn != null) {
  1637. moreGameBtn.destroy();
  1638. }
  1639. }
  1640. }
  1641. /**
  1642. * 是否显示录屏组件
  1643. */
  1644. public isShowRecordWidget() {
  1645. if (!this._isConfigInit) {
  1646. utils.showLog("warn:" + "组件配置未初始化!");
  1647. return false;
  1648. }
  1649. if (this.Tool_Broswer) return true;
  1650. if (PlatUtils.IsDouyin) {
  1651. if (this.getConfigByKey("show_record") == "true") {
  1652. return true;
  1653. }
  1654. utils.showLog("服务器配置不显示录屏按钮!");
  1655. } else if (PlatUtils.IsKwai) {
  1656. if (utils.kwaiTool && utils.kwaiTool.checkCanShowRecored() && this.getConfigByKey("show_record") == "true") {
  1657. return true;
  1658. }
  1659. utils.showLog("服务器配置不显示录屏按钮!");
  1660. }
  1661. return false;
  1662. }
  1663. public hideRecordWidget() {
  1664. if (this._recordWidget && cc.isValid(this._recordWidget)) {
  1665. this._recordWidget.destroy();
  1666. }
  1667. }
  1668. _recordWidget: cc.Node = null;
  1669. /**
  1670. * 显示录屏按钮
  1671. * @param params
  1672. */
  1673. public showRecordWidget(params: any = null): cc.Node {
  1674. if (!this._isConfigInit) {
  1675. utils.showLog("warn:" + "组件配置未初始化!");
  1676. return null;
  1677. }
  1678. if (!this.isShowRecordWidget()) return null;
  1679. if (this.config.otherconfig.recordWidget) {
  1680. let node: cc.Node = cc.instantiate(this.config.otherconfig.recordWidget);
  1681. if (node) {
  1682. if (this._recordWidget && cc.isValid(this._recordWidget)) {
  1683. this._recordWidget.destroy();
  1684. }
  1685. this._recordWidget = node;
  1686. this._recordWidget.zIndex = 9999;
  1687. let widget: cc.Widget = node.getComponent(cc.Widget);
  1688. if (params) {
  1689. if (params.group) {
  1690. node.group = params.group;
  1691. }
  1692. if (params.scale != null) {
  1693. node.scale = params.scale;
  1694. }
  1695. if (params.top != null) {
  1696. widget.isAlignTop = true;
  1697. widget.isAlignBottom = false;
  1698. widget.top = params.top;
  1699. } else if (params.bottom != null) {
  1700. widget.isAlignTop = false;
  1701. widget.isAlignBottom = true;
  1702. widget.bottom = params.bottom;
  1703. }
  1704. if (params.left != null) {
  1705. widget.isAlignLeft = true;
  1706. widget.isAlignRight = false;
  1707. widget.left = params.left;
  1708. } else if (params.right != null) {
  1709. widget.isAlignLeft = false;
  1710. widget.isAlignRight = true;
  1711. widget.right = params.right;
  1712. }
  1713. if (params.parent != null) {
  1714. node.parent = params.parent;
  1715. }
  1716. }
  1717. widget.updateAlignment();
  1718. return node;
  1719. }
  1720. } else {
  1721. utils.showLog("warn:" + "未找到预制体 RecordWidget, 请查看CommonUtils组件上是否赋值!");
  1722. }
  1723. return null;
  1724. }
  1725. /**
  1726. * 是否显示创建快捷方式控件
  1727. */
  1728. public isShowCreateShortcutWidget() {
  1729. if (!this._isConfigInit) {
  1730. utils.showLog("warn:" + "本地数据未初始化!");
  1731. return false;
  1732. }
  1733. if (this.Tool_Broswer) return true;
  1734. if (this.canCreateShortcut()) {
  1735. if (this.getConfigByKey("is_desktop") == "true") {
  1736. return true;
  1737. } else {
  1738. utils.showLog("配置数据中没有 is_desktop 字段, 创建快捷方式按钮不显示!");
  1739. }
  1740. } else {
  1741. utils.showLog("当前平台版本不支持创建桌面快捷方式, 创建快捷方式按钮不显示!");
  1742. }
  1743. return false;
  1744. }
  1745. _shortcutWidget: cc.Node = null;
  1746. /**
  1747. * 创建快捷方式
  1748. * @param callback 点击创建快捷方式按钮后回调函数 Function<ret:boolean>
  1749. * @param params
  1750. */
  1751. public showCreateShortcutWidget(callback: Function = null, params: any = null): cc.Node {
  1752. if (!this._isConfigInit) {
  1753. utils.showLog("warn:" + "组件配置未初始化!");
  1754. return null;
  1755. }
  1756. if (utils.isShowCreateShortcutWidget()) {
  1757. if (this.config.otherconfig.shortcutWidget) {
  1758. let node: cc.Node = cc.instantiate(this.config.otherconfig.shortcutWidget);
  1759. if (node) {
  1760. if (this._shortcutWidget && cc.isValid(this._shortcutWidget)) {
  1761. this._shortcutWidget.destroy();
  1762. }
  1763. this._shortcutWidget = node;
  1764. this._shortcutWidget.zIndex = 9999;
  1765. let widget: cc.Widget = node.getComponent(cc.Widget);
  1766. let shortcutWidget: YZ_ShortcutWidget = node.getComponent("YZ_ShortcutWidget");
  1767. if (shortcutWidget) {
  1768. shortcutWidget.Callback = callback;
  1769. }
  1770. if (params) {
  1771. if (params.group) {
  1772. node.group = params.group;
  1773. }
  1774. if (params.scale != null) {
  1775. node.scale = params.scale;
  1776. }
  1777. if (params.top != null) {
  1778. widget.isAlignTop = true;
  1779. widget.isAlignBottom = false;
  1780. widget.top = params.top;
  1781. } else if (params.bottom != null) {
  1782. widget.isAlignTop = false;
  1783. widget.isAlignBottom = true;
  1784. widget.bottom = params.bottom;
  1785. }
  1786. if (params.left != null) {
  1787. widget.isAlignLeft = true;
  1788. widget.isAlignRight = false;
  1789. widget.left = params.left;
  1790. } else if (params.right != null) {
  1791. widget.isAlignLeft = false;
  1792. widget.isAlignRight = true;
  1793. widget.right = params.right;
  1794. }
  1795. if (params.parent != null) {
  1796. node.parent = params.parent;
  1797. } else {
  1798. cc.director.getScene().addChild(node, 1000);
  1799. }
  1800. }
  1801. widget.updateAlignment();
  1802. return node;
  1803. }
  1804. } else {
  1805. utils.showLog("warn:" + "未找到预制体 ShortcutWidge, 请查看CommonUtils组件上是否赋值!");
  1806. }
  1807. } else {
  1808. utils.showLog("warn:" + "不显示创建桌面图标");
  1809. }
  1810. return null;
  1811. }
  1812. /**
  1813. * 隐藏快捷方式
  1814. */
  1815. public hideCreateShortcutWidget(params: any = null) {
  1816. if (this._shortcutWidget && cc.isValid(this._shortcutWidget)) {
  1817. this._shortcutWidget.destroy();
  1818. }
  1819. }
  1820. /**
  1821. * 注册事件,事件在YZ_Constant类中定义
  1822. * @param eventName : string 事件名 事件在 YZ_Constant 类中定义
  1823. * @param callback 回调函数
  1824. * @param target : cc.Node 目标对象
  1825. */
  1826. public registerEvent(eventName: string, callback: Function, target: any) {
  1827. if (!eventName) {
  1828. utils.showLog("warn:" + "[Utils.registerEvent] param eventName is null!");
  1829. return;
  1830. }
  1831. if (!callback) {
  1832. utils.showLog("warn:" + "[Utils.registerEvent] param callback is null!");
  1833. return;
  1834. }
  1835. if (!target) {
  1836. utils.showLog("warn:" + "[Utils.registerEvent] param target is null!");
  1837. return;
  1838. }
  1839. cc.game.on(eventName, callback, target);
  1840. }
  1841. /**
  1842. * 取消注册事件
  1843. * @param eventName 事件名
  1844. */
  1845. public unregisterEvent(eventName: string) {
  1846. cc.game.off(eventName);
  1847. }
  1848. /**
  1849. * 发送事件
  1850. * @param eventName 事件名
  1851. */
  1852. public emitCommonEvent(eventName: string) {
  1853. cc.game.emit(eventName);
  1854. }
  1855. _gameBox: cc.Node = null;
  1856. /**
  1857. * 显示游戏盒子
  1858. * @param params
  1859. */
  1860. public showGameBox(params: any = null) {
  1861. if (PlatUtils.IsWechat) {
  1862. let isShow: boolean = false;
  1863. // console.log("utils.wechatTool.ServerConfig.openBox",utils.wechatTool.ServerConfig.openBox)
  1864. if (utils.wechatTool.ServerConfig && utils.wechatTool.ServerConfig.openBox) {
  1865. if (utils.wechatTool.ServerConfig.openBox != "true") {
  1866. utils.showLog("服务器游戏盒子配置为关闭状态!");
  1867. return;
  1868. }
  1869. utils.showLog("服务器配置游戏盒子为打开状态");
  1870. isShow = true;
  1871. } else {
  1872. let showTime: number = new Date().getTime() - new Date("2019-10-23").getTime();
  1873. if (showTime > 0) {
  1874. isShow = true;
  1875. utils.showLog("当前时间大于指定时间,可以显示游戏盒子");
  1876. }
  1877. }
  1878. if (!isShow) {
  1879. utils.showLog("warn:" + "当前条件不满足要求,游戏盒子不显示!");
  1880. return;
  1881. }
  1882. let node: cc.Node = cc.instantiate(this.config.otherconfig.gameBox);
  1883. if (node) {
  1884. if (this._gameBox && cc.isValid(this._gameBox)) {
  1885. this._gameBox.destroy();
  1886. }
  1887. this._gameBox = node;
  1888. this._gameBox.zIndex = 9999;
  1889. if (params.parent != null) {
  1890. node.parent = params.parent;
  1891. }
  1892. } else {
  1893. utils.showLog("warn:" + "未找到预制体 GameBox, 请查看CommonUtils组件上是否赋值!");
  1894. }
  1895. }
  1896. }
  1897. _nativeTryGameNode: cc.Node = null;
  1898. tryGameDate: any[] = [];
  1899. nativeNeedChange: boolean = true;
  1900. isShowNativeTryGamesWidget(): boolean {
  1901. if (!this._isConfigInit) {
  1902. utils.showLog("warn:" + "组件配置未初始化!");
  1903. return false;
  1904. }
  1905. if (this.Tool_Broswer) return true;
  1906. if (this.ServerConfig
  1907. && this.ServerConfig.icon_jump_native
  1908. && parseInt(this.ServerConfig.icon_jump_native) > 0) {
  1909. return true;
  1910. } else {
  1911. utils.showLog("warn:" + "配置中没有icon_jump_native参数,原生试玩游戏挂件不显示!");
  1912. }
  1913. return false;
  1914. }
  1915. /**
  1916. * 是否能显示6个元素的交叉推广组件
  1917. */
  1918. public canShowCrossWidget6() {
  1919. if (!this._isConfigInit) {
  1920. utils.showLog("组件配置未初始化!");
  1921. return false;
  1922. }
  1923. if (this.Tool_Broswer) return true;
  1924. if (PlatUtils.IsWechat || PlatUtils.IsOPPO || PlatUtils.IsBaidu || PlatUtils.IsNativeAndroid || PlatUtils.IsNativeIOS) {
  1925. if (utils.isSupportnavigateToMiniGame()) {
  1926. if (this.getConfigByKey("is_cross_game") == "true") {
  1927. return true;
  1928. } else {
  1929. utils.showLog("warn:" + "配置中没有is_cross_game参数,6元素交叉推广组件不显示!");
  1930. }
  1931. } else {
  1932. utils.showLog("warn:" + "当前平台不支持游戏内跳转,6元素交叉推广组件不显示!");
  1933. }
  1934. } else if (PlatUtils.IsDouyin) {
  1935. if (utils.isSupportnavigateToMiniGame() && utils.Tool_Douyin.isShowMoreGamesModal()) {
  1936. if (this.getConfigByKey("is_cross_game") == "true") {
  1937. return true;
  1938. } else {
  1939. utils.showLog("warn:" + "is_cross_game参数为false,6元素交叉推广组件不显示!");
  1940. }
  1941. } else {
  1942. utils.showLog("warn:" + "当前平台不支持游戏内跳转,6元素交叉推广组件不显示!");
  1943. }
  1944. }
  1945. return false;
  1946. }
  1947. /**
  1948. * 显示6元素交叉推广组件
  1949. */
  1950. public showCrossWidget6(): cc.Node {
  1951. if (!this._isConfigInit) {
  1952. utils.showLog("warn:" + "组件配置未初始化!");
  1953. return null;
  1954. }
  1955. if (this.canShowCrossWidget6()) {
  1956. if (this.config.otherconfig.crossWidget6) {
  1957. return cc.instantiate(this.config.otherconfig.crossWidget6);
  1958. } else {
  1959. utils.showLog("warn:" + "未找到预制体 CrossWidget6, 请查看CommonUtils组件上是否赋值!");
  1960. }
  1961. }
  1962. return null;
  1963. }
  1964. /**
  1965. * 显示添加到我的小程序引导
  1966. * @param param 参数值:
  1967. * type: bar(一直展示)/tip(3秒展示)
  1968. */
  1969. public showFavoriteGuide(param?: any) {
  1970. if (PlatUtils.IsBaidu) {
  1971. if (utils._tool_Baidu.canShowFavoriteGuide()) {
  1972. //@ts-ignore
  1973. swan.showFavoriteGuide({
  1974. type: param ? param.type : 'tip',
  1975. content: '一键添加到我的小程序',
  1976. success: res => {
  1977. utils.showLog('添加成功:', res);
  1978. },
  1979. fail: err => {
  1980. utils.showLog('添加失败:', err);
  1981. }
  1982. })
  1983. utils.showLog("显示我的小程序引导成功!");
  1984. } else {
  1985. utils.showLog("当前平台不支持显示添加我的小程序引导");
  1986. }
  1987. }
  1988. }
  1989. /**
  1990. * 验证是否自动弹出签到
  1991. * true : 自动弹出,false : 不自动弹出
  1992. */
  1993. public checkAutoSign(): boolean {
  1994. if (this.getConfigByKey("auto_sign") == "true") {
  1995. return true;
  1996. }
  1997. return false;
  1998. }
  1999. /**
  2000. * 获取当前平台的配置文件
  2001. */
  2002. public get ServerConfig(): any {
  2003. if (this.cur_tool) {
  2004. return this.cur_tool.ServerConfig ? this.cur_tool.ServerConfig : {};
  2005. }
  2006. return {};
  2007. }
  2008. _cur_tool = null;
  2009. /**
  2010. * 获取当前平台的配置文件
  2011. */
  2012. public get cur_tool(): any {
  2013. if (this._cur_tool) return this._cur_tool;
  2014. if (PlatUtils.IsWechat) {
  2015. this._cur_tool = utils.wechatTool;
  2016. } else if (PlatUtils.IsOPPO) {
  2017. this._cur_tool = utils.oppoTool;
  2018. } else if (PlatUtils.IsVIVO) {
  2019. this._cur_tool = utils.Tool_Vivo;
  2020. } else if (PlatUtils.IsQQ) {
  2021. this._cur_tool = utils.Tool_QQ;
  2022. } else if (PlatUtils.IsDouyin) {
  2023. this._cur_tool = utils.Tool_Douyin;
  2024. } else if (PlatUtils.IsBaidu) {
  2025. this._cur_tool = utils.Tool_Baidu;
  2026. } else if (PlatUtils.IsQTT) {
  2027. this._cur_tool = utils.Tool_QTT;
  2028. } else if (PlatUtils.IsXiaoMi) {
  2029. this._cur_tool = utils.Tool_XiaoMi;
  2030. } else if (PlatUtils.ISUC) {
  2031. this._cur_tool = utils.Tool_UC;
  2032. } else if (PlatUtils.ISCocos) {
  2033. this._cur_tool = utils.Tool_Cocosplay;
  2034. } else if (PlatUtils.IsNativeAndroid) {
  2035. this._cur_tool = utils.Tool_Native;
  2036. } else if (PlatUtils.Is4399) {
  2037. this._cur_tool = utils.Tool_4399;
  2038. } else if (PlatUtils.IsKwai) {
  2039. this._cur_tool = utils._tool_Kwai;
  2040. } else if (PlatUtils.IsNativeIOS) {
  2041. this._cur_tool = utils.Tool_IOS;
  2042. } else if (PlatUtils.IsWiFi) {
  2043. this._cur_tool = utils._tool_Wifi;
  2044. } else if (PlatUtils.IsHago) {
  2045. this._cur_tool = utils._tool_Hago;
  2046. } else if (PlatUtils.IsHuaWei) {
  2047. this._cur_tool = utils.Tool_Huawei;
  2048. } else if (PlatUtils.IsFaceBook) {
  2049. this._cur_tool = utils.Tool_Facebook;
  2050. } else if (PlatUtils.IsGoogleWeb) {
  2051. this._cur_tool = utils.Tool_Facebook;
  2052. } else {
  2053. this._cur_tool = utils._tool_Broswer;
  2054. }
  2055. return this._cur_tool;
  2056. }
  2057. serverShowLog: boolean = false;
  2058. /**
  2059. * 显示日志到控制台
  2060. */
  2061. showLogToConsole: boolean = false;
  2062. /**
  2063. * 显示LOG
  2064. */true
  2065. public showLog(msg: any = "", ...any) {
  2066. // if (true) {
  2067. // console.log(msg, ...any);
  2068. // return;
  2069. // }
  2070. if (this.showLogView || this.serverShowLog) {
  2071. if (this.config.otherconfig.logoutView) {
  2072. if (cc.director.getScene()) {
  2073. let logooutView = cc.director.getScene().getChildByName("LogoutView");
  2074. if (!logooutView) {
  2075. logooutView = cc.instantiate(this.config.otherconfig.logoutView);
  2076. cc.director.getScene().addChild(logooutView, 1000);
  2077. }
  2078. logooutView.getComponent("LogOutView").addLog(msg, ...any);
  2079. }
  2080. } else {
  2081. utils.showLog("warn:" + "未找到预制体 LogOutView, 请查看CommonUtils组件上是否赋值!");
  2082. }
  2083. } else {
  2084. if (this.showLogToConsole) {
  2085. console.log(msg, ...any);
  2086. } else {
  2087. cc.log(msg, ...any);
  2088. }
  2089. }
  2090. }
  2091. /**
  2092. * 屏幕震动功能
  2093. * @param type 震动类型 传递枚举:VibrateType
  2094. */
  2095. public vibrate(type: VibrateType = VibrateType.Short) {
  2096. if (PlatUtils.IsWechat) {
  2097. if (type == VibrateType.Short) {
  2098. //@ts-ignore
  2099. //使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
  2100. wx.vibrateShort({ success(res) { }, fail(res) { } });
  2101. } else {
  2102. //@ts-ignore
  2103. wx.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  2104. }
  2105. } else if (PlatUtils.IsOPPO) {
  2106. if (type == VibrateType.Short) {
  2107. //@ts-ignore
  2108. qg.vibrateShort({ success(res) { }, fail(res) { } });//(20 ms)
  2109. } else {
  2110. //@ts-ignore
  2111. qg.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  2112. }
  2113. } else if (PlatUtils.IsVIVO) {
  2114. if (type == VibrateType.Short) {
  2115. //@ts-ignore
  2116. qg.vibrateShort();//(15 ms)
  2117. } else {
  2118. //@ts-ignore
  2119. qg.vibrateLong(); //400 ms
  2120. }
  2121. } else if (PlatUtils.IsQQ) {
  2122. if (type == VibrateType.Short) {
  2123. //@ts-ignore
  2124. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  2125. qq.vibrateShort({ success(res) { }, fail(res) { } });
  2126. } else {
  2127. //@ts-ignore
  2128. qq.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  2129. }
  2130. } else if (PlatUtils.IsDouyin) {
  2131. if (type == VibrateType.Short) {
  2132. //@ts-ignore
  2133. tt.vibrateShort({ success(res) { }, fail(res) { } });
  2134. } else {
  2135. //@ts-ignore
  2136. tt.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  2137. }
  2138. } else if (PlatUtils.IsBaidu) {
  2139. if (type == VibrateType.Short) {
  2140. //@ts-ignore
  2141. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  2142. swan.vibrateShort({ success(res) { }, fail(res) { } });
  2143. } else {
  2144. //@ts-ignore
  2145. swan.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  2146. }
  2147. } else if (PlatUtils.IsWiFi) {
  2148. if (type == VibrateType.Short) {
  2149. //@ts-ignore
  2150. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  2151. wuji.vibrateShort({ success(res) { }, fail(res) { } });
  2152. } else {
  2153. //@ts-ignore
  2154. wuji.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  2155. }
  2156. } else if (PlatUtils.IsNativeAndroid) {
  2157. if (type == VibrateType.Short) {
  2158. //@ts-ignore
  2159. jsb.reflection.callStaticMethod(utils.Tool_Native.jniClassName, "vibrateShort", "()V");
  2160. } else {
  2161. //@ts-ignore
  2162. jsb.reflection.callStaticMethod(utils.Tool_Native.jniClassName, "vibrateLong", "()V");
  2163. }
  2164. }
  2165. }
  2166. /**
  2167. * 游戏开始上报
  2168. * @param level 当前关卡
  2169. * @param model 当前模式: 没有则省略
  2170. */
  2171. StartGame(level: string, model?: string) {
  2172. AldUtils.StartGame(level, model);
  2173. utils.cur_tool && utils.cur_tool.umaOnStart && utils.cur_tool.umaOnStart(level);
  2174. if (PlatUtils.IsDouyin || PlatUtils.IsKwai) {
  2175. this.AutoStartRecord(level);
  2176. }
  2177. }
  2178. /**
  2179. * 游戏胜利上报,显示结算广告
  2180. * @param level 当前关卡
  2181. * @param star 获得星星: 默认为0
  2182. * @param model 当前模式: 没有则省略
  2183. * @param isShowAd 是否调用广告,默认开启调用
  2184. * @returns json{ type:(1:6元素互推、2:单个原生广告),node:节点}
  2185. *
  2186. */
  2187. GameWin(level: string, star: number = 0, model?: string, isShowAd: boolean = true): any {
  2188. AldUtils.GameWin(level, star, model);
  2189. utils.cur_tool && utils.cur_tool.umaReportedLevel && utils.cur_tool.umaReportedLevel(level, LevelStatus.GameWin);
  2190. if (PlatUtils.IsKwai) {
  2191. utils.kwaiTool.isClickEnd = false;
  2192. }
  2193. // if (PlatUtils.IsDouyin || PlatUtils.IsKwai) {
  2194. this.recordEnd();
  2195. // }
  2196. return this.AutoShowStatement(level, true, isShowAd);
  2197. }
  2198. /**
  2199. * 游戏失败上报,显示结算广告
  2200. * @param level 当前关卡
  2201. * @param model 当前模式: 没有则省略
  2202. * @param isShowAd 是否调用广告,默认开启调用
  2203. * @returns json{ type:(1:6元素互推、2:单个原生广告),node:节点}
  2204. */
  2205. GameFail(level: string, model?: string, isShowAd: boolean = true): any {
  2206. AldUtils.GameFail(level, model);
  2207. utils.cur_tool && utils.cur_tool.umaReportedLevel && utils.cur_tool.umaReportedLevel(level, LevelStatus.GameFail);
  2208. // if (PlatUtils.IsDouyin || PlatUtils.IsKwai) {
  2209. this.recordEnd();
  2210. // }
  2211. return this.AutoShowStatement(level, false, isShowAd);
  2212. }
  2213. /**
  2214. * 跳过关卡上报
  2215. * @param level 当前关卡
  2216. * @param model 当前模式: 没有则省略
  2217. */
  2218. GameSkip(level: string, model?: string) {
  2219. AldUtils.GameSkip(level, model);
  2220. }
  2221. /**
  2222. * 事件上报
  2223. * @param eventName 事件名称
  2224. */
  2225. SendEvent(eventName: string) {
  2226. AldUtils.SendEvent(eventName)
  2227. }
  2228. /**
  2229. * 友盟自定义事件上报
  2230. * @param eventID 事件ID
  2231. * @param params 事件内容 Type: obj
  2232. */
  2233. umaEvent(eventID: string, params?) {
  2234. utils.showLog(`事件上报:${eventID}:${params}`);
  2235. if (PlatUtils.IsNativeAndroid) {
  2236. utils.cur_tool && utils.cur_tool.umaTrackEvent && utils.cur_tool.umaTrackEvent("custom", eventID, params);
  2237. } else {
  2238. utils.cur_tool && utils.cur_tool.umaTrackEvent && utils.cur_tool.umaTrackEvent(eventID, params);
  2239. }
  2240. }
  2241. overPageShowTime: number = 0;
  2242. overPageInsertAdIsTouch: boolean = false; // 结算页面的插屏广告是否被点击过
  2243. reportOverPageTouchEvent(overPage: cc.Node) {
  2244. utils.showLog("reportOverPageTouchEvent >>>>>>>");
  2245. this.overPageInsertAdIsTouch = false;
  2246. this.overPageShowTime = new Date().getTime();
  2247. let node = new cc.Node();
  2248. node.width = overPage.width * 2;
  2249. node.height = overPage.height * 2;
  2250. node.on(cc.Node.EventType.TOUCH_START, () => {
  2251. let time = (new Date().getTime() - this.overPageShowTime) / 1000;
  2252. let json: any = {};
  2253. json.data = time;
  2254. utils.SendEventNew(`结算页面点击时间`, "overPageTouch", JSON.stringify(json));
  2255. node.destroy();
  2256. node.removeFromParent();
  2257. }, overPage);
  2258. node['_touchListener']['swallowTouches'] = false;
  2259. overPage.addChild(node, cc.macro.MAX_ZINDEX);
  2260. }
  2261. /**
  2262. * 自定义事件上报
  2263. * @param eventName 事件名称
  2264. */
  2265. SendEventNew(eventName: string, eventId: string = "default", eventData?: string, isCallBack: boolean = true) {
  2266. utils.showLog(`自定义事件上报:${eventName},${eventId},${eventData}`);
  2267. utils.cur_tool && utils.cur_tool.SendEventNew && utils.cur_tool.SendEventNew(eventName, eventId, eventData, isCallBack);
  2268. }
  2269. /**
  2270. * 游戏中使用道具上报
  2271. * @param level 当前关卡
  2272. * @param tooName 道具名称
  2273. * @param model 当前模式: 没有则省略
  2274. */
  2275. public static UseTool(level: string, toolName: string, model?: string): void {
  2276. AldUtils.UseTool(level, toolName, model)
  2277. }
  2278. /**
  2279. * 分享成功次数
  2280. */
  2281. public recored_share_count: number = 0;
  2282. /**
  2283. * 判断算界面是否能显示自动分享 自动强弹视频 自动弹插屏
  2284. * type 1自动分享 2自动强弹视频 3自动弹插屏 4自动弹互推插屏
  2285. */
  2286. public checkResultShow(type): boolean {
  2287. let level = utils.currentLevel;
  2288. let isSuccess = utils.isSuccess;
  2289. let config = utils.ServerConfig;
  2290. if (!config) {
  2291. utils.showLog("warn:" + "服务器配置不存在,只显示结算广告")
  2292. return type == 3;
  2293. }
  2294. if (PlatUtils.IsDouyin) {
  2295. if (config.auto_record_share_count) {
  2296. let recoredCount = config.auto_record_share_count;
  2297. if (recoredCount != 0 && utils.recored_share_count >= recoredCount) {
  2298. utils.showLog(`服务器配置分享次数:${recoredCount} ,已到上限`)
  2299. } else {
  2300. let record_cap = config.auto_record_interval;
  2301. let checkShow: boolean = false;
  2302. if (level > 0 && record_cap != 0) {
  2303. if (record_cap.indexOf(",") == -1) {
  2304. if (level % Number(record_cap) == 0) {
  2305. checkShow = true;
  2306. }
  2307. } else {
  2308. utils.showLog(`指定关卡${config.auto_record_interval}分享录屏,当前关卡为:${level}`);
  2309. let record_cap_arr = record_cap.split(",");
  2310. record_cap_arr.forEach(str => {
  2311. if (level == Number(str)) {
  2312. checkShow = true;
  2313. }
  2314. });
  2315. }
  2316. if (checkShow) {
  2317. if (config.auto_record_share_type == "all") {
  2318. return type == 1;
  2319. }
  2320. if (config.auto_record_share_type == "success") {
  2321. if (utils.isSuccess == true) {
  2322. return type == 1;
  2323. }
  2324. }
  2325. if (config.auto_record_share_type == "fail") {
  2326. if (utils.isSuccess == false) {
  2327. return type == 1;
  2328. }
  2329. }
  2330. }
  2331. }
  2332. }
  2333. }
  2334. }
  2335. utils.showLog(`不能自动分享录屏 分享录屏间隔为:${config.auto_record_interval} 分享类型为:${config.auto_record_share_type}`);
  2336. if (config.auto_video_interval && config.auto_video_interval != 0) {
  2337. let space = config.auto_video_interval;
  2338. let showType = config.auto_video_show_type
  2339. if (level % space == 0) {
  2340. if (showType == "all") {
  2341. return type == 2;
  2342. }
  2343. if (showType == "success") {
  2344. if (isSuccess == true) {
  2345. return type == 2;
  2346. }
  2347. }
  2348. if (showType == "fail") {
  2349. if (isSuccess == false) {
  2350. return type == 2;
  2351. }
  2352. }
  2353. }
  2354. }
  2355. utils.showLog(`不能自动弹视频弹视频间隔为:${config.auto_video_interval} 弹视频类型为:${config.auto_video_show_type}`)
  2356. if (config.auto_rec_insert_interval && config.auto_rec_insert_interval != 0) {
  2357. let space = config.auto_rec_insert_interval;
  2358. let showType = config.auto_rec_insert_type;
  2359. if (level % space == 0) {
  2360. if (showType == "all") {
  2361. return type == 4;
  2362. }
  2363. if (showType == "success") {
  2364. if (isSuccess == true) {
  2365. return type == 4;
  2366. }
  2367. }
  2368. if (showType == "fail") {
  2369. if (isSuccess == false) {
  2370. return type == 4;
  2371. }
  2372. }
  2373. }
  2374. }
  2375. utils.showLog(`不能自动弹互推插屏间隔为:${config.auto_rec_insert_interval} 弹视频类型为:${config.auto_rec_insert_type}`)
  2376. return type == 3;
  2377. }
  2378. /**
  2379. * 结算广告控制
  2380. * level 当前关卡 isSuccess是否胜利
  2381. * qq 若判断2通过弹游戏盒子 判断3通过弹插屏
  2382. * 抖音 若判断2通过则弹视频 判断3过弹插屏
  2383. * 趣头条 若判断2通过弹视频 判断3通过弹互动直弹
  2384. * 其他平台若判断2通过则服务器配置有问题,联系运营修改
  2385. *服务器控制 结算界面自动弹出视频
  2386. */
  2387. public AutoShowStatement(level, isSuccess, isShowAd): any {
  2388. utils.currentLevel = level;
  2389. utils.isSuccess = isSuccess;
  2390. let res: any = { "type": -1, "node": null }
  2391. if (!isShowAd) {
  2392. utils.showLog("isShowAd为false,只上报不显示广告")
  2393. return res;
  2394. }
  2395. let isShowVideo: boolean = false;
  2396. if (this.checkResultShow(2)) {
  2397. if (this.getConfigByKey("result_auto_show_video") == "false") return;
  2398. if (PlatUtils.IsDouyin) {
  2399. utils.showLog("服务器版本:", utils.config.douyinconfig.version, "当前版本:", this.getConfigByKey("version"));
  2400. if (utils.config.douyinconfig.version != this.getConfigByKey("version")) {
  2401. utils.showLog("版本不一致,自动播放视频!")
  2402. utils.adManager.ShowVideo(() => { });
  2403. isShowVideo = true;
  2404. }
  2405. } else if (PlatUtils.IsQQ) {
  2406. if (utils.config.qqconfig.version != this.getConfigByKey("version")) {
  2407. utils.showLog("版本不一致,自动播放视频!")
  2408. utils.adManager.ShowVideo(() => { });
  2409. isShowVideo = true;
  2410. }
  2411. } else if (PlatUtils.IsWiFi) {
  2412. if (utils.config.wifiConfig.version != this.getConfigByKey("version")) {
  2413. utils.showLog("版本不一致,自动播放视频!")
  2414. utils.adManager.ShowVideo(() => { });
  2415. isShowVideo = true;
  2416. }
  2417. } else if (PlatUtils.IsBaidu) {
  2418. if (utils.config.baiduconfig.version != this.getConfigByKey("version")) {
  2419. utils.showLog("版本不一致,自动播放视频!")
  2420. utils.adManager.ShowVideo(() => { });
  2421. isShowVideo = true;
  2422. }
  2423. } else if (PlatUtils.IsKwai) {
  2424. if (utils.config.kwaiConfig.version != this.getConfigByKey("version")) {
  2425. utils.showLog("版本不一致,自动播放视频!")
  2426. utils.adManager.ShowVideo(() => { });
  2427. isShowVideo = true;
  2428. }
  2429. } else if (PlatUtils.IsHago) {
  2430. if (utils.config.hagoConfig.version != this.getConfigByKey("version")) {
  2431. utils.showLog("版本不一致,自动播放视频!")
  2432. utils.adManager.ShowVideo(() => { });
  2433. isShowVideo = true;
  2434. }
  2435. } else if (PlatUtils.IsNativeAndroid) {
  2436. if (utils.config.nativeAndroidConfig.version != this.getConfigByKey("version")) {
  2437. utils.showLog("版本不一致,自动播放视频!")
  2438. if (utils.ServerConfig && this.getConfigByKey("auto_video_type") == "reward_video") {
  2439. utils.adManager.ShowVideo(() => { });
  2440. } else {
  2441. utils.adManager.showFullScreenVideo();
  2442. }
  2443. isShowVideo = true;
  2444. } else {
  2445. utils.showLog("与服务器版本一致,不自动播放视频!")
  2446. }
  2447. } else if (PlatUtils.IsNativeIOS) {
  2448. if (utils.config.nativeIoSConfig.version != this.getConfigByKey("version")) {
  2449. utils.showLog("版本不一致,自动播放视频!")
  2450. if (utils.ServerConfig && this.getConfigByKey("auto_video_type") == "reward_video") {
  2451. utils.adManager.ShowVideo(() => { });
  2452. } else {
  2453. utils.adManager.showFullScreenVideo();
  2454. }
  2455. isShowVideo = true;
  2456. }
  2457. } else if (PlatUtils.IsVIVO) {
  2458. utils.showLog("服务器配置当前显示强弹视频,但当前平台不支持。需修改服务器配置")
  2459. utils.adManager.showStatementAds();
  2460. } else {
  2461. isShowVideo = true;
  2462. utils.adManager.ShowVideo(() => { });
  2463. }
  2464. if (isShowVideo && (PlatUtils.IsDouyin || PlatUtils.IsQQ || PlatUtils.IsNativeAndroid || PlatUtils.IsNativeIOS)) {
  2465. utils.showLog("当前强弹了视频,不显示插屏!");
  2466. } else {
  2467. res = utils.adManager.showStatementAds();
  2468. }
  2469. }
  2470. // if (this.canShowRedBag() && this.yzRedBagInfo.progress >= this.yzRedBagInfo.totalProgress) {
  2471. // utils.showLog("当前红包进度已满,显示获得红包窗口!");
  2472. // // this.showOpenRedBagPanel({ showType: 2 });
  2473. // }
  2474. if (this.checkResultShow(3)) {
  2475. res = utils.adManager.showStatementAds();
  2476. // console.log(" this.checkResultShow(3)", res.node);
  2477. }
  2478. if (PlatUtils.IsDouyin || PlatUtils.IsNativeIOS || PlatUtils.IsBaidu || PlatUtils.IsNativeAndroid) {
  2479. //抖音平台判断是否需要6元素互推
  2480. res.type = 1;
  2481. res.node = utils.showCrossWidget6();
  2482. }
  2483. return res;
  2484. }
  2485. /**
  2486. * 获得一次现金红包
  2487. */
  2488. public addRedBagCount(callFun?: Function) {
  2489. this.yzRedBagInfo.freeRedBagCount++;
  2490. if (callFun) {
  2491. this.rewardCloseFunc = callFun;
  2492. }
  2493. this.showOpenRedBagPanel({ showType: 3 });
  2494. utils.showLog("获得一个现金红包");
  2495. }
  2496. /**
  2497. * 开始游戏自动录屏
  2498. * 暂时只有头条平台有
  2499. * 默认为0 表示不开启,例如3 表示每三关会自动录屏,例如3,6,9 表示只有第3,6,9指定的关卡会自动录屏
  2500. */
  2501. AutoStartRecord(level) {
  2502. if (this.getConfigByKey("auto_record_interval") > 0) {
  2503. utils.recordStart();
  2504. } else {
  2505. utils.showLog("warn:" + "服务器配置不存在auto_record_interva")
  2506. }
  2507. }
  2508. shareRecordPanel: cc.Node = null;
  2509. /**
  2510. * 显示录屏分享窗口
  2511. * @param params
  2512. */
  2513. public showShareRecordPanel(params: any = null) {
  2514. if (!this._isConfigInit) {
  2515. utils.showLog("warn:" + "组件配置未初始化!");
  2516. return null;
  2517. }
  2518. if (this.config.otherconfig.shareRecordPanel) {
  2519. let node: cc.Node = cc.instantiate(this.config.otherconfig.shareRecordPanel);
  2520. if (node) {
  2521. if (this.shareRecordPanel && cc.isValid(this.shareRecordPanel)) {
  2522. this.shareRecordPanel.destroy();
  2523. }
  2524. this.shareRecordPanel = node;
  2525. this.shareRecordPanel.zIndex = 9999;
  2526. let widget: cc.Widget = node.getComponent(cc.Widget);
  2527. if (params) {
  2528. if (params.group) {
  2529. node.group = params.group;
  2530. }
  2531. if (params.scale != null) {
  2532. node.scale = params.scale;
  2533. }
  2534. if (params.top != null) {
  2535. widget.isAlignTop = true;
  2536. widget.isAlignBottom = false;
  2537. widget.top = params.top;
  2538. } else if (params.bottom != null) {
  2539. widget.isAlignTop = false;
  2540. widget.isAlignBottom = true;
  2541. widget.bottom = params.bottom;
  2542. }
  2543. if (params.left != null) {
  2544. widget.isAlignLeft = true;
  2545. widget.isAlignRight = false;
  2546. widget.left = params.left;
  2547. } else if (params.right != null) {
  2548. widget.isAlignLeft = false;
  2549. widget.isAlignRight = true;
  2550. widget.right = params.right;
  2551. }
  2552. if (params.parent != null) {
  2553. node.parent = params.parent;
  2554. } else {
  2555. cc.director.getScene().addChild(this.shareRecordPanel, 1000);
  2556. }
  2557. } else {
  2558. cc.director.getScene().addChild(this.shareRecordPanel, 1000);
  2559. }
  2560. widget.updateAlignment();
  2561. return node;
  2562. }
  2563. } else {
  2564. utils.showLog("未找到预制体 ShareRecordPanel, 请查看CommonUtils组件上是否赋值!");
  2565. }
  2566. return null;
  2567. }
  2568. /**
  2569. * 获取其他辅助配置
  2570. */
  2571. public get otherConfig(): any {
  2572. if (!this._other_config) {
  2573. this._other_config = this.config.otherconfig.localConfig.json.other;
  2574. }
  2575. return this._other_config;
  2576. }
  2577. /**
  2578. * 获取试用皮肤关卡间隔
  2579. * 默认为每5关显示一次
  2580. *
  2581. */
  2582. public isShowTrySkin(curLevel: number): boolean {
  2583. let count: number = 5;
  2584. if (utils.ServerConfig && this.getConfigByKey("try_skin_level_count")) {
  2585. count = this.getConfigByKey("try_skin_level_count");
  2586. }
  2587. if (curLevel % count == 0) {
  2588. if (utils.ServerConfig && this.getConfigByKey("try_skin_show_ad_interval") != undefined) {
  2589. if (curLevel % this.getConfigByKey("try_skin_show_ad_interval") == 0) {
  2590. utils.showLog(`服务器配置间隔${this.getConfigByKey("try_skin_show_ad_interval")}关试用皮肤展示插屏!`);
  2591. utils.adManager.ShowInterstitial();
  2592. }
  2593. }
  2594. return true;
  2595. }
  2596. return false;
  2597. }
  2598. /**
  2599. * 延迟显示跳过或者关闭按钮
  2600. * @param btn 延迟显示按钮的节点
  2601. * @param isCloseBtn 是否返回或者关闭按钮
  2602. * @param location 按钮所在的页面位置
  2603. */
  2604. public showSkipBtn(btn: cc.Node, isCloseBtn: boolean = false, location: BannerLocation = BannerLocation.None): void {
  2605. if (btn) {
  2606. let delayShowBtn: number = PlatUtils.IsNativeAndroid ? 3 : 0;
  2607. if (this.getConfigByKey("skip_btn_show_delay")) {
  2608. delayShowBtn = this.getConfigByKey("skip_btn_show_delay");
  2609. }
  2610. if (isCloseBtn) {
  2611. if (this.getConfigByKey("special_skip_btn_show_delay")) {
  2612. delayShowBtn = this.getConfigByKey("special_skip_btn_show_delay");
  2613. }
  2614. }
  2615. if (PlatUtils.IsTest) {
  2616. this.ServerConfig.over_page_skip_btn_show_delay = 3;
  2617. }
  2618. if (location == BannerLocation.Over) {
  2619. if (this.getConfigByKey("over_page_skip_btn_show_delay")) {
  2620. delayShowBtn = this.getConfigByKey("over_page_skip_btn_show_delay");
  2621. }
  2622. }
  2623. if (delayShowBtn > 0) {
  2624. btn.opacity = 0;
  2625. btn.active = false;
  2626. this.scheduleOnce(() => {
  2627. if (btn && cc.isValid(btn)) {
  2628. btn.active = true;
  2629. btn.runAction(cc.fadeIn(0.3));
  2630. }
  2631. }, delayShowBtn);
  2632. } else {
  2633. if (!btn.active) {
  2634. btn.active = true;
  2635. }
  2636. }
  2637. }
  2638. }
  2639. /**
  2640. * 抖音按钮延迟显示
  2641. * 默认为0秒
  2642. */
  2643. public delayShowNode(btn: cc.Node): void {
  2644. if (btn) {
  2645. btn.opacity = 0;
  2646. btn.active = true;
  2647. let delayShowBtn: number = 0;
  2648. if (this.getConfigByKey("next_btn_show_delay")) {
  2649. delayShowBtn = this.getConfigByKey("next_btn_show_delay");
  2650. }
  2651. this.scheduleOnce(() => {
  2652. if (btn && cc.isValid(btn)) {
  2653. btn.runAction(cc.fadeIn(0.3));
  2654. }
  2655. }, delayShowBtn);
  2656. }
  2657. }
  2658. /**
  2659. * 宝箱界面是否自动勾选
  2660. */
  2661. public isBoxAutoSelectToggle(): boolean {
  2662. let cap_level: number = 0;
  2663. let level = utils.currentLevel;
  2664. if (this.getConfigByKey("box_auto_select_level")) {
  2665. cap_level = Number(this.getConfigByKey("box_auto_select_level"));
  2666. } else {
  2667. utils.showLog("服务器配置不存在,不自动勾选")
  2668. }
  2669. if (cap_level != 0 && (level % cap_level) == 0) {
  2670. return true;
  2671. }
  2672. return false;
  2673. }
  2674. /**
  2675. * 结算界面是否自动勾选
  2676. */
  2677. public isResultAutoSelectToggle(): boolean {
  2678. let cap_level: number = 0;
  2679. let level = utils.currentLevel;
  2680. if (this.getConfigByKey("result_auto_select_level")) {
  2681. cap_level = Number(this.getConfigByKey("result_auto_select_level"));
  2682. } else {
  2683. utils.showLog("服务器配置不存在,不自动勾选")
  2684. }
  2685. if (cap_level != 0 && (level % cap_level) == 0) {
  2686. return true;
  2687. }
  2688. return false;
  2689. }
  2690. /**
  2691. * 试用皮肤界面是否自动勾选
  2692. */
  2693. public isTrySkinAutoSelectToggle(): boolean {
  2694. let cap_level: number = 0;
  2695. let level = utils.currentLevel;
  2696. if (this.getConfigByKey("skin_auto_select_level")) {
  2697. cap_level = Number(this.getConfigByKey("skin_auto_select_level"));
  2698. } else {
  2699. utils.showLog("服务器配置不存在,不自动勾选")
  2700. }
  2701. if (cap_level != 0 && (level % cap_level) == 0) {
  2702. return true;
  2703. }
  2704. return false;
  2705. }
  2706. /**
  2707. * 游戏当前版本
  2708. */
  2709. get gameVersion(): string {
  2710. if (this.cur_tool && this.cur_tool.gameVersion) return this.cur_tool.gameVersion();
  2711. return "-1"
  2712. }
  2713. /**
  2714. * 界面控制
  2715. * @param view
  2716. * 界面类型:皮肤试用界面 宝箱界面
  2717. *
  2718. * 返回值类型
  2719. * @param callback isSelect:按钮是否自动勾选上
  2720. * @param callback msg:文字提示
  2721. * @param callback btnType:初始按钮类型 true为看广告的文本 false为不看广告的文本
  2722. */
  2723. public controView(view: ViewLocation): any {
  2724. let result: any = { "isSelect": true, "msg": "观看视频获得奖励", "btnType": true, "is_open": false };
  2725. let adTipsType: boolean;
  2726. let selectType: number;
  2727. if (!utils.ServerConfig) {
  2728. utils.showLog("服务器配置不存在");
  2729. return result;
  2730. }
  2731. //验证服务器是否开启勾选策略
  2732. if (this.getConfigByKey("open_check_btn") == "false") {
  2733. utils.showLog("服务器配置不开启勾选!");
  2734. return result;
  2735. }
  2736. result.is_open = true;
  2737. switch (view) {
  2738. case ViewLocation.sign:
  2739. selectType = this.getConfigByKey("sign_auto_select_level") ? this.getConfigByKey("sign_auto_select_level") : 0;
  2740. if (this.getConfigByKey("ad_tip_sign_random") == "true") {
  2741. adTipsType = Math.random() >= 0.5 ? true : false;
  2742. } else {
  2743. adTipsType = true;
  2744. }
  2745. if (adTipsType) {
  2746. result.msg = "查看视频获得双倍奖励";
  2747. } else {
  2748. result.msg = "不需要视频奖励";
  2749. }
  2750. break;
  2751. case ViewLocation.trySkin:
  2752. selectType = this.getConfigByKey("tryskin_auto_select_level") ? this.getConfigByKey("tryskin_auto_select_level") : 0;
  2753. if (this.getConfigByKey("ad_tip_tryskin_random") == "true") {
  2754. adTipsType = Math.random() >= 0.5 ? true : false;
  2755. } else {
  2756. adTipsType = true;
  2757. }
  2758. if (adTipsType) {
  2759. result.msg = "查看视频试用皮肤";
  2760. } else {
  2761. result.msg = "不需要视频试用皮肤";
  2762. }
  2763. break;
  2764. case ViewLocation.box:
  2765. selectType = this.getConfigByKey("box_auto_select_level") ? this.getConfigByKey("box_auto_select_level") : 0;
  2766. if (this.getConfigByKey("ad_tip_box_random") == "true") {
  2767. adTipsType = Math.random() >= 0.5 ? true : false;
  2768. } else {
  2769. adTipsType = true;
  2770. }
  2771. if (adTipsType) {
  2772. result.msg = "查看视频获得五倍奖励";
  2773. } else {
  2774. result.msg = "不需要视频奖励";
  2775. }
  2776. break;
  2777. case ViewLocation.successBox:
  2778. selectType = this.getConfigByKey("success_box_auto_select_level") ? this.getConfigByKey("success_box_auto_select_level") : 0;
  2779. break;
  2780. case ViewLocation.failBox:
  2781. selectType = this.getConfigByKey("fail_box_auto_select_level") ? this.getConfigByKey("fail_box_auto_select_level") : 0;
  2782. break;
  2783. case ViewLocation.winPanel:
  2784. selectType = this.getConfigByKey("win_panel_auto_select_level") ? this.getConfigByKey("win_panel_auto_select_level") : 0;
  2785. break;
  2786. case ViewLocation.turntable:
  2787. selectType = this.getConfigByKey("turntable_auto_select_level") ? this.getConfigByKey("turntable_auto_select_level") : 0;
  2788. break;
  2789. }
  2790. if (selectType == 0) {
  2791. result.isSelect = false;
  2792. } else if (selectType == 1) {
  2793. result.isSelect = true;
  2794. } else if (selectType == 2) {
  2795. result.isSelect = Math.random() >= 0.5 ? true : false;
  2796. }
  2797. result.btnType = adTipsType == result.isSelect;
  2798. return result;
  2799. }
  2800. /**
  2801. * 是否能再下一关开始的时候强弹视频
  2802. */
  2803. canShowNextVideo(level): boolean {
  2804. if (utils.ServerConfig && this.getConfigByKey("next_auto_video_interval")) {
  2805. let cap = Number(this.getConfigByKey("next_auto_video_interval"));
  2806. if (cap && cap != 0) {
  2807. if (level % cap == 0) {
  2808. if (PlatUtils.IsDouyin) {
  2809. if (this.getConfigByKey("version") != utils.config.douyinconfig.version) {
  2810. return true;
  2811. }
  2812. } else if (PlatUtils.IsBaidu) {
  2813. if (this.getConfigByKey("version") != utils.config.baiduconfig.version) {
  2814. return true;
  2815. }
  2816. } else if (PlatUtils.ISUC) {
  2817. if (this.getConfigByKey("version") != utils.config.ucConfig.version) {
  2818. return true;
  2819. }
  2820. } else {
  2821. return true;
  2822. }
  2823. } else {
  2824. if (PlatUtils.Is4399) {
  2825. cap = 3;//4399不能读取服务器配置写死间隔
  2826. if (cap != 0 && level % cap == 0) {
  2827. return this.true;
  2828. }
  2829. }
  2830. }
  2831. }
  2832. }
  2833. return false;
  2834. }
  2835. /**
  2836. * 是否显示红包
  2837. */
  2838. public canShowRedBag() {
  2839. if (!this._isConfigInit) {
  2840. utils.showLog("warn:" + "组件配置未初始化!");
  2841. return false;
  2842. }
  2843. if (this.Tool_Broswer) return true;
  2844. if (this.ServerConfig && this.yzRedBagInfo && this.ServerConfig.show_red_bag && this.ServerConfig.show_red_bag == "true") {
  2845. return true;
  2846. }
  2847. utils.showLog("服务器配置不显示红包组件!");
  2848. return false;
  2849. }
  2850. _withdrawalWidget: cc.Node = null;
  2851. /**
  2852. * 隐藏提现框挂件
  2853. */
  2854. public hideWithdrawalWidget() {
  2855. if (this._withdrawalWidget && cc.isValid(this._withdrawalWidget)) {
  2856. this._withdrawalWidget.destroy();
  2857. }
  2858. }
  2859. /**
  2860. * 显示提现框挂件
  2861. * @param params
  2862. */
  2863. public showWithdrawalWidget(params: any = null): cc.Node {
  2864. if (!this._isConfigInit) {
  2865. utils.showLog("warn:" + "组件配置未初始化!");
  2866. return null;
  2867. }
  2868. if (!this.canShowRedBag()) return null;
  2869. if (this.config.otherconfig.withdrawalWidget) {
  2870. let node: cc.Node = cc.instantiate(this.config.otherconfig.withdrawalWidget);
  2871. if (node) {
  2872. if (this._withdrawalWidget && cc.isValid(this._withdrawalWidget)) {
  2873. this._withdrawalWidget.destroy();
  2874. }
  2875. this._withdrawalWidget = node;
  2876. this._withdrawalWidget.zIndex = 9999;
  2877. let widget: cc.Widget = node.getComponent(cc.Widget);
  2878. if (params) {
  2879. if (params.group) {
  2880. node.group = params.group;
  2881. }
  2882. if (params.scale != null) {
  2883. node.scale = params.scale;
  2884. }
  2885. if (params.top != null) {
  2886. widget.isAlignTop = true;
  2887. widget.isAlignBottom = false;
  2888. widget.top = params.top;
  2889. } else if (params.bottom != null) {
  2890. widget.isAlignTop = false;
  2891. widget.isAlignBottom = true;
  2892. widget.bottom = params.bottom;
  2893. }
  2894. if (params.left != null) {
  2895. widget.isAlignLeft = true;
  2896. widget.isAlignRight = false;
  2897. widget.left = params.left;
  2898. } else if (params.right != null) {
  2899. widget.isAlignLeft = false;
  2900. widget.isAlignRight = true;
  2901. widget.right = params.right;
  2902. }
  2903. if (params.parent != null) {
  2904. node.parent = params.parent;
  2905. }
  2906. }
  2907. widget.updateAlignment();
  2908. return node;
  2909. }
  2910. } else {
  2911. utils.showLog("warn:" + "未找到预制体 WithdrawalWidget, 请查看CommonUtils组件上是否赋值!");
  2912. }
  2913. return null;
  2914. }
  2915. _redBagProgressWidget: cc.Node = null;
  2916. /**
  2917. * 隐藏红包进度挂件
  2918. */
  2919. public hideRedBagProgressWidget() {
  2920. if (this._redBagProgressWidget && cc.isValid(this._redBagProgressWidget)) {
  2921. this._redBagProgressWidget.destroy();
  2922. }
  2923. }
  2924. /**
  2925. * 显示红包进度挂件
  2926. * @param params
  2927. */
  2928. public showRedBagProgressWidget(params: any = null): cc.Node {
  2929. if (!this._isConfigInit) {
  2930. utils.showLog("warn:" + "组件配置未初始化!");
  2931. return null;
  2932. }
  2933. if (!this.canShowRedBag()) return null;
  2934. if (this.config.otherconfig.redBagProgressWidget) {
  2935. let node: cc.Node = cc.instantiate(this.config.otherconfig.redBagProgressWidget);
  2936. if (node) {
  2937. if (this._redBagProgressWidget && cc.isValid(this._redBagProgressWidget)) {
  2938. this._redBagProgressWidget.destroy();
  2939. }
  2940. this._redBagProgressWidget = node;
  2941. this._redBagProgressWidget.zIndex = 9999;
  2942. let widget: cc.Widget = node.getComponent(cc.Widget);
  2943. if (params) {
  2944. if (params.location) {
  2945. node.getComponent(RedBagProgressWidget).init(params);
  2946. }
  2947. if (params.group) {
  2948. node.group = params.group;
  2949. }
  2950. if (params.scale != null) {
  2951. node.scale = params.scale;
  2952. }
  2953. if (params.top != null) {
  2954. widget.isAlignTop = true;
  2955. widget.isAlignBottom = false;
  2956. widget.top = params.top;
  2957. } else if (params.bottom != null) {
  2958. widget.isAlignTop = false;
  2959. widget.isAlignBottom = true;
  2960. widget.bottom = params.bottom;
  2961. }
  2962. if (params.left != null) {
  2963. widget.isAlignLeft = true;
  2964. widget.isAlignRight = false;
  2965. widget.left = params.left;
  2966. } else if (params.right != null) {
  2967. widget.isAlignLeft = false;
  2968. widget.isAlignRight = true;
  2969. widget.right = params.right;
  2970. }
  2971. if (params.parent != null) {
  2972. node.parent = params.parent;
  2973. }
  2974. }
  2975. widget.updateAlignment();
  2976. return node;
  2977. }
  2978. } else {
  2979. utils.showLog("warn:" + "未找到预制体 RedBagProgressWidget, 请查看CommonUtils组件上是否赋值!");
  2980. }
  2981. return null;
  2982. }
  2983. _withdrawalPanel: cc.Node = null;
  2984. /**
  2985. * 显示提现弹窗
  2986. * @param params
  2987. */
  2988. public showWithdrawalPanel(params: any = null): cc.Node {
  2989. if (!this._isConfigInit) {
  2990. utils.showLog("warn:" + "组件配置未初始化!");
  2991. return null;
  2992. }
  2993. if (!this.canShowRedBag()) return null;
  2994. if (this.config.otherconfig.withdrawalPanel) {
  2995. let node: cc.Node = cc.instantiate(this.config.otherconfig.withdrawalPanel);
  2996. if (node) {
  2997. if (this._withdrawalPanel && cc.isValid(this._withdrawalPanel)) {
  2998. this._withdrawalPanel.destroy();
  2999. }
  3000. this._withdrawalPanel = node;
  3001. cc.director.getScene().addChild(this._withdrawalPanel, 9999);
  3002. } else {
  3003. utils.showLog("warn:" + "未找到预制体 WithdrawalPanel, 请查看CommonUtils组件上是否赋值!");
  3004. }
  3005. return null;
  3006. }
  3007. }
  3008. _openRedBagPanel: cc.Node = null;
  3009. /**
  3010. * 显示开红包弹窗
  3011. * @param params
  3012. */
  3013. public showOpenRedBagPanel(params: any = null): cc.Node {
  3014. if (params && params.closeCallFunc) {
  3015. this.rewardCloseFunc = params.closeCallFunc;
  3016. }
  3017. if (!this._isConfigInit) {
  3018. utils.showLog("warn:" + "组件配置未初始化!");
  3019. this.rewardCloseFunc && this.rewardCloseFunc();
  3020. return null;
  3021. }
  3022. if (!this.canShowRedBag()) {
  3023. this.rewardCloseFunc && this.rewardCloseFunc();
  3024. return null;
  3025. }
  3026. if (params && params.location && params.location === BannerLocation.Home) {
  3027. if (this.yzRedBagInfo.progress < this.yzRedBagInfo.totalProgress && !this.yzRedBagInfo.isFreeRedBag) {
  3028. utils.showLog("当前红包进度不满足条件且没有免费红包领取,首页不显示拆红包窗口");
  3029. this.rewardCloseFunc && this.rewardCloseFunc();
  3030. return null;
  3031. } else if (!this.yzRedBagInfo.isFreeRedBag) {
  3032. params.showType = 2;
  3033. }
  3034. }
  3035. if (this.config.otherconfig.openRedBagPanel) {
  3036. let node: cc.Node = cc.instantiate(this.config.otherconfig.openRedBagPanel);
  3037. if (node) {
  3038. if (this._openRedBagPanel && cc.isValid(this._openRedBagPanel)) {
  3039. this._openRedBagPanel.destroy();
  3040. }
  3041. this._openRedBagPanel = node;
  3042. if (params && params.showType) {
  3043. this._openRedBagPanel.getComponent(OpenRedBagPanel).initData(params.showType);
  3044. }
  3045. cc.director.getScene().addChild(node, 9999);
  3046. } else {
  3047. utils.showLog("warn:" + "未找到预制体 OpenRedBagPanel, 请查看CommonUtils组件上是否赋值!");
  3048. }
  3049. return null;
  3050. }
  3051. }
  3052. _rewardRedBagPanel: cc.Node = null;
  3053. _rewardRedBagPanelShowCount: number = 0;
  3054. /**
  3055. * 显示获得红包弹窗
  3056. * @param params
  3057. */
  3058. public showRewardRedBagPanel(params: any = null): cc.Node {
  3059. if (!this._isConfigInit) {
  3060. utils.showLog("warn:" + "组件配置未初始化!");
  3061. return null;
  3062. }
  3063. if (!this.canShowRedBag()) return null;
  3064. this._rewardRedBagPanelShowCount++;
  3065. // if (this.ServerConfig && this.ServerConfig.show_reward_red_bag_interval) {
  3066. if (this._rewardRedBagPanelShowCount % 3 != 0) {
  3067. utils.showLog("获得红包弹窗未达到服务器配置的间隔限制!");
  3068. return;
  3069. }
  3070. // }
  3071. if (this.config.otherconfig.rewardRedBagPanel) {
  3072. let node: cc.Node = cc.instantiate(this.config.otherconfig.rewardRedBagPanel);
  3073. if (node) {
  3074. if (this._rewardRedBagPanel && cc.isValid(this._rewardRedBagPanel)) {
  3075. this._rewardRedBagPanel.destroy();
  3076. }
  3077. this._rewardRedBagPanel = node;
  3078. cc.director.getScene().addChild(this._rewardRedBagPanel, 9999);
  3079. } else {
  3080. utils.showLog("warn:" + "未找到预制体 OpenRedBagPanel, 请查看CommonUtils组件上是否赋值!");
  3081. }
  3082. return null;
  3083. }
  3084. }
  3085. /**
  3086. * 是否竖屏互推窗口
  3087. */
  3088. public isVerticalRecommentPanel() {
  3089. if (!this._isConfigInit) {
  3090. utils.showLog("warn:" + "组件配置未初始化!");
  3091. return false;
  3092. }
  3093. if (this.Tool_Broswer) return true;
  3094. if (PlatUtils.IsWechat) {
  3095. if (utils.isSupportnavigateToMiniGame()) {
  3096. if (utils.wechatTool
  3097. && utils.wechatTool.ServerConfig
  3098. && utils.wechatTool.ServerConfig.is_vertical_game) {
  3099. if (utils.wechatTool.ServerConfig.is_vertical_game == "true") {
  3100. return true;
  3101. } else {
  3102. utils.showLog("warn:" + "is_vertical_game参数为false,更多游戏侧边栏组件不显示!");
  3103. }
  3104. } else {
  3105. utils.showLog("warn:" + "配置中没有is_vertical_game参数,更多游戏侧边栏组件不显示!");
  3106. }
  3107. } else {
  3108. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  3109. }
  3110. } else if (PlatUtils.IsOPPO) {
  3111. if (utils.isSupportnavigateToMiniGame()) {
  3112. if (utils.oppoTool
  3113. && utils.oppoTool.ServerConfig
  3114. && utils.oppoTool.ServerConfig.is_vertical_game) {
  3115. if (utils.oppoTool.ServerConfig.is_vertical_game == "true") {
  3116. return true;
  3117. } else {
  3118. utils.showLog("warn:" + "is_vertical_game参数为false,更多游戏侧边栏组件不显示!");
  3119. }
  3120. } else {
  3121. utils.showLog("warn:" + "配置中没有is_vertical_game参数,更多游戏侧边栏组件不显示!");
  3122. }
  3123. } else {
  3124. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  3125. }
  3126. } else if (PlatUtils.IsDouyin) {
  3127. if (PlatUtils.IsAndroid
  3128. && utils.isSupportnavigateToMiniGame()) {
  3129. if (utils.Tool_Douyin
  3130. && utils.Tool_Douyin.ServerConfig
  3131. && utils.Tool_Douyin.ServerConfig.is_vertical_game) {
  3132. if (utils.Tool_Douyin.ServerConfig.is_vertical_game == "true") {
  3133. return true;
  3134. } else {
  3135. utils.showLog("warn:" + "is_vertical_game参数为false,更多游戏侧边栏组件不显示!");
  3136. }
  3137. } else {
  3138. utils.showLog("warn:" + "配置中没有is_vertical_game参数,更多游戏侧边栏组件不显示!");
  3139. }
  3140. } else {
  3141. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  3142. }
  3143. } else if (PlatUtils.IsBaidu) {
  3144. if (utils.isSupportnavigateToMiniGame()) {
  3145. if (utils.Tool_Baidu
  3146. && utils.Tool_Baidu.ServerConfig
  3147. && utils.Tool_Baidu.ServerConfig.is_vertical_game) {
  3148. if (utils.Tool_Baidu.ServerConfig.is_vertical_game == "true") {
  3149. return true;
  3150. } else {
  3151. utils.showLog("warn:" + "is_vertical_game参数为false,更多游戏侧边栏组件不显示!");
  3152. }
  3153. } else {
  3154. utils.showLog("warn:" + "配置中没有is_vertical_game参数,更多游戏侧边栏组件不显示!");
  3155. }
  3156. } else {
  3157. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  3158. }
  3159. } else if (PlatUtils.IsQQ) {
  3160. if (utils.isSupportnavigateToMiniGame()) {
  3161. if (utils.Tool_QQ
  3162. && utils.Tool_QQ.ServerConfig
  3163. && utils.Tool_QQ.ServerConfig.is_vertical_game) {
  3164. if (utils.Tool_QQ.ServerConfig.is_vertical_game == "true") {
  3165. return true;
  3166. } else {
  3167. utils.showLog("warn:" + "is_vertical_game参数为false,更多游戏侧边栏组件不显示!");
  3168. }
  3169. } else {
  3170. utils.showLog("warn:" + "配置中没有is_vertical_game参数,更多游戏侧边栏组件不显示!");
  3171. }
  3172. } else {
  3173. utils.showLog("warn:" + "当前平台不支持游戏内跳转,更多游戏侧边栏组件不显示!");
  3174. }
  3175. } else if (PlatUtils.Is4399) {
  3176. return true;
  3177. } else if (PlatUtils.IsNativeAndroid) {
  3178. if (utils.Tool_Native
  3179. && utils.Tool_Native.ServerConfig
  3180. && utils.Tool_Native.ServerConfig.is_vertical_game) {
  3181. if (utils.Tool_Native.ServerConfig.is_vertical_game == "true") {
  3182. return true;
  3183. } else {
  3184. utils.showLog("warn:" + "is_vertical_game参数为false,更多游戏侧边栏组件不显示!");
  3185. }
  3186. } else {
  3187. utils.showLog("warn:" + "配置中没有is_vertical_game参数,更多游戏侧边栏组件不显示!");
  3188. }
  3189. } else if (PlatUtils.IsNativeIOS) {
  3190. if (utils.Tool_IOS
  3191. && utils.Tool_IOS.ServerConfig
  3192. && utils.Tool_IOS.ServerConfig.is_vertical_game) {
  3193. if (utils.Tool_IOS.ServerConfig.is_vertical_game == "true") {
  3194. return true;
  3195. } else {
  3196. utils.showLog("warn:" + "is_vertical_game参数为false,更多游戏侧边栏组件不显示!");
  3197. }
  3198. } else {
  3199. utils.showLog("warn:" + "配置中没有is_vertical_game参数,更多游戏侧边栏组件不显示!");
  3200. }
  3201. }
  3202. return false;
  3203. }
  3204. /**
  3205. * 显示红包进度挂件
  3206. * @param params
  3207. */
  3208. public showVerticalRecommentPanel(params: any = null): cc.Node {
  3209. if (!this._isConfigInit) {
  3210. utils.showLog("warn:" + "组件配置未初始化!");
  3211. return null;
  3212. }
  3213. if (!this.isVerticalRecommentPanel()) return null;
  3214. if (this.config.otherconfig.verticalRecommentPanel) {
  3215. let node: cc.Node = cc.instantiate(this.config.otherconfig.verticalRecommentPanel);
  3216. if (node) {
  3217. // if (this._redBagProgressWidget && cc.isValid(this._redBagProgressWidget)) {
  3218. // this._redBagProgressWidget.destroy();
  3219. // }
  3220. node.zIndex = 9999;
  3221. let widget: cc.Widget = node.getComponent(cc.Widget);
  3222. if (params) {
  3223. if (params.group) {
  3224. node.group = params.group;
  3225. }
  3226. if (params.scale != null) {
  3227. node.scale = params.scale;
  3228. }
  3229. if (params.top != null) {
  3230. widget.isAlignTop = true;
  3231. widget.isAlignBottom = false;
  3232. widget.top = params.top;
  3233. } else if (params.bottom != null) {
  3234. widget.isAlignTop = false;
  3235. widget.isAlignBottom = true;
  3236. widget.bottom = params.bottom;
  3237. }
  3238. if (params.left != null) {
  3239. widget.isAlignLeft = true;
  3240. widget.isAlignRight = false;
  3241. widget.left = params.left;
  3242. } else if (params.right != null) {
  3243. widget.isAlignLeft = false;
  3244. widget.isAlignRight = true;
  3245. widget.right = params.right;
  3246. }
  3247. if (params.parent != null) {
  3248. node.parent = params.parent;
  3249. }
  3250. if (params.position != null) {
  3251. node.setPosition(CompatibleTool.position(params.position.x, params.position.y))
  3252. }
  3253. }
  3254. widget.updateAlignment();
  3255. return node;
  3256. }
  3257. } else {
  3258. utils.showLog("warn:" + "未找到预制体 verticalRecommentPanel, 请查看CommonUtils组件上是否赋值!");
  3259. }
  3260. return null;
  3261. }
  3262. /**
  3263. * 是否显示用户协议挂件
  3264. */
  3265. public isShowPrivacyWidget(): boolean {
  3266. if (this.Tool_Broswer) return true;
  3267. if (this.getConfigByKey("is_privacy") == "true") {
  3268. return true;
  3269. } else {
  3270. utils.showLog("warn:" + "配置中没有is_privacy参数,更用户协议挂件组件不显示!");
  3271. }
  3272. return false;
  3273. }
  3274. _privacyWidget: cc.Node = null;
  3275. /**
  3276. * 显示用户协议挂件
  3277. * @param params
  3278. */
  3279. public showPrivacyWidget(params: any = null): cc.Node {
  3280. if (utils.isShowPrivacyWidget()) {
  3281. if (this.config.otherconfig.privacyWidget) {
  3282. if (this._privacyWidget && cc.isValid(this._privacyWidget)) {
  3283. this._privacyWidget.destroy();
  3284. }
  3285. let node: cc.Node = cc.instantiate(this.config.otherconfig.privacyWidget);
  3286. this._privacyWidget = node;
  3287. this._privacyWidget.zIndex = 9999;
  3288. let widget: cc.Widget = node.getComponent(cc.Widget);
  3289. if (params) {
  3290. if (params.color) {
  3291. node.children[0].color = params.color;
  3292. }
  3293. if (params.group) {
  3294. node.group = params.group;
  3295. }
  3296. if (params.scale != null) {
  3297. node.scale = params.scale;
  3298. }
  3299. if (params.top != null) {
  3300. widget.isAlignTop = true;
  3301. widget.isAlignBottom = false;
  3302. widget.top = params.top;
  3303. } else if (params.bottom != null) {
  3304. widget.isAlignTop = false;
  3305. widget.isAlignBottom = true;
  3306. widget.bottom = params.bottom;
  3307. }
  3308. if (params.left != null) {
  3309. widget.isAlignLeft = true;
  3310. widget.isAlignRight = false;
  3311. widget.left = params.left;
  3312. } else if (params.right != null) {
  3313. widget.isAlignLeft = false;
  3314. widget.isAlignRight = true;
  3315. widget.right = params.right;
  3316. }
  3317. if (params.parent != null) {
  3318. node.parent = params.parent;
  3319. }
  3320. }
  3321. widget.updateAlignment();
  3322. node.on(cc.Node.EventType.TOUCH_END, () => {
  3323. if (PlatUtils.IsNativeAndroid) {
  3324. utils.Tool_Native && utils.Tool_Native.showPrivacyAgreement();
  3325. } else {
  3326. utils.showPrivacyPanel({ is_widget_click: "true", group: node.group });
  3327. }
  3328. }, this);
  3329. return node;
  3330. } else {
  3331. utils.showLog("warn:" + "隐私政策挂件预制体不存在!")
  3332. }
  3333. } else {
  3334. utils.showLog("warn:" + "不可显示更多游戏侧边栏")
  3335. }
  3336. return null;
  3337. }
  3338. /**
  3339. * 隐藏隐私政策
  3340. */
  3341. public hidePrivacyWidget() {
  3342. if (this._privacyWidget && cc.isValid(this._privacyWidget)) {
  3343. this._privacyWidget.destroy();
  3344. }
  3345. }
  3346. /**
  3347. * 是否显示用户隐私协议弹窗
  3348. */
  3349. public isShowPrivacyPanel(): boolean {
  3350. if (PlatUtils.IsHuaWei || PlatUtils.IsXiaoMi) {
  3351. return true;
  3352. }
  3353. if (this.getConfigByKey("is_privacy_panel")) {
  3354. if (this.getConfigByKey("is_privacy_panel") == "true") {
  3355. return true;
  3356. } else {
  3357. utils.showLog("warn:" + "is_privacy_panel参数为false,用户隐私政策弹窗组件不显示!");
  3358. }
  3359. }
  3360. return false;
  3361. }
  3362. _privacyPanel: cc.Node = null;
  3363. /**
  3364. * 显示用户协议弹窗
  3365. * @param params
  3366. */
  3367. public showPrivacyPanel(params: any = null) {
  3368. utils.showLog("showPrivacyPanel>>>");
  3369. let showPanel: Function = (showDesc: false) => {
  3370. if (this.config.otherconfig.privacyPanel) {
  3371. if (this._privacyPanel && cc.isValid(this._privacyPanel)) {
  3372. this._privacyPanel.destroy();
  3373. }
  3374. let node: cc.Node = cc.instantiate(this.config.otherconfig.privacyPanel);
  3375. let yzUserPrivacyPanel = node.getComponent(YzUserPrivacyPanel);
  3376. yzUserPrivacyPanel.showDesc = showDesc;
  3377. this._privacyPanel = node;
  3378. this._privacyPanel.zIndex = 9999;
  3379. let widget: cc.Widget = node.getComponent(cc.Widget);
  3380. let subject = "深圳市优智信息技术有限公司";
  3381. if (params && params.subject) {
  3382. subject = params.subject;
  3383. }
  3384. let content: string = cc.find("Panel/subject", node).getComponent(cc.Label).string;
  3385. content = content.replace('subject', subject);
  3386. cc.find("Panel/subject", node).getComponent(cc.Label).string = content;
  3387. if (params) {
  3388. if (params.group) {
  3389. node.group = params.group;
  3390. }
  3391. if (params.scale != null) {
  3392. node.scale = params.scale;
  3393. }
  3394. if (params.top != null) {
  3395. widget.isAlignTop = true;
  3396. widget.isAlignBottom = false;
  3397. widget.top = params.top;
  3398. } else if (params.bottom != null) {
  3399. widget.isAlignTop = false;
  3400. widget.isAlignBottom = true;
  3401. widget.bottom = params.bottom;
  3402. }
  3403. if (params.left != null) {
  3404. widget.isAlignLeft = true;
  3405. widget.isAlignRight = false;
  3406. widget.left = params.left;
  3407. } else if (params.right != null) {
  3408. widget.isAlignLeft = false;
  3409. widget.isAlignRight = true;
  3410. widget.right = params.right;
  3411. }
  3412. if (params.parent != null) {
  3413. node.parent = params.parent;
  3414. } else {
  3415. cc.find("Canvas").addChild(node, cc.macro.MAX_ZINDEX);
  3416. }
  3417. } else {
  3418. cc.find("Canvas").addChild(node, cc.macro.MAX_ZINDEX);
  3419. }
  3420. widget.updateAlignment();
  3421. } else {
  3422. utils.showLog("warn:" + "隐私政策弹窗预制体不存在!")
  3423. }
  3424. }
  3425. if (params && params.is_widget_click) {
  3426. showPanel(true);
  3427. } else {
  3428. let ysxy = YZ_LocalStorage.getItem(YZ_Constant.YZ_GAME_YSXY);
  3429. if (ysxy) {
  3430. utils.emitPrivacyCloseEvent();
  3431. utils.showLog("已经同意过隐私协议,不显示隐私协议弹窗!");
  3432. return;
  3433. }
  3434. utils.registerServerDataLoadSuccessEvent(() => {
  3435. showPanel();
  3436. }, this);
  3437. }
  3438. }
  3439. minScale: number = 1;
  3440. maxScale: number = 1.3;
  3441. runTime: number = 0.3;
  3442. /**
  3443. * 显示放大缩小动态
  3444. * @param videoBtn 视频播放按钮
  3445. * @param normalBtn 普通按钮
  3446. * @param changeBtn 是否变换按钮位置
  3447. * @param showHand 是否显示手势
  3448. * @param location 按钮所属的页面位置
  3449. * @returns
  3450. */
  3451. showScaleAction(videoBtn: cc.Node, normalBtn: cc.Node = null, changeBtn: boolean = true, showHand: boolean = true, location: BannerLocation = BannerLocation.None) {
  3452. if (changeBtn) {
  3453. if (!cc.isValid(normalBtn) || !cc.isValid(videoBtn)) return;
  3454. } else {
  3455. if (!cc.isValid(videoBtn)) return;
  3456. }
  3457. if (CC_DEBUG) {
  3458. this.ServerConfig.btn_show_scale = "true";
  3459. this.ServerConfig.change_btn_position = "true"
  3460. this.ServerConfig.over_page_change_btn = "false"
  3461. this.ServerConfig.over_page_scale_btn = "false"
  3462. }
  3463. let scaleNode: cc.Node = videoBtn;
  3464. if (this.getConfigByKey("change_btn_position") == "true" && changeBtn == true) {
  3465. let changePosition: boolean = true;
  3466. if (location == BannerLocation.Over) {
  3467. if (this.getConfigByKey("over_page_change_btn") == "false") {
  3468. changePosition = false;
  3469. utils.showLog("结算页面按钮配置不切换位置!");
  3470. }
  3471. }
  3472. if (changePosition) {
  3473. let rand = Math.floor(Math.random() * 2 + 1);
  3474. let videoPos = videoBtn.position;
  3475. let normalPos = normalBtn.position;
  3476. if (rand % 2 == 0) {
  3477. normalBtn.position = videoPos;
  3478. videoBtn.position = normalPos;
  3479. } else {
  3480. scaleNode = videoBtn;
  3481. normalBtn.position = normalPos;
  3482. videoBtn.position = videoPos;
  3483. }
  3484. scaleNode = normalBtn.position.y > videoBtn.position.y ? normalBtn : videoBtn;
  3485. }
  3486. }
  3487. if (this.getConfigByKey("btn_show_scale") == "true") {
  3488. if (location == BannerLocation.Over &&
  3489. this.getConfigByKey("over_page_scale_btn") == "false") {
  3490. utils.showLog("结算页面按钮配置不缩放按钮!");
  3491. return;
  3492. }
  3493. if (videoBtn) {
  3494. videoBtn.stopAllActions();
  3495. videoBtn.scale = 1;
  3496. }
  3497. if (normalBtn) {
  3498. normalBtn.stopAllActions();
  3499. normalBtn.scale = 1;
  3500. }
  3501. let action = cc.sequence(
  3502. cc.scaleTo(this.runTime, this.maxScale),
  3503. cc.scaleTo(this.runTime, this.minScale));
  3504. scaleNode.runAction(action.repeatForever());
  3505. if (showHand) {
  3506. if (videoBtn) {
  3507. let child = videoBtn.parent.getChildByName("hand")
  3508. if (child) {
  3509. child.destroy();
  3510. child.removeFromParent();
  3511. }
  3512. }
  3513. if (normalBtn) {
  3514. let child = normalBtn.parent.getChildByName("hand")
  3515. if (child) {
  3516. child.destroy();
  3517. child.removeFromParent();
  3518. }
  3519. }
  3520. if (this.config.otherconfig.handPrefab) {
  3521. let hand = cc.instantiate(this.config.otherconfig.handPrefab);
  3522. hand.x = scaleNode.x + scaleNode.width / 2;
  3523. hand.y = scaleNode.y - 135;
  3524. scaleNode.parent.addChild(hand, cc.macro.MAX_ZINDEX + 1, "hand");
  3525. }
  3526. }
  3527. }
  3528. }
  3529. //原生广告最后上报时间
  3530. _lastReportAdTime: number = 0;
  3531. /**
  3532. * 上报原生广告点击
  3533. */
  3534. reportNativeAdClick() {
  3535. if ((new Date().getTime() - this._lastReportAdTime) / 1000 > 3) {
  3536. this._lastReportAdTime = new Date().getTime();
  3537. cc.game.emit(YZ_Constant.YZ_NativeAdClick);
  3538. this.showLog("上报原生广告点击!");
  3539. } else {
  3540. this.showLog("上报原生广告点击间隔时间小于3秒!");
  3541. }
  3542. }
  3543. /**
  3544. * 是否显示结算页面广告点击按钮
  3545. */
  3546. canShowOverPageAdBtn(): boolean {
  3547. if (this.ServerConfig && this.ServerConfig.show_over_page_ad_btn && this.ServerConfig.show_over_page_ad_btn == "true") {
  3548. return true;
  3549. }
  3550. return false;
  3551. }
  3552. /**
  3553. * 显示小游戏官方互推banner
  3554. */
  3555. showRecBanner() {
  3556. if (!utils.adManager.checkShowAdTime()) {
  3557. utils.showLog("显示广告条时间未达限制!");
  3558. return;
  3559. }
  3560. this.cur_tool && this.cur_tool.showRecBanner && this.cur_tool.showRecBanner();
  3561. }
  3562. /**
  3563. * 显示小游戏官方互推九宫格
  3564. */
  3565. showGamePortal() {
  3566. if (!utils.adManager.checkShowAdTime()) {
  3567. utils.showLog("显示广告条时间未达限制!");
  3568. return;
  3569. }
  3570. this.cur_tool && this.cur_tool.showGamePortal && this.cur_tool.showGamePortal();
  3571. }
  3572. /**
  3573. * 显示VIVO九宫格挂件
  3574. * @param params
  3575. * ```
  3576. * {
  3577. * top:number // 距离屏幕顶部的距离
  3578. * }
  3579. * ```
  3580. */
  3581. _curVivoGamePortalLocation: String = "";
  3582. public showVivoGamePortalWidget(params: any = null): void {
  3583. if (!this._isConfigInit) {
  3584. utils.showLog("warn:" + "组件配置未初始化!");
  3585. return;
  3586. }
  3587. if (!PlatUtils.IsVIVO) return;
  3588. if (!utils.adManager.checkShowAdTime()) {
  3589. utils.showLog("显示广告条时间未达限制!");
  3590. return;
  3591. }
  3592. if (this.getConfigByKey("vivo_game_protal") === "true") {
  3593. if (params && params.location && (this.getConfigByKey("vivo_game_protal_locations").indexOf(params.location) < 0)) {
  3594. utils.showLog("当前位置服务器未配置显示VIVO九宫格挂件!");
  3595. this.Tool_Vivo && this.Tool_Vivo.hideGamePortal();
  3596. return;
  3597. }
  3598. this.Tool_Vivo && this.Tool_Vivo.showGamePortal(params.top);
  3599. } else {
  3600. utils.showLog("服务器未配置显示VIVO九宫格挂件!");
  3601. }
  3602. }
  3603. /**
  3604. * 隐藏VIVO九宫格挂件
  3605. * @param params
  3606. */
  3607. public hideVivoGamePortalWidget(): void {
  3608. this.Tool_Vivo && this.Tool_Vivo.hideGamePortal();
  3609. }
  3610. _curGameDrawerAdLocation: string = "";
  3611. /*
  3612. **
  3613. * 显示OPPO互推抽屉盒子广告:
  3614. * 只能显示在左侧,设置top值
  3615. * @param params
  3616. * ```
  3617. * {
  3618. * top:number // 距离屏幕顶部的距离
  3619. * }
  3620. * ```
  3621. */
  3622. public showOppoGameDrawerAdWidget(params: any = null): void {
  3623. if (!this._isConfigInit) {
  3624. utils.showLog("warn:" + "组件配置未初始化!");
  3625. return;
  3626. }
  3627. if (!PlatUtils.IsOPPO) return;
  3628. if (!utils.adManager.checkShowAdTime()) {
  3629. utils.showLog("显示广告条时间未达限制!");
  3630. return;
  3631. }
  3632. if (CC_DEBUG) {
  3633. this.ServerConfig.oppo_game_drawer = "true";
  3634. this.ServerConfig.oppo_game_drawer_locations = "1, 2, 3, 4,5,6"
  3635. }
  3636. if (this.getConfigByKey("oppo_game_drawer") === "true") {
  3637. if (params && params.location && (this.getConfigByKey("oppo_game_drawer_locations").indexOf(params.location) < 0)) {
  3638. utils.showLog("当前位置服务器未配置显示OPPO互推抽屉盒子!");
  3639. this.oppoTool && this.oppoTool.hideGameDrawerAd();
  3640. return;
  3641. }
  3642. // if (params && params.location && this._curGameDrawerAdLocation && this._curGameDrawerAdLocation != params.location) {
  3643. // this.oppoTool && this.oppoTool.hideGameDrawerAd();
  3644. // }
  3645. this.oppoTool && this.oppoTool.showGameDrawerAd(params);
  3646. } else {
  3647. utils.showLog("服务器未配置显示OPPO互推抽屉盒子!");
  3648. }
  3649. }
  3650. /**
  3651. * 隐藏OPPO互推抽屉盒子广告
  3652. * @param params
  3653. */
  3654. public hideOppoGameDrawerAdWidget(): void {
  3655. this.oppoTool && this.oppoTool.hideGameDrawerAd();
  3656. }
  3657. /*
  3658. **
  3659. * 显示OPPO互推横幅广告:
  3660. * @param params
  3661. * ```
  3662. * {
  3663. * top:number // 距离屏幕顶部的距离
  3664. * }
  3665. * ```
  3666. */
  3667. public showOppoRecBanner(params: any = null): void {
  3668. if (!this._isConfigInit) {
  3669. utils.showLog("warn:" + "组件配置未初始化!");
  3670. return;
  3671. }
  3672. if (!PlatUtils.IsOPPO) return;
  3673. if (!utils.adManager.checkShowAdTime()) {
  3674. utils.showLog("显示广告条时间未达限制!");
  3675. return;
  3676. }
  3677. if (CC_DEBUG) {
  3678. this.ServerConfig.oppo_rec_banner = "true";
  3679. this.ServerConfig.oppo_rec_banner_locations = "1, 2, 3, 4"
  3680. }
  3681. if (this.getConfigByKey("oppo_rec_banner") === "true") {
  3682. if (params && params.location && (this.getConfigByKey("oppo_rec_banner_locations").indexOf(params.location) < 0)) {
  3683. utils.showLog("当前位置服务器未配置显示OPPO互推Banner!");
  3684. this.oppoTool && this.oppoTool.hideOppoRecBanner();
  3685. return;
  3686. }
  3687. this.oppoTool && this.oppoTool.showOppoNewRecBanner(params);
  3688. } else {
  3689. utils.showLog("服务器未配置显示OPPO互推Banner!");
  3690. }
  3691. }
  3692. /**
  3693. * 隐藏OPPO互推横幅广告
  3694. * @param params
  3695. */
  3696. public hideOppoRecBanner(): void {
  3697. this.oppoTool && this.oppoTool.hideOppoRecBanner();
  3698. }
  3699. /**
  3700. * 实名认证
  3701. */
  3702. public realNameAuth(code: string, name: string, callBack: Function) {
  3703. utils.showLog(`进行实名制认证:#code=${code} #name=${name}`);
  3704. utils.cur_tool && utils.cur_tool.realNameAuth && utils.cur_tool.realNameAuth(code, name, callBack);
  3705. }
  3706. /**
  3707. * 退出游戏
  3708. */
  3709. public GameExit() {
  3710. this.cur_tool && this.cur_tool.GameExit && this.cur_tool.GameExit();
  3711. }
  3712. _isRealNameAuth: boolean = false;
  3713. _yzRealNameAuthPanel: cc.Node = null;
  3714. /**
  3715. * 显示实名制认证弹窗
  3716. * @param params
  3717. */
  3718. public showYzRealNameAuthPanel(params: any = null): cc.Node {
  3719. utils.showLog("显示实名制认证弹窗!")
  3720. if (!this._isConfigInit) {
  3721. utils.showLog("warn:" + "组件配置未初始化!");
  3722. return;
  3723. }
  3724. if (this.getRealNameAuthLocalData() && this.getRealNameAuthLocalData() == "1") {
  3725. this._isRealNameAuth = true;
  3726. }
  3727. if (this._isRealNameAuth) {
  3728. utils.showLog("已经进行过实名制认证,不显示弹窗!");
  3729. this.emitRealNameAuthCloseEvent();
  3730. return;
  3731. }
  3732. let showTime: number = -1;
  3733. if (PlatUtils.IsNativeAndroid || PlatUtils.IsNativeIOS) {
  3734. showTime = 0;
  3735. }
  3736. if (this.getConfigByKey("show_real_name_auth")) {
  3737. showTime = parseInt(this.getConfigByKey("show_real_name_auth"));
  3738. }
  3739. if (showTime == -1) {
  3740. utils.showLog("服务器控制不显示实名制弹窗!");
  3741. this.emitRealNameAuthCloseEvent();
  3742. return
  3743. }
  3744. if (PlatUtils.IsNativeAndroid) {
  3745. this.scheduleOnce(() => {
  3746. utils.Tool_Native.showRealNameAuthPanel(showTime + "");
  3747. }, showTime);
  3748. return;
  3749. }
  3750. if (this.config.otherconfig.yzRealNameAuthPanel) {
  3751. if (this._yzRealNameAuthPanel && cc.isValid(this._yzRealNameAuthPanel)) {
  3752. this._yzRealNameAuthPanel.destroy();
  3753. }
  3754. let node: cc.Node = cc.instantiate(this.config.otherconfig.yzRealNameAuthPanel);
  3755. if (showTime == -2) {
  3756. //达到防沉迷要求,直接提示下线
  3757. node.getComponent(YzRealNameAuthPanel)._isOffLine = true;
  3758. showTime = 0;
  3759. }
  3760. this._yzRealNameAuthPanel = node;
  3761. this._yzRealNameAuthPanel.zIndex = 9999;
  3762. if (params) {
  3763. if (params.group) {
  3764. node.group = params.group;
  3765. }
  3766. if (params.scale != null) {
  3767. node.scale = params.scale;
  3768. }
  3769. this.scheduleOnce(() => {
  3770. if (params.parent != null) {
  3771. node.parent = params.parent;
  3772. } else {
  3773. cc.find("Canvas").addChild(node);
  3774. }
  3775. }, showTime * 1000);
  3776. } else {
  3777. this.scheduleOnce(() => {
  3778. cc.find("Canvas").addChild(node);
  3779. }, showTime * 1000);
  3780. }
  3781. return node;
  3782. }
  3783. utils.showLog("warn:" + "实名制认证弹窗预制体不存在!")
  3784. return null;
  3785. }
  3786. setRealNameAuthLocalData(value) {
  3787. YZ_LocalStorage.setItem('yz_game_real_name', `${value}`);
  3788. }
  3789. getRealNameAuthLocalData() {
  3790. let realName = YZ_LocalStorage.getItem('yz_game_real_name');
  3791. if (!realName) {
  3792. realName = 0;
  3793. }
  3794. return realName;
  3795. }
  3796. /**
  3797. * 通过字段名称获取服务器对应的配置
  3798. * @param key 字段名称
  3799. * @returns 服务器有配置则返回该配置,无则返回空字符串
  3800. */
  3801. public getConfigByKey(key: string): any {
  3802. if (!this._isConfigInit) {
  3803. utils.showLog("warn:" + "本地数据未初始化!");
  3804. return "";
  3805. }
  3806. if (key && this.ServerConfig && key in this.ServerConfig) {
  3807. return this.ServerConfig[key];
  3808. }
  3809. this.showLog(`warn:字段:${key} 未配置!`);
  3810. return "";
  3811. }
  3812. /**
  3813. * 登录
  3814. * @param successCallFunc 成功回调
  3815. * @param failCallFunc 失败回调
  3816. */
  3817. public login(successCallFunc?: Function, failCallFunc?: Function) {
  3818. this.showLog("=====login====");
  3819. if (successCallFunc) {
  3820. if (PlatUtils.IsDouyin) {
  3821. // if (YZ_LocalStorage.getItem("yz_login", "false") == "true") {
  3822. // successCallFunc && successCallFunc();
  3823. // return;
  3824. // }
  3825. }
  3826. cc.game.targetOff(YZ_Constant.ST_LOGIN_SUCCESS);
  3827. cc.game.on(YZ_Constant.ST_LOGIN_SUCCESS, successCallFunc, this);
  3828. }
  3829. if (failCallFunc) {
  3830. let newFailFunc = () => {
  3831. failCallFunc();
  3832. this.showLoginPanel();
  3833. }
  3834. cc.game.targetOff(YZ_Constant.ST_LOGIN_FAIL);
  3835. cc.game.on(YZ_Constant.ST_LOGIN_FAIL, newFailFunc, this);
  3836. } else {
  3837. let newFailFunc = () => {
  3838. this.showLoginPanel();
  3839. }
  3840. cc.game.targetOff(YZ_Constant.ST_LOGIN_FAIL);
  3841. cc.game.on(YZ_Constant.ST_LOGIN_FAIL, newFailFunc, this);
  3842. }
  3843. if (this.cur_tool && this.cur_tool.login) {
  3844. this.cur_tool.login();
  3845. } else {
  3846. cc.game.targetOff(YZ_Constant.ST_LOGIN_SUCCESS);
  3847. cc.game.targetOff(YZ_Constant.ST_LOGIN_FAIL);
  3848. successCallFunc && successCallFunc();
  3849. }
  3850. }
  3851. _yzLoginPanel: cc.Node = null;
  3852. /**
  3853. * 显示登录弹窗
  3854. */
  3855. public showLoginPanel() {
  3856. if (this.config.otherconfig.yzLoginPanel) {
  3857. let node: cc.Node = cc.instantiate(this.config.otherconfig.yzLoginPanel);
  3858. if (node) {
  3859. if (this._yzLoginPanel && cc.isValid(this._yzLoginPanel)) {
  3860. this._yzLoginPanel.destroy();
  3861. }
  3862. this._yzLoginPanel = node;
  3863. cc.find("Canvas").addChild(node, cc.macro.MAX_ZINDEX);
  3864. return node;
  3865. }
  3866. } else {
  3867. utils.showLog("warn:" + "未找到预制体 YzLoginPanel, 请查看CommonUtils组件上是否赋值!");
  3868. }
  3869. }
  3870. /**
  3871. * 生成UUID
  3872. * @returns uuid
  3873. */
  3874. public generateUUID() {
  3875. var d = new Date().getTime();
  3876. if (window.performance && typeof window.performance.now === "function") {
  3877. d += performance.now(); //use high-precision timer if available
  3878. }
  3879. var uuid = 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  3880. var r = (d + Math.random() * 16) % 16 | 0;
  3881. d = Math.floor(d / 16);
  3882. return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
  3883. });
  3884. return uuid;
  3885. }
  3886. }