local UIBattlePlayerHeadBase = require("View/Battle/UIBattlePlayerHeadBase") local UIHeadSquareCommon = UIViewClass(UIBattlePlayerHeadBase) function UIHeadSquareCommon:OnOpened(context) self.isSelf = BattleDataGetter.GetCurPlayerID() == context.playerID local isMainAwaken, isSubAwaken = BattleDataGetter.GetHeroIsAwaken(context.playerID, context.mainHeroId) UTL.Item.SetHeroIconByHeroId(self.img_MainHero, context.mainHeroId, isMainAwaken) UTL.Item.SetHeroIconByHeroId(self.img_SubHero, context.subHeroId, isSubAwaken) self:RegistEvent() self:SetImgBloodColor() self:InitHeadBG() end function UIHeadSquareCommon:InitHeadBG() if BattleDataGetter.GetMyCampID() == self.context.campId then if self.isSelf then UIUtils.SetImageByAssetBundle(self.img, MDL.SyncFourCountryWar.SelfSquare) UIUtils.SetImageByAssetBundle(self.img02, MDL.SyncFourCountryWar.SelfRound) else UIUtils.SetImageByAssetBundle(self.img, MDL.SyncFourCountryWar.TeamSquare) UIUtils.SetImageByAssetBundle(self.img02, MDL.SyncFourCountryWar.TeamRound) end else UIUtils.SetImageByAssetBundle(self.img, MDL.SyncFourCountryWar.EnemySquare) UIUtils.SetImageByAssetBundle(self.img02, MDL.SyncFourCountryWar.EnemyRound) end end function UIHeadSquareCommon:SetPlayerHp(hpPercent) self.img_Blood.fillAmount = hpPercent or 1 end function UIHeadSquareCommon:SetImgBloodColor() if self.context.ImgBloodPath then UIUtils.SetImageByAssetBundle(self.img_Blood, self.context.ImgBloodPath) end end function UIHeadSquareCommon:OnHeroEntityDead(entity) if entity:GetPlayerID() == self.context.playerID then local reviveTimer = entity.components.revive.ReviveTimer UIUtils.SetGray(self.img_MainHero, true) UIUtils.SetGray(self.img_SubHero, true) if reviveTimer and reviveTimer > 0 then self.txt_Number:ResetAndBeginTimer(false, math.ceil(reviveTimer/1000)) else self.txt_Number:EndTimer() end end end function UIHeadSquareCommon:OnHPMessageChanged(entity) if entity:GetPlayerID() == self.context.playerID then local comp_Attr = entity.components.attr local hplmt = comp_Attr:GetAttrValueNum(LuaConst.AttrType.hplmt) if hplmt <= 0 then return end local hp = FP.tonumberV1(comp_Attr.hp) local pc = FP.tonumberV1(comp_Attr.pc) local totalValue = pc + hp >= hplmt and pc + hp or hplmt self:SetPlayerHp(hp/totalValue) end end function UIHeadSquareCommon:OnPlayerRevive(entity) if entity:GetPlayerID() == self.context.playerID then UIUtils.SetGray(self.img_MainHero, false) UIUtils.SetGray(self.img_SubHero, false) end end return UIHeadSquareCommon