gameManager.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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. ClientEvent.dispatchEvent(config.EventRun.BACK_GAME_LIST)
  387. }else{
  388. console.log("没有全部加载完成!")
  389. }
  390. }
  391. public initEvent(){
  392. ClientEvent.offAll(config.EventRun.NOTICE_EVENT)
  393. ClientEvent.offAll(config.EventRun.WIDGET_FINISH)
  394. ClientEvent.offAll(config.EventRun.WIDGET_FAIL)
  395. ClientEvent.offAll(config.EventRun.WIDGET_DRAG_OTHER_FINISH)
  396. ClientEvent.offAll(config.EventRun.WIDGET_QUESTION_SELECT_FINISH)
  397. ClientEvent.offAll(config.EventRun.ON_WIDGET_FINISH_COLLECT_EVENT)
  398. ClientEvent.offAll(config.EventRun.WIDGET_HIDE)
  399. ClientEvent.offAll(config.EventRun.SHOW_ZHAO_BU_TONG_FINISH_STATUS)
  400. ClientEvent.offAll(config.EventRun.ON_ZHAO_BU_TONG_ALL_FINISH)
  401. ClientEvent.offAll(config.EventRun.TOP_VIEW_CLOSE)
  402. ClientEvent.offAll(config.EventRun.TOP_VIEW_FINISH)
  403. ClientEvent.offAll(config.EventRun.TOP_VIEW_FAIL)
  404. ClientEvent.offAll(config.EventRun.TOP_VIEW_HIDE)
  405. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_FAIL)
  406. ClientEvent.offAll(config.EventRun.ON_COUNT_DOWN_START)
  407. ClientEvent.offAll(config.EventRun.ON_SHOW_RULE_BTN)
  408. ClientEvent.offAll(config.EventRun.ON_BOSS_HURT)
  409. ClientEvent.on(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  410. ClientEvent.on(config.EventRun.WIDGET_FAIL,this.onWidgetFailEvent.bind(this),this)
  411. ClientEvent.on(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
  412. ClientEvent.on(config.EventRun.WIDGET_QUESTION_SELECT_FINISH,this.onWidgetQuestionSelectFinishEvent.bind(this),this)
  413. ClientEvent.on(config.EventRun.TOP_VIEW_CLOSE,this.onUiCloseEvent.bind(this),this)
  414. ClientEvent.on(config.EventRun.TOP_VIEW_FINISH,this.onUiFinishEvent.bind(this),this)
  415. ClientEvent.on(config.EventRun.TOP_VIEW_FAIL,this.onUiFailEvent.bind(this),this)
  416. ClientEvent.on(config.EventRun.TOP_VIEW_HIDE,this.onUiHideEvent.bind(this),this)
  417. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_FAIL,this.onCountDownFailEvent.bind(this),this)
  418. ClientEvent.on(config.EventRun.ON_COUNT_DOWN_START,this.onStartCountDownEvent.bind(this),this)
  419. }
  420. public initGR(gr:game_run){
  421. this.mGameRun = gr;
  422. gameManager.Singleton = this;
  423. this.mSceneManager.init(this)
  424. this.clearRes()
  425. }
  426. public clearRes(){
  427. gameManager.res_map.clear()
  428. gameManager.mp3_cache.clear()
  429. }
  430. public init(gr:game_run,data:scene_item_data[]){
  431. // this.mGameRun = gr;
  432. // gameManager.Singleton = this;
  433. // this.mSceneManager.init(this)
  434. // this.mCurSceneIndex = main.Singleton.edit_scene_view.getCurSelectSceneIndex()
  435. // this.mGameData = data;
  436. // if( this.mGameData.length<=0){
  437. // return tools.showToast("错误的场景信息")
  438. // }
  439. // this.startLevelGame()
  440. }
  441. public runGame(data:scene_item_data[]){
  442. this.mCurSceneIndex = 0;
  443. this.mGameData = data;
  444. if( this.mGameData.length<=0){
  445. return tools.showToast("错误的场景信息")
  446. }
  447. this.startLevelGame()
  448. }
  449. public onLaunch(call,delay=0.7){
  450. this.mGameRun.onlaunch(call,delay)
  451. }
  452. public getTopFloorLayer():Node {
  453. return this.mGameRun.top_floor_layer;
  454. }
  455. FilterChildScene(data:scene_item_data[]){
  456. let temp_scene = []
  457. for (let index = 0; index < data.length; index++) {
  458. const element = data[index];
  459. if(!element.is_child_scene){
  460. temp_scene.push(element)
  461. }
  462. }
  463. return temp_scene;
  464. }
  465. protected onDestroy(): void {
  466. ClientEvent.off(config.EventRun.WIDGET_FINISH,this.onWidgetFinishEvent.bind(this),this)
  467. ClientEvent.off(config.EventRun.WIDGET_DRAG_OTHER_FINISH,this.onWidgetDragOtherFinishEvent.bind(this),this)
  468. ClientEvent.off(config.EventRun.WIDGET_QUESTION_SELECT_FINISH,this.onWidgetQuestionSelectFinishEvent.bind(this),this)
  469. }
  470. public startLevelGame(){
  471. this.mGameRun.unInit()
  472. this.initEvent()
  473. // console.log("this.mGameData",this.mGameData,this.mCurSceneIndex)
  474. this.mSceneManager.startLevelGame(this.mGameData[this.mCurSceneIndex])
  475. taskServce.initTask(this.mGameData[this.mCurSceneIndex]._task_data)
  476. this.scheduleOnce(()=>{
  477. this.startGame()
  478. },0.5)
  479. if(gameManager.isPlayGameLevelMusic==false) {
  480. gameManager.isPlayGameLevelMusic = true
  481. if(gameManager.Singleton.getLevelData()){
  482. this.mSceneManager.stopMusic()
  483. this.mSceneManager.playMusic(this.mLevelData.piped_music,true)
  484. }
  485. }
  486. }
  487. public loadSceneTask(data: task_data) {
  488. this.mGameRun.loadSceneTask(data)
  489. }
  490. public loadScene(pages: scene_item_data[],type:number){
  491. this.mGameRun.loadSceneLayer(pages,type)
  492. }
  493. public loadUi(ui_widge_list:widget_item_data[]){
  494. this.mGameRun.loadUILayer(ui_widge_list)
  495. }
  496. public loadTextSound(ui_widge_list:widget_item_data[]){
  497. this.mGameRun.loadTextSound(ui_widge_list)
  498. }
  499. public loadQuestion(ui_widge_list:widget_item_data[]){
  500. this.mGameRun.initQuestionList(ui_widge_list)
  501. }
  502. public initCountDownList(ui_widge_list:widget_item_data[]){
  503. this.mGameRun.initCountDownList(ui_widge_list)
  504. }
  505. public initTaskUi(data:task_data){
  506. this.mGameRun.initTaskUi(data)
  507. }
  508. public startGame(){
  509. taskServce.startFirstEvent()
  510. }
  511. public showCheck(call){
  512. this.mGameRun.showCheck(call)
  513. }
  514. public showLoadingLevel(){
  515. this.mGameRun.showLoadingLevel()
  516. }
  517. public hideLoadingLevel(){
  518. this.mGameRun.hideLoadingLevel()
  519. }
  520. public showUnLockView(lock_one_call,lock_all_one_day){
  521. this.mGameRun.showUnLockView(lock_one_call,lock_all_one_day)
  522. }
  523. public showUnLockLongStoryView(lock_one_call) {
  524. this.mGameRun.showUnLockLongStoryView(lock_one_call)
  525. }
  526. public static getWidgetList(scene_data:scene_item_data):widget_item_data[]{
  527. let temp:widget_item_data[] = []
  528. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  529. const data = scene_data.page_widget_list[index];
  530. if(data.type<=4 ||data.type==config.Widget_Type_List.CONTAINER_LAYER){
  531. temp.push(data)
  532. }
  533. }
  534. return temp;
  535. }
  536. public static getUIWidgetList(scene_data:scene_item_data){
  537. let temp:widget_item_data[] = []
  538. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  539. const data = scene_data.page_widget_list[index];
  540. if(data.type===config.Widget_Type_List.UI_TOP){
  541. if(data.att.top_data!=null&&data.att.top_data.top_ui_type!=config.top_view_type.__null){
  542. temp.push(data)
  543. }
  544. }
  545. }
  546. return temp;
  547. }
  548. public isCurScenePageCheckWidgetFinish(widget_id:number){
  549. return this.mGameRun.isCurScenePageCheckWidgetFinish(widget_id);
  550. }
  551. public isCurScenePageCheckWidgetShow(widget_id:number){
  552. return this.mGameRun.isCurScenePageCheckWidgetShow(widget_id);
  553. }
  554. public static getQuestionwidgetList(scene_data:scene_item_data){
  555. let temp:widget_item_data[] = []
  556. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  557. const data = scene_data.page_widget_list[index];
  558. if(data.type===config.Widget_Type_List.QUESTION_SELECT){
  559. if(data.att.question_select!=null){
  560. temp.push(data)
  561. }
  562. }
  563. }
  564. return temp;
  565. }
  566. public static getTextSoundWidgetList(scene_data:scene_item_data){
  567. let temp:widget_item_data[] = []
  568. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  569. const data = scene_data.page_widget_list[index];
  570. if(data.type===config.Widget_Type_List.TEXT_SOUND){
  571. if(data.att.text_sound_data!=null){
  572. temp.push(data)
  573. }
  574. }
  575. }
  576. return temp;
  577. }
  578. public static getCountDownWidgetList(scene_data:scene_item_data){
  579. let temp:widget_item_data[] = []
  580. for (let index = 0; index < scene_data.page_widget_list.length; index++) {
  581. const data = scene_data.page_widget_list[index];
  582. if(data.type===config.Widget_Type_List.COUNT_DOWN){
  583. if(data.att.count_down!=null){
  584. temp.push(data)
  585. }
  586. }
  587. }
  588. return temp;
  589. }
  590. public static getCacheSpriteFrameByName(node:Node,sfName:string){
  591. let sf = gameManager.res_map.get(sfName)
  592. if(sf==null){
  593. if(node!=null){
  594. // console.log('未有缓存的---sfName=',sfName)
  595. tools.loadUrl(sfName,node.getComponent(Sprite))
  596. }
  597. }
  598. return sf
  599. }
  600. public static getCacheSoundByName(sfName:string){
  601. // return control.mp3_cache.get(sfName)
  602. return gameManager.mp3_cache.get(sfName)
  603. }
  604. public static initUiBaseAtt(node:Node,att:ui_att_item){
  605. node.getComponent(UITransform).setContentSize(new Size(att.width,att.height))
  606. node.position = new Vec3(att.x,att.y);
  607. node.getComponent(Sprite).spriteFrame = gameManager.getCacheSpriteFrameByName(node,att.res)
  608. }
  609. onWidgetFinishEvent(widget_id:number, finish_event_item:event_item){
  610. taskServce.onWidgetFinishEvent(widget_id, finish_event_item)
  611. }
  612. onWidgetQuestionSelectFinishEvent(widget_id:number, score:number) {
  613. taskServce.onWidgetQuestionSelectFinishEvent(widget_id, score)
  614. }
  615. onWidgetDragOtherFinishEvent(widget_id:number, score:number) {
  616. taskServce.onWidgetDragOtherFinishEvent(widget_id, score)
  617. }
  618. onWidgetFailEvent(widget_id:number){
  619. taskServce.onWidgetFailEvent(widget_id)
  620. }
  621. onUiCloseEvent(event_id:number){
  622. taskServce.extEventByEventId(event_id)
  623. }
  624. onUiFinishEvent(event_id:number){
  625. taskServce.extEventByEventId(event_id)
  626. }
  627. onUiFailEvent(event_id:number){
  628. taskServce.extEventByEventId(event_id)
  629. }
  630. onUiHideEvent(widget_id:number) {
  631. taskServce.checkFinishZhaoXiJieWidget(widget_id)
  632. }
  633. onCountDownFailEvent(event_id:number){
  634. taskServce.extEventByEventId(event_id)
  635. }
  636. onStartCountDownEvent(event_id:number){
  637. taskServce.extEventByEventId(event_id)
  638. }
  639. exeEvent(event_id:number){
  640. taskServce.extEventByEventId(event_id)
  641. }
  642. exeSuccessTriggerEvent(trigger_event_id:number) {
  643. taskServce.exeSuccessTriggerEvent(trigger_event_id)
  644. }
  645. exeNextDelayEvent(event_item:event_item) {
  646. taskServce.exeNextDelayEvent(event_item)
  647. }
  648. showFindRuleTips(){
  649. this.mGameRun.showFindRuleTips()
  650. }
  651. showTips(){
  652. this.mGameRun.showTips()
  653. }
  654. showRule(){
  655. this.mGameRun.showRule()
  656. }
  657. getSceneManager(){
  658. return this.mSceneManager;
  659. }
  660. IsOpenRuleStatus(){
  661. return taskServce.guo_ju_qing_binding_event_id==-1;
  662. }
  663. //点击按钮音效
  664. public sys_click_button_music(){
  665. if(gameManager.sys_data!=null){
  666. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_button_music)
  667. }
  668. }
  669. // //失败吓人音效
  670. // public sys_fail_scary_music(){
  671. // if(gameManager.sys_data!=null){
  672. // this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_scary_music)
  673. // }
  674. // }
  675. //失败后攻击音效
  676. public sys_fail_attack_music(){
  677. if(gameManager.sys_data!=null){
  678. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_attack_music)
  679. }
  680. }
  681. //失败提示音效
  682. public sys_fail_prompt_music(){
  683. if(gameManager.sys_data!=null){
  684. this.mSysSound.playSound(gameManager.sys_data.content.sys_fail_prompt_music)
  685. }
  686. }
  687. //正确通关音效
  688. public sys_success_complete_music(){
  689. if(gameManager.sys_data!=null){
  690. this.mSysSound.playSound(gameManager.sys_data.content.sys_success_complete_music)
  691. }
  692. }
  693. //点击正确细节音效
  694. public sys_click_correct_detail_music(){
  695. if(gameManager.sys_data!=null){
  696. this.mSysSound.playSound(gameManager.sys_data.content.sys_click_correct_detail_music)
  697. }
  698. }
  699. public checkWidgetList(list:other_widget_finish_listen_item[],is_finish_status:boolean=false):other_widget_finish_listen_item[]{
  700. let event_list = [];
  701. for (let index = 0; index < list.length; index++) {
  702. const item = list[index];
  703. let isFinish = this.mGameRun.isCurScenePageCheckWidgetFinish(item.widget_id)
  704. // console.log('item.widget_id=',item.widget_id, 'isFinish=',isFinish)
  705. let event_id = item.event_id;
  706. if(event_id!=-1) {
  707. if(is_finish_status && isFinish) {
  708. event_list.push(item)
  709. }
  710. if(!is_finish_status && !isFinish) {
  711. event_list.push(item)
  712. }
  713. }
  714. }
  715. return event_list;
  716. }
  717. public static getUserUnlockLevesData():UserUnlockLevesData{
  718. if(gameManager.g_userUnlockLevesData == null) {
  719. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  720. }
  721. return gameManager.g_userUnlockLevesData;
  722. }
  723. public static setUserUnlockLevesData(data:any){
  724. if(gameManager.g_userUnlockLevesData == null) {
  725. gameManager.g_userUnlockLevesData = new UserUnlockLevesData()
  726. }
  727. if(data != null) {
  728. gameManager.g_userUnlockLevesData = data.content
  729. // console.log('g_userUnlockLevesData=',gameManager.g_userUnlockLevesData)
  730. }
  731. }
  732. public static LookVideoCallBack(call){
  733. if(call!=null){
  734. let ad_id = SdkUtil.getAdId(config.AD_TYPE.ADD_TIME)
  735. SdkUtil.showVideoAd(ad_id,(res)=>{
  736. if(res.isEnded){
  737. call()
  738. }
  739. // 统计-激励视频广告
  740. let level_id = gameManager.Singleton.getLevelData().id
  741. let collect_data = statisticsManager.get_collect_ads_data(level_id, res, config.STATISTICS_ACTION_TYPE.ADD_TIME)
  742. statisticsManager.request_collect_rewardVideoData(collect_data)
  743. })
  744. }
  745. }
  746. public getCurSceneLayerPage(){
  747. return this.mGameRun.getCurSceneLayerPage()
  748. }
  749. public static request_user_unlock_number_status(status = config.User_unlock_levels_number_status.GET, success_callback:any, fail_callback:any) {
  750. if(status != config.User_unlock_levels_number_status.GET) {
  751. gameManager.Singleton.showLoadingLevel()
  752. }
  753. http.run_post(http.user_unlock_number_status(),{'stype':status}, (err,data)=> {
  754. // console.log('err=',err,'status=',status,'解锁次数=',data)
  755. if(status != config.User_unlock_levels_number_status.GET) {
  756. gameManager.Singleton.hideLoadingLevel()
  757. }
  758. if(!err) {
  759. let _data = JSON.parse(data)
  760. if(_data.code==config.MSG_CODE.SUCCESS){
  761. gameManager.setUserUnlockLevesData(_data)
  762. success_callback(_data)
  763. } else{
  764. fail_callback()
  765. }
  766. } else {
  767. fail_callback()
  768. }
  769. })
  770. }
  771. }