PauseUI.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Created by carolsail
  2. import UIbase from '../utils/UIbase';
  3. import LocalData from '../manager/LocalData';
  4. import PrefabUtil from '../utils/manager/PrefabUtil';
  5. import AudioMgr from '../manager/AudioMgr';
  6. import AudioPath from '../datas/AudioPath';
  7. import GameUI from './GameUI';
  8. import HomeUI from './HomeUI';
  9. import Plat from '../utils/Palt';
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class PauseUI extends UIbase {
  13. private static _inst:PauseUI;
  14. public static get inst()
  15. {
  16. if(this._inst==null || this._inst.node==null)
  17. {
  18. let v=cc.instantiate(PrefabUtil.get("PauseUI"));
  19. this._inst=v.getComponent(PauseUI);
  20. }
  21. return this._inst;
  22. }
  23. @property(cc.Sprite)
  24. musicSprite: cc.Sprite = null
  25. @property(cc.Sprite)
  26. soundSprite: cc.Sprite = null
  27. // @property(cc.Node)
  28. // btnClose: cc.Node = null
  29. @property(cc.SpriteFrame)
  30. openFrame: cc.SpriteFrame = null
  31. @property(cc.SpriteFrame)
  32. closeFrame: cc.SpriteFrame = null
  33. start() {
  34. this.updateMusic();
  35. this.updateSound();
  36. }
  37. protected onShow(): void {
  38. Plat.showBanner()
  39. }
  40. protected onHide(): void {
  41. Plat.hideBanner()
  42. }
  43. onClickClose() {
  44. AudioMgr.playSound(AudioPath.CLICK)
  45. this.hideUI();
  46. }
  47. onClickSound()
  48. {
  49. AudioMgr.playSound(AudioPath.CLICK)
  50. LocalData.yx = !LocalData.yx
  51. this.updateSound()
  52. }
  53. onClickMusic() {
  54. AudioMgr.playSound(AudioPath.CLICK)
  55. LocalData.yy = !LocalData.yy
  56. if ( LocalData.yy==true)
  57. {
  58. AudioMgr.playBgm();
  59. }
  60. else
  61. {
  62. AudioMgr.stopBgm();
  63. }
  64. this.updateMusic()
  65. }
  66. updateMusic() {
  67. this.musicSprite.spriteFrame = LocalData.yy==true?this.openFrame:this.closeFrame
  68. }
  69. updateSound() {
  70. this.soundSprite.spriteFrame = LocalData.yx==true?this.openFrame:this.closeFrame
  71. }
  72. onClickHome()
  73. {
  74. this.hideUI();
  75. HomeUI.inst.showUI();
  76. }
  77. onClickResume()
  78. {
  79. GameUI.inst.is_game_pause=false;
  80. this.hideUI();
  81. }
  82. }