local UIInBattleView = UIViewClass() local tonumberV1 = FP.tonumberV1 local SelfEntityMaxCount = 3 --去掉自己 local TeamMemberCount = 2 local HpMaterialPath = ConstAssetPathConfig.CIRCLE_HP_MATERIAL_PATH local HpImgPath = ConstAssetPathConfig.HpImgPath2 function UIInBattleView:OnCreated() self.SwitchHeroCD = BattleDataGetter.GetSwitchHeroCD() / 1000 --key:entityId, value:View self.selfEntityView = {} self.teamEntityView = {} self.teamBuffPanel = {} self.buffPanel = {} end function UIInBattleView:OnOpened(context) self.InitMaterial = false if BattleDataGetter.IsSelectOneReviveLevel() or BattleDataGetter.IsDemonGodLevel() or BattleDataGetter.IsCityWarWaitingLevel() then self:OnOpened_SelectOneReview(context) else self:OnOpened_Common(context) end self.playerId = BattleDataGetter.GetCurPlayerID() end function UIInBattleView:OnClosed() UTL.Material.ResetHpMaterialPoolCount() end -- 普通的三切头像 function UIInBattleView:OnOpened_Common(context) --因为1V1的地方血条继承了这个脚本,先临时修改一下 if self.SelectOneReview then UIUtils.SetActive(self.SelectOneReview.gameObject, false) end if self.CommonReview then UIUtils.SetActive(self.CommonReview.gameObject, true) end self:RegistSystemEvent(EventID.Level_Pause, self.PauseSwitchCD) self:RegistSystemEvent(EventID.Player_Revive, self.OnPlayerRevive) self:RegistSystemEvent(EventID.Level_SwitchHero, self.OnSwitchHero) self:RegistSystemEvent(EventID.UI_KeyboardControl_Switch_Team, self.SwitchHero) self:RegistSystemEvent(EventID.UIBattle_Level_CreateEntityByData, self.SetTeamPlayerData) self:RegistSystemEvent(EventID.UIBattle_PlayerHPMessageChanged, self.OnHPMessageChanged) self:RegistSystemEvent(EventID.Player_AdjutantCoolDown, self.UpdateAdjutantCD) self.PlayerSelf[1].img_MainHeroMask.useRealTimeUpdate = false self.PlayerSelf[1].img_SubHeroCDMask.useRealTimeUpdate = false self:OpenInit() end -- 选将复活的头像 function UIInBattleView:OnOpened_SelectOneReview(context) self:RegistSystemEvent(EventID.UI_UpdateBuff_Self, self.UpdateBuffShow) self:RegistSystemEvent(EventID.Set_CurEntity, self.BuffEntityChange) if self.SelectOneReview then UIUtils.SetActive(self.SelectOneReview.gameObject, true) end if self.CommonReview then UIUtils.SetActive(self.CommonReview.gameObject, false) end local myTeamID = LogicUpdateManager._curEntity:GetTeamID() local myPlayerID = LevelManager.IsBattleWaitLevel() and LuaConst.BATTLE_WAIT_PLAYER_PlayID or BattleDataGetter.GetCurPlayerID() local view = self.player_self:OpenView( GetViewClass(Const_UI_Lua.UIEnum.UIBattlePlayerHeadPin), {playerID = myPlayerID} ) local entityId = LogicUpdateManager._curEntity:GetEntityID() self.buffPanel[1] = { buffView = view.buffItem_Root:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), {entityId = entityId}), entityId = entityId, } if BattleDataGetter.IsShowTeammateInSelectOneReviveLevel() then local playerIDList = LevelPlayerManager.GetPlayerIDListOfTeam(myTeamID) local playerCount = 1 for i, v in ipairs(playerIDList) do if v ~= BattleDataGetter.GetCurPlayerID() then -- 自己不一定在自己队伍的开始 self.group_Player[playerCount]:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattlePlayerHeadPin), { playerID = v }) playerCount = playerCount + 1 end end end self:RegistSystemEvent(EventID.UI_SelectOneRevive_SelfDead, self.OnSelectOneSelfDead) self:RegistSystemEvent(EventID.UIBattle_TeammateActive, self.OnTeammateActive) end function UIInBattleView:BuffEntityChange() local entityId = BattleDataGetter.GetCurEntityID() self.buffPanel[1].buffView:OnEntityChange(entityId) self.buffPanel[1].entityId = entityId end function UIInBattleView:OpenInit() self:RegistSystemEvent(EventID.Set_CurEntity, self.SetPlayerSelfData) self:RegistSystemEvent(EventID.UI_UpdateBuff_Self, self.UpdateBuffShow) self:RegistSystemEvent(EventID.UI_UpdateBuff_OtherHero, self.UpdateOtherBuffShow) self:InitView() self:SetPlayerSelfData() if BattleDataGetter.IsTeamLevel() then self:SetTeamPlayerData() else UIUtils.SetActive(self.group_Team.gameObject, false) end end function UIInBattleView:InitView() if BattleDataGetter.IsTeamLevel() then local entityId = BattleDataGetter.GetCurEntityID() self.buffPanel[1] = { buffView = self.PlayerSelf[1].buffItem_Root:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UITeamBattleBuffPanel), {buffType = LuaConst.UIBuffShowType.PlayerSelf, entityId = entityId}), entityId = entityId, } else self:InitSelfBuffView() end end function UIInBattleView:InitSelfBuffView() local entityList = BattleDataGetter.GetMyHeroEntityTable() local count = 1 if self:IsCanSwitchHeroLevel() then count = entityList and #entityList or 0 end for i = 1, count do if self.buffPanel[i] then self.buffPanel[i].buffView:CloseView() end if (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.ClimbTower) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.NationClimbTower) ) or i == 1 then local entityId = entityList[i].EntityID self.buffPanel[i] = { buffView = self.PlayerSelf[i].buffItem_Root:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), {buffType = LuaConst.UIBuffShowType.PlayerSelf, entityId = entityId}), entityId = entityId, } end end end function UIInBattleView:SetPlayerSelfData() table.clearArray(self.selfEntityView) local entityList = nil if self.playerId then entityList = BattleDataGetter.GetHeroEntityTable(self.playerId) else entityList = BattleDataGetter.GetMyHeroEntityTable() end local count = 1 if self:IsCanSwitchHeroLevel() then count = entityList and #entityList or 0 end for i = 1, count do local entityId = entityList[i].EntityID UIUtils.SetActive(self.PlayerSelf[i].gameObject, true) self.selfEntityView[entityId] = self.PlayerSelf[i] self.PlayerSelf[i].img_MainHeroMask.useRealTimeUpdate = false self.PlayerSelf[i].img_SubHeroCDMask.useRealTimeUpdate = false if i > 1 then UIUtils.SetActive(self.PlayerSelf[i].txt_PlayerName.gameObject, false) self.PlayerSelf[i].state_SubHero:SetState(1) if not self.InitMaterial then self.PlayerSelf[i].img_HeroHp.material = UTL.Material.GetCircleHpMaterial() end UIUtils.SetImageByAssetBundle(self.PlayerSelf[i].img_HeroHp, HpImgPath) end self:SetOnePlayerData(false, entityList[i]) if self.buffPanel[i] then self.buffPanel[i].buffView:OnEntityChange(entityId) self.buffPanel[i].entityId = entityId end end if BattleDataGetter.GetCurLevelType() == LuaConst.LevelType.ExpelMonster then UIUtils.SetActive(self.PlayerSelf[3].img_ExpelMonsterMask, true) else UIUtils.SetActive(self.PlayerSelf[3].img_ExpelMonsterMask, false) end self.InitMaterial = true for i = count + 1, SelfEntityMaxCount do if self.PlayerSelf[i] then UIUtils.SetActive(self.PlayerSelf[i].gameObject, false) end end end function UIInBattleView:SetOnePlayerData(isRevive, entity) if not isRevive then self:SetPlayerHeadInfo(entity) end self:SetAdjustData(entity) self:OnHPMessageChanged(entity) local playerView = self.selfEntityView[entity.EntityID] or self.teamEntityView[entity.EntityID] if playerView and playerView.img_MainHeroMask then playerView.img_MainHeroMask:EndTimer() playerView.img_MainHeroMask:SetSpriteMaskFillAmount(0) end end function UIInBattleView:SetAdjustData(entity) local entityView = self.selfEntityView[entity.EntityID] if not entityView or not entityView.img_SubHeroBg then return end local skillData, curCDLeft, totalCD = self:GetAdjustSkillData(entity) if skillData then UIUtils.SetActive(entityView.img_SubHeroHead, true) UIUtils.SetActive(entityView.img_Empty, false) local skillPath = ConstAssetPathConfig.path2 .. skillData.Icon .. ".png" UIUtils.SetImageByAssetBundle(entityView.img_SubHeroHead, skillPath) local isMusouActive, isAdjutantActive = LevelPlayerManager.IsEntityMagicWeaponActive(entity) if isAdjutantActive then UIUtils.SetGray(entityView.img_SubHeroHead, false) if curCDLeft and curCDLeft > 0 then entityView.img_SubHeroCDMask:SetAndContinueTimer(false, curCDLeft / 1000, totalCD / 1000) UIUtils.SetActive(entityView.img_Active, false) else entityView.img_SubHeroCDMask:EndTimer() if entity:IsAlive() then UIUtils.SetActive(entityView.img_Active, true) end end else UIUtils.SetGray(entityView.img_SubHeroHead, true) UIUtils.SetActive(entityView.img_Active, false) end else UIUtils.SetActive(entityView.img_SubHeroHead, false) UIUtils.SetActive(entityView.img_Empty, true) UIUtils.SetActive(entityView.img_Active, false) end end function UIInBattleView:UpdateAdjutantCD(entity, cdTime) if BattleDataGetter.CheckEntityBelongsToPlayer(entity.EntityID, self.playerId) then local playerView = self.selfEntityView[entity.EntityID] if playerView == nil then return end if cdTime then playerView.img_SubHeroCDMask:ResetAndBeginTimer(false, cdTime / 1000) UIUtils.SetActive(playerView.img_Active, false) else playerView.img_SubHeroCDMask:EndTimer() if entity:IsAlive() then UIUtils.SetActive(playerView.img_Active, true) end end end end function UIInBattleView:GetAdjustSkillData(entity) local adjutantComponent = entity.components.adjutant if adjutantComponent.AdjutantEntity then local skillList = adjutantComponent.AdjutantEntity.components.skillBase.CurSkillDataList for __, skillData in ipairs(skillList) do if skillData.Type == LuaConst.SkillType.AdjutantMusou then return skillData, adjutantComponent.AdjutantCD, adjutantComponent.TotalCD end end end return nil, 0, 0 end local TeamNameShowLength = 6 function UIInBattleView:SetTeamPlayerData() if not BattleDataGetter.IsTeamLevel() then return end table.clearArray(self.teamEntityView) UIUtils.SetActive(self.group_Team.gameObject, true) --队友 local myEntity = BattleDataGetter.GetCurEntity() if not myEntity then return end local SelfPlayerID = BattleDataGetter.GetCurPlayerID() local teamHeroEntities = BattleDataGetter.GetHeroEntities() local index = 0 for playerID, teamEntity in pairs(teamHeroEntities) do if teamEntity and myEntity:GetCampID() == teamEntity[1]:GetCampID() then if playerID ~= SelfPlayerID and teamEntity and index < TeamMemberCount then local entity = teamEntity[1] index = index + 1; UIUtils.SetActive(self.group_Team[index].gameObject, true) self.teamEntityView[entity.EntityID] = self.group_Team[index] UIUtils.SetActive(self.group_Team[index].txt_PlayerName.gameObject, true) local name = entity._logicInitData.Name local strLen = UTL.String.GetStrCharCount(name, 2) if strLen > TeamNameShowLength then UIUtils.SetLabel(self.group_Team[index].txt_PlayerName, UTL.String.CutStrByLength(name, TeamNameShowLength) .. "...") else UIUtils.SetLabel(self.group_Team[index].txt_PlayerName, name) end self:SetOnePlayerData(false, entity) self.group_Team[index].img_HeroHpBg:SetState(1) UIUtils.SetActive(self.group_Team[index].img_SubHeroBg, false) if not self.teamBuffPanel[index] then local entityId = entity:GetEntityID() local playerId = entity:GetPlayerID() self.teamBuffPanel[index] = { playerId = playerId, buffView = self.group_Team[index].buffItem_Root:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UITeamBattleBuffPanel), {entityId = entityId}) } else self.teamBuffPanel[index].buffView:OnEntityChange(entity:GetEntityID()) end end end end for i = index + 1, TeamMemberCount do UIUtils.SetActive(self.group_Team[i].gameObject, false) end return index > 0 end function UIInBattleView:SetPlayerName(entity) if self.teamEntityView[entity.EntityID] then if self.teamEntityView[entity.EntityID].txt_TeammateName then UIUtils.SetLabel(self.teamEntityView[entity.EntityID].txt_TeammateName, entity._logicInitData.Name) end end end --复活恢复 function UIInBattleView:OnPlayerRevive(entity) self:SetOnePlayerData(true, entity) end --更新自己的buff function UIInBattleView:UpdateBuffShow(entity, buffData, time, layer, sourceEntityId) for i, v in pairs(self.buffPanel) do if v.entityId == entity:GetEntityID() then v.buffView:UpdateBuffShow(buffData, time, layer, sourceEntityId) end end end --更新队友的buff function UIInBattleView:UpdateOtherBuffShow(entity, buffData, time, layer, sourceEntityId) for i, v in pairs(self.teamBuffPanel) do if v.playerId == entity:GetPlayerID() then v.buffView:UpdateBuffShow(buffData, time, layer, sourceEntityId) end end end function UIInBattleView:IsCanSwitchHeroLevel() local levelType = BattleDataGetter.GetCurLevelType() return levelType ~= LuaConst.LevelType.Resource end function UIInBattleView:SwitchHero(index) if BattleDataGetter.GetCurLevelType() == LuaConst.LevelType.GuildBossTown then CTL.Tips.AddTipsMsg(Const_IDS.IDS_GuildBoss_SwitchHeroNotInbattle) return end if index == 2 then LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.SwitchHeroToIndex2) elseif index == 3 then LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.SwitchHeroToIndex3) end end function UIInBattleView:OnButtonClicked(comp) if comp == self.PlayerSelf[2].event_SwitchHero then self:SwitchHero(2) elseif comp == self.PlayerSelf[3].event_SwitchHero then if BattleDataGetter.GetCurLevelType() == LuaConst.LevelType.ExpelMonster then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ActivityBossFight_Hint_13) return end self:SwitchHero(3) end end function UIInBattleView:SetPlayerHeadInfo(entity) local heroId = entity:GetCharacterID() local isAwaken = BattleDataGetter.GetHeroIsAwaken(entity:GetPlayerID(), heroId) if self.selfEntityView[entity.EntityID] then UTL.Item.SetHeroIconByHeroId(self.selfEntityView[entity.EntityID].img_HeroHead, heroId, isAwaken) elseif self.teamEntityView[entity.EntityID] then UTL.Item.SetHeroIconByHeroId(self.teamEntityView[entity.EntityID].img_HeroHead, heroId, isAwaken) end end function UIInBattleView:OnHPMessageChanged(entity) if self.selfEntityView[entity.EntityID] then self:RefreshEnityHp(self.selfEntityView[entity.EntityID], entity) elseif self.teamEntityView[entity.EntityID] then self:RefreshEnityHp(self.teamEntityView[entity.EntityID], entity) end end function UIInBattleView:RefreshEnityHp(playerView, entity) 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 if self.selfEntityView[entity.EntityID] and self.selfEntityView[entity.EntityID] ~= self.PlayerSelf[1] then playerView.img_HeroHp.material:SetFloat("_Percent", hp / totalValue*0.52 + 0.37) else UIUtils.SetAtlasImageFillAmount(playerView.img_HeroHp, hp / totalValue) end --死亡蒙版,和卫松讨论用血量来做,现在的死亡事件没有entity参数 if hp <= 0 and playerView.img_MainHeroMask then playerView.img_MainHeroMask:EndTimer(); --playerView.img_MainHeroMask:SetSpriteMaskFillAmount(1) UIUtils.SetGray(playerView.img_HeroHead, true) UIUtils.SetActive(playerView.img_Active, false) local isMusouActive, isAdjutantActive = LevelPlayerManager.IsEntityMagicWeaponActive(entity) if isAdjutantActive and playerView.img_SubHeroCDMask then playerView.img_SubHeroCDMask:EndTimer() playerView.img_SubHeroCDMask:SetSpriteMaskFillAmount(1) UIUtils.SetGray(playerView.img_SubHeroHead, true) end else UIUtils.SetGray(playerView.img_HeroHead, false) UIUtils.SetGray(playerView.img_SubHeroHead, false) end end function UIInBattleView:PauseSwitchCD(pause) for index = 2, 3 do if pause then self.PlayerSelf[index].img_MainHeroMask:PauseTimer() else self.PlayerSelf[index].img_MainHeroMask:ResumeTimer() end end end --换将 function UIInBattleView:OnSwitchHero(type, entity) self:SwitchHeroByType(type, entity:IsPlayerSelf()) end function UIInBattleView:SwitchHeroByType(type, isSelf) if type == LuaConst.SwitchHeroType.Dead then if isSelf then self:SetPlayerSelfData() self:UpdateSwitchCDByDeath() elseif BattleDataGetter.IsTeamLevel() then self:SetTeamPlayerData() end elseif type == LuaConst.SwitchHeroType.Manual then if isSelf then self:SetPlayerSelfData() self:UpdateSwitchCDByManual() elseif BattleDataGetter.IsTeamLevel() then self:SetTeamPlayerData() end elseif type == LuaConst.SwitchHeroType.LevelAction then if isSelf then self:SetPlayerSelfData() end end end --死亡换将的CD function UIInBattleView:UpdateSwitchCDByDeath() local entityList = BattleDataGetter.GetMyHeroEntityTable() for index = 2, SelfEntityMaxCount do if entityList[index] and not entityList[index]:IsAlive() then self.PlayerSelf[index].img_MainHeroMask:EndTimer() self.PlayerSelf[index].img_MainHeroMask:SetSpriteMaskFillAmount(1) else self.PlayerSelf[index].img_MainHeroMask:ResetAndBeginTimer(false, self.SwitchHeroCD) end end end --手动换将后的CD function UIInBattleView:UpdateSwitchCDByManual() local entityList = BattleDataGetter.GetMyHeroEntityTable() for index = 2, SelfEntityMaxCount do if entityList[index] and entityList[index]:IsAlive() then self.PlayerSelf[index].img_MainHeroMask:ResetAndBeginTimer(false, self.SwitchHeroCD) else self.PlayerSelf[index].img_MainHeroMask:SetSpriteMaskFillAmount(1) end end end function UIInBattleView:OnSelectOneSelfDead(info) CTL.Sound.PlayGameSound("SFX_die") if not LevelManager.IsReplayBattle() then CameraController.Instance:SetGray(true) if BattleDataGetter.IsCityWarLevel() then UIManager.OpenView(Const_UI_Lua.UIEnum.UIChangAnSiegeRevive, info) else UIManager.OpenView(Const_UI_Lua.UIEnum.UISwitchHeroReviveView, info) end end end --来队友了 function UIInBattleView:OnTeammateActive(playerID) if playerID == BattleDataGetter.GetCurPlayerID() then return end local myTeamID = LogicUpdateManager._curEntity:GetTeamID() if BattleDataGetter.IsShowTeammateInSelectOneReviveLevel() then local playerIDList = LevelPlayerManager.GetPlayerIDListOfTeam(myTeamID) --此时我一定是队伍中了,只要把队友放最后就行 self.group_Player[#playerIDList -1]:OpenView( GetViewClass(Const_UI_Lua.UIEnum.UIBattlePlayerHeadPin), {playerID = playerID} ) end end return UIInBattleView