UIMgr.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * 界面相关的工具
  3. */
  4. require("UIInfo")
  5. const Proxy = require('Proxy');
  6. /**
  7. * 登录数据管理
  8. */
  9. let UIMgr = {
  10. //* ************* 初始化 ************* *//
  11. /**
  12. * 初始化
  13. *
  14. */
  15. init () {
  16. if (CC_EDITOR) {
  17. return;
  18. }
  19. this.UIRoots = {
  20. [window.JMC.Proxy.Main]:"Main",
  21. [window.JMC.Proxy.Navigation]:"Navigation",
  22. [window.JMC.Proxy.Toast]:"Toast",
  23. [window.JMC.Proxy.UI]:"UI",
  24. };
  25. },
  26. getUIRoot () {
  27. let curScene = cc.director.getScene();
  28. let root = curScene.getChildByName('Canvas').getChildByName("Root").getChildByName("UIRoot");
  29. return root;
  30. },
  31. open(type, param) {
  32. let prefabPath = 'edt_prefab/' + window.JMC.UIPath[type];
  33. this.showUI(prefabPath, param)
  34. },
  35. showUI(prefabPath, alertData, cb, cache = false) {
  36. G.LogUtils.warn('showAlert', prefabPath);
  37. let self = this;
  38. let temp = undefined;
  39. cc.loader.loadRes(prefabPath, cc.Prefab, (completedCount, totalCount, item)=>{
  40. temp = G.AppUtils.getLoadProgressInfo(temp, completedCount, totalCount);
  41. G.AppUtils.getSceneCtrl().updateLoadingProgress(temp.precent * 100, 100, item);
  42. }, (err, prefab) => {
  43. G.AppUtils.getSceneCtrl().updateLoadingProgress(100, 100, undefined);
  44. if (err) {
  45. G.AppUtils.getSceneCtrl().addToast('网络异常!');
  46. G.LogUtils.error('[showAlert]', err);
  47. if (cb) {
  48. cb(undefined, 'error', err);
  49. }
  50. return;
  51. }
  52. let node = cc.instantiate(prefab);
  53. if (cb) {
  54. cb(alert, 'willShow', undefined);
  55. }
  56. let uiRoot = self.getUIRoot();
  57. let proxy = node.getComponent(Proxy);
  58. if (proxy){
  59. uiRoot = uiRoot.getChildByName(self.UIRoots[proxy.type])
  60. }
  61. // let uiRoot = this.getUIRoot();
  62. // .getChildByName(this.UIRoots[type])
  63. let ret = self.pushUI(uiRoot, node);
  64. if (!ret) {
  65. return;
  66. }
  67. if (!cache) {
  68. cc.loader.releaseRes(prefabPath);
  69. }
  70. });
  71. },
  72. /**
  73. * 弹出指定弹框
  74. *
  75. * @author Pyden
  76. * @date 2019-03-22
  77. * @param {JMAlertBase} alert 弹框
  78. */
  79. pushUI (uiRoot, node) {
  80. if (!cc.isValid(node) || !cc.isValid(uiRoot)) {
  81. return false;
  82. }
  83. uiRoot.addChild(node);
  84. cc.game.emit('e_ui_push_alert', {node});
  85. return true;
  86. },
  87. }
  88. module.exports = UIMgr;