local UIGVGFightInBattleInfo = UIViewClass() function UIGVGFightInBattleInfo:OnCreated() self.playerIdToBuffPanel = {} -- 武将buff列表 映射关系 index To UISyncTeamBuffPanel self.playerIdToCol = {} -- 武将UI列表 映射关系 index To heroId end function UIGVGFightInBattleInfo:OnOpened(context) self:RegistSystemEvent(EventID.UIBattle_PlayerHPMessageChanged, self.OnHPMessageChanged) --血量变化 self:RegistSystemEvent(EventID.UI_UpdateBuff_Self, self.UpdateBuffShow) -- 自身buff变化 self:RegistSystemEvent(EventID.UI_UpdateBuff_OtherHero, self.UpdateBuffShow) -- 他人buff变化 self:RegistSystemEvent(EventID.After_Hero_Dead, self.OnHeroDead) self:SetPlayerInfo(self.group_PlayerInfo2, BattleDataGetter.GetPlayerInfo(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID), MDL.GVGFight.GetEnemyScore(), false) self:SetPlayerInfo(self.group_PlayerInfo1, BattleDataGetter.GetPlayerInfo(LuaConst.STANDALONE_PLAYER_PlayID), MDL.GVGFight.GetBadgeScore(), true) self:InitEntity() self:OnUpdateCountdownTimer() self:StartRepeatFunc(self.OnUpdateCountdownTimer, 1) end function UIGVGFightInBattleInfo:SetPlayerInfo(collection, info, score, isMe) if string.isNilOrEmpty(info.guildName) then UIUtils.SetActive(collection.group_GuildNameIcon, false) UIUtils.SetLabelText(collection.txt_GuildName, Const_IDS.IDS_GVGFight_InCity_NoGuild) else collection.txt_GuildName.text = info.guildName UIUtils.SetActive(collection.group_GuildNameIcon, true) CTL.Guild.SetGuildEmblem(collection.img_GuildIcon, collection.txt_GuildNameInitiate, info.emblemFrame, info.guildEmblemContent) end collection.txt_PlayerName.text = info.name if LevelManager.IsLootMine() then collection.state_Mine:SetState(1) if isMe then CTL.Character.SetSelfPortraitAndFrame(collection.HeroHead) else CTL.Character.SetPortraitAndFrame(collection.HeroHead, info.portraitId, info.frameId) end else collection.state_Mine:SetState(0) local data = CTL.GVGFight.GetGVGFightBadgeData(score or 0) collection.stateCount:SetState(data.BadgeStar) if string.isNilOrEmpty(data.BadgeEffects) then -- 设置徽章图标 UIUtils.SetActive(collection.img_MedalIcon, true) UIUtils.SetImageByAssetBundle(collection.img_MedalIcon, data.BadgeIcon) collection.effect_Medal:StopUIEffect() UIUtils.SetActive(collection.effect_Medal, false) else -- 设置徽章特效 UIUtils.SetActive(collection.effect_Medal, true) collection.effect_Medal:PlayUIEffect(data.BadgeEffects, 0) UIUtils.SetActive(collection.img_MedalIcon, false) end end end function UIGVGFightInBattleInfo:InitEntity() local ownEntityList = BattleDataGetter.GetHeroEntityTable(LuaConst.STANDALONE_PLAYER_PlayID) local enemyEntityList = BattleDataGetter.GetHeroEntityTable(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) for i, v in ipairs(self.group_PlayerInfo1.selfHeadView) do UIUtils.SetActive(v.texture_Head, false) UIUtils.SetActive(v.texture_HeadEmpty, true) UIUtils.SetActive(v.black_Bg, false) end for i, v in ipairs(self.group_PlayerInfo2.enemyHeadView) do UIUtils.SetActive(v.texture_Head, false) UIUtils.SetActive(v.texture_HeadEmpty, true) UIUtils.SetActive(v.black_Bg, false) end local ArmyCount = 0 if #ownEntityList >= #enemyEntityList then ArmyCount = #ownEntityList else ArmyCount = #enemyEntityList end for i = 1, ArmyCount do local ownEntity = ownEntityList[i] if ownEntity then local playerId = ownEntity:GetPlayerID() local characterId = ownEntity:GetCharacterID() self.playerIdToCol[playerId] = self.playerIdToCol[playerId] or {} local col = self.group_PlayerInfo1.selfHeadView[i] self.playerIdToCol[playerId][characterId] = col self.playerIdToBuffPanel[playerId] = self.playerIdToBuffPanel[playerId] or {} self.playerIdToBuffPanel[playerId][characterId] = col.buffCanvas:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UISyncTeamBuffPanel), {entityId = ownEntity:GetEntityID(), buffType = LuaConst.UIBuffShowType.PlayerSelf}) if characterId > 0 then UIUtils.SetActive(col.texture_Head, true) UIUtils.SetActive(col.texture_HeadEmpty, false) UTL.Item.SetHeroIconByHeroId(col.texture_Head, characterId, BattleDataGetter.GetHeroIsAwaken(playerId, characterId)) end end local enemyEntity = enemyEntityList[i] if enemyEntity then local enemyPlayerId = enemyEntity:GetPlayerID() local enemyCharacterId = enemyEntity:GetCharacterID() self.playerIdToCol[enemyPlayerId] = self.playerIdToCol[enemyPlayerId] or {} local enemyCol = self.group_PlayerInfo2.enemyHeadView[i] self.playerIdToCol[enemyPlayerId][enemyCharacterId] = enemyCol self.playerIdToBuffPanel[enemyPlayerId] = self.playerIdToBuffPanel[enemyPlayerId] or {} self.playerIdToBuffPanel[enemyPlayerId][enemyCharacterId] = enemyCol.buffCanvas:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UISyncTeamBuffPanel), {entityId = enemyEntity:GetEntityID(), buffType = LuaConst.UIBuffShowType.PlayerOthers}) if enemyCharacterId > 0 then UIUtils.SetActive(enemyCol.texture_Head, true) UIUtils.SetActive(enemyCol.texture_HeadEmpty, false) UTL.Item.SetHeroIconByHeroId(enemyCol.texture_Head, enemyCharacterId, BattleDataGetter.GetHeroIsAwaken(enemyPlayerId, enemyCharacterId)) else UIUtils.SetActive(enemyCol.texture_HeadEmpty, true) end end end end function UIGVGFightInBattleInfo:OnHPMessageChanged(entity) local collection = self.playerIdToCol[entity:GetPlayerID()] and self.playerIdToCol[entity:GetPlayerID()][entity:GetCharacterID()] if collection 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 local fillAmount = hp/totalValue or 1 collection.img_CountDown_Green.fillAmount = fillAmount if fillAmount > 0 then UIUtils.SetActive(collection.black_Bg, false) else UIUtils.SetActive(collection.black_Bg, true) end end end function UIGVGFightInBattleInfo:OnUpdateCountdownTimer(deltaTime, timeSinceUpdate) local curTimer = BattleDataGetter.GetRemainTime() UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(curTimer)) end -- 更新武将Buff function UIGVGFightInBattleInfo:UpdateBuffShow(entity, buffData, time, layer, sourceEntityId) local buffPanelDic = self.playerIdToBuffPanel[entity:GetPlayerID()] if not buffPanelDic then return end local buffPanel = buffPanelDic[entity:GetCharacterID()] if buffPanel then buffPanel:UpdateBuffShow(buffData, time, layer, sourceEntityId) end end function UIGVGFightInBattleInfo:OnHeroDead(entity) local buffPanelDic = self.playerIdToBuffPanel[entity:GetPlayerID()] if not buffPanelDic then return end local buffPanel = buffPanelDic[entity:GetCharacterID()] if buffPanel then buffPanel:CloseView() buffPanelDic[entity:GetCharacterID()] = nil end end return UIGVGFightInBattleInfo