setting.ts 3.3 KB

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