setting.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. }
  48. this.onButtonListen(this.btn_user, ()=>{
  49. this.lab_user.active = true
  50. this.lab_user.getComponent(Label).string = 'id:' + userDataManager.user_data.id
  51. })
  52. this.onButtonListen(this.btn_clear_local_data, ()=>{
  53. userDataManager.clearUserFreeAdsData()
  54. })
  55. this.initData()
  56. }
  57. initData() {
  58. let setting_data = GameManager.getSettingData()
  59. this.updateYinyueStatus(setting_data.isOpenYinYue)
  60. this.updateShengyinStatus(setting_data.isOpenYinXiao)
  61. this.updateZhendongStatus(setting_data.isOpenZhendong)
  62. }
  63. updateYinyueStatus(open:boolean) {
  64. if(open) {
  65. this.yinyue_btn_on.active = true
  66. this.yinyue_btn_off.active = false
  67. } else {
  68. this.yinyue_btn_on.active = false
  69. this.yinyue_btn_off.active = true
  70. }
  71. let setting_data = GameManager.getSettingData()
  72. if(open==setting_data.isOpenYinYue) {
  73. return
  74. }
  75. setting_data.isOpenYinYue = open
  76. GameManager.saveSettingData(setting_data)
  77. }
  78. updateShengyinStatus(open:boolean) {
  79. if(open) {
  80. this.shengyin_btn_on.active = true
  81. this.shengyin_btn_off.active = false
  82. } else {
  83. this.shengyin_btn_on.active = false
  84. this.shengyin_btn_off.active = true
  85. }
  86. let setting_data = GameManager.getSettingData()
  87. if(open==setting_data.isOpenYinXiao) {
  88. return
  89. }
  90. setting_data.isOpenYinXiao = open
  91. GameManager.saveSettingData(setting_data)
  92. }
  93. updateZhendongStatus(open:boolean) {
  94. if(open) {
  95. this.zhendong_btn_on.active = true
  96. this.zhendong_btn_off.active = false
  97. } else {
  98. this.zhendong_btn_on.active = false
  99. this.zhendong_btn_off.active = true
  100. }
  101. let setting_data = GameManager.getSettingData()
  102. if(open==setting_data.isOpenZhendong) {
  103. return
  104. }
  105. setting_data.isOpenZhendong = open
  106. GameManager.saveSettingData(setting_data)
  107. }
  108. }