local UIBattleBuffPanel = UIViewClass() local EventSystem = require('Event/EventSystem') local ZERO = 0 local MAX = 9999 --超过这个时间认定为永久buff local tonumberV1 = FP.tonumberV1 local type = type local isNilOrEmpty = string.isNilOrEmpty local function SortBuffList(a, b) local buffDataA = a.BuffInfoData local buffDataB = b.BuffInfoData local priorityA = buffDataA.IconPriority local priorityB = buffDataB.IconPriority local addTimeA = a.AddTime local addTimeB = b.AddTime if priorityA ~= priorityB then return priorityA > priorityB else if addTimeA ~= addTimeB then return addTimeA > addTimeB else return buffDataA.BuffID < buffDataB.BuffID end end end function UIBattleBuffPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_DelayToTownPlay, self.OnLevelLoaded) self.showType = context.buffType self.entityId = context.entityId self.isRefreshCD = false self.isBeginTimer = false self.pauseRefresh = false self.buffItemList = {} self.initBuffInfoList = {} self:RegistSystemEvent(EventID.Level_Pause, self.PauseCD) self:RegistSystemEvent(EventID.Player_HidingUpdate, self.PauseCDByHidingUpdate) --刷新buff BattleDataGetter.GetShowingBuffInfoByEntityId(self.entityId, self.initBuffInfoList) for i, v in ipairs(self.initBuffInfoList) do v.AddTime = UTL.Time.GetServerTimestamp() end for _,v in ipairs(self.initBuffInfoList) do if v.SourceEntity then self:UpdateBuffShow(v.BuffInfoData, v.BuffTimer, v.BuffLayer, v.SourceEntity.EntityID) end end if self.showType == LuaConst.UIBuffShowType.PlayerSelf then self:RegistSystemEvent(EventID.Set_CurEntity, self.OnEntityChange) self:RegistSystemEvent(EventID.UI_SelectOneReviveOver, self.OnSelectOneReviveOver) elseif self.showType == LuaConst.UIBuffShowType.PlayerOthers then self:RegistSystemEvent(EventID.Level_SwitchHero, self.OnSwitchHero) end end function UIBattleBuffPanel:OnSwitchHero(type, entity) self:OnEntityChange(entity:GetEntityID()) end function UIBattleBuffPanel:OnLevelLoaded() --当前可能正处于暂停状态 if BattleDataGetter.IsLevelPause() then self:PauseCD(true) end end function UIBattleBuffPanel:PauseCDByHidingUpdate(entityId,pause) if entityId == self.entityId then if pause == nil then pause = false end self:PauseCD(pause) end end function UIBattleBuffPanel:PauseCD(pause) self.pauseRefresh = true self.isRefreshCD = true self.isBeginTimer = pause self.obj_ScrollPanel:RefreshCells() self.isRefreshCD = false self.pauseRefresh = false end function UIBattleBuffPanel:OnSelectOneReviveOver(entity) if entity and entity:GetEntityID() == BattleDataGetter.GetCurEntityID() then self:OnEntityChange(entity:GetEntityID()) end end --切换武将,需要清除上一个武将的buff function UIBattleBuffPanel:OnEntityChange(entityId) --清除buff for i = #self.buffItemList, 1, -1 do table.remove(self.buffItemList,i) end self.obj_ScrollPanel:ClearCells() --初始化buff table.clearArray(self.initBuffInfoList) self.entityId = entityId BattleDataGetter.GetShowingBuffInfoByEntityId(self.entityId, self.initBuffInfoList) for i, v in ipairs(self.initBuffInfoList) do v.AddTime = UTL.Time.GetServerTimestamp() end for _,v in ipairs(self.initBuffInfoList) do if v.SourceEntity then self:UpdateBuffShow(v.BuffInfoData,v.BuffTimer,v.BuffLayer,v.SourceEntity.EntityID) end end end function UIBattleBuffPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.obj_ScrollPanel then --防止cell从池子里取出来的amount不对,重新设一下 --cellTable.sprite_CDMask:SetSpriteMaskFillAmount(0) if self.isRefreshCD then if data.BuffTimer <= MAX then if self.isBeginTimer then cellTable.sprite_CDMask:PauseTimer() else cellTable.sprite_CDMask:ResumeTimer() end else cellTable.sprite_CDMask:EndTimer() cellTable.sprite_CDMask:SetSpriteMaskFillAmount(0) end else local buffInfoData = data.BuffInfoData UIUtils.SetImageByAssetBundle(cellTable.sprite_BuffIcon, UTL.String.GetSmallIconPath(buffInfoData.BuffIcon)) local buffTime = data.BuffTimer local entity = BattleDataGetter.GetEntityByEntityID(self.entityId) if buffTime <= MAX then if buffTime and buffTime > 0 then local leftTime = BattleDataGetter.GetEntityBuffUpdateTimerByID(entity, data.BuffID) leftTime = leftTime > 0 and leftTime or buffTime cellTable.sprite_CDMask:ResetAndBeginTimer(true, buffTime - leftTime, buffTime) else cellTable.sprite_CDMask:EndTimer() end else --常驻显示图标即可 cellTable.sprite_CDMask:EndTimer() cellTable.sprite_CDMask:SetSpriteMaskFillAmount(0) end --层数 local layer = data.BuffLayer if layer and layer > 1 then cellTable.lab_FloorNum.text = layer else cellTable.lab_FloorNum.text = nil end end end end function UIBattleBuffPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.obj_ScrollPanel then if not self.pauseRefresh then UIManager.OpenView(Const_UI_Lua.UIEnum.UIBattleBuffDetailTips, {buffInfoList = self.buffItemList, entityId = self.entityId}, "Common/UIBuffTips") end end end function UIBattleBuffPanel:GetBuffItemInfoIndex(buffData, sourceEntityId) local index = -1 for i, buffItemInfo in ipairs(self.buffItemList) do if buffItemInfo.BuffID == buffData.BuffID then if buffData.IsRecordSource then if sourceEntityId == buffItemInfo.SourceEntityId then index = i break end else index = i break end end end return index end function UIBattleBuffPanel:IsIconBuffShow(buffData) if isNilOrEmpty(buffData.BuffIcon) then return false end --主城buff不显示在战斗中,暂时不需要,先注释 --if MDL.HomeMain.GetIfBuffCapital(buffData.BuffID) then -- return false --end return true end function UIBattleBuffPanel:AddBuffItem(buffData, time, layer, sourceEntityId) local buffItemInfo = { BuffID = buffData.BuffID, BuffInfoData = buffData, BuffLayer = layer, BuffTimer = time, SourceEntityId = sourceEntityId, AddTime = UTL.Time.GetServerTimestamp(), } table.insert(self.buffItemList, 1, buffItemInfo) table.sort(self.buffItemList, SortBuffList) return buffItemInfo, self:GetBuffItemInfoIndex(buffData, sourceEntityId) end --战斗推一个buff过来,判断当前是否在显示,是重置时间,不是则新增 --同样的buff,判断层数或者时长为0,将buff销毁 function UIBattleBuffPanel:UpdateBuffShow(buffData, time, layer, sourceEntityId) if self:IsIconBuffShow(buffData) then local buffTime = type(time) == "table" and tonumberV1(time) or time local index = self:GetBuffItemInfoIndex(buffData, sourceEntityId) if index > 0 then --已经存在,更新显示 local buffItemInfo = self.buffItemList[index] if buffTime > ZERO and layer > ZERO then buffItemInfo.BuffTimer = buffTime buffItemInfo.BuffLayer = layer self.obj_ScrollPanel:UpdateIndex(index - 1, buffItemInfo) else for i, data in ipairs(self.buffItemList) do if data == buffItemInfo then table.remove(self.buffItemList, i) break end end self.obj_ScrollPanel:ReloadAll(self.buffItemList) end else --新增的 if buffTime > ZERO and layer > ZERO then local newBuffData, newBuffIndex = self:AddBuffItem(buffData, buffTime, layer, sourceEntityId) self.obj_ScrollPanel:InsertData(newBuffIndex - 1, newBuffData, 0) end end EventSystem.Dispatch(EventID.UI_UpdateBuff_Tips, self.entityId, self.buffItemList) end end return UIBattleBuffPanel