PauseUI.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * 游戏内暂停
  3. */
  4. import GamePlay from "../GamePlay";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class PauseUI extends cc.Component {
  8. @property(cc.Node)
  9. node_bg: cc.Node = null;
  10. @property(cc.Node)
  11. node_closeBtn: cc.Node = null;
  12. @property(cc.Node)
  13. node_musicSwitch: cc.Node = null;
  14. @property(cc.Node)
  15. node_music_on: cc.Node = null;
  16. @property(cc.Node)
  17. node_music_off: cc.Node = null;
  18. @property(cc.Node)
  19. node_effectSwitch: cc.Node = null;
  20. @property(cc.Node)
  21. node_effect_on: cc.Node = null;
  22. @property(cc.Node)
  23. node_effect_off: cc.Node = null;
  24. @property(cc.Node)
  25. node_restartBtn: cc.Node = null;
  26. @property(cc.Node)
  27. node_exitBtn: cc.Node = null;
  28. start() {
  29. mk.ad.showNative(4);
  30. this.node_bg.setContentSize(cc.winSize.width, cc.winSize.height);
  31. this.initEvent();
  32. }
  33. onEnable() {
  34. this.initMsuicSwitchState();
  35. this.initEffectSwitchState();
  36. }
  37. //初始化
  38. initMsuicSwitchState() {
  39. this.node_music_on.active = mk.audio.getSwitchMusic();
  40. this.node_music_off.active = !this.node_music_on.active
  41. }
  42. initEffectSwitchState() {
  43. this.node_effect_on.active = mk.audio.getSwitchEffect();
  44. this.node_effect_off.active = !this.node_effect_on.active;
  45. }
  46. initEvent() {
  47. this.node_closeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  48. this.node_musicSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  49. this.node_effectSwitch.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  50. this.node_restartBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  51. this.node_exitBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  52. }
  53. onClickBtn(event: cc.Event.EventTouch) {
  54. mk.audio.playEffect("button");
  55. switch (event.currentTarget) {
  56. case this.node_closeBtn:
  57. this.onClickClose();
  58. break;
  59. case this.node_musicSwitch:
  60. this.onClickMusicSwitch();
  61. break;
  62. case this.node_effectSwitch:
  63. this.onClickEffectSwitch();
  64. break;
  65. case this.node_exitBtn:
  66. this.onClickExitBtn();
  67. break;
  68. case this.node_restartBtn:
  69. this.onClickRestartBtn();
  70. break;
  71. }
  72. }
  73. onClickClose() {
  74. console.log("点击关闭按钮", this.node.name);
  75. mk.ui.closePanel(this.node.name);
  76. mk.ad.destroyNativeAd();
  77. }
  78. onClickMusicSwitch() {
  79. mk.audio.switchMusicFunc();
  80. this.initMsuicSwitchState();
  81. }
  82. onClickEffectSwitch() {
  83. mk.audio.switchEffectFunc();
  84. this.initEffectSwitchState();
  85. }
  86. onClickRestartBtn() {
  87. GamePlay.Inst.restart();
  88. mk.ui.closePanel(this.node.name);
  89. mk.ad.destroyNativeAd();
  90. }
  91. onClickExitBtn() {
  92. mk.ui.closePanel("PauseUI")
  93. GamePlay.Inst.restart();//退出不扣体力
  94. GamePlay.Inst.node.active = false;
  95. mk.ad.destroyNativeAd();
  96. }
  97. }