setting.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { _decorator, Component, Node, Toggle } from 'cc';
  2. import { uiManager } from '../../manager/uiManager';
  3. import { base_ui } from '../../fw/base_ui';
  4. import { audioManager } from '../../manager/audioManager';
  5. import { GameManager } from '../../GameManager';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('setting')
  8. export class setting extends base_ui {
  9. @property(Node) btn_close:Node = null
  10. @property(Node) yinyue_btn_on:Node = null;
  11. @property(Node) yinyue_btn_off:Node = null;
  12. @property(Node) shengyin_btn_on:Node = null;
  13. @property(Node) shengyin_btn_off:Node = null;
  14. @property(Node) zhendong_btn_on:Node = null;
  15. @property(Node) zhendong_btn_off:Node = null;
  16. protected start(): void {
  17. this.onButtonListen(this.btn_close, ()=>{
  18. this.close()
  19. })
  20. this.onButtonListen(this.yinyue_btn_on, ()=>{
  21. this.updateYinyueStatus(false)
  22. audioManager.Instance().pauseHomeBgm()
  23. })
  24. this.onButtonListen(this.yinyue_btn_off, ()=>{
  25. this.updateYinyueStatus(true)
  26. audioManager.Instance().playHomeBgm()
  27. })
  28. this.onButtonListen(this.shengyin_btn_on, ()=>{
  29. this.updateShengyinStatus(false)
  30. })
  31. this.onButtonListen(this.shengyin_btn_off, ()=>{
  32. this.updateShengyinStatus(true)
  33. })
  34. this.onButtonListen(this.zhendong_btn_on, ()=>{
  35. this.updateZhendongStatus(false)
  36. })
  37. this.onButtonListen(this.zhendong_btn_off, ()=>{
  38. this.updateZhendongStatus(true)
  39. })
  40. this.initData()
  41. }
  42. initData() {
  43. let setting_data = GameManager.getSettingData()
  44. this.updateYinyueStatus(setting_data.isOpenYinYue)
  45. this.updateShengyinStatus(setting_data.isOpenYinXiao)
  46. this.updateZhendongStatus(setting_data.isOpenZhendong)
  47. }
  48. updateYinyueStatus(open:boolean) {
  49. if(open) {
  50. this.yinyue_btn_on.active = true
  51. this.yinyue_btn_off.active = false
  52. } else {
  53. this.yinyue_btn_on.active = false
  54. this.yinyue_btn_off.active = true
  55. }
  56. let setting_data = GameManager.getSettingData()
  57. setting_data.isOpenYinYue = open
  58. GameManager.saveSettingData(setting_data)
  59. }
  60. updateShengyinStatus(open:boolean) {
  61. if(open) {
  62. this.shengyin_btn_on.active = true
  63. this.shengyin_btn_off.active = false
  64. } else {
  65. this.shengyin_btn_on.active = false
  66. this.shengyin_btn_off.active = true
  67. }
  68. let setting_data = GameManager.getSettingData()
  69. setting_data.isOpenYinXiao = open
  70. GameManager.saveSettingData(setting_data)
  71. }
  72. updateZhendongStatus(open:boolean) {
  73. if(open) {
  74. this.zhendong_btn_on.active = true
  75. this.zhendong_btn_off.active = false
  76. } else {
  77. this.zhendong_btn_on.active = false
  78. this.zhendong_btn_off.active = true
  79. }
  80. let setting_data = GameManager.getSettingData()
  81. setting_data.isOpenZhendong = open
  82. GameManager.saveSettingData(setting_data)
  83. }
  84. }