view_launch.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.1)
  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. }
  132. if(progress_number==50){
  133. this.isStop = true;
  134. let all = 0;
  135. const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG);
  136. let item = gameManager.get_cur_level_by_categoryid(element.id);
  137. let key = `${element.id}_${item.level}`;
  138. let str = StorageManager.instance.getGlobalData(key);
  139. if(str===""||str===undefined||str===null){
  140. all++;
  141. gameManager.loadLevelImg(element.id,item.level,()=>{
  142. this.isStop = false;
  143. })
  144. }
  145. if(all===0){
  146. this.isStop = false;
  147. }
  148. }
  149. if(progress_number==60){
  150. this.isStop = true;
  151. let all = 0;
  152. const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.YI_QI_ZHAO_CHA);
  153. let item = gameManager.get_cur_level_by_categoryid(element.id);
  154. let key = `${element.id}_${item.level}`;
  155. let str = StorageManager.instance.getGlobalData(key);
  156. if(str===""||str===undefined||str===null){
  157. all++;
  158. gameManager.loadLevelImg(element.id,item.level,()=>{
  159. this.isStop = false;
  160. })
  161. }
  162. if(all===0){
  163. this.isStop = false;
  164. }
  165. }
  166. if(progress_number==70){
  167. this.isStop = true;
  168. let temp_count = 0;
  169. let call = ()=>{
  170. temp_count++;
  171. if(temp_count>=4){
  172. this.isStop = false;
  173. }
  174. }
  175. gameManager.loadSysMusic(call);
  176. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE,call);
  177. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.YI_QI_ZHAO_CHA,call);
  178. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG,call);
  179. }
  180. if(progress_number==80){
  181. self.isStop = true;
  182. http.get(config.static_url.user_test,(err,data)=>{
  183. if(!err){
  184. self.isStop = false;
  185. let _data = JSON.parse(data);
  186. if(_data.code==config.MSG_CODE.SUCCESS){
  187. gameManager.init_test_user_list( _data.content);
  188. }
  189. }
  190. })
  191. }
  192. if(progress_number>=100){
  193. this.finishLoading();
  194. this.unschedule(this.setupLoading)
  195. progress_number = 100;
  196. }
  197. this.lab_progress.getComponent(Label).string = `加载中 ${progress_number} %...`;
  198. this.progress.getComponent(ProgressBar).progress += 0.05;
  199. }
  200. finishLoading(){
  201. console.log("finish");
  202. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_BACK_HOME_VIEW);
  203. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER);
  204. this.node.removeFromParent();
  205. }
  206. }