InitLoadView.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import BasicView from "../../../Engine/Basic/BasicView";
  2. import { _EJsonRes } from "../../../Engine/Data/CommonDataType";
  3. import EventManager from "../../../Engine/Event/EventManager";
  4. import JsonResources from "../../../Engine/Resources/JsonResources";
  5. import LoadProgress from "../../../Engine/Component/View/LoadProgress";
  6. import { _EGameBehavior, ConstObject, _EGameJsonRes } from "../../Data/GameDataType";
  7. import { _IUserData } from "../../Data/User/UserConfig";
  8. import GameEventName from "../../Event/GameEventName";
  9. import { _IViewResConfig } from "../../../Engine/View/Data/ViewConfig";
  10. import GameAudioResData from "../../Game/Data/GameMusicResData";
  11. /**
  12. * 启动页
  13. */
  14. export default class InitLoadView extends BasicView {
  15. public static resPath: string = "InitLoadView";
  16. /**进度条 */
  17. private progress: fgui.GProgressBar;
  18. protected _initView(): void {
  19. this.progress = this.fgui.getChild("progress").asProgress;
  20. // 更新加载进度条
  21. EventManager.onEvent(GameEventName.Res.Res_LoadProgress, this, (_progress: number) => {
  22. this.progress.value = _progress*this.progress.max;
  23. });
  24. let load1 = false;
  25. let load2 = false;
  26. cc.assetManager.loadBundle("res/prefab", (err: Error, prefab: cc.AssetManager.Bundle) => {
  27. cc.assetManager.loadBundle("res/audio", (err: Error, audio: cc.AssetManager.Bundle) => {
  28. load1 = true;
  29. if (load1 == true && load2 == true) {
  30. this.laodComplete();
  31. }
  32. });
  33. });
  34. // 加载游戏资源
  35. {
  36. // 加载配置表
  37. let json: Array<string> = [];
  38. for (let name in _EJsonRes) {
  39. json.push(_EJsonRes[name]);
  40. }
  41. for (let name in _EGameJsonRes) {
  42. json.push(_EGameJsonRes[name]);
  43. }
  44. JsonResources.loadJsonResources(ConstObject.ResPath, json, 1/4, 0,
  45. () => {
  46. // 关闭事件监听
  47. EventManager.offEventByTarget(this);
  48. let viewResConfig: _IViewResConfig = JsonResources.getResources(_EJsonRes.ResGroup)["InitLoadView"];
  49. this.addComponentIntance(new LoadProgress(this.progress, (_progress: number) => {
  50. this.progress.getChild("progressText").asTextField.text = Math.round(_progress)+"%";
  51. }, () => {
  52. load2 = true;
  53. if (load1 == true && load2 == true) {
  54. this.laodComplete();
  55. }
  56. }, viewResConfig));
  57. }
  58. );
  59. }
  60. }
  61. protected _refreshView(): void {
  62. }
  63. protected _clearView(): void {
  64. }
  65. protected resize () {
  66. this.fgui.width = fgui.GRoot.inst.width;
  67. }
  68. private laodComplete (): void {
  69. EventManager.sendEvent(GameEventName.Audio.Audio_PlayMusic, GameAudioResData.BGM);
  70. EventManager.sendEvent(GameEventName.Behavior.Behavior_SetPreconditionData, _EGameBehavior.Hall, {initLoad: true});
  71. EventManager.sendEventByTargetID(GameEventName.Behavior.Behavior_EnterBehavior, ConstObject.GameFlowTreeID, _EGameBehavior.Gameing);
  72. }
  73. }