setting.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. import { config } from '../config';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('setting')
  9. export class setting extends base_ui {
  10. @property(Node) btn_close:Node = null
  11. @property(Node) yinyue_btn_on:Node = null;
  12. @property(Node) yinyue_btn_off:Node = null;
  13. @property(Node) shengyin_btn_on:Node = null;
  14. @property(Node) shengyin_btn_off:Node = null;
  15. @property(Node) zhendong_btn_on:Node = null;
  16. @property(Node) zhendong_btn_off:Node = null;
  17. @property(Node) btn_user:Node = null;
  18. @property(Node) lab_user:Node = null;
  19. @property(Node) btn_clear_local_data:Node = null;
  20. protected start(): void {
  21. this.onButtonListen(this.btn_close, ()=>{
  22. this.close()
  23. })
  24. this.onButtonListen(this.yinyue_btn_on, ()=>{
  25. this.updateYinyueStatus(false)
  26. audioManager.Instance().pauseHomeBgm()
  27. })
  28. this.onButtonListen(this.yinyue_btn_off, ()=>{
  29. this.updateYinyueStatus(true)
  30. audioManager.Instance().playHomeBgm()
  31. })
  32. this.onButtonListen(this.shengyin_btn_on, ()=>{
  33. this.updateShengyinStatus(false)
  34. })
  35. this.onButtonListen(this.shengyin_btn_off, ()=>{
  36. this.updateShengyinStatus(true)
  37. })
  38. this.onButtonListen(this.zhendong_btn_on, ()=>{
  39. this.updateZhendongStatus(false)
  40. })
  41. this.onButtonListen(this.zhendong_btn_off, ()=>{
  42. this.updateZhendongStatus(true)
  43. })
  44. // 彩蛋
  45. if(config.debug) {
  46. this.btn_clear_local_data.active = true
  47. } else{
  48. this.btn_clear_local_data.active = false
  49. }
  50. this.onButtonListen(this.btn_user, ()=>{
  51. this.lab_user.active = true
  52. this.lab_user.getComponent(Label).string = 'id:' + userDataManager.user_data.id
  53. })
  54. this.onButtonListen(this.btn_clear_local_data, ()=>{
  55. userDataManager.clearUserFreeAdsData()
  56. })
  57. this.initData()
  58. }
  59. initData() {
  60. let setting_data = GameManager.getSettingData()
  61. this.updateYinyueStatus(setting_data.isOpenYinYue)
  62. this.updateShengyinStatus(setting_data.isOpenYinXiao)
  63. this.updateZhendongStatus(setting_data.isOpenZhendong)
  64. }
  65. updateYinyueStatus(open:boolean) {
  66. if(open) {
  67. this.yinyue_btn_on.active = true
  68. this.yinyue_btn_off.active = false
  69. } else {
  70. this.yinyue_btn_on.active = false
  71. this.yinyue_btn_off.active = true
  72. }
  73. let setting_data = GameManager.getSettingData()
  74. if(open==setting_data.isOpenYinYue) {
  75. return
  76. }
  77. setting_data.isOpenYinYue = open
  78. GameManager.saveSettingData(setting_data)
  79. }
  80. updateShengyinStatus(open:boolean) {
  81. if(open) {
  82. this.shengyin_btn_on.active = true
  83. this.shengyin_btn_off.active = false
  84. } else {
  85. this.shengyin_btn_on.active = false
  86. this.shengyin_btn_off.active = true
  87. }
  88. let setting_data = GameManager.getSettingData()
  89. if(open==setting_data.isOpenYinXiao) {
  90. return
  91. }
  92. setting_data.isOpenYinXiao = open
  93. GameManager.saveSettingData(setting_data)
  94. }
  95. updateZhendongStatus(open:boolean) {
  96. if(open) {
  97. this.zhendong_btn_on.active = true
  98. this.zhendong_btn_off.active = false
  99. } else {
  100. this.zhendong_btn_on.active = false
  101. this.zhendong_btn_off.active = true
  102. }
  103. let setting_data = GameManager.getSettingData()
  104. if(open==setting_data.isOpenZhendong) {
  105. return
  106. }
  107. setting_data.isOpenZhendong = open
  108. GameManager.saveSettingData(setting_data)
  109. }
  110. }