settingPanel.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { _decorator, Component, Node, profiler, Sprite, SpriteFrame } from 'cc';
  2. import { AudioManager } from '../../framework/audioManager';
  3. import { StorageManager } from '../../framework/storageManager';
  4. import { uiManager } from '../../framework/uiManager';
  5. import { gameConstants } from '../../game/gameConstants';
  6. import * as i18n from '../../../../extensions/i18n/assets/LanguageData'
  7. const { ccclass, property } = _decorator;
  8. const STATE_LIST = {
  9. OPEN: 0,
  10. CLOSE: 1,
  11. }
  12. @ccclass('SettingPanel')
  13. export class SettingPanel extends Component {
  14. private _isDebugOpen: boolean = false;
  15. private _isMusicOpen: boolean = false;
  16. @property(Sprite)
  17. public spBtnDebug: Sprite = null!;
  18. @property(Sprite)
  19. public spBtnMusic: Sprite = null!;
  20. @property(SpriteFrame)
  21. sfDebugList: Array<SpriteFrame> = [];
  22. @property(SpriteFrame)
  23. sfMusicList: Array<SpriteFrame> = [];
  24. show() {
  25. this._isMusicOpen = AudioManager.instance.getAudioSetting(true);
  26. this._changeState(this.spBtnMusic, this.sfMusicList, this._isMusicOpen);
  27. this._isDebugOpen = StorageManager.instance.getGlobalData("debug") ?? false;
  28. this._changeState(this.spBtnDebug, this.sfDebugList, this._isDebugOpen);
  29. }
  30. private _changeState(spParget: Sprite, list: Array<SpriteFrame>, isOpen: boolean) {
  31. if (isOpen) {
  32. spParget.spriteFrame = list[STATE_LIST.OPEN];
  33. } else {
  34. spParget.spriteFrame = list[STATE_LIST.CLOSE];
  35. }
  36. }
  37. public onBtnClose() {
  38. AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.COUNTDOWNGETGOLD);
  39. uiManager.instance.hideDialog(gameConstants.PANEL_PATH_LIST.SETTING);
  40. }
  41. public onBtnDebug() {
  42. AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.COUNTDOWNGETGOLD);
  43. this._isDebugOpen = !this._isDebugOpen;
  44. this._changeState(this.spBtnDebug, this.sfDebugList, this._isDebugOpen);
  45. StorageManager.instance.setGlobalData("debug", this._isDebugOpen);
  46. this._isDebugOpen === true ? profiler.showStats() : profiler.hideStats();
  47. }
  48. public onBtnMusic() {
  49. AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.COUNTDOWNGETGOLD);
  50. this._isMusicOpen = !this._isMusicOpen;
  51. this._changeState(this.spBtnMusic, this.sfMusicList, this._isMusicOpen);
  52. if (this._isMusicOpen) {
  53. AudioManager.instance.openMusic();
  54. AudioManager.instance.openSound();
  55. } else {
  56. AudioManager.instance.closeMusic();
  57. AudioManager.instance.closeSound();
  58. }
  59. }
  60. public onBtnLanguage() {
  61. AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.COUNTDOWNGETGOLD);
  62. let nowLanguage;
  63. if (i18n._language === gameConstants.I18_LANGUAGE.CHINESE) {
  64. nowLanguage = gameConstants.I18_LANGUAGE.ENGLISH;
  65. } else {
  66. nowLanguage = gameConstants.I18_LANGUAGE.CHINESE;
  67. }
  68. i18n.init(nowLanguage);
  69. i18n.updateSceneRenderers();
  70. }
  71. }