local UIEntityBasePanel = require "View/Battle/BattleEntityUI/UIEntityBasePanel" local UIEntityHeroPanel = UIViewClass(UIEntityBasePanel) local EntityUIBaseModule = require("View/Battle/BattleEntityUI/EntityUIModule/EntityUIBaseModule") local EventSystem = require("Event/EventSystem") local LuaUpdater = require("Main/LuaUpdater") local LuaBit = require("bit") local HPImagePath = { [LuaConst.BloodBarColorType.Red] = ConstAssetPathConfig.Path45, [LuaConst.BloodBarColorType.Blue] = ConstAssetPathConfig.AssetPath211, [LuaConst.BloodBarColorType.Green] = ConstAssetPathConfig.FriendPath, [LuaConst.BloodBarColorType.Yellow] = ConstAssetPathConfig.AssetPath212, } local NameColor = { [LuaConst.BloodBarColorType.Red] = {1, 151/255, 143/255}, [LuaConst.BloodBarColorType.Blue] = {189/255, 232/255, 1}, [LuaConst.BloodBarColorType.White] = {1, 1, 1}, } local Const_TotalwIdTH = 135 function UIEntityHeroPanel:OnCreated() self.uiElementParams = { UseZoom = false, -- 是否使用头顶大小跟随距离变化 MaxDistSqrModelUI = 30 * 30, -- 最远显示UI距离平方 } self.enemyHideType = false self.friendHideType = false end function UIEntityHeroPanel:OnOpened(context) self:RegistSystemEvent(EventID.UIBattle_HeroElement_Create, self.CreateHeroElement) -- 创建名字板UI self:RegistSystemEvent(EventID.UIBattle_HeroElement_SetImageColor, self.SetImageColor) -- 修改血条颜色 self:RegistSystemEvent(EventID.UIBattle_HeroElement_SetNameColor, self.SetNameColor) -- 修改名字颜色 self:RegistSystemEvent(EventID.UIBattle_Element_TopShowTitle, self.ElementTopShowTitle) -- 设置头顶称号(显隐) self:RegistSystemEvent(EventID.UIBattle_Element_SetHeadUI, self.ElementSetHeadUI) self:RegistSystemEvent(EventID.UIBattle_Element_RemoveHeadUI, self.ElementRemoveHeadUI) self:RegistSystemEvent(EventID.UIBattle_Element_RefreshHeadUI, self.ElementRefreshHeadUI) self:RegistSystemEvent(EventID.Level_InitLevel, self.OnInitLevel) self:RegistSystemEvent(EventID.UIBattle_Element_OffsetY, self.SetUIOffsetY) -- 修改UI位置Y的偏移 self:RegistSystemEvent(EventID.UIBattle_Element_UpdateLevel, self.ElementUpdateLevel) ---设置势力战战场等级 end function UIEntityHeroPanel:OnInitLevel() if BattleDataGetter.IsDragonArteryLevel() then --龙脉战要求名字版近大远小 self.uiElementParams = { UseZoom = true, MaxDistSqrModelUI = 30 * 30, ModelUIMinDistance = 5, ModelUIMaxDistance = 50, ModelUIMinScale = 1, ModelUIMaxScale = 1.2, } elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncUnfairTeamPVP) then --天地群雄3v3距离改长 self.uiElementParams = { UseZoom = false, MaxDistSqrModelUI = 100 * 100, } else self.uiElementParams = { UseZoom = false, MaxDistSqrModelUI = 30 * 30, } end end -- sourceEntity 用其信息给expEntity创建名字板 function UIEntityHeroPanel:CreateHeroElement(expEntity, name, sourceEntity) if expEntity.RenderEntity then local entity = expEntity.Entity local nameResult = name if sourceEntity then entity = sourceEntity nameResult = BattleDataGetter.GetEntityUIName(sourceEntity) if expEntity.hasModelUI then EventSystem.Dispatch(EventID.UIBattle_ExpEntity_UIDispose, expEntity.RenderEntity) else if expEntity.Entity._logicInitData.CharacterType == LuaConst.CharacterType.Monster then expEntity:SetModel3DUIVisible(false) end end end local elementData = self:CreateElementData(expEntity) local element = elementData.element element.state_Hp:SetState((entity:IsHero() or entity:IsIllusion()) and 0 or 1) if sourceEntity then local hp, maxHp, pc = BattleDataGetter.GetHpAndPCInfo(expEntity.Entity) local totalValue = math.max(pc + hp, maxHp) UIUtils.ChangeWidth(elementData.element.sprite_HpFg.gameObject, Const_TotalwIdTH * hp / totalValue) UIUtils.ChangeWidth(elementData.element.sprite_PcFg.gameObject, Const_TotalwIdTH * pc / totalValue) else EntityUIBaseModule.ElementActive(elementData, false) end local playerSelf = entity:IsPlayerSelf() local mainPlayer = entity:IsMainEntityOfPlayer() if mainPlayer then UIUtils.SetLabel(elementData.element.localLab_Name, nameResult) else UIUtils.SetLabel(elementData.element.localLab_Name, "") end if playerSelf and mainPlayer then UIUtils.SetImageByAssetBundle(element.sprite_HpFg, HPImagePath[LuaConst.BloodBarColorType.Green]) element.state_icon:SetState(0) else if elementData.isEnemy then UIUtils.SetImageByAssetBundle(element.sprite_HpFg, HPImagePath[LuaConst.BloodBarColorType.Red]) element.state_icon:SetState(2) else UIUtils.SetImageByAssetBundle(element.sprite_HpFg, HPImagePath[LuaConst.BloodBarColorType.Blue]) element.state_icon:SetState(1) end end expEntity:CreateHeadUI(sourceEntity) UIUtils.SetActive(elementData.element.group_level, false) if expEntity.PetRenderEntity then local petElementData = self:CreatePetElementData(expEntity) local color = petElementData.isEnemy and UTL.Color.ModelNameColor.Red or UTL.Color.ModelNameColor.Blue local name = expEntity:GetPetName(color) UIUtils.SetLabel(petElementData.element.localLab_Name, name) petElementData.element.state_Hp:SetState(2) expEntity:SetModelUI_PetTitle() end else if BattleDataGetter.IsTownLevel() then EventSystem.Dispatch(EventID.UI_AddBattleModelUI) end end end function UIEntityHeroPanel:SetMaxDistSqrModelUI(distance) -- 防止基类执行逻辑 end -- 设置隐藏层级(实现基类方法) function UIEntityHeroPanel:SetHideType(hideLayer, hide) if hide then if LuaBit.band(hideLayer, LuaBit.lshift(1, LuaConst.Layer.Hero_Friend)) > 0 then self.friendHideType = true end if LuaBit.band(hideLayer, LuaBit.lshift(1, LuaConst.Layer.Hero_Enemy)) > 0 then self.enemyHideType = true end else self.enemyHideType = false self.friendHideType = false end end ---------- Start 具体的子项Element操作 Start ---------- -- 改变名字(实现基类方法) function UIEntityHeroPanel:ElementChangeName(renderEntity, name) local elementData = self.elementDic[renderEntity] if elementData then UIUtils.SetLabel(elementData.element.localLab_Name, name) self:ElementRefreshHeadUI(renderEntity) end end function UIEntityHeroPanel:ElementChangeColorName(renderEntity, name) local elementData = self.elementDic[renderEntity] if elementData then UIUtils.SetLabel(elementData.element.localLab_Name, name) end end function UIEntityHeroPanel:SetImageColor(renderEntity, colorType) local elementData = self.elementDic[renderEntity] local imagePath = HPImagePath[colorType] if elementData and not string.isNilOrEmpty(imagePath) then UIUtils.SetImageByAssetBundle(elementData.element.sprite_HpFg, imagePath) end end function UIEntityHeroPanel:SetNameColor(renderEntity, colorType) local elementData = self.elementDic[renderEntity] local nameColor = NameColor[colorType] if elementData and nameColor ~= nil then UIUtils.SetLocalTextColor(elementData.element.localLab_Name, nameColor[1], nameColor[2], nameColor[3]) end end -- 更新血条(实现基类方法) function UIEntityHeroPanel:ElementUpdateHP(renderEntity, hp, pc, maxHp, init) local elementData = self.elementDic[renderEntity] if elementData then local totalValue = math.max(pc + hp, maxHp) if totalValue > 0 then UIUtils.ChangeWidth(elementData.element.sprite_HpFg.gameObject, Const_TotalwIdTH * hp / totalValue) UIUtils.ChangeWidth(elementData.element.sprite_PcFg.gameObject, Const_TotalwIdTH * pc / totalValue) end end end function UIEntityHeroPanel:GetElementHide(elementData) return (elementData.isEnemy and self.enemyHideType) or (self.friendHideType and not elementData.isEnemy) end function UIEntityHeroPanel:GetModelNameTrans(renderEntity) local elementData = self.elementDic[renderEntity] if elementData then return elementData.element.localLab_Name.transform end end function UIEntityHeroPanel:ElementUpdateLevel(renderEntity, level) local elementData = self.elementDic[renderEntity] if elementData then elementData.element.label_level.text = level UIUtils.SetActive(elementData.element.group_level, true) end end ------------ End 具体的子项Element操作 End ------------ return UIEntityHeroPanel