PauseUI.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 = mk.audio.getSwitchMusic();
  58. this.node_music_off.active = !this.node_music_on.active
  59. }
  60. initEffectSwitchState() {
  61. this.node_effect_on.active = mk.audio.getSwitchEffect();
  62. this.node_effect_off.active = !this.node_effect_on.active;
  63. }
  64. initEvent() {
  65. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  66. this.node_musicSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  67. this.node_effectSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  68. this.node_restartBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  69. this.node_exitBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  70. }
  71. onClickBtn(event: cc.Event.EventTouch) {
  72. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  73. mk.audio.playEffect("button");
  74. switch (event.currentTarget) {
  75. case this.node_closeBtn:
  76. this.onClickClose();
  77. break;
  78. case this.node_musicSwitch:
  79. this.onClickMusicSwitch();
  80. break;
  81. case this.node_effectSwitch:
  82. this.onClickEffectSwitch();
  83. break;
  84. case this.node_exitBtn:
  85. this.onClickExitBtn();
  86. break;
  87. case this.node_restartBtn:
  88. this.onClickRestartBtn();
  89. break;
  90. }
  91. }
  92. onClickClose() {
  93. // this.node.active = false;
  94. console.log("点击关闭按钮", this.node.name);
  95. mk.ui.closePanel(this.node.name);
  96. }
  97. onClickMusicSwitch() {
  98. mk.audio.switchMusicFunc();
  99. this.initMsuicSwitchState();
  100. }
  101. onClickEffectSwitch() {
  102. mk.audio.switchEffectFunc();
  103. this.initEffectSwitchState();
  104. }
  105. onClickRestartBtn() {
  106. //GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击重新开始按钮");
  107. GamePlay.Inst.restart();
  108. mk.ui.closePanel(this.node.name);
  109. }
  110. onClickExitBtn() {
  111. GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击退出按钮");
  112. mk.ui.closePanel("PauseUI")
  113. GamePlay.Inst.restart(false);//退出不扣体力
  114. GamePlay.Inst.node.active = false;
  115. // let timeOut = setTimeout(()=>{
  116. // Main.Inst.node_start.active = true;
  117. // Main.Inst.node_game.active = false;
  118. // },2000)
  119. }
  120. }