gameManager.ts 30 KB

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