ViewManager.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import MainGameView from "./MainGameView";
  2. import InGameView from "./InGameView";
  3. export enum ViewType{MainView,IngameView};
  4. export interface SC{
  5. Show();
  6. Close();
  7. }
  8. export class ViewManager{
  9. private static ins:ViewManager;
  10. public showexportview:number = 0;
  11. private popViewDic:[any][any] = [];
  12. public ViewSprite:Laya.Sprite = new Laya.Sprite();
  13. public OtherViewSprite:Laya.Sprite = new Laya.Sprite();
  14. public curView:any;
  15. constructor(){
  16. ViewManager.ins = this;
  17. Laya.stage.addChild(this.ViewSprite);
  18. Laya.stage.addChild(this.OtherViewSprite);
  19. }
  20. public static get Instance():ViewManager{
  21. if(ViewManager.ins){
  22. return ViewManager.ins
  23. }
  24. else{
  25. return new ViewManager();
  26. }
  27. }
  28. ShowView(_viewtype:ViewType,data = null){
  29. if(this.curView != null){
  30. this.curView.Close();
  31. this.curView.destroy();
  32. this.curView.removeSelf();
  33. }
  34. // GuangGao.Clear();
  35. this.curView = this.CreateView(_viewtype);
  36. this.curView.name = ViewType[_viewtype];
  37. this.ViewSprite.addChild(this.curView);
  38. this.curView.Show(data);
  39. }
  40. CloseView(){
  41. if(this.curView != null){
  42. this.curView.Close();
  43. this.curView.destroy();
  44. this.curView.removeSelf();
  45. }
  46. }
  47. //全屏导出页
  48. public OpenPopView(viewType:ViewType,data:any = null)
  49. {
  50. // GuangGao.Clear();
  51. var popView;
  52. if(this.popViewDic[viewType])
  53. {
  54. popView = this.popViewDic[viewType];
  55. this.OtherViewSprite.setChildIndex(popView,this.OtherViewSprite.numChildren - 1);
  56. popView.visible = true;
  57. }
  58. else
  59. {
  60. popView = this.CreateView(viewType);
  61. this.OtherViewSprite.addChild(popView);
  62. this.popViewDic[viewType] = popView;
  63. }
  64. this.showexportview = 1;
  65. popView.OnOpen(data);
  66. }
  67. public ClosePopView(viewType:ViewType)
  68. {
  69. var popView = this.popViewDic[viewType];
  70. if(popView == null){
  71. return;
  72. }
  73. // GuangGao.Clear();
  74. popView.OnHide();
  75. popView.visible = false;
  76. this.showexportview = 0;
  77. }
  78. ClearPopViews()
  79. {
  80. // GuangGao.Clear();
  81. }
  82. CreateView(_viewtype:ViewType){
  83. switch (_viewtype) {
  84. case ViewType.MainView:
  85. return new MainGameView();
  86. case ViewType.IngameView:
  87. return new InGameView();
  88. }
  89. return null;
  90. }
  91. }