PauseUI.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import GamePlay from "../GamePlay";
  8. import PlayerConst from "../data/PlayerConst";
  9. import EffectMgr from "../mgr/EffectMgr";
  10. import GameMgr, { UI_NAME } from "../mgr/GameMgr";
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class PauseUI extends cc.Component {
  14. @property(cc.Node)
  15. node_bg: cc.Node = null;
  16. @property(cc.Node)
  17. node_closeBtn: cc.Node = null;
  18. @property(cc.Node)
  19. node_musicSwitch: cc.Node = null;
  20. @property(cc.Node)
  21. node_music_on: cc.Node = null;
  22. @property(cc.Node)
  23. node_music_off: cc.Node = null;
  24. @property(cc.Node)
  25. node_effectSwitch: cc.Node = null;
  26. @property(cc.Node)
  27. node_effect_on: cc.Node = null;
  28. @property(cc.Node)
  29. node_effect_off: cc.Node = null;
  30. @property(cc.Node)
  31. node_restartBtn: cc.Node = null;
  32. @property(cc.Node)
  33. node_exitBtn: cc.Node = null;
  34. // LIFE-CYCLE CALLBACKS:
  35. // onLoad () {}
  36. start() {
  37. this.node_bg.setContentSize(cc.winSize.width, cc.winSize.height);
  38. this.initEvent();
  39. }
  40. onEnable() {
  41. GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "进入暂停界面");
  42. //显示广告
  43. // AdMgr.Inst.showNativeAd(4, true);
  44. this.initMsuicSwitchState();
  45. this.initEffectSwitchState();
  46. }
  47. onDisable() {
  48. //显示广告
  49. // AdMgr.Inst.destroyNativeAd();
  50. }
  51. // update (dt) {}
  52. init() {
  53. //this.initSwitchState();
  54. }
  55. //初始化
  56. initMsuicSwitchState() {
  57. // this.node_music_on.active = AudioMgr.Inst.getSwitchMusic();
  58. // this.node_music_off.active = !this.node_music_on.active
  59. }
  60. initEffectSwitchState() {
  61. mk.console.log("初始化开关!!!!!!!!!!!!!!!")
  62. // this.node_effect_on.active = AudioMgr.Inst.getSwitchEffect();
  63. // this.node_effect_off.active = !this.node_effect_on.active;
  64. }
  65. initEvent() {
  66. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  67. this.node_musicSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  68. this.node_effectSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  69. this.node_restartBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  70. this.node_exitBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  71. }
  72. onClickBtn(event: cc.Event.EventTouch) {
  73. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  74. mk.audio.playEffect("ef_button_click");
  75. switch (event.currentTarget) {
  76. case this.node_closeBtn:
  77. this.onClickClose();
  78. break;
  79. case this.node_musicSwitch:
  80. this.onClickMusicSwitch();
  81. break;
  82. case this.node_effectSwitch:
  83. this.onClickEffectSwitch();
  84. break;
  85. case this.node_exitBtn:
  86. this.onClickExitBtn();
  87. break;
  88. case this.node_restartBtn:
  89. this.onClickRestartBtn();
  90. break;
  91. }
  92. }
  93. onClickClose() {
  94. // this.node.active = false;
  95. console.log("点击关闭按钮", this.node.name);
  96. mk.ui.closePanel(this.node.name);
  97. }
  98. onClickMusicSwitch() {
  99. // AudioMgr.Inst.turnSwitchMusic();
  100. // this.initMsuicSwitchState();
  101. }
  102. onClickEffectSwitch() {
  103. // AudioMgr.Inst.turnSwitchEffect();
  104. // this.initEffectSwitchState();
  105. }
  106. onClickRestartBtn() {
  107. GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击重新开始按钮");
  108. if (PlayerConst.energyNum <= 0) {
  109. EffectMgr.Inst.addTip("体力不足,请补充体力");
  110. // this.node.active = false;
  111. mk.ui.closePanel("PauseUI");
  112. return;
  113. }
  114. GamePlay.Inst.restart();
  115. // this.node.active = false;
  116. mk.ui.closePanel(this.node.name);
  117. }
  118. onClickExitBtn() {
  119. GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击退出按钮");
  120. mk.ui.closePanel("PauseUI")
  121. GamePlay.Inst.restart(false);//退出不扣体力
  122. GamePlay.Inst.node.active = false;
  123. // let timeOut = setTimeout(()=>{
  124. // Main.Inst.node_start.active = true;
  125. // Main.Inst.node_game.active = false;
  126. // },2000)
  127. }
  128. }