PauseView.ts 5.1 KB

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