PauseUI.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. }
  37. start() {
  38. mk.ad.showNativeAd(4);
  39. this.node_bg.setContentSize(cc.winSize.width, cc.winSize.height);
  40. this.initEvent();
  41. }
  42. onEnable() {
  43. GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "进入暂停界面");
  44. //显示广告
  45. // AdMgr.Inst.showNativeAd(4, true);
  46. this.initMsuicSwitchState();
  47. this.initEffectSwitchState();
  48. }
  49. onDisable() {
  50. //显示广告
  51. // AdMgr.Inst.destroyNativeAd();
  52. }
  53. // update (dt) {}
  54. init() {
  55. //this.initSwitchState();
  56. }
  57. //初始化
  58. initMsuicSwitchState() {
  59. this.node_music_on.active = mk.audio.getSwitchMusic();
  60. this.node_music_off.active = !this.node_music_on.active
  61. }
  62. initEffectSwitchState() {
  63. this.node_effect_on.active = mk.audio.getSwitchEffect();
  64. this.node_effect_off.active = !this.node_effect_on.active;
  65. }
  66. initEvent() {
  67. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  68. this.node_musicSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  69. this.node_effectSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  70. this.node_restartBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  71. this.node_exitBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  72. }
  73. onClickBtn(event: cc.Event.EventTouch) {
  74. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  75. mk.audio.playEffect("button");
  76. switch (event.currentTarget) {
  77. case this.node_closeBtn:
  78. this.onClickClose();
  79. break;
  80. case this.node_musicSwitch:
  81. this.onClickMusicSwitch();
  82. break;
  83. case this.node_effectSwitch:
  84. this.onClickEffectSwitch();
  85. break;
  86. case this.node_exitBtn:
  87. this.onClickExitBtn();
  88. break;
  89. case this.node_restartBtn:
  90. this.onClickRestartBtn();
  91. break;
  92. }
  93. }
  94. onClickClose() {
  95. // this.node.active = false;
  96. console.log("点击关闭按钮", this.node.name);
  97. mk.ui.closePanel(this.node.name);
  98. mk.ad.destroyNativeAd();
  99. }
  100. onClickMusicSwitch() {
  101. mk.audio.switchMusicFunc();
  102. this.initMsuicSwitchState();
  103. }
  104. onClickEffectSwitch() {
  105. mk.audio.switchEffectFunc();
  106. this.initEffectSwitchState();
  107. }
  108. onClickRestartBtn() {
  109. //GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击重新开始按钮");
  110. GamePlay.Inst.restart();
  111. mk.ui.closePanel(this.node.name);
  112. }
  113. onClickExitBtn() {
  114. GameMgr.Inst.sendEvent(UI_NAME.PauseUI, "点击退出按钮");
  115. mk.ui.closePanel("PauseUI")
  116. GamePlay.Inst.restart(false);//退出不扣体力
  117. GamePlay.Inst.node.active = false;
  118. // let timeOut = setTimeout(()=>{
  119. // Main.Inst.node_start.active = true;
  120. // Main.Inst.node_game.active = false;
  121. // },2000)
  122. mk.ad.destroyNativeAd();
  123. }
  124. }