PausePanel.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * 代码描述
  3. */
  4. import { Audio } from "../../common/src/Audio";
  5. import { Store } from "../../common/src/Store";
  6. import { UIManager } from "../../common/src/UIManager";
  7. import { Utils } from "../../common/src/Utils";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export class PausePanel extends cc.Component {
  11. @property({ type: cc.Node, tooltip: '按钮节点1' })
  12. button1: cc.Node = null;
  13. @property({ type: cc.Node, tooltip: '按钮节点2' })
  14. button2: cc.Node = null;
  15. private enabledMusic: boolean = true;
  16. private enabledEffect: boolean = true;
  17. onEnable() {
  18. this.node.getChildByName('panel').getChildByName('closeButton').on('click', this.onClose, this);
  19. this.button1.getChildByName('musicEffect').on('click', this.onMusicEffect, this);
  20. this.button1.getChildByName('music').on('click', this.onMusic, this);
  21. this.button2.getChildByName('restart').on('click', this.onRestart, this);
  22. this.button2.getChildByName('quit').on('click', this.onQuit, this);
  23. this.enabledMusic = Store.getBool('enabledMusic', true);
  24. this.enabledEffect = Store.getBool('enabledEffect', true);
  25. this.node.getChildByName('panel').scale = 0.7;
  26. Utils.openPanel(this.node.getChildByName('panel'));
  27. this.switchMask();
  28. }
  29. /**关闭 */
  30. private onClose() {
  31. Audio.playSoundByPath('pause:res/snd/click');
  32. UIManager.close('pause:PausePanel', true);
  33. }
  34. /**音效*/
  35. private onMusicEffect(): void {
  36. Audio.playSoundByPath('pause:res/snd/click');
  37. if (this.enabledEffect) {
  38. this.enabledEffect = false;
  39. }
  40. else {
  41. this.enabledEffect = true;
  42. }
  43. Audio.enableSound(this.enabledEffect);
  44. this.button1.getChildByName('musicEffect').getChildByName('mask').active = !this.enabledEffect;
  45. }
  46. /**音乐 */
  47. private onMusic(): void {
  48. Audio.playSoundByPath('pause:res/snd/click');
  49. if (this.enabledMusic) {
  50. this.enabledMusic = false;
  51. }
  52. else {
  53. this.enabledMusic = true;
  54. }
  55. Audio.enableMusic(this.enabledMusic);
  56. this.button1.getChildByName('music').getChildByName('mask').active = !this.enabledMusic;
  57. }
  58. /**重开 */
  59. private onRestart(): void {
  60. Audio.playSoundByPath('pause:res/snd/click');
  61. UIManager.close('pause:PausePanel', true);
  62. cc.systemEvent.emit('restart');
  63. }
  64. /**退出 */
  65. private onQuit(): void {
  66. Audio.playSoundByPath('pause:res/snd/click');
  67. }
  68. private switchMask(): void {
  69. this.button1.getChildByName('musicEffect').getChildByName('mask').active = !this.enabledEffect;
  70. this.button1.getChildByName('music').getChildByName('mask').active = !this.enabledMusic;
  71. }
  72. }