PauseView.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import BasicView from "../../../Engine/Basic/BasicView";
  2. import { _ECommonState, _EJsonRes, _IViewConfig } from "../../../Engine/Data/CommonDataType";
  3. import EventManager from "../../../Engine/Event/EventManager";
  4. import TimeManager from "../../../Engine/Time/TimeManager";
  5. import Tool from "../../../Engine/Tool/Tool";
  6. import GameManager from "../../Game/GameManager";
  7. import { ConstObject } from "../../Data/GameDataType";
  8. import GameMusicResData from "../../Game/Data/GameMusicResData";
  9. import GameEventName from "../../Event/GameEventName";
  10. import SDKManager from "../../SDK/SDKManager";
  11. import GameView from "../GameView/GameView";
  12. import HintView from "../HintView/HintView";
  13. import JsonResources from "../../../Engine/Resources/JsonResources";
  14. /**
  15. * 暂停页
  16. */
  17. export default class PauseView extends BasicView {
  18. public static resPath: string = "PauseView";
  19. protected _initView(): void {
  20. ConstObject.GameState = _ECommonState.Pause;
  21. TimeManager.pause();
  22. let resetButton: fgui.GComponent = this.fgui.getChild("resetButton").asCom;
  23. Tool.Tool2D.Button.addEvent(resetButton, {
  24. "touchend": () => {
  25. this.onReset();
  26. }
  27. }, this.fgui.id, 0.9, 0.9, 0, false);
  28. let continueButton: fgui.GComponent = this.fgui.getChild("continueButton").asCom;
  29. Tool.Tool2D.Button.addEvent(continueButton, {
  30. "touchend": () => {
  31. this.onContinue();
  32. }
  33. }, this.fgui.id, 0.9, 0.9, 0, false);
  34. let quitButton: fgui.GComponent = this.fgui.getChild("quitButton").asCom;
  35. Tool.Tool2D.Button.addEvent(quitButton, {
  36. "touchend": () => {
  37. this.onQuit();
  38. }
  39. }, this.fgui.id, 0.9, 0.9, 0, false);
  40. SDKManager.addButton([
  41. {
  42. button: continueButton,
  43. color: [
  44. cc.Color.BLACK,
  45. cc.Color.BLACK,
  46. ],
  47. callback: () => {
  48. if (ConstObject.FirstEnter == false) {
  49. this.onContinue();
  50. }
  51. }
  52. },
  53. {
  54. button: resetButton,
  55. color: [
  56. cc.Color.BLACK,
  57. cc.Color.BLACK,
  58. ],
  59. callback: () => {
  60. if (ConstObject.FirstEnter == false) {
  61. this.onReset();
  62. }
  63. }
  64. },
  65. {
  66. button: quitButton,
  67. color: [
  68. cc.Color.BLACK,
  69. cc.Color.BLACK,
  70. ],
  71. callback: () => {
  72. if (ConstObject.FirstEnter == false) {
  73. this.onQuit();
  74. }
  75. }
  76. }
  77. ]);
  78. EventManager.sendEvent(GameEventName.Music.Music_PauseSound, null);
  79. if (ConstObject.FirstEnter == true) {
  80. this.fgui.node.zIndex = -1000;
  81. // this.onContinue();
  82. EventManager.onEvent(GameEventName.SDK.SDK_Confirm, this, this.onContinue, 1);
  83. }
  84. EventManager.sendEvent(GameEventName.View.View_ShowView, HintView);
  85. }
  86. protected _refreshView(): void {
  87. let viewConfig: _IViewConfig = JsonResources.getResources(_EJsonRes.ViewConfig);
  88. this.fgui.node.zIndex = viewConfig.ZIndex[PauseView.resPath] as any;
  89. }
  90. protected _clearView(): void {
  91. TimeManager.resume();
  92. SDKManager.removeButton();
  93. EventManager.sendEvent(GameEventName.Music.Music_ResumeSound, null);
  94. EventManager.sendEvent(GameEventName.View.View_DestroyView, HintView);
  95. if (ConstObject.FirstEnter == false) {
  96. ConstObject.GameState = _ECommonState.Runing;
  97. }
  98. }
  99. protected resize () {
  100. this.fgui.width = fgui.GRoot.inst.width;
  101. }
  102. private onReset (): void {
  103. ConstObject.GameState = _ECommonState.None;
  104. EventManager.sendEvent(GameEventName.Music.Music_PlaySound, GameMusicResData.ClickButton);
  105. EventManager.sendEvent(GameEventName.View.View_DestroyView, PauseView);
  106. EventManager.sendEvent(GameEventName.View.View_ShowView, GameView);
  107. GameManager.setGameView(GameEventName.View.View_ShowView);
  108. }
  109. private onContinue (): void {
  110. if (ConstObject.FirstEnter == false) {
  111. EventManager.sendEvent(GameEventName.Music.Music_PlaySound, GameMusicResData.ClickButton);
  112. }
  113. EventManager.sendEvent(GameEventName.View.View_DestroyView, PauseView);
  114. }
  115. private onQuit (): void {
  116. EventManager.sendEvent(GameEventName.Music.Music_PlaySound, GameMusicResData.ClickButton);
  117. EventManager.sendEvent(GameEventName.Game_QuitGame);
  118. }
  119. }