local UIOfficialPrivilegeStrengthen = UIViewClass() local FightIcon = "zq_icon_zhanli" --战力icon ----------- function UIOfficialPrivilegeStrengthen:OnOpened(context) self.context = context self.groupList = {self.group1, self.group2, self.group3,} -- 设置标题 UIUtils.SetLabelText(self.UIOfficialPrivilegePopUpLeft.UICommonPopUp.txt_Title, Const_IDS[context.Name]) -- 设置描述 self.UIOfficialPrivilegePopUpLeft.txt_OfficialPrivilegeInfo.text = string.FormatByIdsKey(context.FunctionDes, CTL.OfficialPrivilege.GetRightsBuffContinueTime(context)) self:InitLimitLoop() self:InitStrengthenBuffAttr() self:RefreshStrengthenBuffState() self:RefreshStrengthenBuffConsume(true) -- 先初始化完,在监听事件 self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshConsumeOrOwn) self:RegistSystemEvent(EventID.UI_RefreshOfficialPrivilegeInfo, self.RefreshOptNum) self:RegistSystemEvent(EventID.UI_RefreshOfficialPositionInfo, self.RefreshStrengthenBuffState) end function UIOfficialPrivilegeStrengthen:OnBackButtonPressed() self:OnButtonClicked(self.UIOfficialPrivilegePopUpLeft.UICommonPopUp.btn_Close) end function UIOfficialPrivilegeStrengthen:OnButtonClicked(comp) if self.UIOfficialPrivilegePopUpLeft.UICommonPopUp.btn_Close == comp then self:CloseView() elseif self.group1.btn_BuildUp == comp then self:UseOfficialStrengthen(1) elseif self.group2.btn_BuildUp == comp then self:UseOfficialStrengthen(2) elseif self.group3.btn_BuildUp == comp then self:UseOfficialStrengthen(3) end end function UIOfficialPrivilegeStrengthen:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.UIOfficialPrivilegePopUpLeft.loop_Limit then if data == CTL.OfficialPrivilege.LimitType.ConsumeOrOwn then UIUtils.SetLabelText(cellTable.txt_LimitTitle, Const_IDS.IDS_OfficialPrivilege_Have) local itemID = self.context.ItemID UTL.Item.MoneyIcon(cellTable.img_Icon, itemID) local count = MDL.Bag.GetItemCount(itemID) cellTable.txt_Num.text = count == 0 and UTL.Color.FormatRedColor(count) or count UIUtils.SetActive(cellTable.btn_Add, true) elseif data == CTL.OfficialPrivilege.LimitType.UseNum then UIUtils.SetLabelText(cellTable.txt_LimitTitle, Const_IDS[self.context.UseTimesDes]) local rightsInfoNum = MDL.OfficialPrivilege.GetPrivilegeInfoNum(self.context.RightsID) local leftNum = math.max(self.context.UseTimes - rightsInfoNum) cellTable.txt_Num.text = string.format("%s/%d", leftNum == 0 and UTL.Color.FormatRedColor(leftNum) or leftNum, self.context.UseTimes) end end end function UIOfficialPrivilegeStrengthen:OnCellClicked(scrollRect, index, cellTable, target, data) if data == CTL.OfficialPrivilege.LimitType.ConsumeOrOwn then if target == cellTable.btn_Add then local sourcesList = MDL.ItemSources.GetItemSourcesById(self.context.ItemID) if #sourcesList > 0 then CTL.ItemSources.ExecuteSourceFunctionById(sourcesList[1].sourceId, self.context.ItemID) end else UTL.ItemTips.ShowCommonTipsById(self.context.ItemID) end end end ----------- function UIOfficialPrivilegeStrengthen:InitLimitLoop() if self.UIOfficialPrivilegePopUpLeft.loop_Limit.Count == 0 then self.UIOfficialPrivilegePopUpLeft.loop_Limit:AddData(CTL.OfficialPrivilege.LimitType.ConsumeOrOwn, CTL.OfficialPrivilege.LimitUIType.HaveItem) self.UIOfficialPrivilegePopUpLeft.loop_Limit:AddData(CTL.OfficialPrivilege.LimitType.UseNum, CTL.OfficialPrivilege.LimitUIType.NoItem) else self.UIOfficialPrivilegePopUpLeft.loop_Limit:RefreshCells() end end function UIOfficialPrivilegeStrengthen:RefreshConsumeOrOwn() self.UIOfficialPrivilegePopUpLeft.loop_Limit:UpdateIndex(0) self:RefreshStrengthenBuffConsume(false) end function UIOfficialPrivilegeStrengthen:RefreshOptNum() self.UIOfficialPrivilegePopUpLeft.loop_Limit:UpdateIndex(1) end ---------- 以下为buff刷新,根据刷新位置不同拆成多个方法 ---------- -- 设置buff加成显示(使用动态加载的方式) function UIOfficialPrivilegeStrengthen:InitStrengthenBuffAttr() for i, v in DataSheetManager.OfficialRightsPower:GetEnumerator() do local groupGo = self.groupList[i] local townBuffShowData = DataSheetManager.CapitalBuffData:GetDataByRelateID(v.BuffID) for index, attrInfo in ipairs(townBuffShowData.Attr_Table) do local group_AttrGo = groupGo.group_Attr[index] if not group_AttrGo then group_AttrGo = self:InstantiateCollection(groupGo.group_Attr, self.templateAttr.gameObject) end UIUtils.SetActive(group_AttrGo.gameObject, true) local attrData = DataSheetManager.AttrData:GetDataByID(attrInfo.AttrID) if attrData then UTL.Item.SetAtlasSprite(group_AttrGo.img_Icon, "UI_Common", string.isNilOrEmpty(attrData.Icon) and FightIcon or attrData.Icon) UIUtils.SetLabelText(group_AttrGo.txt_Attr, Const_IDS[attrData.Name]) group_AttrGo.txt_Num.text = string.format("+%s%%", attrInfo.AttrNum) else logging.error(LTAG.ERROR, "官职职权系统 : 强身buff配置有问题,请检查CapitalBuffData表;RelateID = ", townBuffShowData.RelateID) end end for index = #townBuffShowData.Attr_Table + 1, #groupGo.group_Attr do UIUtils.SetActive(groupGo.group_Attr[i].gameObject, false) end end end -- 刷新buff开启状态 function UIOfficialPrivilegeStrengthen:RefreshStrengthenBuffState() for i, v in DataSheetManager.OfficialRightsPower:GetEnumerator() do local groupGo = self.groupList[i] groupGo.txt_Lv.text = string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_Level, v.PowerLevel) -- 判断是否开启状态 local isArriveGrade = CTL.OfficialPosition.CheckIfUnlock(v.GradeID) local officialName = CTL.OfficialPosition.GetOfficialPositionName(v.GradeID) groupGo.btn_BuildUp:SetGray(not isArriveGrade) local lockColor = UTL.Color.ModelNameColor.White if not isArriveGrade then lockColor = UTL.Color.ModelNameColor.Red end UIUtils.SetLabel(groupGo.txt_Limit, string.FormatByIdsId(Const_IDS.IDS_OfficialPrivilege_Locked, lockColor, officialName)) end end -- 刷新buff消耗 function UIOfficialPrivilegeStrengthen:RefreshStrengthenBuffConsume(isInit) for i, v in DataSheetManager.OfficialRightsPower:GetEnumerator() do local groupGo = self.groupList[i] -- 设置图标 if isInit then UTL.Item.MoneyIcon(groupGo.img_CostIcon, self.context.ItemID) end -- 设置消耗 local count = MDL.Bag.GetItemCount(self.context.ItemID) local constItemNum = self.context.Parm[i] groupGo.txt_Cost.text = count >= constItemNum and constItemNum or UTL.Color.FormatRedColor(constItemNum) end end -------------------------------------------------------------- function UIOfficialPrivilegeStrengthen:UseOfficialStrengthen(strengThenLevel) if not CTL.OfficialPrivilege.CheckOfficialPrivilegeCanUse(self.context) then return end local count = MDL.Bag.GetItemCount(self.context.ItemID) if count >= self.context.Parm[strengThenLevel] then MDL.OfficialPrivilege.OfficialStrengthenRequest(strengThenLevel) else CTL.OfficialPrivilege.ShowOfficialPrivilegeCostNotEnough(self.context.RightsID) end end return UIOfficialPrivilegeStrengthen