gameManager.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. import { _decorator, AudioClip, AudioSource, Component, Node, Size, Sprite, SpriteFrame, sys, UITransform, Vec3 } from 'cc';
  2. import { game_run } from './game_run';
  3. import { attributes_data, event_item, LevelItemData, other_widget_finish_listen_item, scene_item_data, sysMessage, task_data, ui_att_item, UserData, UserUnlockLevesData, widget_item_data } from '../../data/data';
  4. import { config } from '../config';
  5. import { sceneManager } from './sceneManager';
  6. import { http } from '../http';
  7. import { tools } from '../tools';
  8. import { taskServce } from './TaskSchedule/taskServce';
  9. import { ClientEvent } from '../clientEvent';
  10. import { sysSound } from './sysSound';
  11. import { SdkUtil } from '../sdkUtil';
  12. import { statisticsManager } from '../statisticsManager';
  13. import { fail } from './ui/fail';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('gameManager')
  16. export class gameManager extends Component {
  17. private mGameRun:game_run = null;
  18. private mGameData:scene_item_data[] = [];
  19. private mCurSceneIndex:number =0; //当前第几个场景
  20. public static Singleton:gameManager = null;
  21. private static g_userData:UserData;
  22. private static g_userUnlockLevesData:UserUnlockLevesData;
  23. public static res_map:Map<string,SpriteFrame> = new Map()
  24. public static mp3_cache:Map<string,AudioClip> = new Map()
  25. private mLevelData:LevelItemData = null;
  26. private static sys_data:sysMessage = null;
  27. private static isLoadingStatus:boolean = false;
  28. public static lookVideoAdsNumber:number = 0;
  29. public static isTestUser:boolean = false;
  30. public static isPlayGameLevelMusic:boolean = false;
  31. @property(sceneManager) mSceneManager:sceneManager = null;
  32. @property(sysSound) mSysSound:sysSound = null;
  33. protected start(): void {
  34. gameManager.Singleton = this;
  35. }
  36. public static isFreeAds():boolean {
  37. if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME||sys.platform==sys.Platform.WECHAT_GAME) {
  38. if(gameManager.isTestUser==false) {
  39. return false
  40. }
  41. }
  42. return true
  43. }
  44. public static is24Free():boolean{
  45. if(gameManager.getStaticUserData().freeTime==undefined){
  46. gameManager.getStaticUserData().freeTime = 0;
  47. gameManager.saveUserData()
  48. }
  49. if(gameManager.getStaticUserData().freeTime!=0){
  50. let cur_time = new Date()
  51. let old_time = new Date(gameManager.getStaticUserData().freeTime)
  52. let timeDiff = cur_time.getTime() - old_time.getTime();
  53. // console.log("old",tools.getLocalTime(old))
  54. // console.log("cur",tools.getLocalTime(cur))
  55. var seconds = Math.floor(timeDiff / 1000);
  56. var minutes = Math.floor(seconds / 60);
  57. // var hours = Math.floor(minutes / 60);
  58. console.log("相隔几分钟",minutes)
  59. if(minutes>=1440){
  60. gameManager.getStaticUserData().freeTime = 0;
  61. gameManager.saveUserData()
  62. return false;
  63. }else{
  64. return true;
  65. }
  66. }
  67. return false;
  68. }
  69. public static setUser24Free(){
  70. gameManager.g_userData.freeTime = new Date().getTime()
  71. gameManager.saveUserData()
  72. }
  73. public static loadSceneRes(level_id:number,scene_num:number,cb){
  74. if(scene_num<1){
  75. return
  76. }
  77. gameManager.isLoadingStatus = true;
  78. let scene_count = 0;
  79. let start_loading_all_res =()=>{
  80. let count = 0;
  81. let num = 0;
  82. let load_call = ()=>{
  83. count++;
  84. // console.log("count",count,num,scene_count,scene_num)
  85. if(scene_count==scene_num){
  86. if(count>=num){
  87. gameManager.isLoadingStatus = false;
  88. console.log("完成全部加载!")
  89. }
  90. }
  91. }
  92. if(scene_num<=2){
  93. gameManager.isLoadingStatus = false;
  94. console.log("完成全部加载!")
  95. return
  96. }
  97. for (let i = 2; i <= scene_num; i++) {
  98. let url = http.get_level_resource(level_id,i)
  99. http.run_get_static(url,(err,data)=>{
  100. if(!err){
  101. let _data = JSON.parse(data)
  102. scene_count++;
  103. num += _data.content.length;
  104. if(scene_count==scene_num){
  105. if(num==0){
  106. gameManager.isLoadingStatus = false;
  107. console.log("完成全部加载!")
  108. return
  109. }else{
  110. if(count>=num){
  111. gameManager.isLoadingStatus = false;
  112. console.log("完成全部加载!")
  113. return
  114. }
  115. }
  116. }
  117. // console.log("run_get:",scene_count,_data.content.length,i)
  118. for (let index = 0; index < _data.content.length; index++) {
  119. const url:string = _data.content[index];
  120. load_res(url,load_call)
  121. }
  122. }else{
  123. tools.showToast(`获取关卡错误${err}`)
  124. }
  125. })
  126. }
  127. }
  128. // console.log("scene_num",scene_num)
  129. let load_res = (url:string,call)=>{
  130. let hz = url.substring(url.length-3,url.length);
  131. if(hz==="png"||hz==="jpg"){
  132. tools.loadSceneImg(url,(d)=>{
  133. first_load_res.delete(url)
  134. gameManager.res_map.set(d.url,d.sf)
  135. call()
  136. })
  137. }
  138. if(hz==="mp3"){
  139. tools.loadSceneMp3(url,(d)=>{
  140. first_load_res.delete(url)
  141. gameManager.mp3_cache.set(d.url,d.clip)
  142. call()
  143. })
  144. }
  145. }
  146. let first_finish_call = ()=>{
  147. first_load_res.forEach((v,k)=>{
  148. const url:string =k;
  149. load_res(url,()=>{
  150. if(first_load_res.size<=0){
  151. cb()
  152. start_loading_all_res()
  153. }
  154. })
  155. })
  156. }
  157. let first_count = 0;
  158. let first_load_res:Map<string,boolean> = new Map;
  159. for (let i = 0; i < 2; i++) {
  160. let url = http.get_level_resource(level_id,i)
  161. http.run_get_static(url,(err,data)=>{
  162. if(!err){
  163. let _data = JSON.parse(data)
  164. first_count++;
  165. for (let index = 0; index < _data.content.length; index++) {
  166. const url:string = _data.content[index];
  167. first_load_res.set(url,false)
  168. }
  169. if(first_count==2){
  170. scene_count=1;
  171. first_finish_call()
  172. }
  173. }
  174. })
  175. }
  176. }
  177. public setLevelData(data:LevelItemData){
  178. this.mLevelData = data;
  179. }
  180. public getLevelData(){
  181. return this.mLevelData;
  182. }
  183. public static setSysData(data:sysMessage){
  184. gameManager.sys_data = data;
  185. }
  186. public static getSysData(){
  187. return gameManager.sys_data;
  188. }
  189. public getSceneCurIndex():number {
  190. return this.mCurSceneIndex
  191. }
  192. public getSceneCurTotalCount():number {
  193. return this.mGameData.length
  194. }
  195. public static loadSceneMp3(){
  196. }
  197. public static getUserData():UserData{
  198. let str = sys.localStorage.getItem(config.USER_DATA)
  199. if(str==undefined||str==""||str==null){
  200. return null;
  201. }
  202. let user:UserData = JSON.parse(str)
  203. return user;
  204. }
  205. public static getStaticUserData(){
  206. return gameManager.g_userData
  207. }
  208. public static setUserData(user:UserData){
  209. gameManager.g_userData = user;
  210. gameManager.saveUserData()
  211. }
  212. public static saveUserData(){
  213. if(gameManager.g_userData!=null){
  214. sys.localStorage.setItem(config.USER_DATA, JSON.stringify(gameManager.g_userData));
  215. }
  216. }
  217. public static getZbOpenid(): string {
  218. let zb_openid = '';
  219. try {
  220. zb_openid = sys.localStorage.getItem(config.ZB_OPENID)
  221. } catch {
  222. console.log("getZbOpenid fail")
  223. }
  224. return zb_openid
  225. }
  226. public static setZbOpenid(id: String) {
  227. sys.localStorage.setItem(config.ZB_OPENID, id)
  228. }
  229. public reLife(){
  230. let ad_id = SdkUtil.getAdId(config.AD_TYPE.RE_LIFE)
  231. SdkUtil.showVideoAd(ad_id,(res)=>{
  232. if(res.isEnded){
  233. this.mGameRun.onlaunch(()=>{
  234. gameManager.Singleton.startLevelGame()
  235. })
  236. }
  237. // 统计-激励视频广告
  238. let level_id = gameManager.Singleton.getLevelData().id
  239. let collect_data = statisticsManager.get_collect_ads_data(level_id, res, config.STATISTICS_ACTION_TYPE.GUAN_KA_FU_HUO)
  240. statisticsManager.request_collect_rewardVideoData(collect_data)
  241. })
  242. }
  243. public reStartGame(){
  244. this.mGameRun.onlaunch(()=>{
  245. this.mCurSceneIndex = 0;
  246. gameManager.Singleton.startLevelGame()
  247. })
  248. }
  249. public levleIsUnLock(levle_id:number){
  250. let isunlock = false;
  251. for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
  252. const id = gameManager.getStaticUserData().unlock_levels[index];
  253. if(id==levle_id){
  254. isunlock = true;
  255. break;
  256. }
  257. }
  258. return isunlock
  259. }
  260. public unLockLevel(levle_id:number){
  261. let is_have = false;
  262. for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
  263. const id = gameManager.getStaticUserData().unlock_levels[index];
  264. if(id==levle_id){
  265. is_have = true;
  266. break;
  267. }
  268. }
  269. if(!is_have){
  270. gameManager.getStaticUserData().unlock_levels.push(levle_id)
  271. gameManager.saveUserData()
  272. gameManager.Singleton.sync_data()
  273. }
  274. }
  275. public sync_data(){
  276. let url = http.sync_data()
  277. let unlock_levels = gameManager.getStaticUserData().unlock_levels;
  278. http.run_post(url,{"unlock_levels":JSON.stringify(unlock_levels)},(err,data)=>{
  279. if(!err){
  280. // console.log("sync_data finish!"+JSON.stringify(unlock_levels));
  281. }
  282. })
  283. }
  284. public nextScene(){
  285. this.mCurSceneIndex++;
  286. let not_scene = false;
  287. if(this.mCurSceneIndex>=this.mGameData.length){
  288. not_scene = true;
  289. }
  290. if(!not_scene){
  291. let task_data = this.mGameData[this.mCurSceneIndex]._task_data
  292. if(task_data==null||task_data==undefined) {
  293. return tools.showToast('没有任务')
  294. }
  295. let call_back =(()=>{
  296. this.mGameRun.unInit()
  297. this.startLevelGame()
  298. })
  299. if(task_data.is_open_interlude_default_animation==undefined||
  300. task_data.is_open_interlude_default_animation==null) {
  301. task_data.is_open_interlude_default_animation = true
  302. }
  303. if(task_data.is_open_interlude_default_animation) {
  304. this.onLaunch(()=>{
  305. call_back()
  306. })
  307. } else {
  308. call_back()
  309. }
  310. }else{
  311. // tools.showToast("没有场景了!")
  312. }
  313. // this.onLaunch(()=>{
  314. // this.mCurSceneIndex++;
  315. // let not_scene = false;
  316. // if(this.mCurSceneIndex>=this.mGameData.length){
  317. // not_scene = true;
  318. // }
  319. // if(!not_scene){
  320. // this.mGameRun.unInit()
  321. // this.startLevelGame()
  322. // }else{
  323. // // tools.showToast("没有场景了!")
  324. // }
  325. // })
  326. }
  327. public gameOver(){
  328. ClientEvent.dispatchEvent(config.EventRun.ON_WIN)
  329. }
  330. public gameFail() {
  331. console.log('游戏失败')
  332. }
  333. public gotoGameLevel() {
  334. SdkUtil.ttStartScreenRecording()
  335. statisticsManager.startRecordUserLevel()
  336. }
  337. public backGameList(status = config.BACK_GAME_STATUS.NORMAL){
  338. if(!gameManager.isLoadingStatus){
  339. this.unscheduleAllCallbacks()
  340. this.mGameRun.backGameList()
  341. gameManager.Singleton.mSceneManager.play_sys_music()
  342. gameManager.isPlayGameLevelMusic = false
  343. SdkUtil.ttStopScreenRecording(true)
  344. if(status == config.BACK_GAME_STATUS.WIN) {
  345. statisticsManager.uploadRecordUserLevel(true)
  346. } else {
  347. statisticsManager.uploadRecordUserLevel(false)
  348. }
  349. }else{
  350. console.log("没有全部加载完成!")
  351. }
  352. }
  353. public initEvent(){
  354. ClientEvent.offAll(config.EventRun.NOTICE_EVENT)
  355. ClientEvent.offAll(config.EventRun.WIDGET_FINISH)
  356. ClientEvent.offAll(config.EventRun.WIDGET_FAIL)
  357. ClientEvent.offAll(config.EventRun.WIDGET_DRAG_OTHER_FINISH)
  358. ClientEvent.offAll(config.EventRun.ON_WIDGET_FINISH_COLLECT_EVENT)
  359. ClientEvent.offAll(config.EventRun.WIDGET_HIDE)
  360. ClientEvent.offAll(config.EventRun.SHOW_ZHAO_BU_TONG_FINISH_STATUS)
  361. ClientEvent.offAll(config.EventRun.ON_ZHAO_BU_TONG_ALL_FINISH)
  362. ClientEvent.offAll(config.EventRun.TOP_VIEW_CLOSE)
  363. ClientEvent.offAll(config.EventRun.TOP_VIEW_FINISH)
  364. ClientEvent.offAll(config.EventRun.TOP_VIEW_FAIL)
  365. ClientEvent.offAll(config.EventRun.TOP_VIEW_HIDE)
  366. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_FAIL)
  367. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_START)
  368. ClientEvent.offAll(config.EventRun.ON_SHOW_RULE_BTN)
  369. ClientEvent.offAll(config.EventRun.ON_BOSS_HURT)
  370. ClientEvent.on(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  371. ClientEvent.on(config.EventRun.WIDGET_FAIL,this.onWidgetFailEvent.bind(this),this)
  372. ClientEvent.on(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
  373. ClientEvent.on(config.EventRun.TOP_VIEW_CLOSE,this.onUiCloseEvent.bind(this),this)
  374. ClientEvent.on(config.EventRun.TOP_VIEW_FINISH,this.onUiFinishEvent.bind(this),this)
  375. ClientEvent.on(config.EventRun.TOP_VIEW_FAIL,this.onUiFailEvent.bind(this),this)
  376. ClientEvent.on(config.EventRun.TOP_VIEW_HIDE,this.onUiHideEvent.bind(this),this)
  377. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_FAIL,this.onCountDownFailEvent.bind(this),this)
  378. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_START,this.onStartCountDownEvent.bind(this),this)
  379. }
  380. public initGR(gr:game_run){
  381. this.mGameRun = gr;
  382. gameManager.Singleton = this;
  383. this.mSceneManager.init(this)
  384. this.clearRes()
  385. }
  386. public clearRes(){
  387. gameManager.res_map.clear()
  388. gameManager.mp3_cache.clear()
  389. }
  390. public init(gr:game_run,data:scene_item_data[]){
  391. // this.mGameRun = gr;
  392. // gameManager.Singleton = this;
  393. // this.mSceneManager.init(this)
  394. // this.mCurSceneIndex = main.Singleton.edit_scene_view.getCurSelectSceneIndex()
  395. // this.mGameData = data;
  396. // if( this.mGameData.length<=0){
  397. // return tools.showToast("错误的场景信息")
  398. // }
  399. // this.startLevelGame()
  400. }
  401. public runGame(data:scene_item_data[]){
  402. this.mCurSceneIndex = 0;
  403. this.mGameData = data;
  404. if( this.mGameData.length<=0){
  405. return tools.showToast("错误的场景信息")
  406. }
  407. this.startLevelGame()
  408. }
  409. public onLaunch(call,delay=0.7){
  410. this.mGameRun.onlaunch(call)
  411. }
  412. public getTopFloorLayer():Node {
  413. return this.mGameRun.top_floor_layer;
  414. }
  415. FilterChildScene(data:scene_item_data[]){
  416. let temp_scene = []
  417. for (let index = 0; index < data.length; index++) {
  418. const element = data[index];
  419. if(!element.is_child_scene){
  420. temp_scene.push(element)
  421. }
  422. }
  423. return temp_scene;
  424. }
  425. protected onDestroy(): void {
  426. ClientEvent.off(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  427. ClientEvent.off(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
  428. }
  429. public startLevelGame(){
  430. this.mGameRun.unInit()
  431. this.initEvent()
  432. // console.log("this.mGameData",this.mGameData,this.mCurSceneIndex)
  433. this.mSceneManager.startLevelGame(this.mGameData[this.mCurSceneIndex])
  434. taskServce.initTask(this.mGameData[this.mCurSceneIndex]._task_data)
  435. this.scheduleOnce(()=>{
  436. this.startGame()
  437. },0.5)
  438. if(gameManager.isPlayGameLevelMusic==false) {
  439. gameManager.isPlayGameLevelMusic = true
  440. if(gameManager.Singleton.getLevelData()){
  441. this.mSceneManager.stopMusic()
  442. this.mSceneManager.playMusic(this.mLevelData.piped_music,true)
  443. }
  444. }
  445. }
  446. public loadSceneTask(data: task_data) {
  447. this.mGameRun.loadSceneTask(data)
  448. }
  449. public loadScene(pages: scene_item_data[],type:number){
  450. this.mGameRun.loadSceneLayer(pages,type)
  451. }
  452. public loadUi(ui_widge_list:widget_item_data[]){
  453. this.mGameRun.loadUILayer(ui_widge_list)
  454. }
  455. public loadTextSound(ui_widge_list:widget_item_data[]){
  456. this.mGameRun.loadTextSound(ui_widge_list)
  457. }
  458. public loadQuestion(ui_widge_list:widget_item_data[]){
  459. this.mGameRun.initQuestionList(ui_widge_list)
  460. }
  461. public initCountDownList(ui_widge_list:widget_item_data[]){
  462. this.mGameRun.initCountDownList(ui_widge_list)
  463. }
  464. public initTaskUi(data:task_data){
  465. this.mGameRun.initTaskUi(data)
  466. }
  467. public startGame(){
  468. taskServce.startFirstEvent()
  469. }
  470. public showCheck(call){
  471. this.mGameRun.showCheck(call)
  472. }
  473. public showLoadingLevel(){
  474. this.mGameRun.showLoadingLevel()
  475. }
  476. public hideLoadingLevel(){
  477. this.mGameRun.hideLoadingLevel()
  478. }
  479. public showUnLockView(lock_one_call,lock_all_one_day){
  480. this.mGameRun.showUnLockView(lock_one_call,lock_all_one_day)
  481. }
  482. public static getWidgetList(scene_data:scene_item_data):widget_item_data[]{
  483. let temp:widget_item_data[] = []
  484. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  485. const data = scene_data.page_widget_list[index];
  486. if(data.type<=4 ){
  487. temp.push(data)
  488. }
  489. }
  490. return temp;
  491. }
  492. public static getUIWidgetList(scene_data:scene_item_data){
  493. let temp:widget_item_data[] = []
  494. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  495. const data = scene_data.page_widget_list[index];
  496. if(data.type===config.Widget_Type_List.UI_TOP){
  497. if(data.att.top_data!=null&&data.att.top_data.top_ui_type!=config.top_view_type.__null){
  498. temp.push(data)
  499. }
  500. }
  501. }
  502. return temp;
  503. }
  504. public isCurScenePageCheckWidgetFinish(widget_id:number){
  505. return this.mGameRun.isCurScenePageCheckWidgetFinish(widget_id);
  506. }
  507. public isCurScenePageCheckWidgetShow(widget_id:number){
  508. return this.mGameRun.isCurScenePageCheckWidgetShow(widget_id);
  509. }
  510. public static getQuestionwidgetList(scene_data:scene_item_data){
  511. let temp:widget_item_data[] = []
  512. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  513. const data = scene_data.page_widget_list[index];
  514. if(data.type===config.Widget_Type_List.QUESTION_SELECT){
  515. if(data.att.question_select!=null){
  516. temp.push(data)
  517. }
  518. }
  519. }
  520. return temp;
  521. }
  522. public static getTextSoundWidgetList(scene_data:scene_item_data){
  523. let temp:widget_item_data[] = []
  524. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  525. const data = scene_data.page_widget_list[index];
  526. if(data.type===config.Widget_Type_List.TEXT_SOUND){
  527. if(data.att.text_sound_data!=null){
  528. temp.push(data)
  529. }
  530. }
  531. }
  532. return temp;
  533. }
  534. public static getCountDownWidgetList(scene_data:scene_item_data){
  535. let temp:widget_item_data[] = []
  536. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  537. const data = scene_data.page_widget_list[index];
  538. if(data.type===config.Widget_Type_List.COUNT_DOWN){
  539. if(data.att.count_down!=null){
  540. temp.push(data)
  541. }
  542. }
  543. }
  544. return temp;
  545. }
  546. public static getCacheSpriteFrameByName(node:Node,sfName:string){
  547. let sf = gameManager.res_map.get(sfName)
  548. if(sf==null){
  549. if(node!=null){
  550. tools.loadUrl(sfName,node.getComponent(Sprite))
  551. }
  552. }
  553. return sf
  554. }
  555. public static getCacheSoundByName(sfName:string){
  556. // return control.mp3_cache.get(sfName)
  557. return gameManager.mp3_cache.get(sfName)
  558. }
  559. public static initUiBaseAtt(node:Node,att:ui_att_item){
  560. node.getComponent(UITransform).setContentSize(new Size(att.width,att.height))
  561. node.position = new Vec3(att.x,att.y);
  562. node.getComponent(Sprite).spriteFrame = gameManager.getCacheSpriteFrameByName(node,att.res)
  563. }
  564. onWidgetFinishEvent(widget_id:number, finish_event_item:event_item){
  565. taskServce.onWidgetFinishEvent(widget_id, finish_event_item)
  566. }
  567. onWidgetDragOtherFinishEvent(widget_id:number, score:number) {
  568. taskServce.onWidgetDragOtherFinishEvent(widget_id, score)
  569. }
  570. onWidgetFailEvent(widget_id:number){
  571. taskServce.onWidgetFailEvent(widget_id)
  572. }
  573. onUiCloseEvent(event_id:number){
  574. taskServce.extEventByEventId(event_id)
  575. }
  576. onUiFinishEvent(event_id:number){
  577. taskServce.extEventByEventId(event_id)
  578. }
  579. onUiFailEvent(event_id:number){
  580. taskServce.extEventByEventId(event_id)
  581. }
  582. onUiHideEvent(widget_id:number) {
  583. taskServce.checkFinishZhaoXiJieWidget(widget_id)
  584. }
  585. onCountDownFailEvent(event_id:number){
  586. taskServce.extEventByEventId(event_id)
  587. }
  588. onStartCountDownEvent(event_id:number){
  589. taskServce.extEventByEventId(event_id)
  590. }
  591. exeEvent(event_id:number){
  592. taskServce.extEventByEventId(event_id)
  593. }
  594. exeSuccessTriggerEvent(trigger_event_id:number) {
  595. taskServce.exeSuccessTriggerEvent(trigger_event_id)
  596. }
  597. exeNextDelayEvent(event_item:event_item) {
  598. taskServce.exeNextDelayEvent(event_item)
  599. }
  600. showFindRuleTips(){
  601. this.mGameRun.showFindRuleTips()
  602. }
  603. showTips(){
  604. this.mGameRun.showTips()
  605. }
  606. showRule(){
  607. this.mGameRun.showRule()
  608. }
  609. getSceneManager(){
  610. return this.mSceneManager;
  611. }
  612. IsOpenRuleStatus(){
  613. return taskServce.guo_ju_qing_binding_event_id==-1;
  614. }
  615. //点击按钮音效
  616. public sys_click_button_music(){
  617. if(gameManager.sys_data!=null){
  618. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_button_music)
  619. }
  620. }
  621. // //失败吓人音效
  622. // public sys_fail_scary_music(){
  623. // if(gameManager.sys_data!=null){
  624. // this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_scary_music)
  625. // }
  626. // }
  627. //失败后攻击音效
  628. public sys_fail_attack_music(){
  629. if(gameManager.sys_data!=null){
  630. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_attack_music)
  631. }
  632. }
  633. //失败提示音效
  634. public sys_fail_prompt_music(){
  635. if(gameManager.sys_data!=null){
  636. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_prompt_music)
  637. }
  638. }
  639. //正确通关音效
  640. public sys_success_complete_music(){
  641. if(gameManager.sys_data!=null){
  642. this.mSysSound.playSound(gameManager.sys_data.content.sys_success_complete_music)
  643. }
  644. }
  645. //点击正确细节音效
  646. public sys_click_correct_detail_music(){
  647. if(gameManager.sys_data!=null){
  648. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_correct_detail_music)
  649. }
  650. }
  651. public checkWidgetList(list:other_widget_finish_listen_item[]):number{
  652. let event_id = -1;
  653. for (let index = 0; index < list.length; index++) {
  654. const item = list[index];
  655. let isFinish = this.mGameRun.isCurScenePageCheckWidgetFinish(item.widget_id)
  656. if(!isFinish){
  657. event_id = item.event_id;
  658. break;
  659. }
  660. }
  661. return event_id;
  662. }
  663. public static getUserUnlockLevesData():UserUnlockLevesData{
  664. if(gameManager.g_userUnlockLevesData == null) {
  665. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  666. }
  667. return gameManager.g_userUnlockLevesData;
  668. }
  669. public static setUserUnlockLevesData(data:any){
  670. if(gameManager.g_userUnlockLevesData == null) {
  671. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  672. }
  673. if(data != null) {
  674. gameManager.g_userUnlockLevesData = data.content
  675. // console.log('g_userUnlockLevesData=',gameManager.g_userUnlockLevesData)
  676. }
  677. }
  678. public static LookVideoCallBack(call){
  679. if(call!=null){
  680. let ad_id = SdkUtil.getAdId(config.AD_TYPE.ADD_TIME)
  681. SdkUtil.showVideoAd(ad_id,(res)=>{
  682. if(res.isEnded){
  683. call()
  684. }
  685. // 统计-激励视频广告
  686. let level_id = gameManager.Singleton.getLevelData().id
  687. let collect_data = statisticsManager.get_collect_ads_data(level_id, res, config.STATISTICS_ACTION_TYPE.ADD_TIME)
  688. statisticsManager.request_collect_rewardVideoData(collect_data)
  689. })
  690. }
  691. }
  692. public getCurSceneLayerPage(){
  693. return this.mGameRun.getCurSceneLayerPage()
  694. }
  695. public static request_user_unlock_number_status(status = config.User_unlock_levels_number_status.GET, success_callback:any, fail_callback:any) {
  696. if(status != config.User_unlock_levels_number_status.GET) {
  697. gameManager.Singleton.showLoadingLevel()
  698. }
  699. http.run_post(http.user_unlock_number_status(),{'stype':status}, (err,data)=> {
  700. // console.log('err=',err,'status=',status,'解锁次数=',data)
  701. if(status != config.User_unlock_levels_number_status.GET) {
  702. gameManager.Singleton.hideLoadingLevel()
  703. }
  704. if(!err) {
  705. let _data = JSON.parse(data)
  706. if(_data.code==config.MSG_CODE.SUCCESS){
  707. gameManager.setUserUnlockLevesData(_data)
  708. success_callback(_data)
  709. } else{
  710. fail_callback()
  711. }
  712. } else {
  713. fail_callback()
  714. }
  715. })
  716. }
  717. }