local UISettingSoundPanel = UIViewClass() local LocalizationCfg = require "Localization/LocalizationCfg" local ColorGray = Color.New(152/255, 152/255, 152/255,1) local ColorWhite = Color.New(1,1,1,1) local DubVoiceLanguage = { LocalizationCfg.LANGUAGE_SC_WORLD, LocalizationCfg.LANGUAGE_ENGLISH, } local DubVoiceLanguageIDS = { Const_IDS.IDS_SettingVoice_Language1, Const_IDS.IDS_SettingVoice_Language2, } function UISettingSoundPanel:OnOpened(context) self:SetSound(LuaConst.SettingKeyEnum.BgmProgress,self.progress_Bgm) self:SetSound(LuaConst.SettingKeyEnum.SoundProgress,self.progress_Sound) self:SetSound(LuaConst.SettingKeyEnum.DubProgress,self.progress_Dub) self:SetSound(LuaConst.SettingKeyEnum.EnvironmentalProgress,self.progress_Environmental) self.txt_Bgm.text = string.format( "%.0f%%",self.progress_Bgm.value*100) self.txt_Sound.text = string.format( "%.0f%%",self.progress_Sound.value*100) self.txt_Dub.text = string.format( "%.0f%%",self.progress_Dub.value*100) self.txt_Environmental.text = string.format( "%.0f%%",self.progress_Environmental.value*100) self:SetButton() if CTL.Sound.CanChangeAudioLanguage() then UIUtils.SetActive(self.Language, true) UTL.Toggle.InitToggleGroupByIDS(self.group_ViewMode, "Label", DubVoiceLanguageIDS) -- 设置语言选中 local dubVoiceLanguage = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.DubVoiceLanguage) for i, v in ipairs(DubVoiceLanguage) do if v == dubVoiceLanguage then -- index 从0开始 self.group_ViewMode:SelectIndex(i - 1) break end end else UIUtils.SetActive(self.Language, false) end end function UISettingSoundPanel:SetSound(prefsKey,slider) local value = MDL.Setting.GetKeyValue(prefsKey) if not MDL.Setting.HasKey(prefsKey) then slider.value = 1 else slider.value = value/100 end end function UISettingSoundPanel:SetButton() self:RefreshBGMBtn(false) self:RefreshSoundBtn(false) self:RefreshDubBtn(false) self:RefreshEnvironmentalBtn(false) end function UISettingSoundPanel:OnButtonClicked(comp) if self.btn_BGM == comp then local isOpen = self:RefreshBGMBtn(true) if isOpen then if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.BgmProgress) then CTL.Sound.SetRTPCValue("MUSIC_Bus", MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.BgmProgress)) else CTL.Sound.SetRTPCValue("MUSIC_Bus", 100) end else CTL.Sound.SetRTPCValue("MUSIC_Bus", 0) end MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.BgmState, isOpen) elseif self.btn_Sound == comp then local isOpen = self:RefreshSoundBtn(true) if isOpen then if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.SoundProgress) then CTL.Sound.SetRTPCValue("SFX_Bus", MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SoundProgress)) else CTL.Sound.SetRTPCValue("SFX_Bus", 100) end else CTL.Sound.SetRTPCValue("SFX_Bus", 0) end MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.SoundState, isOpen) elseif self.btn_Dub == comp then local isOpen = self:RefreshDubBtn(true) if isOpen then if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.DubProgress) then CTL.Sound.SetRTPCValue("VO_Bus", MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.DubProgress)) else CTL.Sound.SetRTPCValue("VO_Bus", 100) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.DubProgress, true) end else CTL.Sound.SetRTPCValue("VO_Bus", 0) end MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.DubState, isOpen) elseif self.btn_Environmental == comp then local isOpen = self:RefreshEnvironmentalBtn(true) if isOpen then if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.EnvironmentalProgress) then CTL.Sound.SetRTPCValue("Amb_Bus", MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.EnvironmentalProgress)) else CTL.Sound.SetRTPCValue("Amb_Bus", 100) MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.EnvironmentalProgress, true) end else CTL.Sound.SetRTPCValue("Amb_Bus", 0) end MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.EnvironmentalState, isOpen) end end function UISettingSoundPanel:OnValueChanged(comp, state) if comp == self.progress_Bgm and MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.BgmState) then -- 背景音乐 MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.BgmProgress, state * 100) --int型不能存储float 乘以100 存储 CTL.Sound.SetRTPCValue("MUSIC_Bus", 100*state) self.txt_Bgm.text = string.format( "%.0f%%", self.progress_Bgm.value*100) elseif comp == self.progress_Sound and MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SoundState) then -- 音效 MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.SoundProgress, state * 100) CTL.Sound.SetRTPCValue("SFX_Bus", 100*state) self.txt_Sound.text = string.format( "%.0f%%", self.progress_Sound.value*100) elseif comp == self.progress_Dub and MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.DubState) then -- 配音 MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.DubProgress, state * 100) CTL.Sound.SetRTPCValue("VO_Bus", 100*state) self.txt_Dub.text = string.format( "%.0f%%", self.progress_Dub.value*100) elseif comp == self.progress_Environmental and MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.EnvironmentalState) then -- 环境音 MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.EnvironmentalProgress, state * 100) CTL.Sound.SetRTPCValue("Amb_Bus", 100*state) self.txt_Environmental.text = string.format( "%.0f%%", self.progress_Environmental.value * 100) elseif comp == self.group_ViewMode then -- state 从0开始 local setDubVoiceLanguage = DubVoiceLanguage[state + 1] local dubVoiceLanguage = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.DubVoiceLanguage) if setDubVoiceLanguage ~= dubVoiceLanguage then MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.DubVoiceLanguage, setDubVoiceLanguage) LuaNetManager.RebootGame() end end end function UISettingSoundPanel:RefreshBGMBtn(isBtn) local isOpen = true if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.BgmState) then isOpen = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.BgmState) if isBtn then isOpen = not isOpen end end self.txt_Bgm.text = string.format( "%.0f%%", isOpen and self.progress_Bgm.value*100 or 0) self.BGM_Open.gameObject:SetActive(isOpen) self.BGM_Close.gameObject:SetActive(not isOpen) self.progress_Bgm.interactable = isOpen self.stateSwitch_BGM:SetState(isOpen and 0 or 1) return isOpen end function UISettingSoundPanel:RefreshSoundBtn(isBtn) local isOpen = true if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.SoundState) then isOpen = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.SoundState) if isBtn then isOpen = not isOpen end end self.txt_Sound.text = string.format( "%.0f%%", isOpen and self.progress_Sound.value*100 or 0) self.Sound_Open.gameObject:SetActive(isOpen) self.Sound_Close.gameObject:SetActive(not isOpen) self.progress_Sound.interactable = isOpen self.stateSwitch_Sound:SetState(isOpen and 0 or 1) return isOpen end function UISettingSoundPanel:RefreshDubBtn(isBtn) local isOpen = true if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.DubState) then isOpen = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.DubState) if isBtn then isOpen = not isOpen end end self.txt_Dub.text = string.format( "%.0f%%", isOpen and self.progress_Dub.value*100 or 0) self.Dub_Open.gameObject:SetActive(isOpen) self.Dub_Close.gameObject:SetActive(not isOpen) self.progress_Dub.interactable = isOpen self.stateSwitch_Dub:SetState(isOpen and 0 or 1) return isOpen end function UISettingSoundPanel:RefreshEnvironmentalBtn(isBtn) local isOpen = true if MDL.Setting.HasKey(LuaConst.SettingKeyEnum.EnvironmentalState) then isOpen = MDL.Setting.GetKeyValue(LuaConst.SettingKeyEnum.EnvironmentalState) if isBtn then isOpen = not isOpen end end self.txt_Environmental.text = string.format( "%.0f%%", isOpen and self.progress_Environmental.value * 100 or 0) self.Environmental_Open.gameObject:SetActive(isOpen) self.Environmental_Close.gameObject:SetActive(not isOpen) self.progress_Environmental.interactable = isOpen self.stateSwitch_Environmental:SetState(isOpen and 0 or 1) return isOpen end return UISettingSoundPanel