setting.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { _decorator, Component, Label, Node, Sprite, Toggle } from 'cc';
  2. import { StorageManager } from '../framework/storageManager';
  3. import { AudioManager } from '../framework/audioManager';
  4. import { config } from '../config';
  5. import { gameManager } from '../gameManager';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('setting')
  8. export class setting extends Component {
  9. @property(Node) btn_back:Node;
  10. @property(Node) btn_check_user_id:Node;
  11. @property(Node) lab_user_id:Node;
  12. @property(Node) btn_sound:Node;
  13. @property(Node) btn_music:Node;
  14. @property(Node) spr_sound:Node;
  15. @property(Node) spr_music:Node;
  16. private m_cancel_back = null;
  17. private touch_number:number = 0;
  18. start() {
  19. let self = this;
  20. this.btn_back.on(Node.EventType.TOUCH_END,()=>{
  21. gameManager.playBtnSound()
  22. if(this.m_cancel_back!=null){
  23. this.m_cancel_back()
  24. }
  25. self.close();
  26. },this);
  27. this.btn_sound.on(Node.EventType.TOUCH_END,()=>{
  28. gameManager.playBtnSound()
  29. if( this.btn_sound.getComponent(Toggle).isChecked){
  30. AudioManager.instance.openSound()
  31. }else{
  32. AudioManager.instance.closeSound()
  33. }
  34. this.updateStatus();
  35. },this);
  36. this.btn_music.on(Node.EventType.TOUCH_END,()=>{
  37. gameManager.playBtnSound()
  38. if( this.btn_music.getComponent(Toggle).isChecked){
  39. AudioManager.instance.openMusic()
  40. }else{
  41. AudioManager.instance.closeMusic()
  42. }
  43. this.updateStatus();
  44. },this);
  45. this.btn_check_user_id.on(Node.EventType.TOUCH_START,()=>{
  46. this.touch_number+=1;
  47. if(this.touch_number===3){
  48. this.lab_user_id.active = true;
  49. }
  50. },this)
  51. this.lab_user_id.getComponent(Label).string = `id:${gameManager.userInfo.id}`
  52. this.lab_user_id.active = false;
  53. this.updateStatus();
  54. }
  55. updateStatus(){
  56. let state = StorageManager.instance.getGlobalData('music');
  57. if(state==""||state==null||state==undefined){
  58. state = 'true'
  59. }
  60. if(state === 'true'){
  61. this.btn_music.getComponent(Toggle).isChecked = true;
  62. this.spr_music.getComponent(Sprite).grayscale = false;
  63. }else{
  64. this.btn_music.getComponent(Toggle).isChecked = false;
  65. this.spr_music.getComponent(Sprite).grayscale = true;
  66. }
  67. state = StorageManager.instance.getGlobalData('sound');
  68. if(state==""||state==null||state==undefined){
  69. state = 'true'
  70. }
  71. if(state === 'true'){
  72. this.btn_sound.getComponent(Toggle).isChecked = true;
  73. this.spr_sound.getComponent(Sprite).grayscale = false;
  74. }else{
  75. this.btn_sound.getComponent(Toggle).isChecked = false;
  76. this.spr_sound.getComponent(Sprite).grayscale = true;
  77. }
  78. }
  79. close(){
  80. this.node.removeFromParent();
  81. }
  82. public show(cancel_back){
  83. this.m_cancel_back = cancel_back;
  84. }
  85. }