local UISettingQualityPanel = UIViewClass() local CUSTOMINDEX = -1 local LODMAX = 2 local EventSystem = require 'Event/EventSystem' local QualityLevelIDS = { "IDS_Low", -- 低 "IDS_Middle", -- 中 "IDS_High", -- 高 } local QualityLevelImage = { "ImageQuality_Low", -- 低 "ImageQuality_Middle", -- 中 "ImageQuality_High", -- 高 } local Index_Full_Screen = 999 --不在LuaConst.SupportResolution枚举内则认为全屏 function UISettingQualityPanel:OnCreated(context) self.RecommendedImage = {self.img_Recommended_1, self.img_Recommended_2, self.img_Recommended_3} end function UISettingQualityPanel:OnOpened(context) self:RegistSystemEvent(EventID.Game_ScreenResolutionChanged, self.ScreenResolutionChanged) self:Refresh() local index = CTL.Setting.GetLodLevel() if not MDL.Setting.HasKey(LuaConst.SettingKeyEnum.Recommend) then MDL.Setting.SetKeyValue(LuaConst.SettingKeyEnum.Recommend, index) end self:RefreshLODLevel(index) --帧率设置 self.FPSLevel:SelectIndex(CTL.Setting.GetFrameLimitation()) self.hasInitUI = true -- 初始初始化UI 的时候 使用了selectIndex 可能与预制中选中的不同,触发valuechange中的方法。使用这个参数区别初始化时是否使用valuechange特殊方法 -- 推荐画质 UIUtils.SetActive(self.RecommendedImage[SettingAPI.deviceLevel + 1], true) UIUtils.SetLabelText(self.txt_RecommendQuality, Const_IDS[QualityLevelIDS[SettingAPI.deviceLevel + 1]]) -- 分辨率 self:InitResolutionOptionLoop() end function UISettingQualityPanel:Refresh() if CTL.Setting.IsCustom() then self.Resolution:SetAllGray(false) self.Material:SetAllGray(false) self.EffectLevel:SetAllGray(false) self.Antialiasing:SetAllGray(false) self.Shadow:SetAllGray(false) self.Glow:SetAllGray(false) else self.Resolution:SetAllGray(true,true) self.Material:SetAllGray(true,true) self.EffectLevel:SetAllGray(true,true) self.Antialiasing:SetAllGray(true,true) self.Shadow:SetAllGray(true,true) self.Glow:SetAllGray(true,true) end self.hideTips = true local ScreenResolution = CTL.Setting.GetEnumSettingLevel(LuaConst.SettingKeyEnum.ScreenResolution) local ShaderQuality = CTL.Setting.GetEnumSettingLevel(LuaConst.SettingKeyEnum.ShaderQuality) local ParticleQuality = CTL.Setting.GetEnumSettingLevel(LuaConst.SettingKeyEnum.ParticleQuality) local AA = CTL.Setting.GetEnumSettingLevel(LuaConst.SettingKeyEnum.AA) local ShadowQuality = CTL.Setting.GetEnumSettingLevel(LuaConst.SettingKeyEnum.ShadowQuality) local Bloom = CTL.Setting.GetEnumSettingLevel(LuaConst.SettingKeyEnum.Bloom) self.Resolution:SelectIndex(ScreenResolution) self.Material:SelectIndex(ShaderQuality) self.EffectLevel:SelectIndex(ParticleQuality) self.Antialiasing:SelectIndex(AA) self.Shadow:SelectIndex(ShadowQuality) self.Glow:SelectIndex(Bloom) self.hideTips = false -- PC分辨率 self.isChoosingResolution = false self:RefreshResolution() end function UISettingQualityPanel:OnClosed() CTL.Setting.SaveQuality() end function UISettingQualityPanel:SetQualityUIState(index) --在LODMax上面还有个自定义,在index为3的时候,lodLevel应该为 -1 if index <= LODMAX then local skillPath = ConstAssetPathConfig.skillPath1..QualityLevelImage[index +1]..".png" UIUtils.SetImageByAssetBundle(self.img_Image, skillPath) UIUtils.SetActive(self.group_SystemInfo, true) UIUtils.SetActive(self.group_CustomInfo, false) else UIUtils.SetActive(self.group_SystemInfo, false) UIUtils.SetActive(self.group_CustomInfo, true) end self:Refresh() end function UISettingQualityPanel:OnValueChanged(comp, index) if not self.hasInitUI then if comp == self.QualityLevel then --初始化不应该执行回调,只需要将数据显示到界面上即可 self:SetQualityUIState(index) end return end if comp == self.Resolution then CTL.Setting.SetCustomQualityValue(LuaConst.SettingKeyEnum.ScreenResolution, index) elseif comp == self.Material then CTL.Setting.SetCustomQualityValue(LuaConst.SettingKeyEnum.ShaderQuality, index) elseif comp == self.EffectLevel then CTL.Setting.SetCustomQualityValue(LuaConst.SettingKeyEnum.ParticleQuality, index) elseif comp == self.Antialiasing then CTL.Setting.SetCustomQualityValue(LuaConst.SettingKeyEnum.AA, index) elseif comp == self.Shadow then CTL.Setting.SetCustomQualityValue(LuaConst.SettingKeyEnum.ShadowQuality, index) elseif comp == self.Glow then CTL.Setting.SetCustomQualityValue(LuaConst.SettingKeyEnum.Bloom, index) elseif comp == self.QualityLevel then if index <= LODMAX then CTL.Setting.ForceSetQuality(index, MDL.Setting.SwitchLodType.Manual) else --在LODMax上面还有个自定义,在index为3的时候,lodLevel应该为 -1 CTL.Setting.ForceSetQuality(CUSTOMINDEX, MDL.Setting.SwitchLodType.Manual) end self:SetQualityUIState(index) elseif comp == self.FPSLevel then if GameAppInfo.IsPCOrMacPackage() then CTL.Setting.SaveFrameLimitation(index) else local fpsVeryHighIndex = 1 if index == fpsVeryHighIndex then UTL.MessageBox.ShowOKCancelNoCloseBox(nil, Const_IDS.IDS_FrameSetting_Confirm, function() CTL.Setting.SaveFrameLimitation(index) end, function() self.FPSLevel:SelectIndex(CTL.Setting.GetFrameLimitation()) end) else CTL.Setting.SaveFrameLimitation(index) end end end end function UISettingQualityPanel:RefreshLODLevel(lodLevel) if lodLevel == CUSTOMINDEX then lodLevel = LODMAX + 1 end self.QualityLevel:SelectIndex(lodLevel) end --region 分辨率 function UISettingQualityPanel:InitResolutionOptionLoop() self.loop_Resolution:ClearCells() local resolutionIndex = CTL.Setting.GetDefaultResolution() UIUtils.SetLabel(self.txt_Number, self:GetResolutionStr(resolutionIndex)) local maxResolutionLen = #LuaConst.SupportResolution --最后一个分辨率只有在mac下生效 local displayerWidth, displayerHeight = CTL.Setting.GetCurrentResolution() logging.crit(LTAG.CRIT, "GetCurrentResolution", displayerWidth, displayerHeight) for i = 1, maxResolutionLen do if displayerWidth and displayerWidth < LuaConst.SupportResolution[i][1] then break end self.loop_Resolution:AddData(i,0) end self.loop_Resolution:AddData(Index_Full_Screen,0) end function UISettingQualityPanel:GetResolutionStr(resolutionIndex) local tb = LuaConst.SupportResolution[resolutionIndex] if not tb then return UIUtils.GetLocalizedTxt(Const_IDS.IDS_PCPackage_FullSceen) end return string.format("%s×%s",tb[1],tb[2]) end function UISettingQualityPanel:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loop_Resolution then UIUtils.SetLabel(self.txt_Number, self:GetResolutionStr(data)) self:OnButtonClicked(self.btn_Resolution) CTL.Setting.SetResolutionByIndex(data) end end function UISettingQualityPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Resolution then UIUtils.SetLabel(cellTable.txt_Option, self:GetResolutionStr(data)) end end function UISettingQualityPanel:OnButtonClicked(comp) if comp == self.btn_Resolution then self.isChoosingResolution = not self.isChoosingResolution UIUtils.SetActive(self.img_ArrowUp, not self.isChoosingResolution) UIUtils.SetActive(self.img_ArrowDown, self.isChoosingResolution) UIUtils.SetActive(self.loop_Resolution, self.isChoosingResolution) end end function UISettingQualityPanel:RefreshResolution() if not GameAppInfo.IsPCOrMacPackage() then UIUtils.SetActive(self.group_Resolution, false) return else UIUtils.SetActive(self.Resolution.gameObject,false) end UIUtils.SetActive(self.img_ArrowUp, not self.isChoosingResolution) UIUtils.SetActive(self.img_ArrowDown, self.isChoosingResolution) end function UISettingQualityPanel:ScreenResolutionChanged() UIUtils.FitScreenResolution(self.gameObject) end return UISettingQualityPanel