view_launch.ts 10 KB

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