local UIBattleBossBattleInfoView = UIViewClass() local HP_STYLE_COUNT = 3 --血条颜色变化数量 local ANIM_DURATION = 0.3 --不是多层血条 或者 多层血条最后一层的运动是时间 local ANIM_DURATION_QUICK = 0.1 -- 多层血条的最初血条运动时间 快速的消失 local ICON_BOSS = ConstAssetPathConfig.ICON_BOSS local ICON_WEAK = ConstAssetPathConfig.ICON_WEAK local UIANIMATIONTIME = 0.2 -- 选择多boss血条时的动画时间 local EventSystem = require 'Event/EventSystem' function UIBattleBossBattleInfoView:OnCreated() self.hpAnimSimple = {} self.hpAnimWithCallBack = {} self.hpAnimWithCallBackParams = {} if LevelManager.IsGoldHeroTrail() then self.damageDelta = MDL.SuperGoldBoss.GetLastBossDamageDelta() or 0 else self.damageDelta = 0 end if self.group_GoldHero then UIUtils.SetActive(self.group_GoldHero, BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GoldHeroCooperate) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.GoldHeroTrail)) end end function UIBattleBossBattleInfoView:OnOpened(context) self:RegistSystemEvent(EventID.UIBattle_BossHPChanged, self.OnHPChanged) self:RegistSystemEvent(EventID.UIBattle_BossAMChanged, self.OnAMChanged) self:RegistSystemEvent(EventID.UI_UpdateBuff_Boss, self.UpdateBuffShow) self:RegistSystemEvent(EventID.UIBattle_RefreshBossHP, self.RefreshBossHP) --self:RegistSystemEvent(EventID.UIBattle_BossInfoShow, self.ShowBossInfo)--这个暂时没用到 问策划策划也说不知道干嘛的,只有UE说这里要显示"xxx正在xxx",所以注了 --monsterId是CharacterID,不是EntityID self.bindingEntityID = context.entityID self.buffPanel = self.buffItem_Root:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), {buffType = LuaConst.UIBuffShowType.Boss, entityId = self.bindingEntityID}) self.bindingMonsterId = BattleDataGetter.GetCharacterIDByEntityID(self.bindingEntityID) self.curIndex = HP_STYLE_COUNT self.isFirst = true self:SetDisplayInfo() end function UIBattleBossBattleInfoView:SetDisplayInfo() local monsterData = DataSheetManager.MonsterData:GetDataByID(self.bindingMonsterId) UIUtils.SetLabelText(self.BossName, Const_IDS[monsterData.MonsterNameIDS]) if monsterData and monsterData.BossHpLayer > 0 then self.bossHpLayer = monsterData.BossHpLayer self.curBossHpLayer = monsterData.BossHpLayer else self.bossHpLayer = 1 self.curBossHpLayer = 1 self.hpGroup[1].gameObject:SetActive(false) self.hpGroup[2].gameObject:SetActive(false) end if self.hpValue then --军团boss没有血条 self.hpValue.text = "x"..self.curBossHpLayer end local monsterModelData = DataSheetManager.MonsterModelData:GetDataByID(monsterData.ModelID) self.bossIconName = monsterModelData.BossHeadIcon self:RefreshBossIcon() end function UIBattleBossBattleInfoView:RefreshBossIcon() if string.isNilOrEmpty(self.bossIconName) then self.state_Icon:SetState(0) UIUtils.SetImageByAssetBundle(self.BossIcon, ICON_BOSS) else self.state_Icon:SetState(1) UTL.Item.ItemIconByName(self.img_HeroIcon, self.bossIconName) end end --Buff变化 function UIBattleBossBattleInfoView:UpdateBuffShow(buffData, time, layer, sourceEntityId, entityID) if entityID == self.bindingEntityID then self.buffPanel:UpdateBuffShow(buffData, time, layer, sourceEntityId) end end --血量变化 function UIBattleBossBattleInfoView:OnHPChanged(hp, maxHp , entityID, damageDelta) if entityID == self.bindingEntityID then self.hp = hp self.maxHp = maxHp if self.isFirst then self:SetHpValue(hp, maxHp) self.isFirst = false else self:DoAnimation(hp, maxHp) end if hp <= 0 then self:SetBossDead() end self.damageDelta = self.damageDelta + (-damageDelta) self.txt_Damage.text = math.ceil(self.damageDelta) end end function UIBattleBossBattleInfoView:RefreshBossHP() local entity = BattleDataGetter.GetEntityByEntityID(self.bindingEntityID) if entity then local hp = FP.tonumberV1( entity:GetHp() ) local maxHp = FP.tonumberV1( entity:GetMaxHp() ) self:DoAnimation(hp, maxHp) if hp <= 0 then self:SetBossDead() end end end function UIBattleBossBattleInfoView:SetBossDead() for i, v in ipairs(self.hpGroup) do self:FinishUIAnimationByIndex(i, true) self:FinishUIAnimationByIndex(i, false) v.transform:SetLocalScale(0) end self.sprite_AmFg_BossMask.fillAmount = 0 UIUtils.SetGray(self.BossIcon, true) UIUtils.SetGray(self.img_HeroIcon, true) end function UIBattleBossBattleInfoView:SetHpValue(hp, maxHp) if maxHp - hp < 1 then return end self.curHp = hp --这块向上取整会丢失一些误差,但是可以接受 --如果用floor向下取整或者直接使用float,在计算的时候,会因为误差和精度问题,导致一些情况下,计算出来的boss血量层数会超过设定的boss血量层数 --问题出在nextLayerValue = math.ceil(hp / layerHpCount)之中的向上取整,但是因为血条本身的机制原因,这里必须向上取整,所以退而求其次,只能都向上取整,这样不会出现上述离谱的情况 local layerHpCount = math.ceil(maxHp / self.bossHpLayer) -- 每层血量 local scaleValue = hp < maxHp and hp % layerHpCount / layerHpCount or 1 --当前伤害最后一层掉多少比例 local nextLayerValue = math.ceil(hp / layerHpCount) -- 当前伤害掉到第几层血 self.isDamage = false if nextLayerValue ~= self.curBossHpLayer then -- 当前伤害掉层数了 self.nextScaleValue = scaleValue --下一次动画 缩放比例 self.curBossHpLayer = nextLayerValue -- 当前层数 if self.curBossHpLayer > 2 then --当前层数最后三层了 不用移动层数image self.hpGroup[self.curIndex].transform:SetAsFirstSibling() self.hpGroup[self.curIndex].transform:SetLocalScale(1) else self.hpGroup[self.curIndex].transform:SetLocalScale(0) if self.curBossHpLayer == 1 then self.curIndex = self.curIndex - 1 self.hpGroup[self.curIndex].transform:SetLocalScale(0) end end self.curIndex = self.curIndex - 1 if self.curIndex == 0 then self.curIndex = HP_STYLE_COUNT end end self.hpGroup[self.curIndex].transform:SetLocalScale(scaleValue) self.hpGroup[self.curIndex].transform:SetAsLastSibling() if self.hpValue then --军团boss没有血条 self.hpValue.text = "x"..self.curBossHpLayer -- 当前层数 end end function UIBattleBossBattleInfoView:DoAnimation(hp, maxHp) if not self.curHp then self.curHp = maxHp return end self.isDamage = (self.curHp - hp >= 0) self.curHp = hp if self.curBossHpLayer > 0 then -- 如果层数大于0 --这块向上取整会丢失一些误差,但是可以接受 --如果用floor向下取整或者直接使用float,在计算的时候,会因为误差和精度问题,导致一些情况下,计算出来的boss血量层数会超过设定的boss血量层数 --问题出在nextLayerValue = math.ceil(hp / layerHpCount)之中的向上取整,但是因为血条本身的机制原因,这里必须向上取整,所以退而求其次,只能都向上取整,这样不会出现上述离谱的情况 local layerHpCount = math.ceil(maxHp / self.bossHpLayer) -- 每层血量 local scaleValue = hp < maxHp and hp % layerHpCount / layerHpCount or 1 --当前伤害最后一层掉多少比例 local nextValue = hp / layerHpCount local nextLayerValue = math.ceil(nextValue) -- 当前伤害掉到第几层血 if nextLayerValue ~= self.curBossHpLayer then -- 当前伤害掉层数了 if nextLayerValue > self.bossHpLayer then self.isDamage = false nextLayerValue = self.bossHpLayer end self.nextScaleValue = scaleValue --下一次动画 缩放比例 self.curBossHpLayer = nextLayerValue -- 当前层数 local targetDestinationPos = self.isDamage and 0 or 1 --- 因为掉层了 0.1秒把当前层缩放到0 然后在把下一层的动画开启 self:FinishUIAnimationByIndex(self.curIndex, false) self:FinishUIAnimationByIndex(self.curIndex, true) local playingID = self.hpAnimWithCallBack[self.curIndex] if playingID then self:ScaleToSize(playingID, targetDestinationPos, 1, ANIM_DURATION_QUICK) else playingID = self:ScaleToSize(self.hpGroup[self.curIndex].transform, targetDestinationPos, 1, ANIM_DURATION_QUICK, true) self.hpAnimWithCallBack[self.curIndex] = playingID end self.hpAnimWithCallBackParams[playingID] = scaleValue else -- 当前没有掉层 只是本层移动 self:FinishUIAnimationByIndex(self.curIndex, true) if self.hpAnimSimple[self.curIndex] then self:ScaleToSize(self.hpAnimSimple[self.curIndex], scaleValue, 1, ANIM_DURATION) else self.hpAnimSimple[self.curIndex] = self:ScaleToSize(self.hpGroup[self.curIndex].transform, scaleValue, 1, ANIM_DURATION, false) end --将当前掉血的血条放到最上边 self.hpGroup[self.curIndex].transform:SetAsLastSibling() end end end function UIBattleBossBattleInfoView:OnUIAnimationStoped(playingID) local scaleValue = self.hpAnimWithCallBackParams[playingID] if self.isDamage then --伤害,当前血条要被放到最后,并且设置成1 if self.curBossHpLayer > 2 then --当前层数最后三层了 不用移动层数image self:FinishUIAnimationByIndex(self.curIndex, false) self:FinishUIAnimationByIndex(self.curIndex, true) self.hpGroup[self.curIndex].transform:SetAsFirstSibling() self.hpGroup[self.curIndex].transform:SetLocalScale(1) end self.curIndex = self.curIndex - 1 if self.curIndex == 0 then self.curIndex = HP_STYLE_COUNT end else --回血,当前血条的上一个index的血条要放到最前边并且置成0 self.curIndex = self.curIndex + 1 if self.curIndex > HP_STYLE_COUNT then self.curIndex = self.curIndex - HP_STYLE_COUNT end if self.curBossHpLayer ~= self.bossHpLayer then self:FinishUIAnimationByIndex(self.curIndex, false) self:FinishUIAnimationByIndex(self.curIndex, true) self.hpGroup[self.curIndex].transform:SetAsLastSibling() self.hpGroup[self.curIndex].transform:SetLocalScale(0) end end if self.hpValue then --军团boss没有血条 self.hpValue.text = "x"..self.curBossHpLayer -- 当前层数 end if self.nextScaleValue then --移动到下一层的正确比例处 self:FinishUIAnimationByIndex(self.curIndex, true) local playingID = self.hpAnimSimple[self.curIndex] if playingID then self:ScaleToSize(self.hpAnimSimple[self.curIndex], scaleValue, 1, ANIM_DURATION) else playingID = self:ScaleToSize(self.hpGroup[self.curIndex].transform, scaleValue, 1, ANIM_DURATION, false) self.hpAnimSimple[self.curIndex] = playingID end self.nextScaleValue = nil end end function UIBattleBossBattleInfoView:FinishUIAnimationByIndex(index, isCallBack) if isCallBack then local animIdCB = self.hpAnimWithCallBack[index] if animIdCB then self:StopUIAnimation(animIdCB, false, true) end else local animationId = self.hpAnimSimple[index] if animationId then self:StopUIAnimation(animationId, false, true) end end end --霸体变化 function UIBattleBossBattleInfoView:OnAMChanged(am, maxAm, lastAm, entity) if self.bindingEntityID == entity.EntityID then local percent = maxAm == 0 and 0 or am/maxAm if lastAm>0 then if percent<=0 then self.sprite_AmFg_BossMask.fillAmount = 1 if self.BossAm_ShineLoop == nil then self.BossAm_ShineLoop = self:PlayUIAnimation("BossAm_ShineLoop") else self:PlayUIAnimation( self.BossAm_ShineLoop) end if self.effect_weak then self.effect_weak:PlayUIEffect() else logging.error(LTAG.ERROR , "UIBattleBossBattleInfoView.effect_weak 为 nil ,self.BossIcon 是否为空: " , self.BossIcon == nil) end self.state_Icon:SetState(0) UIUtils.SetImageByAssetBundle(self.BossIcon,ICON_WEAK) else if self.BossAm_ShineLoop then self:StopUIAnimation(self.BossAm_ShineLoop) end self.sprite_AmFg_BossMask.fillAmount = percent self:RefreshBossIcon() end elseif lastAm<=0 and percent==1 then self.sprite_AmFg_BossMask.fillAmount = 1 self:RefreshBossIcon() if self.BossAm_ShineLoop then self:StopUIAnimation(self.BossAm_ShineLoop) end if self.BossAm_Return == nil then self.BossAm_Return = self:PlayUIAnimation("BossAm_Return") else self:PlayUIAnimation(self.BossAm_Return ) end end end end function UIBattleBossBattleInfoView:ActiveUI(context, onlyActive) self.gameObject:SetActive(true) end function UIBattleBossBattleInfoView:HideUI() self.gameObject:SetActive(false) end function UIBattleBossBattleInfoView:OnClosed() if self.buffPanel then self.buffPanel:CloseView() if self.damageDelta and self.damageDelta > 0 then EventSystem.Dispatch(EventID.UI_SuperGoldBoss_CloseBossBattleInfoViewDmgDelta, self.damageDelta) end end end function UIBattleBossBattleInfoView:SetBossHPBarWidth(width) self.contents.transform:SetSizeDelta(width, nil) end function UIBattleBossBattleInfoView:SetPosAndScale(posX, scale) local y = scale == 1 and 0 or 15 if posX then if self.posHandleID then self:MoveToPos(self.posHandleID, posX, y, UIANIMATIONTIME) else self.posHandleID = self:MoveToPos(self.gameObject.transform, posX, y, UIANIMATIONTIME, false) end end if self.scaleHandleID then self:ScaleToSize(self.scaleHandleID, scale, scale, UIANIMATIONTIME) else self.scaleHandleID = self:ScaleToSize(self.gameObject.transform, scale, scale, UIANIMATIONTIME, false) end end function UIBattleBossBattleInfoView:FinishUIAnimationDone() if self.posHandleID then self:StopUIAnimation(self.posHandleID, false, true) end if self.scaleHandleID then self:StopUIAnimation(self.scaleHandleID, false, true) end end --这个暂时没用到 问策划策划也说不知道干嘛的,只有UE说这里要显示"xxx正在xxx",所以注了 -- function UIBattleBossBattleInfoView:ShowBossInfo(infoText) -- if infoText then -- self.group_Info.lab_Info.text = infoText -- UIUtils.SetActive(self.group_Info.transform, true) -- else -- UIUtils.SetActive(self.group_Info.transform, false) -- end -- end return UIBattleBossBattleInfoView