local UIMedal = UIViewClass() local AddStr = "+%d" --------------------------- 系统函数 ----------------------------- function UIMedal:OnOpened(context) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title,Const_IDS.IDS_Resonance_Title) self:RegistSystemEvent(EventID.UI_ResonanceChange_Refresh, self.RefreshPanel) self:RefreshPanel() end function UIMedal:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.scroll_Resonance then local subInfo = MDL.FormationResonance.GetSubResonanceInfo(data.ResonanceChildID) if not subInfo then return end local subLevel = subInfo.level local subInfoCfg = MDL.FormationResonance.GetSubResonanceInfoCfg(data.ResonanceChildID, subLevel) local curScore = subInfoCfg and subInfoCfg.Score or 0 UIUtils.SetLabelText(cellTable.txt_Name, Const_IDS[data.ResonanceChildName]) UIUtils.SetImageByAssetBundle(cellTable.img_Icon, data.Icon) UIUtils.SetLabel(cellTable.txt_Level, string.FormatByIdsId(Const_IDS["IDS_Resonance_Level"], subLevel)) UIUtils.SetLabel(cellTable.txt_Num01, curScore) local nextSubInfoCfg = MDL.FormationResonance.GetSubResonanceInfoCfg(data.ResonanceChildID, subLevel + 1) UIUtils.SetActive(cellTable.group_Next, nextSubInfoCfg ~= nil) if nextSubInfoCfg then UIUtils.SetLabel(cellTable.txt_Num02, string.format(AddStr, (nextSubInfoCfg.Score - curScore))) end elseif scrollRect == self.scroll_Attr then local attrCfg = DataSheetManager.AttrData:GetDataByID(data.AttrType) UIUtils.SetLabelText(cellTable.txt_Attr, Const_IDS[attrCfg.Name]) UIUtils.SetLabel(cellTable.txt_Num, attrCfg.Type and data.AttrNum or CTL.FormationResonance.GetPercentStr(data.AttrNum)) elseif scrollRect == self.scroll_AttrNew then local attrCfg = DataSheetManager.AttrData:GetDataByID(data.AttrType) UIUtils.SetLabelText(cellTable.txt_Attr, Const_IDS[attrCfg.Name]) local numStr = attrCfg.Type and data.AttrNum or CTL.FormationResonance.GetPercentStr(data.AttrNum) UIUtils.SetLabel(cellTable.txt_Num, index == 0 and UTL.Color.FormatGreenColor(numStr) or numStr) end end function UIMedal:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.scroll_Resonance then UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceInfo, {subResonanceID = data.ResonanceChildID, isShowGoto = true}) end end function UIMedal:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIMedal:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_MedalInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceInfo) elseif comp == self.btn_LevelUp then local nextResonanceCfg = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(MDL.FormationResonance.GetMainResonanceLevel() + 1) if not nextResonanceCfg then return end local isCanLevelup, curScore, curItemCount = MDL.FormationResonance.IsCanLevelupMainResonance() if not isCanLevelup then if nextResonanceCfg.NeedScore > curScore then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Resonance_Button_UnLevelUp"]) return end if curItemCount ~= -1 and nextResonanceCfg.ItemNum > curItemCount then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Resonance_Button_ItemLack"]) return end end MDL.FormationResonance.RequestResonanceLevelUp() elseif comp == self.item.event_Click then local nextResonanceCfg = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(MDL.FormationResonance.GetMainResonanceLevel() + 1) if nextResonanceCfg and nextResonanceCfg.ItemID ~= 0 then UTL.ItemTips.ShowCommonTipsById(nextResonanceCfg.ItemID) end elseif comp == self.btn_AttrInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDescriptionPanel,{target = self.showPanelPoint, posType = LuaConst.DescriptionPanelType.LeftUpper, text = UIUtils.GetLocalizedTxt(Const_IDS["IDS_Resonance_Attr_Hint"])}) elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.ResonanceAll}) end end ------------------------------------------------------------------- function UIMedal:RefreshPanel() -- 主共鸣 local mainResonanceLevel = MDL.FormationResonance.GetMainResonanceLevel() local amountScore = MDL.FormationResonance.GetAmountScore() local curResonanceCfg = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(mainResonanceLevel) local nextResonanceCfg = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(mainResonanceLevel + 1) -- 当前 UIUtils.SetLabel(self.txt_Level, MDL.FormationResonance.GetMainResonanceLevel()) UIUtils.SetActive(self.img_Icon, false) if curResonanceCfg then UIUtils.SetActive(self.img_Icon, true) UIUtils.SetImageByAssetBundle(self.img_Icon, curResonanceCfg.Icon) UIUtils.SetImageByAssetBundle(self.img_BgIcon, curResonanceCfg.IconUnderframe) end -- 当前属性 local updateAttrIndex = CTL.FormationResonance.FindUpdateAttrIndex(mainResonanceLevel) local curAttrTable = curResonanceCfg.Attr_Table self.scroll_Attr:ClearCells() self.scroll_Attr:AddData(curAttrTable[updateAttrIndex], 0) for i, v in ipairs (curAttrTable) do if i ~= updateAttrIndex then self.scroll_Attr:AddData(v, 0) end end for i = 1, #self.group_Fire do UIUtils.SetActive(self.group_Fire[i].gameObject, curResonanceCfg and i <= curResonanceCfg.Star or false) end if curResonanceCfg then UIUtils.SetLabelText(self.txt_Medal, Const_IDS[curResonanceCfg.ResonanceName]) else UIUtils.SetLabel(self.txt_Medal, nil) end -- 升级 UIUtils.SetActive(self.group_Max, nextResonanceCfg == nil) UIUtils.SetActive(self.group_LevelUp, nextResonanceCfg ~= nil) UIUtils.SetActive(self.group_Item, nextResonanceCfg ~= nil and nextResonanceCfg.ItemID ~= 0) UIUtils.SetActive(self.btn_LevelUp, nextResonanceCfg ~= nil) if nextResonanceCfg then local isCanLevelup, curScore, curItemCount = MDL.FormationResonance.IsCanLevelupMainResonance() -- 下一等级属性 local nextAttrTable = nextResonanceCfg.Attr_Table self.scroll_AttrNew:ClearCells() self.scroll_AttrNew:AddData(nextAttrTable[updateAttrIndex], 0) for i, v in ipairs (nextAttrTable) do if i ~= updateAttrIndex then self.scroll_AttrNew:AddData(v, 0) end end UIUtils.SetLabel(self.txt_ConsumeNum, CTL.FormationResonance.GetConsumeText(curScore, nextResonanceCfg.NeedScore)) if nextResonanceCfg.ItemID ~= 0 then UTL.Item.SetItemCell(self.item, nextResonanceCfg.ItemID, nextResonanceCfg.ItemNum) UIUtils.SetLabel(self.item.lab_Count, CTL.FormationResonance.GetConsumeText(curItemCount, nextResonanceCfg.ItemNum)) end self.btn_LevelUp:SetGray(not isCanLevelup, true) end -- 子共鸣滑动列表 if self.scroll_Resonance.Count == 0 then for _, v in ipairs(MDL.FormationResonance.GetSubResonanceList()) do if v and MDL.Unlock.IsUnlock(v.FunctionID) then self.scroll_Resonance:AddData(v, 0) end end else for i = 1, self.scroll_Resonance.Count do self.scroll_Resonance:UpdateIndex(i - 1) end end end return UIMedal