gameManager.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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, 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 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. private static getUserSelectLongStoryCacheData():SelectLongStoryData {
  230. let str = sys.localStorage.getItem(config.USER_SELECT_LONG_STORY_DATA)
  231. if(str==undefined||str==""||str==null){
  232. return new SelectLongStoryData()
  233. }
  234. return JSON.parse(str)
  235. }
  236. public static getUserSelectLongStoryPage(long_story_id:number):number {
  237. let data = gameManager.getUserSelectLongStoryCacheData()
  238. if(data.id==long_story_id && data.page>0) {
  239. return data.page
  240. }
  241. return 1
  242. }
  243. public static setUserSelectLongStoryPage(long_story_id:number, page:number) {
  244. let data = gameManager.getUserSelectLongStoryCacheData()
  245. data.id = long_story_id
  246. data.page = page
  247. sys.localStorage.setItem(config.USER_SELECT_LONG_STORY_DATA, JSON.stringify(data))
  248. }
  249. public static getUserSelectLongStoryLevelId():number {
  250. let data = gameManager.getUserSelectLongStoryCacheData()
  251. return data.level_id
  252. }
  253. public static setUserSelectLongStoryLevelId(long_story_id:number, level_id:number) {
  254. let data = gameManager.getUserSelectLongStoryCacheData()
  255. data.id = long_story_id
  256. data.level_id = level_id
  257. sys.localStorage.setItem(config.USER_SELECT_LONG_STORY_DATA, JSON.stringify(data))
  258. }
  259. public reLife(){
  260. let ad_id = SdkUtil.getAdId(config.AD_TYPE.RE_LIFE)
  261. SdkUtil.showVideoAd(ad_id,(res)=>{
  262. if(res.isEnded){
  263. this.mGameRun.onlaunch(()=>{
  264. gameManager.Singleton.startLevelGame()
  265. })
  266. }
  267. // 统计-激励视频广告
  268. let level_id = gameManager.Singleton.getLevelData().id
  269. let collect_data = statisticsManager.get_collect_ads_data(level_id, res, config.STATISTICS_ACTION_TYPE.GUAN_KA_FU_HUO)
  270. statisticsManager.request_collect_rewardVideoData(collect_data)
  271. })
  272. }
  273. public reStartGame(){
  274. this.mGameRun.onlaunch(()=>{
  275. this.mCurSceneIndex = 0;
  276. gameManager.Singleton.startLevelGame()
  277. })
  278. }
  279. public levleIsUnLock(levle_id:number){
  280. let isunlock = false;
  281. for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
  282. const id = gameManager.getStaticUserData().unlock_levels[index];
  283. if(id==levle_id){
  284. isunlock = true;
  285. break;
  286. }
  287. }
  288. return isunlock
  289. }
  290. public unLockLevel(levle_id:number){
  291. let is_have = false;
  292. for (let index = 0; index < gameManager.getStaticUserData().unlock_levels.length; index++) {
  293. const id = gameManager.getStaticUserData().unlock_levels[index];
  294. if(id==levle_id){
  295. is_have = true;
  296. break;
  297. }
  298. }
  299. if(!is_have){
  300. gameManager.getStaticUserData().unlock_levels.push(levle_id)
  301. gameManager.saveUserData()
  302. gameManager.Singleton.sync_data()
  303. }
  304. }
  305. public sync_data(){
  306. let url = http.sync_data()
  307. let unlock_levels = gameManager.getStaticUserData().unlock_levels;
  308. http.run_post(url,{"unlock_levels":JSON.stringify(unlock_levels)},(err,data)=>{
  309. if(!err){
  310. // console.log("sync_data finish!"+JSON.stringify(unlock_levels));
  311. }
  312. })
  313. }
  314. public nextScene(){
  315. this.mCurSceneIndex++;
  316. let not_scene = false;
  317. if(this.mCurSceneIndex>=this.mGameData.length){
  318. not_scene = true;
  319. }
  320. if(!not_scene){
  321. let task_data = this.mGameData[this.mCurSceneIndex]._task_data
  322. if(task_data==null||task_data==undefined) {
  323. return tools.showToast('没有任务')
  324. }
  325. let call_back =(()=>{
  326. this.mGameRun.unInit()
  327. this.startLevelGame()
  328. })
  329. if(task_data.is_open_interlude_default_animation==undefined||
  330. task_data.is_open_interlude_default_animation==null) {
  331. task_data.is_open_interlude_default_animation = true
  332. }
  333. if(task_data.is_open_interlude_default_animation) {
  334. this.onLaunch(()=>{
  335. call_back()
  336. })
  337. } else {
  338. call_back()
  339. }
  340. }else{
  341. // tools.showToast("没有场景了!")
  342. }
  343. // this.onLaunch(()=>{
  344. // this.mCurSceneIndex++;
  345. // let not_scene = false;
  346. // if(this.mCurSceneIndex>=this.mGameData.length){
  347. // not_scene = true;
  348. // }
  349. // if(!not_scene){
  350. // this.mGameRun.unInit()
  351. // this.startLevelGame()
  352. // }else{
  353. // // tools.showToast("没有场景了!")
  354. // }
  355. // })
  356. }
  357. public gameOver(){
  358. ClientEvent.dispatchEvent(config.EventRun.ON_WIN)
  359. }
  360. public gameFail() {
  361. console.log('游戏失败')
  362. }
  363. public gotoGameLevel() {
  364. SdkUtil.ttStartScreenRecording()
  365. statisticsManager.startRecordUserLevel()
  366. }
  367. public backGameList(status = config.BACK_GAME_STATUS.NORMAL){
  368. if(!gameManager.isLoadingStatus){
  369. this.unscheduleAllCallbacks()
  370. this.mGameRun.backGameList()
  371. gameManager.Singleton.mSceneManager.play_sys_music()
  372. gameManager.isPlayGameLevelMusic = false
  373. SdkUtil.ttStopScreenRecording(true)
  374. if(status == config.BACK_GAME_STATUS.WIN) {
  375. statisticsManager.uploadRecordUserLevel(true)
  376. } else {
  377. statisticsManager.uploadRecordUserLevel(false)
  378. }
  379. }else{
  380. console.log("没有全部加载完成!")
  381. }
  382. }
  383. public initEvent(){
  384. ClientEvent.offAll(config.EventRun.NOTICE_EVENT)
  385. ClientEvent.offAll(config.EventRun.WIDGET_FINISH)
  386. ClientEvent.offAll(config.EventRun.WIDGET_FAIL)
  387. ClientEvent.offAll(config.EventRun.WIDGET_DRAG_OTHER_FINISH)
  388. ClientEvent.offAll(config.EventRun.WIDGET_QUESTION_SELECT_FINISH)
  389. ClientEvent.offAll(config.EventRun.ON_WIDGET_FINISH_COLLECT_EVENT)
  390. ClientEvent.offAll(config.EventRun.WIDGET_HIDE)
  391. ClientEvent.offAll(config.EventRun.SHOW_ZHAO_BU_TONG_FINISH_STATUS)
  392. ClientEvent.offAll(config.EventRun.ON_ZHAO_BU_TONG_ALL_FINISH)
  393. ClientEvent.offAll(config.EventRun.TOP_VIEW_CLOSE)
  394. ClientEvent.offAll(config.EventRun.TOP_VIEW_FINISH)
  395. ClientEvent.offAll(config.EventRun.TOP_VIEW_FAIL)
  396. ClientEvent.offAll(config.EventRun.TOP_VIEW_HIDE)
  397. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_FAIL)
  398. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_START)
  399. ClientEvent.offAll(config.EventRun.ON_SHOW_RULE_BTN)
  400. ClientEvent.offAll(config.EventRun.ON_BOSS_HURT)
  401. ClientEvent.on(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  402. ClientEvent.on(config.EventRun.WIDGET_FAIL,this.onWidgetFailEvent.bind(this),this)
  403. ClientEvent.on(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
  404. ClientEvent.on(config.EventRun.WIDGET_QUESTION_SELECT_FINISH,this.onWidgetQuestionSelectFinishEvent.bind(this),this)
  405. ClientEvent.on(config.EventRun.TOP_VIEW_CLOSE,this.onUiCloseEvent.bind(this),this)
  406. ClientEvent.on(config.EventRun.TOP_VIEW_FINISH,this.onUiFinishEvent.bind(this),this)
  407. ClientEvent.on(config.EventRun.TOP_VIEW_FAIL,this.onUiFailEvent.bind(this),this)
  408. ClientEvent.on(config.EventRun.TOP_VIEW_HIDE,this.onUiHideEvent.bind(this),this)
  409. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_FAIL,this.onCountDownFailEvent.bind(this),this)
  410. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_START,this.onStartCountDownEvent.bind(this),this)
  411. }
  412. public initGR(gr:game_run){
  413. this.mGameRun = gr;
  414. gameManager.Singleton = this;
  415. this.mSceneManager.init(this)
  416. this.clearRes()
  417. }
  418. public clearRes(){
  419. gameManager.res_map.clear()
  420. gameManager.mp3_cache.clear()
  421. }
  422. public init(gr:game_run,data:scene_item_data[]){
  423. // this.mGameRun = gr;
  424. // gameManager.Singleton = this;
  425. // this.mSceneManager.init(this)
  426. // this.mCurSceneIndex = main.Singleton.edit_scene_view.getCurSelectSceneIndex()
  427. // this.mGameData = data;
  428. // if( this.mGameData.length<=0){
  429. // return tools.showToast("错误的场景信息")
  430. // }
  431. // this.startLevelGame()
  432. }
  433. public runGame(data:scene_item_data[]){
  434. this.mCurSceneIndex = 0;
  435. this.mGameData = data;
  436. if( this.mGameData.length<=0){
  437. return tools.showToast("错误的场景信息")
  438. }
  439. this.startLevelGame()
  440. }
  441. public onLaunch(call,delay=0.7){
  442. this.mGameRun.onlaunch(call,delay)
  443. }
  444. public getTopFloorLayer():Node {
  445. return this.mGameRun.top_floor_layer;
  446. }
  447. FilterChildScene(data:scene_item_data[]){
  448. let temp_scene = []
  449. for (let index = 0; index < data.length; index++) {
  450. const element = data[index];
  451. if(!element.is_child_scene){
  452. temp_scene.push(element)
  453. }
  454. }
  455. return temp_scene;
  456. }
  457. protected onDestroy(): void {
  458. ClientEvent.off(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  459. ClientEvent.off(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
  460. ClientEvent.off(config.EventRun.WIDGET_QUESTION_SELECT_FINISH,this.onWidgetQuestionSelectFinishEvent.bind(this),this)
  461. }
  462. public startLevelGame(){
  463. this.mGameRun.unInit()
  464. this.initEvent()
  465. // console.log("this.mGameData",this.mGameData,this.mCurSceneIndex)
  466. this.mSceneManager.startLevelGame(this.mGameData[this.mCurSceneIndex])
  467. taskServce.initTask(this.mGameData[this.mCurSceneIndex]._task_data)
  468. this.scheduleOnce(()=>{
  469. this.startGame()
  470. },0.5)
  471. if(gameManager.isPlayGameLevelMusic==false) {
  472. gameManager.isPlayGameLevelMusic = true
  473. if(gameManager.Singleton.getLevelData()){
  474. this.mSceneManager.stopMusic()
  475. this.mSceneManager.playMusic(this.mLevelData.piped_music,true)
  476. }
  477. }
  478. }
  479. public loadSceneTask(data: task_data) {
  480. this.mGameRun.loadSceneTask(data)
  481. }
  482. public loadScene(pages: scene_item_data[],type:number){
  483. this.mGameRun.loadSceneLayer(pages,type)
  484. }
  485. public loadUi(ui_widge_list:widget_item_data[]){
  486. this.mGameRun.loadUILayer(ui_widge_list)
  487. }
  488. public loadTextSound(ui_widge_list:widget_item_data[]){
  489. this.mGameRun.loadTextSound(ui_widge_list)
  490. }
  491. public loadQuestion(ui_widge_list:widget_item_data[]){
  492. this.mGameRun.initQuestionList(ui_widge_list)
  493. }
  494. public initCountDownList(ui_widge_list:widget_item_data[]){
  495. this.mGameRun.initCountDownList(ui_widge_list)
  496. }
  497. public initTaskUi(data:task_data){
  498. this.mGameRun.initTaskUi(data)
  499. }
  500. public startGame(){
  501. taskServce.startFirstEvent()
  502. }
  503. public showCheck(call){
  504. this.mGameRun.showCheck(call)
  505. }
  506. public showLoadingLevel(){
  507. this.mGameRun.showLoadingLevel()
  508. }
  509. public hideLoadingLevel(){
  510. this.mGameRun.hideLoadingLevel()
  511. }
  512. public showUnLockView(lock_one_call,lock_all_one_day){
  513. this.mGameRun.showUnLockView(lock_one_call,lock_all_one_day)
  514. }
  515. public static getWidgetList(scene_data:scene_item_data):widget_item_data[]{
  516. let temp:widget_item_data[] = []
  517. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  518. const data = scene_data.page_widget_list[index];
  519. if(data.type<=4 ){
  520. temp.push(data)
  521. }
  522. }
  523. return temp;
  524. }
  525. public static getUIWidgetList(scene_data:scene_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===config.Widget_Type_List.UI_TOP){
  530. if(data.att.top_data!=null&&data.att.top_data.top_ui_type!=config.top_view_type.__null){
  531. temp.push(data)
  532. }
  533. }
  534. }
  535. return temp;
  536. }
  537. public isCurScenePageCheckWidgetFinish(widget_id:number){
  538. return this.mGameRun.isCurScenePageCheckWidgetFinish(widget_id);
  539. }
  540. public isCurScenePageCheckWidgetShow(widget_id:number){
  541. return this.mGameRun.isCurScenePageCheckWidgetShow(widget_id);
  542. }
  543. public static getQuestionwidgetList(scene_data:scene_item_data){
  544. let temp:widget_item_data[] = []
  545. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  546. const data = scene_data.page_widget_list[index];
  547. if(data.type===config.Widget_Type_List.QUESTION_SELECT){
  548. if(data.att.question_select!=null){
  549. temp.push(data)
  550. }
  551. }
  552. }
  553. return temp;
  554. }
  555. public static getTextSoundWidgetList(scene_data:scene_item_data){
  556. let temp:widget_item_data[] = []
  557. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  558. const data = scene_data.page_widget_list[index];
  559. if(data.type===config.Widget_Type_List.TEXT_SOUND){
  560. if(data.att.text_sound_data!=null){
  561. temp.push(data)
  562. }
  563. }
  564. }
  565. return temp;
  566. }
  567. public static getCountDownWidgetList(scene_data:scene_item_data){
  568. let temp:widget_item_data[] = []
  569. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  570. const data = scene_data.page_widget_list[index];
  571. if(data.type===config.Widget_Type_List.COUNT_DOWN){
  572. if(data.att.count_down!=null){
  573. temp.push(data)
  574. }
  575. }
  576. }
  577. return temp;
  578. }
  579. public static getCacheSpriteFrameByName(node:Node,sfName:string){
  580. let sf = gameManager.res_map.get(sfName)
  581. if(sf==null){
  582. if(node!=null){
  583. // console.log('未有缓存的---sfName=',sfName)
  584. tools.loadUrl(sfName,node.getComponent(Sprite))
  585. }
  586. }
  587. return sf
  588. }
  589. public static getCacheSoundByName(sfName:string){
  590. // return control.mp3_cache.get(sfName)
  591. return gameManager.mp3_cache.get(sfName)
  592. }
  593. public static initUiBaseAtt(node:Node,att:ui_att_item){
  594. node.getComponent(UITransform).setContentSize(new Size(att.width,att.height))
  595. node.position = new Vec3(att.x,att.y);
  596. node.getComponent(Sprite).spriteFrame = gameManager.getCacheSpriteFrameByName(node,att.res)
  597. }
  598. onWidgetFinishEvent(widget_id:number, finish_event_item:event_item){
  599. taskServce.onWidgetFinishEvent(widget_id, finish_event_item)
  600. }
  601. onWidgetQuestionSelectFinishEvent(widget_id:number, score:number) {
  602. taskServce.onWidgetQuestionSelectFinishEvent(widget_id, score)
  603. }
  604. onWidgetDragOtherFinishEvent(widget_id:number, score:number) {
  605. taskServce.onWidgetDragOtherFinishEvent(widget_id, score)
  606. }
  607. onWidgetFailEvent(widget_id:number){
  608. taskServce.onWidgetFailEvent(widget_id)
  609. }
  610. onUiCloseEvent(event_id:number){
  611. taskServce.extEventByEventId(event_id)
  612. }
  613. onUiFinishEvent(event_id:number){
  614. taskServce.extEventByEventId(event_id)
  615. }
  616. onUiFailEvent(event_id:number){
  617. taskServce.extEventByEventId(event_id)
  618. }
  619. onUiHideEvent(widget_id:number) {
  620. taskServce.checkFinishZhaoXiJieWidget(widget_id)
  621. }
  622. onCountDownFailEvent(event_id:number){
  623. taskServce.extEventByEventId(event_id)
  624. }
  625. onStartCountDownEvent(event_id:number){
  626. taskServce.extEventByEventId(event_id)
  627. }
  628. exeEvent(event_id:number){
  629. taskServce.extEventByEventId(event_id)
  630. }
  631. exeSuccessTriggerEvent(trigger_event_id:number) {
  632. taskServce.exeSuccessTriggerEvent(trigger_event_id)
  633. }
  634. exeNextDelayEvent(event_item:event_item) {
  635. taskServce.exeNextDelayEvent(event_item)
  636. }
  637. showFindRuleTips(){
  638. this.mGameRun.showFindRuleTips()
  639. }
  640. showTips(){
  641. this.mGameRun.showTips()
  642. }
  643. showRule(){
  644. this.mGameRun.showRule()
  645. }
  646. getSceneManager(){
  647. return this.mSceneManager;
  648. }
  649. IsOpenRuleStatus(){
  650. return taskServce.guo_ju_qing_binding_event_id==-1;
  651. }
  652. //点击按钮音效
  653. public sys_click_button_music(){
  654. if(gameManager.sys_data!=null){
  655. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_button_music)
  656. }
  657. }
  658. // //失败吓人音效
  659. // public sys_fail_scary_music(){
  660. // if(gameManager.sys_data!=null){
  661. // this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_scary_music)
  662. // }
  663. // }
  664. //失败后攻击音效
  665. public sys_fail_attack_music(){
  666. if(gameManager.sys_data!=null){
  667. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_attack_music)
  668. }
  669. }
  670. //失败提示音效
  671. public sys_fail_prompt_music(){
  672. if(gameManager.sys_data!=null){
  673. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_prompt_music)
  674. }
  675. }
  676. //正确通关音效
  677. public sys_success_complete_music(){
  678. if(gameManager.sys_data!=null){
  679. this.mSysSound.playSound(gameManager.sys_data.content.sys_success_complete_music)
  680. }
  681. }
  682. //点击正确细节音效
  683. public sys_click_correct_detail_music(){
  684. if(gameManager.sys_data!=null){
  685. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_correct_detail_music)
  686. }
  687. }
  688. public checkWidgetList(list:other_widget_finish_listen_item[],is_finish_status:boolean=false):other_widget_finish_listen_item[]{
  689. let event_list = [];
  690. for (let index = 0; index < list.length; index++) {
  691. const item = list[index];
  692. let isFinish = this.mGameRun.isCurScenePageCheckWidgetFinish(item.widget_id)
  693. // console.log('item.widget_id=',item.widget_id, 'isFinish=',isFinish)
  694. let event_id = item.event_id;
  695. if(event_id!=-1) {
  696. if(is_finish_status && isFinish) {
  697. event_list.push(item)
  698. }
  699. if(!is_finish_status && !isFinish) {
  700. event_list.push(item)
  701. }
  702. }
  703. }
  704. return event_list;
  705. }
  706. public static getUserUnlockLevesData():UserUnlockLevesData{
  707. if(gameManager.g_userUnlockLevesData == null) {
  708. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  709. }
  710. return gameManager.g_userUnlockLevesData;
  711. }
  712. public static setUserUnlockLevesData(data:any){
  713. if(gameManager.g_userUnlockLevesData == null) {
  714. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  715. }
  716. if(data != null) {
  717. gameManager.g_userUnlockLevesData = data.content
  718. // console.log('g_userUnlockLevesData=',gameManager.g_userUnlockLevesData)
  719. }
  720. }
  721. public static LookVideoCallBack(call){
  722. if(call!=null){
  723. let ad_id = SdkUtil.getAdId(config.AD_TYPE.ADD_TIME)
  724. SdkUtil.showVideoAd(ad_id,(res)=>{
  725. if(res.isEnded){
  726. call()
  727. }
  728. // 统计-激励视频广告
  729. let level_id = gameManager.Singleton.getLevelData().id
  730. let collect_data = statisticsManager.get_collect_ads_data(level_id, res, config.STATISTICS_ACTION_TYPE.ADD_TIME)
  731. statisticsManager.request_collect_rewardVideoData(collect_data)
  732. })
  733. }
  734. }
  735. public getCurSceneLayerPage(){
  736. return this.mGameRun.getCurSceneLayerPage()
  737. }
  738. public static request_user_unlock_number_status(status = config.User_unlock_levels_number_status.GET, success_callback:any, fail_callback:any) {
  739. if(status != config.User_unlock_levels_number_status.GET) {
  740. gameManager.Singleton.showLoadingLevel()
  741. }
  742. http.run_post(http.user_unlock_number_status(),{'stype':status}, (err,data)=> {
  743. // console.log('err=',err,'status=',status,'解锁次数=',data)
  744. if(status != config.User_unlock_levels_number_status.GET) {
  745. gameManager.Singleton.hideLoadingLevel()
  746. }
  747. if(!err) {
  748. let _data = JSON.parse(data)
  749. if(_data.code==config.MSG_CODE.SUCCESS){
  750. gameManager.setUserUnlockLevesData(_data)
  751. success_callback(_data)
  752. } else{
  753. fail_callback()
  754. }
  755. } else {
  756. fail_callback()
  757. }
  758. })
  759. }
  760. }