view_launch.ts 11 KB

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