local UIBattleEnemyPanel = UIViewClass() -- [[ -- 通用敌人界面 -- ]] -------------------- function UIBattleEnemyPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_UpdateBuff_OtherHero, self.UpdateBuffShow) self:RegistSystemEvent(EventID.Level_SwitchHero, self.OnSwitchHero) -- 注册Update self.enemyHeroId = {} -- 敌方英雄Id列表 映射关系 index To heroId self.enemyEntityBuffPanel = {} -- 敌方buff界面 映射关系 index To UISyncTeamBuffPanel self.isDead = {} -- 敌方死亡列表 self.enemyEntityIndex = {} -- 敌方 PlayerId List self:StartRepeatFunc(self.RepeatFunc, 0) self.comboViewRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleCombo), {isShowComboType = LuaConst.ComboType.IsKillHero}) self:CreateEnemyHead() end function UIBattleEnemyPanel:OnButtonClicked(comp) if comp == self.btn_Shezhi then UIManager.OpenView(Const_UI_Lua.UIEnum.UISettingMainPanel) end end -------------------- function UIBattleEnemyPanel:RepeatFunc(deltaTime, timeSinceUpdate) local curTimer = BattleDataGetter.GetRemainTime() UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(curTimer)) end -- 根据战斗信息筛选敌方英雄 function UIBattleEnemyPanel:CreateEnemyHead() local teamHeroEntities = BattleDataGetter.GetHeroEntities() local sortList = {} for i, teamEntity in ipairs(teamHeroEntities) do local entity = teamEntity[1] if entity._logicInitData.EntityCampID ~= LevelPlayerManager.MainEntityCampID then table.insert(sortList, entity) end end for i, v in ipairs(self.enemyList) do UIUtils.SetActive(v.gameObject, false) end for i, entity in ipairs(sortList) do table.insert(self.enemyEntityIndex, entity:GetPlayerID()) self:RegistSystemEvent(entity.Event_EntityHPChanged, self.RefreshPlayer) self:InitEnemy(entity, #self.enemyEntityIndex) end end -- 换将 function UIBattleEnemyPanel:OnSwitchHero(type, entity) self:RefreshPlayer(entity) end -- 刷新敌方英雄 function UIBattleEnemyPanel:RefreshPlayer(entity) if not CampManager.IsEnemyCamp(entity:GetCampID(),LevelPlayerManager.MainEntityCampID) then return end for i, v in ipairs(self.enemyEntityIndex) do if v == entity:GetPlayerID() then self:InitEnemy(entity, i) return end end end -- 初始化敌方英雄 function UIBattleEnemyPanel:InitEnemy(entity, index) if index > 3 then return -- 劫镖敌人3个人 也只有3个头像 超过会报错 但是测试过程中 可能有超过3个人 这么写一下 如果判断celltable 有其它问题可能给检测不到 end local roleId = entity._logicInitData.CharacterID local cellTable = self.enemyList[index] UIUtils.SetActive(cellTable.gameObject, true) -- 加载头像 if self.enemyHeroId[index] ~= roleId then self.enemyHeroId[index] = roleId UTL.Item.SetHeroIconByHeroId(cellTable.texture_HeadImg, roleId, BattleDataGetter.GetHeroIsAwaken(entity:GetPlayerID(), roleId)) local entityId = entity:GetEntityID() if self.enemyEntityBuffPanel[index] then self.enemyEntityBuffPanel[index]:OnEntityChange(entityId) else self.enemyEntityBuffPanel[index] = self.enemyList[index].buffCanvas:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UISyncTeamBuffPanel), {entityId = entityId, buffType = LuaConst.UIBuffShowType.PlayerOthers}) end end cellTable.sprite_HpFg_Show.fillAmount = FP.tonumberV1(entity.components.attr.hp / entity.components.attr:GetAttrValue(LuaConst.AttrType.hplmt)) local reviveTime = entity.components.revive.ReviveTimer if reviveTime > 0 then if not self.isDead[entity._logicInitData.CharacterID] then self.isDead[entity._logicInitData.CharacterID] = reviveTime UIUtils.SetActive(cellTable.sprite_ReviveMask, true) end else UIUtils.SetActive(cellTable.sprite_ReviveMask, false) self.isDead[entity._logicInitData.CharacterID] = nil end end -- 更新敌方英雄buff function UIBattleEnemyPanel:UpdateBuffShow(entity, buffData, time, layer, sourceEntityId) for i, v in ipairs(self.enemyEntityIndex) do if v == entity:GetPlayerID() then if self.enemyList[i] then self.enemyEntityBuffPanel[i]:UpdateBuffShow(buffData, time, layer, sourceEntityId) return end end end end return UIBattleEnemyPanel