ViewObject.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { ReveData } from "../util/CHttp";
  2. import CHttpEvent from "../util/CHttpEvent";
  3. import Main from "./Main";
  4. const {ccclass, property} = cc._decorator;
  5. @ccclass
  6. export default class ViewObject extends cc.Component implements CHttpEvent {
  7. public main:Main
  8. /**
  9. * 当前界面从那个界面创建过来
  10. * 用于返回上个界面
  11. */
  12. public prev:ViewObject;
  13. /**
  14. * 关闭回调
  15. */
  16. public closeCallback:()=>void;
  17. public setCloseCallback(closeCallback:()=>void){
  18. this.closeCallback = closeCallback
  19. }
  20. /**
  21. *
  22. * @param prev 父界面
  23. */
  24. public show(prev?:ViewObject){
  25. if(prev){
  26. this.prev = prev;
  27. this.prev.__close();
  28. }
  29. this.main.viewManage.popView(this.node);
  30. if(this.main && this.main.gameHttp){
  31. this.main.gameHttp.pushEvent(this);
  32. }
  33. }
  34. /**
  35. * 只是关闭界面,不销毁
  36. */
  37. public __close(){
  38. this.node.removeFromParent();
  39. if(this.closeCallback){
  40. this.closeCallback()
  41. }
  42. }
  43. /**
  44. * 退出销毁界面
  45. */
  46. public exitDistroy(){
  47. if(this.main && this.main.gameHttp){
  48. this.main.gameHttp.popEvent(this);
  49. }
  50. this.node.destroy();
  51. if(this.prev){
  52. //如果存在父界面将其显示出来
  53. this.prev.show();
  54. }
  55. if(this.closeCallback){
  56. this.closeCallback()
  57. }
  58. }
  59. /**
  60. * 销毁所有父界面
  61. */
  62. public __distroyAll(){
  63. if(this.main && this.main.gameHttp){
  64. this.main.gameHttp.popEvent(this);
  65. }
  66. if(this.prev && this.prev.isValid){
  67. this.prev.__distroyAll();
  68. }
  69. if(this.node.isValid){
  70. this.node.destroy();
  71. }
  72. if(this.closeCallback){
  73. this.closeCallback()
  74. }
  75. }
  76. /**
  77. * 监听网络
  78. * @param reveData
  79. */
  80. public httpEvent(reveData:ReveData){
  81. // cc.log('viewObject reve : ',this);
  82. }
  83. }