setting.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. setting_data.isOpenYinYue = open
  57. GameManager.saveSettingData(setting_data)
  58. }
  59. updateShengyinStatus(open:boolean) {
  60. if(open) {
  61. this.shengyin_btn_on.active = true
  62. this.shengyin_btn_off.active = false
  63. } else {
  64. this.shengyin_btn_on.active = false
  65. this.shengyin_btn_off.active = true
  66. }
  67. let setting_data = GameManager.getSettingData()
  68. setting_data.isOpenYinXiao = open
  69. GameManager.saveSettingData(setting_data)
  70. }
  71. updateZhendongStatus(open:boolean) {
  72. if(open) {
  73. this.zhendong_btn_on.active = true
  74. this.zhendong_btn_off.active = false
  75. } else {
  76. this.zhendong_btn_on.active = false
  77. this.zhendong_btn_off.active = true
  78. }
  79. let setting_data = GameManager.getSettingData()
  80. setting_data.isOpenZhendong = open
  81. GameManager.saveSettingData(setting_data)
  82. }
  83. }