view_launch.ts 9.8 KB

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