123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /** @format */
- import {UI} from '../enums/UI'
- import {BaseUI} from './BaseUI'
- import {Data, GameControl, Mgr} from '../GameControl'
- import {ccUtils} from '../utils/ccUtils'
- import {observer, render, node, label, editBox, list, toggle} from '../mobx/observer'
- import {msgCmd} from '../proto/msg_cmd'
- import {i18nLabel} from '../uiutils/i18nLabel'
- import {DIS_ID, EVENT, GAME_TYPE, Language, LOCAL} from '../enums/Enum'
- import List from '../uiutils/List'
- import {DataConfig} from '../config/DataConfig'
- import {manual} from '../proto/typedef'
- import {HotOptions} from '../hotupdate/hotupdate'
- import {ILoginUI} from '../interface/UIInterface'
- const {ccclass, property} = cc._decorator
- /** 战令所有数据 */
- interface languageData {
- id: number
- name: string
- language: Language
- }
- @ccclass
- @observer
- export class SettingUI extends BaseUI {
- @toggle('music/tog')
- musicToggle: cc.Toggle //音乐
- @toggle('sound/tog')
- soundToggle: cc.Toggle //音乐
- @node('redeem_code')
- redeemCodeNode: cc.Node //兑换码弹出界面
- @node('language')
- languageNode: cc.Node //多语言弹出界面
- @list('language/language_list')
- languageList: List //多语言滑动列表
- languageDataList: languageData[] = [
- {id: 1, name: 'English', language: Language.en},
- {id: 2, name: '中文(简体)', language: Language.zh},
- // {id: 3, name: '中文(繁體)', language: Language.zh},
- ]
- //当前选择的语言-如果是第一次默认选择配置表的语言
- selectLanguage: number
- onLoad() {}
- onShow(args, fromUI: number) {
- let bgmEnable = Mgr.storage.getNumber(LOCAL.bgmVolume, 1)
- let sfxEnable = Mgr.storage.getNumber(LOCAL.sfxVolume, 1)
- let data1 = DataConfig[DIS_ID.language].data1
- let curLanguageStr = Mgr.storage.getString(LOCAL.selectLanguage, this.languageDataList[data1 - 1].language)
- this.languageDataList.forEach((value, key) => {
- if (curLanguageStr == this.languageDataList[key].language) {
- this.selectLanguage = this.languageDataList[key].id
- }
- })
- let isMusic: boolean = bgmEnable == 1
- let isSound: boolean = sfxEnable == 1
- Mgr.audio.setBGMVolume(bgmEnable)
- Mgr.audio.setSFXVolume(sfxEnable)
- this.setToggleIsSelect(this.musicToggle.node, isMusic)
- this.setToggleIsSelect(this.soundToggle.node, isSound)
- this.musicToggle.isChecked = isMusic
- this.soundToggle.isChecked = isSound
- this.languageList.numItems = this.languageDataList.length
- let i18nLb = cc.find('version_lb', this.node).getComponent(i18nLabel)
- i18nLb.setParamByIndex(Data.main.localVersion, 0)
- }
- onHide(): any {
- Mgr.event.removeAll(this)
- }
- initLanguageItem(node: cc.Node, index: number) {
- //当前选中的语言
- ccUtils.setColor(this.selectLanguage - 1 == index ? '#FFEF81' : '#AAAAAA', node, 'lb')
- ccUtils.setLabel(this.languageDataList[index].name, node, 'lb')
- }
- setToggleIsSelect(node: cc.Node, isChecked: boolean) {
- cc.find('Background', node).active = !isChecked
- cc.find('checkmark', node).active = isChecked
- }
- //点击事件-音乐=======================================
- onClickMusic(toggle: cc.Toggle) {
- this.setToggleIsSelect(toggle.node, toggle.isChecked)
- Mgr.audio.setBGMVolume(toggle.isChecked ? 1 : 0)
- }
- //点击事件-音效=======================================
- onClickSound(toggle: cc.Toggle) {
- this.setToggleIsSelect(toggle.node, toggle.isChecked)
- Mgr.audio.setSFXVolume(toggle.isChecked ? 1 : 0)
- }
- //点击事件-打开兑换码界面=======================================
- onClickRedeemCode() {
- this.redeemCodeNode.active = true
- }
- //点击事件-关闭兑换码界面=======================================
- onClickCloseRedeemCode() {
- this.redeemCodeNode.active = false
- }
- //点击事件-打开多语言选择界面=======================================
- onClickLanguage() {
- this.languageNode.active = true
- }
- //点击事件-关闭多语言选择界面=======================================
- onClickCloseLanguage() {
- this.languageNode.active = false
- }
- //选择语言
- onSwitchLanguage(event: cc.Button) {
- this.selectLanguage = event.target['_listId'] + 1
- Mgr.storage.set(LOCAL.selectLanguage, this.languageDataList[event.target['_listId']].language)
- this.languageList.numItems = this.languageDataList.length
- Mgr.i18n.setLanguage(this.languageDataList[event.target['_listId']].language)
- Mgr.event.trigger(EVENT.changeLanguage)
- }
- //公告
- onClickAnnouncement(event: cc.Button) {
- Mgr.ui.show(UI.AnnouncementUI)
- }
- //切换账号
- onSwitchAccount() {
- Mgr.platform.logout()
- GameControl.resetGame()
- }
- //选择服务器
- onClickSelGate() {
- Mgr.ui.closeAll()
- Mgr.ui.show(UI.LoginUI, {chooseServer: true})
- }
- }
|