SettingUI.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, GameControl, Mgr} from '../GameControl'
  5. import {ccUtils} from '../utils/ccUtils'
  6. import {observer, render, node, label, editBox, list, toggle} from '../mobx/observer'
  7. import {msgCmd} from '../proto/msg_cmd'
  8. import {i18nLabel} from '../uiutils/i18nLabel'
  9. import {DIS_ID, EVENT, GAME_TYPE, Language, LOCAL} from '../enums/Enum'
  10. import List from '../uiutils/List'
  11. import {DataConfig} from '../config/DataConfig'
  12. import {manual} from '../proto/typedef'
  13. import {HotOptions} from '../hotupdate/hotupdate'
  14. import {ILoginUI} from '../interface/UIInterface'
  15. const {ccclass, property} = cc._decorator
  16. /** 战令所有数据 */
  17. interface languageData {
  18. id: number
  19. name: string
  20. language: Language
  21. }
  22. @ccclass
  23. @observer
  24. export class SettingUI extends BaseUI {
  25. @toggle('music/tog')
  26. musicToggle: cc.Toggle //音乐
  27. @toggle('sound/tog')
  28. soundToggle: cc.Toggle //音乐
  29. @node('redeem_code')
  30. redeemCodeNode: cc.Node //兑换码弹出界面
  31. @node('language')
  32. languageNode: cc.Node //多语言弹出界面
  33. @list('language/language_list')
  34. languageList: List //多语言滑动列表
  35. languageDataList: languageData[] = [
  36. {id: 1, name: 'English', language: Language.en},
  37. {id: 2, name: '中文(简体)', language: Language.zh},
  38. // {id: 3, name: '中文(繁體)', language: Language.zh},
  39. ]
  40. //当前选择的语言-如果是第一次默认选择配置表的语言
  41. selectLanguage: number
  42. onLoad() {}
  43. onShow(args, fromUI: number) {
  44. let bgmEnable = Mgr.storage.getNumber(LOCAL.bgmVolume, 1)
  45. let sfxEnable = Mgr.storage.getNumber(LOCAL.sfxVolume, 1)
  46. let data1 = DataConfig[DIS_ID.language].data1
  47. let curLanguageStr = Mgr.storage.getString(LOCAL.selectLanguage, this.languageDataList[data1 - 1].language)
  48. this.languageDataList.forEach((value, key) => {
  49. if (curLanguageStr == this.languageDataList[key].language) {
  50. this.selectLanguage = this.languageDataList[key].id
  51. }
  52. })
  53. let isMusic: boolean = bgmEnable == 1
  54. let isSound: boolean = sfxEnable == 1
  55. Mgr.audio.setBGMVolume(bgmEnable)
  56. Mgr.audio.setSFXVolume(sfxEnable)
  57. this.setToggleIsSelect(this.musicToggle.node, isMusic)
  58. this.setToggleIsSelect(this.soundToggle.node, isSound)
  59. this.musicToggle.isChecked = isMusic
  60. this.soundToggle.isChecked = isSound
  61. this.languageList.numItems = this.languageDataList.length
  62. let i18nLb = cc.find('version_lb', this.node).getComponent(i18nLabel)
  63. i18nLb.setParamByIndex(Data.main.localVersion, 0)
  64. }
  65. onHide(): any {
  66. Mgr.event.removeAll(this)
  67. }
  68. initLanguageItem(node: cc.Node, index: number) {
  69. //当前选中的语言
  70. ccUtils.setColor(this.selectLanguage - 1 == index ? '#FFEF81' : '#AAAAAA', node, 'lb')
  71. ccUtils.setLabel(this.languageDataList[index].name, node, 'lb')
  72. }
  73. setToggleIsSelect(node: cc.Node, isChecked: boolean) {
  74. cc.find('Background', node).active = !isChecked
  75. cc.find('checkmark', node).active = isChecked
  76. }
  77. //点击事件-音乐=======================================
  78. onClickMusic(toggle: cc.Toggle) {
  79. this.setToggleIsSelect(toggle.node, toggle.isChecked)
  80. Mgr.audio.setBGMVolume(toggle.isChecked ? 1 : 0)
  81. }
  82. //点击事件-音效=======================================
  83. onClickSound(toggle: cc.Toggle) {
  84. this.setToggleIsSelect(toggle.node, toggle.isChecked)
  85. Mgr.audio.setSFXVolume(toggle.isChecked ? 1 : 0)
  86. }
  87. //点击事件-打开兑换码界面=======================================
  88. onClickRedeemCode() {
  89. this.redeemCodeNode.active = true
  90. }
  91. //点击事件-关闭兑换码界面=======================================
  92. onClickCloseRedeemCode() {
  93. this.redeemCodeNode.active = false
  94. }
  95. //点击事件-打开多语言选择界面=======================================
  96. onClickLanguage() {
  97. this.languageNode.active = true
  98. }
  99. //点击事件-关闭多语言选择界面=======================================
  100. onClickCloseLanguage() {
  101. this.languageNode.active = false
  102. }
  103. //选择语言
  104. onSwitchLanguage(event: cc.Button) {
  105. this.selectLanguage = event.target['_listId'] + 1
  106. Mgr.storage.set(LOCAL.selectLanguage, this.languageDataList[event.target['_listId']].language)
  107. this.languageList.numItems = this.languageDataList.length
  108. Mgr.i18n.setLanguage(this.languageDataList[event.target['_listId']].language)
  109. Mgr.event.trigger(EVENT.changeLanguage)
  110. }
  111. //公告
  112. onClickAnnouncement(event: cc.Button) {
  113. Mgr.ui.show(UI.AnnouncementUI)
  114. }
  115. //切换账号
  116. onSwitchAccount() {
  117. Mgr.platform.logout()
  118. GameControl.resetGame()
  119. }
  120. //选择服务器
  121. onClickSelGate() {
  122. Mgr.ui.closeAll()
  123. Mgr.ui.show(UI.LoginUI, {chooseServer: true})
  124. }
  125. }