view_launch.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import { _decorator, Button, Component, Label, log, Node, ProgressBar, sys } from 'cc';
  2. import { http } from '../http/http';
  3. import { config } from '../config';
  4. import { gameManager } from '../gameManager';
  5. import { ClientEvent } from '../framework/clientEvent';
  6. import { StorageManager } from '../framework/storageManager';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('launch_view')
  9. export class launch_view extends Component {
  10. @property(Node) progress;
  11. @property(Node) lab_progress;
  12. private isStop = false;
  13. private PageList = [null,1,1,1];
  14. start() {
  15. this.progress.getComponent(ProgressBar).progress = 0;
  16. // this.Interval_id=setInterval(this.setupLoading.bind(this),200);
  17. gameManager.havNoAllAd = config.hav_no_allAd
  18. this.schedule(this.setupLoading,0.05)
  19. }
  20. setupLoading(){
  21. let self = this;
  22. let progress_number = Math.floor(this.progress.getComponent(ProgressBar).progress *100);
  23. if(self.isStop){
  24. return;
  25. }
  26. if(progress_number==10){
  27. self.isStop = true;
  28. http.get(config.static_url.category,(err,data)=>{
  29. if(!err){
  30. self.isStop = false;
  31. let _data = JSON.parse(data);
  32. if(_data.code==config.MSG_CODE.SUCCESS){
  33. gameManager.set_server_play_list_data( _data.content);
  34. }
  35. }
  36. })
  37. }
  38. if(progress_number==20){
  39. this.isStop = true;
  40. let login_call_back = ()=>{
  41. http.post(config.api_url.login,formData,(err,data)=>{
  42. if(!err){
  43. let _data = JSON.parse(data);
  44. // console.log("config.api_url.login",data)
  45. if(_data.code==config.MSG_CODE.SUCCESS){
  46. gameManager.set_server_user_data(_data.content)
  47. this.isStop = false;
  48. }
  49. return
  50. }
  51. })
  52. }
  53. let formData = null;
  54. let user_id =gameManager.getUserId();
  55. if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME){
  56. if(user_id==""||user_id==null||user_id==undefined){
  57. console.log("本地没有数据")
  58. tt.login({
  59. force: true,
  60. success(res) {
  61. let code = res.code;
  62. let anonymousCode = res.anonymousCode;
  63. console.log(`login 调用成功${res.code} ${res.anonymousCode}`);
  64. // console.log("code==",code);
  65. // console.log("anonymousCode==",anonymousCode);
  66. http.post(config.api_url.get_open_id,{"code":code,"anonymous_code":anonymousCode},(err,data)=>{
  67. if(!err){
  68. let _data = JSON.parse(data);
  69. if(_data.code==config.MSG_CODE.SUCCESS){
  70. gameManager.setUserId( _data.content.openid)
  71. // StorageManager.instance.setUserId(_data.content.openid);
  72. formData = {"openid":gameManager.getUserId(),"avatarUrl": ""}
  73. login_call_back();
  74. // console.log("_data.content.data.openid",_data.content.openid)
  75. }
  76. return
  77. }
  78. })
  79. },
  80. fail(res) {
  81. console.log(`login 调用失败`);
  82. },
  83. });
  84. }else{
  85. console.log("本地有数据")
  86. formData = {"openid":gameManager.getUserId(),"avatarUrl": ""}
  87. login_call_back();
  88. }
  89. }else{
  90. formData = new FormData();
  91. formData.append("openid", "123");
  92. formData.append("avatarUrl", "");
  93. login_call_back();
  94. }
  95. }
  96. if(progress_number===30){
  97. if(gameManager.userInfo.unlock_levels==""){
  98. gameManager.init_unlock_levels();
  99. this.isStop = true;
  100. let form_Data = null;
  101. if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME){
  102. form_Data = {"coin": gameManager.userInfo.coin+"","unlock_levels": gameManager.get_unlock_levels()}
  103. }else{
  104. form_Data = new FormData();
  105. form_Data.append("coin", gameManager.userInfo.coin+"");
  106. form_Data.append("unlock_levels", gameManager.get_unlock_levels());
  107. }
  108. http.post(config.api_url.sync_data,form_Data,(_err,c_data)=>{
  109. console.log("c__data _err:",_err)
  110. if(!_err){
  111. let c__data = JSON.parse(c_data);
  112. console.log("c__data",c__data)
  113. if(c__data.code==config.MSG_CODE.SUCCESS){
  114. this.isStop = false;
  115. }
  116. }
  117. })
  118. }else{
  119. gameManager.update_unlock_levels()
  120. }
  121. }
  122. if(progress_number==40){
  123. // this.isStop = true;
  124. // let all = 0;
  125. // const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE);
  126. // let item = gameManager.get_cur_level_by_categoryid(element.id);
  127. // let key = `${element.id}_${item.level}`;
  128. // let str = StorageManager.instance.getGlobalData(key);
  129. // if(str===""||str===undefined||str===null){
  130. // all++;
  131. // gameManager.loadLevelImg(element.id,item.level,()=>{
  132. // this.isStop = false;
  133. // })
  134. // }
  135. // if(all===0){
  136. // this.isStop = false;
  137. // }
  138. // gameManager.loadLevelImg(element.id,item.level,()=>{
  139. // this.isStop = false;
  140. // })
  141. }
  142. if(progress_number==50){
  143. this.isStop = true;
  144. let all = 0;
  145. const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG);
  146. let item = gameManager.get_cur_level_by_categoryid(element.id);
  147. // let key = `${element.id}_${item.level}`;
  148. // let str = StorageManager.instance.getGlobalData(key);
  149. // if(str===""||str===undefined||str===null){
  150. // all++;
  151. // gameManager.loadLevelImg(element.id,item.level,()=>{
  152. // this.isStop = false;
  153. // })
  154. // }
  155. // if(all===0){
  156. // this.isStop = false;
  157. // }
  158. gameManager.loadLevelImg(element.id,item.level,()=>{
  159. this.isStop = false;
  160. })
  161. }
  162. if(progress_number==60){
  163. this.isStop = true;
  164. let all = 0;
  165. const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.YI_QI_ZHAO_CHA);
  166. let item = gameManager.get_cur_level_by_categoryid(element.id);
  167. // let key = `${element.id}_${item.level}`;
  168. // let str = StorageManager.instance.getGlobalData(key);
  169. // if(str===""||str===undefined||str===null){
  170. // all++;
  171. // gameManager.loadLevelImg(element.id,item.level,()=>{
  172. // this.isStop = false;
  173. // })
  174. // }
  175. // if(all===0){
  176. // this.isStop = false;
  177. // }
  178. gameManager.loadLevelImg(element.id,item.level,()=>{
  179. this.isStop = false;
  180. })
  181. }
  182. if(progress_number==70){
  183. this.isStop = true;
  184. let call = ()=>{
  185. this.isStop = false;
  186. }
  187. gameManager.loadSysMusic(call);
  188. }
  189. if(progress_number==75){
  190. this.isStop = true;
  191. let call = ()=>{
  192. this.isStop = false;
  193. }
  194. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.YI_QI_ZHAO_CHA,call);
  195. }
  196. if(progress_number==80){
  197. self.isStop = true;
  198. http.get(config.static_url.user_test,(err,data)=>{
  199. if(!err){
  200. self.isStop = false;
  201. let _data = JSON.parse(data);
  202. if(_data.code==config.MSG_CODE.SUCCESS){
  203. gameManager.init_test_user_list( _data.content);
  204. }
  205. }
  206. })
  207. }
  208. if(progress_number==85){
  209. this.isStop = true;
  210. let call = ()=>{
  211. this.isStop = false;
  212. }
  213. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE,call);
  214. }
  215. if(progress_number==85){
  216. this.isStop = true;
  217. let call = ()=>{
  218. this.isStop = false;
  219. }
  220. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG,call);
  221. }
  222. if(progress_number==90){
  223. this.isStop = true;
  224. let call = ()=>{
  225. this.isStop = false;
  226. }
  227. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.YI_QI_ZHAO_CHA,call);
  228. }
  229. if(progress_number>=100){
  230. this.finishLoading();
  231. this.unschedule(this.setupLoading)
  232. progress_number = 100;
  233. gameManager.isFinishLoad = true;
  234. }
  235. this.lab_progress.getComponent(Label).string = `加载中... ${progress_number} %`;
  236. this.progress.getComponent(ProgressBar).progress += 0.025;
  237. }
  238. finishLoading(){
  239. console.log("finish");
  240. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_BACK_HOME_VIEW);
  241. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER);
  242. this.node.removeFromParent();
  243. }
  244. }