TapSetMusic.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { GameViewType } from "../../main/ViewManage";
  2. import ViewObject from "../../main/ViewObject";
  3. /**
  4. * 声音设置
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class TapSetMusic extends ViewObject {
  9. @property(cc.Sprite)
  10. mMusicSprite1: cc.Sprite = null;//背景音乐音量
  11. @property(cc.Sprite)
  12. mMusicSprite2: cc.Sprite = null;//背景音乐音量
  13. @property(cc.SpriteFrame)
  14. mON: cc.SpriteFrame = null;
  15. @property(cc.SpriteFrame)
  16. mOFF: cc.SpriteFrame = null;
  17. @property(cc.Slider)
  18. mMusicSlider1: cc.Slider = null;//背景音乐音量
  19. @property(cc.Slider)
  20. mMusicSlider2: cc.Slider = null;//效果音乐音量
  21. onLoad() {
  22. this.mMusicSlider1.node.on('slide', this.s1Callback, this);
  23. this.mMusicSlider2.node.on('slide', this.s2Callback, this);
  24. this.flush();
  25. }
  26. /**
  27. *
  28. * @param prev 父界面
  29. */
  30. public show(prev?:ViewObject){
  31. if(prev){
  32. this.prev = prev;
  33. this.prev.__close();
  34. }
  35. this.main.viewManage.popView1(this.node);
  36. if(this.main && this.main.gameHttp){
  37. this.main.gameHttp.pushEvent(this);
  38. }
  39. }
  40. public flush() {
  41. let setting = this.main.player.setting;
  42. if (setting.music_ON_OFF_1) {
  43. this.mMusicSprite1.spriteFrame = this.mON;
  44. } else {
  45. this.mMusicSprite1.spriteFrame = this.mOFF;
  46. }
  47. if (setting.music_ON_OFF_2) {
  48. this.mMusicSprite2.spriteFrame = this.mON;
  49. } else {
  50. this.mMusicSprite2.spriteFrame = this.mOFF;
  51. }
  52. this.mMusicSlider1.progress = setting.music_Slider_1;
  53. this.mMusicSlider2.progress = setting.music_Slider_2;
  54. }
  55. public onclick1() {
  56. let setting = this.main.player.setting;
  57. setting.music_ON_OFF_1 = !setting.music_ON_OFF_1;
  58. this.flush();
  59. if (setting.music_ON_OFF_1) {
  60. this.main.resumeMusic();
  61. } else {
  62. this.main.pauseMusic();
  63. }
  64. this.main.player.saveSetting();
  65. }
  66. public conclick2() {
  67. let setting = this.main.player.setting;
  68. setting.music_ON_OFF_2 = !setting.music_ON_OFF_2;
  69. this.flush();
  70. this.main.player.saveSetting();
  71. }
  72. public s1Callback(silder: cc.Slider) {
  73. let setting = this.main.player.setting;
  74. setting.music_Slider_1 = silder.progress;
  75. if (this.main.bgmId >= 0) {
  76. cc.audioEngine.setMusicVolume(setting.music_Slider_1);
  77. }
  78. this.main.player.saveSetting();
  79. }
  80. public s2Callback(silder: cc.Slider) {
  81. let setting = this.main.player.setting;
  82. setting.music_Slider_2 = silder.progress;
  83. this.main.player.saveSetting();
  84. }
  85. public exitLogin() {
  86. cc.director.loadScene('hotUpdate')
  87. }
  88. public openNotice() {
  89. this.main.viewManage.loadFunc(GameViewType.tap_set_Ann, (viewObject: ViewObject) => {
  90. // let tap_set_Ann:Tap_set_Ann = viewObject as Tap_set_Ann;
  91. viewObject.show(this);
  92. });
  93. }
  94. }