You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**
  2. * Copyright (c) 2014,www.easygame.org
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the easygame.org nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. var __reflect = (this && this.__reflect) || function (p, c, t) {
  28. p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
  29. };
  30. var __extends = this && this.__extends || function __extends(t, e) {
  31. function r() {
  32. this.constructor = t;
  33. }
  34. for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
  35. r.prototype = e.prototype, t.prototype = new r();
  36. };
  37. var Main = (function (_super) {
  38. __extends(Main, _super);
  39. function Main() {
  40. var _this = _super.call(this) || this;
  41. //RES资源全部下载完成
  42. _this.loadResAllComplete = false;
  43. //easy game的配置文件时候下载完成
  44. _this._isEasyGameOk = false; //游戏配置下载完毕
  45. _this._isSoundOk = false; //声音准备完毕
  46. _this._isProjectUIOk = false; //公用UI下载完毕
  47. _this._isCreateScene = false; //是否已创建场景
  48. _this._isLoadingViewOk = false; //view的loading是否准备好了
  49. _this._progressCalculate = null;
  50. _this._isViewEnter = false; //第一个加载的view是否已经准备完成
  51. _this.loadResAllComplete = false;
  52. _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
  53. return _this;
  54. }
  55. Main.prototype.onAddToStage = function (event) {
  56. //初始化全局数据,以便Heatbeat可以使用
  57. easy.GlobalSetting.initData();
  58. //初始化Resource资源加载库
  59. easy.ResManager.loadConfig(easy.GlobalSetting.CDN_RES + "loading_main.json", ["loading_main"], this.onResLoadingMianComplete, this);
  60. //下载loading view的内容
  61. easy.ResManager.loadConfig(easy.GlobalSetting.CDN_RES + "loading_view.json", ["loading_view"], this.onResLoadingViewComplete, this);
  62. easy.EventManager.addEventListener(easy.EventType.VIEW_ENTER, this.onHiddenloadingMain, this);
  63. };
  64. /**
  65. * loading view配置文件的加载完成
  66. * @param event
  67. */
  68. Main.prototype.onResLoadingViewComplete = function (event) {
  69. this._isLoadingViewOk = true;
  70. };
  71. /**
  72. * loading main配置文件的加载完成
  73. * @param event
  74. */
  75. Main.prototype.onResLoadingMianComplete = function (event) {
  76. //console.log("@Main onLoadingMianResourceLoadComplete=" + event.groupName);
  77. if (RES.isGroupLoaded("loading_main")) {
  78. //设置加载进度界面
  79. this.loadingMain = new modules.loadingProgressMainBar(); //loading main
  80. this.stage.addChild(this.loadingMain);
  81. this.loadingMain.width = easy.GlobalSetting.DISPLAY_WIDTH;
  82. this.loadingMain.height = easy.GlobalSetting.DISPLAY_HEIGHT;
  83. this.loadingMain.enter();
  84. //启动进度条计数
  85. this._progressCalculate = new easy.ProgressCalculate(10);
  86. easy.HeartBeat.addListener(this, this.onHbProgress, 2);
  87. //初始化Resource资源加载库
  88. easy.ResManager.loadConfig(easy.GlobalSetting.CDN_RES + "resource.json", ["group_easygame_config"], this.onResLoadGameConfigComplete, this);
  89. //提前加载Json数据,创建场景的时候,可能就需要用到数据了
  90. //modules.DataManager.loadJsonFile();
  91. //加载公用资源,如果设置有公用资源请打开此项
  92. //easy.ResManager.loadResFile("modules");
  93. //easy.EventManager.addEventListener(easy.EventType.PROJECT_RES_DOWNLOADED, this.onProjectResDownloaded, this);
  94. this._isProjectUIOk = true;
  95. }
  96. };
  97. /**
  98. * 控制进度条
  99. * @type {number}
  100. */
  101. Main.prototype.onHbProgress = function () {
  102. var progress = this._progressCalculate.progress();
  103. //console.log("progress=" + progress);
  104. this._progressCalculate._progressSpeedUp = (this.loadResAllComplete && this._isProjectUIOk && this._isViewEnter);
  105. this.loadingMain.setProgress(progress, 100);
  106. if (this.loadResAllComplete && !this._isCreateScene && this._isLoadingViewOk)
  107. this.createScene();
  108. if (progress == 100) {
  109. easy.HeartBeat.removeListener(this, this.onHbProgress);
  110. this.removeLoadingUI();
  111. }
  112. };
  113. /**
  114. * 将loading页面移除,开始创建场景
  115. */
  116. Main.prototype.removeLoadingUI = function () {
  117. if (this.loadingMain) {
  118. this.loadingMain.outer();
  119. }
  120. };
  121. /**
  122. * 公用资源加载完成的通知
  123. * @param myEvent
  124. */
  125. Main.prototype.onProjectResDownloaded = function (myEvent) {
  126. easy.EventManager.removeEventListener(easy.EventType.PROJECT_RES_DOWNLOADED, this.onProjectResDownloaded, this);
  127. this._isProjectUIOk = true;
  128. this.checkAllResourceLoaded();
  129. };
  130. /**
  131. * preload资源组加载完成
  132. */
  133. Main.prototype.onResLoadGameConfigComplete = function (event) {
  134. //console.log("@Main onResourceLoadComplete=" + event.groupName);
  135. if (RES.isGroupLoaded("group_easygame_config")) {
  136. this._isEasyGameOk = true;
  137. //下载全部完成
  138. //设置帧频
  139. easy.GlobalSetting.FRAME_RATE = 60;
  140. //EasyGame初始化
  141. easy.EasyGame.init();
  142. //设置界面切换的loading,view的loading和Win的loading可以设置成不一样的类
  143. easy.ViewManager.defaultLoadingClass = easy.DefaultLoadingView; //loading view
  144. easy.PopupManager.defaultLoadingClass = easy.DefaultLoadingView; //loading view
  145. }
  146. this.checkAllResourceLoaded();
  147. };
  148. /**
  149. * 声音加载完成
  150. */
  151. Main.prototype.onResLoadSoundComplete = function (event) {
  152. //console.log("@Main onResourceLoadComplete=" + event.groupName);
  153. if (RES.isGroupLoaded("sound")) {
  154. this._isSoundOk = true;
  155. //声音加载完毕,播放背景音文件
  156. easy.Sound.play("sound_bg", 0, 0);
  157. }
  158. };
  159. /**
  160. * 检测是否所有需要的资源全部加载完成
  161. * 下载全部完成的情况下设置loadAllComplete标志,等待loading的全部反应
  162. */
  163. Main.prototype.checkAllResourceLoaded = function () {
  164. if (this._isEasyGameOk && this._isProjectUIOk) {
  165. //创建场景
  166. if (easy.GlobalSetting.APP_STORAGE == easy.GlobalSetting.STORAGE_NET || easy.GlobalSetting.APP_STORAGE == easy.GlobalSetting.STORAGE_LOCAL_NET) {
  167. this.loadDataFromNet();
  168. }
  169. else {
  170. this.loadResAllComplete = true;
  171. }
  172. }
  173. };
  174. /**
  175. * 隐藏加载进度条
  176. */
  177. Main.prototype.onHiddenloadingMain = function (myEvent) {
  178. this._isViewEnter = true;
  179. easy.EventManager.removeEventListener(easy.EventType.VIEW_ENTER, this.onHiddenloadingMain, this);
  180. //声音加载
  181. easy.ResManager.addGroupCompleteListener("sound", this.onResLoadSoundComplete, this);
  182. };
  183. /**
  184. * 需要从网络初始化信息
  185. */
  186. Main.prototype.loadDataFromNet = function () {
  187. //TODO 这里填写需要网络加载的信息,完成后,请调用loadDataFromNetComplete()方法,加载主场景
  188. //this.loadDataFromNetComplete();
  189. };
  190. /**
  191. * 从网络加载初始化信息完成
  192. */
  193. Main.prototype.loadDataFromNetComplete = function () {
  194. //TODO 网络信息的初始化,请在这里填写
  195. this.loadResAllComplete = true;
  196. };
  197. /**
  198. * 创建场景
  199. */
  200. Main.prototype.createScene = function () {
  201. if (this._isCreateScene)
  202. return; //防止多次创建
  203. this._isCreateScene = true;
  204. //console.log("main.createScene")
  205. //TODO 切换到第一个主场景
  206. var getStorage = localStorage.getItem('page');
  207. var durationTime = parseInt(localStorage.getItem('time')) + 300000;
  208. var getTime = new Date().getTime();
  209. console.log(new Date().getTime());
  210. console.log(durationTime);
  211. console.log(getStorage);
  212. if (getStorage == "10" && getTime <= durationTime) {
  213. localStorage.setItem('page', "");
  214. easy.ViewManager.show(modules.index10View, null, false);
  215. }
  216. else {
  217. easy.ViewManager.show(modules.index1View, null, false);
  218. }
  219. //TODO 提前预设空闲下载,加快后续的模块载入速度
  220. easy.ResManager.addIdleDownload(modules.index1View);
  221. easy.ResManager.addIdleDownload(modules.index2View);
  222. easy.ResManager.addIdleDownload(modules.index3View);
  223. easy.ResManager.addIdleDownload(modules.index4View);
  224. easy.ResManager.addIdleDownload(modules.index5View);
  225. easy.ResManager.addIdleDownload(modules.index6View);
  226. easy.ResManager.addIdleDownload(modules.index7View);
  227. easy.ResManager.addIdleDownload(modules.index8View);
  228. easy.ResManager.addIdleDownload(modules.index9View);
  229. easy.ResManager.addIdleDownload(modules.index10View);
  230. easy.ResManager.addIdleDownload(modules.index11View);
  231. easy.ResManager.addIdleDownload(modules.index12View);
  232. easy.ResManager.addIdleDownload(modules.index13View);
  233. easy.ResManager.addIdleDownload(modules.index14View);
  234. //TODO 动画的预加载方式
  235. //easy.AnimateManager.getAnimateData("need_to_download_name");
  236. };
  237. return Main;
  238. }(egret.DisplayObjectContainer));
  239. __reflect(Main.prototype, "Main");