local UIResonanceInfo = UIViewClass() local MainResonanceContinueShowCount = DataSheetManager.ConstData:GetDataByID("ResonanceAllShowNextNum").IntValue local AddStr = "+%d" local InitCount = 10 --初始这几个元素保证连续滑动不打断,往后每隔OptimizeCount考虑分段加载。 local OptimizeCount = 20 --分段加载的每段格子数。 ------------------------------ 系统函数 ------------------------------ function UIResonanceInfo:OnCreated() self.subTypeId = -1 self.isShowGoto = false end function UIResonanceInfo:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title,Const_IDS.IDS_Treasure_Information_1) if context then self.subTypeId = context.subResonanceID self.isShowGoto = context.isShowGoto local subCfg = MDL.FormationResonance.GetSubResonanceCfg(self.subTypeId) UIUtils.SetActive(self.UICommonPopUp.img_Info, subCfg.GuidanceNotesID > 0) end self:RegistSystemEvent(EventID.UI_ResonanceChange_Refresh, self.RefreshPanel) self.loadStartLevel = 0 self.loadEndLevel = 0 self:RefreshPanel() end function UIResonanceInfo:OnClosed() UIUtils.SetActive(self.UICommonPopUp.img_Info, false) end function UIResonanceInfo:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.scroll_Info then if self.subTypeId == -1 then if not data then UIUtils.SetActive(cellTable.group_Displayed, false) UIUtils.SetActive(cellTable.group_Empty, true) return end UIUtils.SetActive(cellTable.group_Displayed, true) UIUtils.SetActive(cellTable.group_Empty, false) local mainLevel = MDL.FormationResonance.GetMainResonanceLevel() local cfg = DataSheetManager.ResonanceAll:GetDataByResonanceLevel(data) if not cfg then return end -- 当前 UIUtils.SetActive(cellTable.bg_NotReach, data > mainLevel) UIUtils.SetActive(cellTable.bg_Reach, data <= mainLevel) UIUtils.SetActive(cellTable.group_Now, data == mainLevel) UIUtils.SetImageByAssetBundle(cellTable.img_Icon, cfg.Icon) UIUtils.SetImageByAssetBundle(cellTable.img_Bg, cfg.IconUnderframe) UIUtils.SetLabel(cellTable.txt_Level, string.FormatByIdsId(Const_IDS["IDS_Resonance_Level"], data)) UIUtils.SetLabelText(cellTable.txt_Medal, Const_IDS[cfg.ResonanceName]) for i = 1, #cellTable.group_Fire do UIUtils.SetActive(cellTable.group_Fire[i], i <= cfg.Star) end UIUtils.SetLabel(cellTable.txt_Num01, CTL.FormationResonance.GetConsumeText(MDL.FormationResonance.GetAmountScore(), cfg.NeedScore)) UIUtils.SetLabel(cellTable.txt_Desc02, nil) UIUtils.SetLabel(cellTable.txt_Num02, nil) if cfg.ItemID ~= 0 then local itemCfg = DataSheetManager.ItemData:GetDataByID(cfg.ItemID) UIUtils.SetLabelText(cellTable.txt_Desc02, Const_IDS[itemCfg.Name]) UIUtils.SetLabel(cellTable.txt_Num02, CTL.FormationResonance.GetConsumeText(MDL.Bag.GetItemCount(cfg.ItemID), cfg.ItemNum)) end for i, v in ipairs (cfg.Attr_Table) do local attrUI = cellTable.scroll_Attr[i] local attrCfg = DataSheetManager.AttrData:GetDataByID(v.AttrType) UIUtils.SetActive(attrUI.gameObject, attrCfg ~= nil) if attrCfg then UIUtils.SetLabelText(attrUI.txt_Attr, Const_IDS[attrCfg.Name]) UIUtils.SetLabel(attrUI.txt_Num, attrCfg.Type and v.AttrNum or CTL.FormationResonance.GetPercentStr(v.AttrNum)) end end else if not data then UIUtils.SetActive(cellTable.group_Displayed, false) UIUtils.SetActive(cellTable.group_Empty, true) return end UIUtils.SetActive(cellTable.group_Displayed, true) UIUtils.SetActive(cellTable.group_Empty, false) local level = type(data) == "number" and data or data.level local subInfo = MDL.FormationResonance.GetSubResonanceInfo(self.subTypeId) local subLevel = MDL.FormationResonance.GetMainResonanceLevel() UIUtils.SetActive(cellTable.bg_NotReach, level > subInfo.level) UIUtils.SetActive(cellTable.bg_Reach, level <= subInfo.level) UIUtils.SetActive(cellTable.group_Now, level == subInfo.level) local conditionStr, conditionNeedCount = CTL.FormationResonance.GetCompleteCondition(self.subTypeId, level) local cfg = MDL.FormationResonance.GetSubResonanceCfg(self.subTypeId) local infoCfg = MDL.FormationResonance.GetSubResonanceInfoCfg(self.subTypeId, level) if not infoCfg then logging.error(LTAG.ERROR, "lost infoCfg at typeid:",self.subTypeId,", level:",level) end local param = type(data) == "table" and CTL.FormationResonance.GetConditionShowParam(self.subTypeId, data.param) or conditionNeedCount UIUtils.SetImageByAssetBundle(cellTable.img_Icon, cfg.Icon) UIUtils.SetLabel(cellTable.txt_Level, string.FormatByIdsId(Const_IDS["IDS_Resonance_Level"], level)) UIUtils.SetLabel(cellTable.txt_ConditionDesc, conditionStr) UIUtils.SetLabel(cellTable.txt_ConditionNum, CTL.FormationResonance.GetConsumeText(param, conditionNeedCount)) UIUtils.SetLabel(cellTable.txt_ConsumeNum, infoCfg.Score) for i = 1, 3 do local attrData = infoCfg.Attr_Table[i] local attrUI = cellTable.group_Attr[i] UIUtils.SetActive(attrUI.gameObject, attrData ~= nil) if attrData then local attrCfg = DataSheetManager.AttrData:GetDataByID(attrData.AttrType) if attrCfg then UIUtils.SetLabelText(attrUI.txt_Desc, Const_IDS[attrCfg.Name]) UIUtils.SetLabel(attrUI.txt_Num, string.format(AddStr, attrData.AttrNum)) end end end end end end function UIResonanceInfo:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIResonanceInfo:OnButtonClicked(comp) if comp == self.UICommonPopUp.img_Info then local subCfg = MDL.FormationResonance.GetSubResonanceCfg(self.subTypeId) UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = subCfg.GuidanceNotesID}) elseif comp == self.UICommonPopUp.btn_Close then CTL.FormationResonance.ClearJumpSubTypeId() self:CloseView() elseif comp == self.btn_Goto then if self.subTypeId ~= -1 then if self.isShowGoto then CTL.FormationResonance.JumpToSpecificFunctionPanel(self.subTypeId) else self:OnBackButtonPressed() end end end end ------------------------------------------------------------------------ function UIResonanceInfo:RefreshPanel() self.scroll_Info:ClearCells() if self.subTypeId == -1 then UIUtils.SetActive(self.btn_Info, false) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS["IDS_Resonance_SubTitle_AttrView"]) UIUtils.SetActive(self.btn_Goto, false) local mainLevel = MDL.FormationResonance.GetMainResonanceLevel() local showMainCount = mainLevel + MainResonanceContinueShowCount <= DataSheetManager.ResonanceAll:GetDataCount() - 1 and mainLevel + MainResonanceContinueShowCount or DataSheetManager.ResonanceAll:GetDataCount() - 1 for i = 1, showMainCount do self.scroll_Info:AddData(i, 0) end if showMainCount < DataSheetManager.ResonanceAll:GetDataCount() - 1 then self.scroll_Info:AddData(nil, 0) end self.scroll_Info:MoveIndex(mainLevel >= 1 and mainLevel - 1 or 0) else local subInfo = MDL.FormationResonance.GetSubResonanceInfo(self.subTypeId) if not subInfo then return end local subLevel = subInfo.level local subCfg = MDL.FormationResonance.GetSubResonanceCfg(self.subTypeId) UIUtils.SetActive(self.btn_Info, subCfg.GuidanceNotesID ~= 0) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS[subCfg.ResonanceChildName]) --如果为false会使滑动列表的y中心有微量偏移,导致OnScrollTop失败,所以子共鸣详情按钮常开,只切换字 UIUtils.SetActive(self.btn_Goto, true) UIUtils.SetLabelText(self.txt_Goto, self.isShowGoto and Const_IDS.IDS_TaskTowards or Const_IDS.IDS_BUTTON_CONFIRM) self.loadStartLevel = 1 self.loadEndLevel = subLevel -- 初始化的时候显示在当前等级,所以加载的最大等级就是当前等级 local moveIndex = subLevel >= 1 and subLevel - 1 or 0 if subLevel > OptimizeCount + InitCount then -- self.loadStartLevel = subLevel - OptimizeCount moveIndex = OptimizeCount end for i = self.loadStartLevel, self.loadEndLevel do self.scroll_Info:AddData(i, 1) end if subInfo.conds and #subInfo.conds > 0 then for _, v in ipairs (subInfo.conds) do self.scroll_Info:AddData(v, 1) end if MDL.FormationResonance.GetSubResonanceInfoCfg(self.subTypeId, subLevel + #subInfo.conds + 1) then self.scroll_Info:AddData(nil, 1) end end self.scroll_Info:MoveIndex(moveIndex) end end function UIResonanceInfo:OnScrollTop(comp, isTop) if comp == self.scroll_Info and isTop and self.loadStartLevel > 1 then --还没滑到真正的头部,再往前加载一段数据 local oldHead = self.loadStartLevel local moveIndex = 0 if oldHead > InitCount + OptimizeCount then --再往前一段 self.loadStartLevel = oldHead - OptimizeCount moveIndex = OptimizeCount - 1 else --往前到头 self.loadStartLevel = 1 moveIndex = oldHead - 2 end self.scroll_Info:ClearCells() for i = self.loadStartLevel, self.loadEndLevel do self.scroll_Info:AddData(i, 1) end local subInfo = MDL.FormationResonance.GetSubResonanceInfo(self.subTypeId) if not subInfo then return end if subInfo.conds and #subInfo.conds > 0 then for _, v in ipairs (subInfo.conds) do self.scroll_Info:AddData(v, 1) end if MDL.FormationResonance.GetSubResonanceInfoCfg(self.subTypeId, subInfo.level + #subInfo.conds + 1) then self.scroll_Info:AddData(nil, 1) end end self.scroll_Info:MoveIndex(moveIndex) end end return UIResonanceInfo