setting.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { _decorator, Component, Label, Node, Toggle } from 'cc';
  2. import { base_ui } from '../fw/base_ui';
  3. import { audioManager } from '../manager/audioManager';
  4. import { GameManager } from '../GameManager';
  5. import { userDataManager } from '../manager/userDataManager';
  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. @property(Node) btn_user:Node = null;
  17. @property(Node) lab_user:Node = null;
  18. protected start(): void {
  19. this.onButtonListen(this.btn_close, ()=>{
  20. this.close()
  21. })
  22. this.onButtonListen(this.yinyue_btn_on, ()=>{
  23. this.updateYinyueStatus(false)
  24. audioManager.Instance().pauseHomeBgm()
  25. })
  26. this.onButtonListen(this.yinyue_btn_off, ()=>{
  27. this.updateYinyueStatus(true)
  28. audioManager.Instance().playHomeBgm()
  29. })
  30. this.onButtonListen(this.shengyin_btn_on, ()=>{
  31. this.updateShengyinStatus(false)
  32. })
  33. this.onButtonListen(this.shengyin_btn_off, ()=>{
  34. this.updateShengyinStatus(true)
  35. })
  36. this.onButtonListen(this.zhendong_btn_on, ()=>{
  37. this.updateZhendongStatus(false)
  38. })
  39. this.onButtonListen(this.zhendong_btn_off, ()=>{
  40. this.updateZhendongStatus(true)
  41. })
  42. this.onButtonListen(this.btn_user, ()=>{
  43. this.lab_user.active = true
  44. this.lab_user.getComponent(Label).string = 'id:' + userDataManager.user_data.id
  45. })
  46. this.initData()
  47. }
  48. initData() {
  49. let setting_data = GameManager.getSettingData()
  50. this.updateYinyueStatus(setting_data.isOpenYinYue)
  51. this.updateShengyinStatus(setting_data.isOpenYinXiao)
  52. this.updateZhendongStatus(setting_data.isOpenZhendong)
  53. }
  54. updateYinyueStatus(open:boolean) {
  55. if(open) {
  56. this.yinyue_btn_on.active = true
  57. this.yinyue_btn_off.active = false
  58. } else {
  59. this.yinyue_btn_on.active = false
  60. this.yinyue_btn_off.active = true
  61. }
  62. let setting_data = GameManager.getSettingData()
  63. if(open==setting_data.isOpenYinYue) {
  64. return
  65. }
  66. setting_data.isOpenYinYue = open
  67. GameManager.saveSettingData(setting_data)
  68. }
  69. updateShengyinStatus(open:boolean) {
  70. if(open) {
  71. this.shengyin_btn_on.active = true
  72. this.shengyin_btn_off.active = false
  73. } else {
  74. this.shengyin_btn_on.active = false
  75. this.shengyin_btn_off.active = true
  76. }
  77. let setting_data = GameManager.getSettingData()
  78. if(open==setting_data.isOpenYinXiao) {
  79. return
  80. }
  81. setting_data.isOpenYinXiao = open
  82. GameManager.saveSettingData(setting_data)
  83. }
  84. updateZhendongStatus(open:boolean) {
  85. if(open) {
  86. this.zhendong_btn_on.active = true
  87. this.zhendong_btn_off.active = false
  88. } else {
  89. this.zhendong_btn_on.active = false
  90. this.zhendong_btn_off.active = true
  91. }
  92. let setting_data = GameManager.getSettingData()
  93. if(open==setting_data.isOpenZhendong) {
  94. return
  95. }
  96. setting_data.isOpenZhendong = open
  97. GameManager.saveSettingData(setting_data)
  98. }
  99. }