local UIGuildWarCampTopView = UIViewClass() local COUNTDOWNTIME = 5 --准备区5秒倒计时 local EmptyHeroIconPath = ConstAssetPathConfig.EmptyHeroIconPath local GuildWarSerialKillNum = DataSheetManager.ConstData:GetDataByID("GuildWarSerialKillNum").IntValue local HideTime = 7 function UIGuildWarCampTopView:OnOpened(context) self.allHide = true self.hideLoopKill = {} self.group_Occupy.gameObject:SetActive(false) self:RegistSystemEvent(EventID.UI_GuildWarKillInfoNotice,self.OnNewKillMsg) local data = MDL.GuildWar.GetBattleInfo() if data.selfCamp.guildInfo then self.group_Left.txt_GuildName.text = data.selfCamp.guildInfo.guildName self.group_Right.txt_GuildName.text = data.enemyCamp.guildInfo.guildName end self.lastSelfHpPercent = 10 -- 血量剩余几成 -- 必须在self:OnHpValueChange(data)之前设置 self.lastEnemyHpPercent = 10 -- 血量剩余几成-- 必须在self:OnHpValueChange(data)之前设置 self:RegistSystemEvent(EventID.UI_GuildWarHpUpdate, self.OnHpValueChange) self:RegistSystemEvent(EventID.UI_GuildWarCampTopViewRefresh,self.OnTeamPlayerChange) self:RegistSystemEvent(EventID.Level_StrongHoldShowUIAreaEnter,self.OnItemTriggerOccupyEnter) self:RegistSystemEvent(EventID.Level_StrongHoldShowUIAreaExit,self.OnItemTriggerOccupyExit) self:RegistSystemEvent(EventID.Level_HeroDead,self.OnHeroDead) self:RegistSystemEvent(EventID.UI_GuildWarGroupInfosUpdate, self.InitPlayer) self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIGuildWarMapBtns)) self.comboViewRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleCombo), {isShowComboType = LuaConst.ComboType.IsKillHero}) if BattleDataGetter.IsGuildWarWaitingArea() then self.group_Time.gameObject:SetActive(true) local readyStageTime = MDL.GuildWar.GetReadyStageTime() if readyStageTime then self:RefresGuildWarReadyStageTime(readyStageTime) else self:RegistSystemEvent(EventID.UI_RefresGuildWarReadyStageTime, self.RefresGuildWarReadyStageTime) end self.group_SquadInfo.gameObject:SetActive(false) UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildWarBattleGround) data.selfCamp.hpValue = nil data.selfCamp.killNum = 0 data.enemyCamp.hpValue = nil data.enemyCamp.killNum = 0 else self.group_SquadInfo.gameObject:SetActive(true) self:InitPlayer() -- repeatCount 小于等于0表示无限重复 self:StartRepeatFunc(self.SetTime, 1, 0) self.firstCellPosX, self.firstCellPosY= self.loop_Kill[3].gameObject.transform:GetAnchoredPosition() MDL.GuildWar.C2GGetGuildWarProductReq() end self:OnHpValueChange(data) self.group_Left.txt_Num.text = 0 self.group_Right.txt_Num.text = 0 end function UIGuildWarCampTopView:RefresGuildWarReadyStageTime(readyStageTime) local nextTime = readyStageTime - UTL.Time.GetServerTimestamp() if nextTime > 0 then local str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildWar_PrepareTimeCountdown) if nextTime - COUNTDOWNTIME > 0 then self:StartRepeatFunc(self.OnStartCountDown, nextTime - COUNTDOWNTIME, 1) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIBattleCountDownFormalPanel, { nextTime }) end self.txt_Time:ResetAndBeginCustomTimer(false, nextTime, 0, str) else self:RegistSystemEvent(EventID.UI_RefresGuildWarReadyStageTime, self.RefresGuildWarReadyStageTime) end end function UIGuildWarCampTopView:OnStartCountDown(deltaTime, timeSinceUpdate) UIManager.OpenView(Const_UI_Lua.UIEnum.UIBattleCountDownFormalPanel,{COUNTDOWNTIME}) end function UIGuildWarCampTopView:OnHpValueChange(data) self:SetCampInfo(self.group_Left, data.selfCamp.hpValue) self:SetCampInfo(self.group_Right, data.enemyCamp.hpValue) self.group_Left.txt_Num.text = data.selfCamp.killNum or 0 self.group_Right.txt_Num.text = data.enemyCamp.killNum or 0 -- 以下代码时弹战报 if data.selfCamp.hpValue and data.enemyCamp.hpValue then local totalHP = MDL.GuildWar.MaxGuildWarBaseHp local selfafterP = math.ceil(data.selfCamp.hpValue * 10 / totalHP) if self.lastSelfHpPercent ~= selfafterP then self.lastSelfHpPercent = selfafterP MDL.GuildWar.ShowWallHpReportTips(true ,selfafterP) end local enemyafterP = math.ceil(data.enemyCamp.hpValue * 10 / totalHP) if self.lastEnemyHpPercent ~= enemyafterP then self.lastEnemyHpPercent = enemyafterP MDL.GuildWar.ShowWallHpReportTips(false ,enemyafterP) end end end function UIGuildWarCampTopView:SetCampInfo(obj,info) if info then local value = math.getPreciseDecimal(info / MDL.GuildWar.MaxGuildWarBaseHp,3) obj.txt_DefenseHP.text = (value*100).."%" obj.slider_HP.value = value else obj.txt_DefenseHP.text = "100%" obj.slider_HP.value = 1 end end function UIGuildWarCampTopView:GetPlayers(players,index) local firstIndex = (math.ceil(index/3)-1)*3+ 1 if firstIndex == index then return firstIndex,{players[index], players[index + 1],players[index + 2]} elseif index -firstIndex == 1 then return firstIndex,{players[index], players[firstIndex],players[index + 1]} elseif index - firstIndex == 2 then return firstIndex,{players[index], players[firstIndex],players[index - 1]} end end function UIGuildWarCampTopView:InitPlayer() local info = BattleDataGetter.GetGuildWar_MyTeamInfo() local groupInfos = MDL.GuildWar.GetGroupInfos() if groupInfos == nil then MDL.GuildWar.C2GGetGuildWarPrepareInfo() MDL.Guild.GetGuildInfoReq() return end local teamInfo = nil for i,v in ipairs(groupInfos) do for _,player in pairs(v.players) do if player.isHasPlayer and player.headInfo.acid == BattleDataGetter.GetAcID() then local index, players = self:GetPlayers(v.players,_) teamInfo = {index = index, players = players } end end end for i,v in ipairs(teamInfo.players) do if v.isHasPlayer then if v.headInfo.acid ~= BattleDataGetter.GetAcID() then -- 队友的头像 -- 小队队友只展示在场主将头像 if info[v.headInfo.acid] then self:SetPlayerIcon(self.groups[i], info[v.headInfo.acid], v.headInfo.name) else self:SetPlayerIcon(self.groups[i], nil, v.headInfo.name) end else if info[v.headInfo.acid] then --自己的头像 打开轮转头像 self:SetSelfPlayerIcon(self.groups[1], info[v.headInfo.acid].playerID, v.headInfo.name) end --buff显示 if self.myBuffView then self.myBuffView:OnEntityChange(BattleDataGetter.GetCurEntityID()) else self:RegistSystemEvent(EventID.UI_UpdateBuff_Self, self.UpdateBuffShow) self.myBuffView = self.groups[1].buff_View:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), {buffType = LuaConst.UIBuffShowType.PlayerSelf, entityId = BattleDataGetter.GetCurEntityID()}) end end self.groups[i].gameObject:SetActive(true) else self.groups[i].gameObject:SetActive(false) end end self.teamInfo = teamInfo self.txt_SquadName.text = string.FormatByIdsId(Const_IDS.IDS_GuildWar_Team,math.ceil(teamInfo.index/3)) end function UIGuildWarCampTopView:GetTime( value) if value then return (value - LogicUpdateManager._clientHandleFrame) * LuaConst.TimeSpan end end function UIGuildWarCampTopView:SetSelfPlayerIcon(obj, playerId, name) obj.txt_PlayerName.text = name obj.ownHead:OpenView( GetViewClass(Const_UI_Lua.UIEnum.UIBattlePlayerHeadPinGuildWar), {playerID = playerId}, "Battle/UIBattlePlayerHeadPin" ) end function UIGuildWarCampTopView:SetPlayerIcon(obj, data, name) obj.txt_PlayerName.text = name if data then self:SetHeroState(obj.group_PlayerPortrait_Big, data.playerID, data.heroID[1], data.reviveTime and self:GetTime(data.reviveTime[1])) obj.group_PlayerPortrait_Big.img_CountDown_Green.gameObject:SetActive(false) obj.group_PlayerPortrait_Big.img_CountDown_Blue.gameObject:SetActive(true) self:SetPlayerHp(obj.group_PlayerPortrait_Big.img_CountDown_Blue,data.hpPercent) else obj.group_PlayerPortrait_Big.img_CountDown_Green.gameObject:SetActive(false) obj.group_PlayerPortrait_Big.img_CountDown_Blue.gameObject:SetActive(false) if not obj.group_PlayerPortrait_Big.texture_Head.sprite then UIUtils.SetImageByAssetBundle(obj.group_PlayerPortrait_Big.texture_Head, EmptyHeroIconPath) end end end --更新自己的buff function UIGuildWarCampTopView:UpdateBuffShow(entity, buffData, time, layer, sourceEntityId) if BattleDataGetter.GetCurEntityID() == entity:GetEntityID() then self.myBuffView:UpdateBuffShow(buffData, time, layer, sourceEntityId) end end function UIGuildWarCampTopView:SetPlayerHp(obj, hpPercent) obj.fillAmount = hpPercent or 1 end function UIGuildWarCampTopView:SetHeroState(obj, playerID, heroId, reviveTime) UTL.Item.SetHeroIconByHeroId(obj.texture_Head, heroId, BattleDataGetter.GetHeroIsAwaken(playerID, heroId)) if reviveTime and reviveTime > 0 then UIUtils.SetGray(obj.texture_Head, true) else UIUtils.SetGray(obj.texture_Head, false) end end function UIGuildWarCampTopView:OnTeamPlayerChange(playerId) if self.teamInfo then local info,acid = BattleDataGetter.GetGuildWar_TeamInfo(playerId) for i,v in ipairs(self.teamInfo.players) do if v.isHasPlayer then if acid == v.headInfo.acid then if v.headInfo.acid ~= BattleDataGetter.GetAcID() then self:SetPlayerIcon(self.groups[i], info , v.headInfo.name) end if not self.groups[i].gameObject.activeSelf then self.groups[i].gameObject:SetActive(true) end break end end end end end function UIGuildWarCampTopView:OnNewKillMsg(msg) self:ShowKillMsg(msg) --self.loop_Kill:InsertData(0,msg,0) self:AddStrongKill(msg) end function UIGuildWarCampTopView:ShowKillMsg(msg) if self.allHide then local cell = self.loop_Kill[3] self:OnCellInit(cell,msg) cell.gameObject:SetActive(true) --第一次显示 播放最下层信息动画 self.firstId = self:PlayUIAnimation(ConstAssetPathConfig.AssetPath111, self.loop_Kill[3].gameObject.transform,true) self.hideLoopKill[self.loop_Kill[3]] = UTL.Time.GetLocalTimestamp() self.playing = true self.allHide = false self:StartRepeatFunc(self.HideLoopKill, 1, -1) else self.curShowMsgs = self.curShowMsgs or {} table.insert(self.curShowMsgs,msg) if not self.playing then self:PlayNext() end end end function UIGuildWarCampTopView:AddStrongKill(msg) if msg.firstBlood == 1 then self:SetKillInfo(msg,"IDS_GuildWar_KillBroadcast_FirstBlood") -- 第一滴血 else if msg.killNumsB > 3 then self:SetKillInfo(msg,"IDS_GuildWar_KillBroadcast_Shutdown") --终结 end if msg.killNums > MDL.GuildWar.GetKillMaxTitleId() then if(msg.killNums - MDL.GuildWar.GetKillMaxTitleId())%GuildWarSerialKillNum == 0 then local data = DataSheetManager.GuildWarKillBroadcast:GetDataByID(MDL.GuildWar.GetKillMaxTitleId()) if data then self:SetKillInfo(msg,data.Text) end end else local __, data = DataSheetManager.GuildWarKillBroadcast:TryGetDataByID(msg.killNums) if data then self:SetKillInfo(msg,data.Text) end end end end function UIGuildWarCampTopView:SetKillInfo(msg,dec) if msg.playerHeroIdA > 0 and msg.playerHeroIdB then if not self.strongKillList or (#self.strongKillList == 0 and not self.showKillInfoPlaying) then self.strongKillList = self.strongKillList or {} table.insert( self.strongKillList, {msg,dec} ) self:ShowKillInfo() else table.insert( self.strongKillList, {msg,dec} ) end end end function UIGuildWarCampTopView:ShowKillInfo() if #self.strongKillList == 0 then self.group_KillTip.gameObject:SetActive(false) else self.group_KillTip.gameObject:SetActive(true) self.animationId = self:PlayUIAnimation("AnimationSF",true) self.showKillInfoPlaying = true local data = table.remove(self.strongKillList, 1) UIUtils.SetLabelText(self.group_KillTip.txt_KillScore,Const_IDS[data[2]]) UTL.Item.SetHeroIconByHeroId(self.group_KillTip.texture_Head_1, data[1].playerHeroIdA, BattleDataGetter.GetHeroIsAwaken(data[1].playerIdA, data[1].playerHeroIdA)) UTL.Item.SetHeroIconByHeroId(self.group_KillTip.texture_Head_2, data[1].playerHeroIdB, BattleDataGetter.GetHeroIsAwaken(data[1].playerIdB, data[1].playerHeroIdB)) self:StartRepeatFunc(self.DelayShowKillInfo, 3, 1) if self:IsMyCamp(data[1]) then self.group_KillTip.txt_PlayerName_1.text = UTL.Color.FormatTextByColor("e46b71",data[1].playerNameA) self.group_KillTip.txt_PlayerName_2.text = self:GetPlayerNameColor(data[1].playerNameB) else self.group_KillTip.txt_PlayerName_1.text = self:GetPlayerNameColor(data[1].playerNameA) self.group_KillTip.txt_PlayerName_2.text = UTL.Color.FormatTextByColor("e46b71",data[1].playerNameB) end CTL.Sound.PlayGameSound("UI_jibai") end end function UIGuildWarCampTopView:DelayShowKillInfo() self.showKillInfoPlaying = false self:ShowKillInfo() end function UIGuildWarCampTopView:OnUIAnimationStoped(id) --动画结束 显示手指 聚焦特效等 if self.animationId == id then self.group_KillTip.effect_KillIcon:PlayUIEffect() elseif self.killPlayId == id then if self.curShowMsgs and #self.curShowMsgs > 0 then local cell1 = self.loop_Kill[1] local cell2 = self.loop_Kill[2] local cell3 = self.loop_Kill[3] self.loop_Kill[1] = cell2 self.loop_Kill[2] = cell3 self.loop_Kill[3] = cell1 local msg = table.remove(self.curShowMsgs, 1) self:OnCellInit(self.loop_Kill[3],msg) self.loop_Kill[3].gameObject.transform:SetAnchoredPosition(self.firstCellPosX,self.firstCellPosY) if not self.loop_Kill[3].gameObject.activeInHierarchy then self.loop_Kill[3].gameObject:SetActive(true) end self.firstId = self:PlayUIAnimation(ConstAssetPathConfig.AssetPath111, self.loop_Kill[3].gameObject.transform,true) self.hideLoopKill[self.loop_Kill[3]] = UTL.Time.GetLocalTimestamp() end elseif self.firstId == id then self:PlayNext() end end function UIGuildWarCampTopView:PlayNext() if self.curShowMsgs and #self.curShowMsgs > 0 then self.playing = true --击杀动画 已经显示的上移 腾出位置给新的显示动画 if self.hideLoopKill[self.loop_Kill[2]] then self:PlayUIAnimation(ConstAssetPathConfig.Path16, self.loop_Kill[2].gameObject.transform) self.hideLoopKill[self.loop_Kill[2]] = UTL.Time.GetLocalTimestamp() end self.killPlayId = self:PlayUIAnimation(ConstAssetPathConfig.Path16, self.loop_Kill[3].gameObject.transform, true) --之前方式为SetActive true 开销较高 优化成修改坐标移除屏幕外 self.loop_Kill[1].gameObject.transform:SetAnchoredPosition(30000,30000) self.hideLoopKill[self.loop_Kill[3]] = UTL.Time.GetLocalTimestamp() else self.playing = false end end function UIGuildWarCampTopView:HideLoopKill() for k,v in pairs(self.hideLoopKill) do if v then local time = UTL.Time.GetLocalTimestamp() - v if time >= HideTime then self:PlayUIAnimation(ConstAssetPathConfig.AssetPath112, k.gameObject.transform) self.hideLoopKill[k] = nil end end end if not next(self.hideLoopKill) then self.allHide = true end end function UIGuildWarCampTopView:OnCellInit(cellTable,data) if self:IsMyCamp(data) then cellTable.txt_Name01.text = UTL.Color.FormatTextByColor("e46b71",data.playerNameA) cellTable.txt_Name02.text = self:GetPlayerNameColor(data.playerNameB) else cellTable.txt_Name01.text = self:GetPlayerNameColor(data.playerNameA) cellTable.txt_Name02.text = UTL.Color.FormatTextByColor("e46b71",data.playerNameB) end end function UIGuildWarCampTopView:IsMyCamp(data) if string.isNilOrEmpty(data.guildIdA) then return data.guildIdB == MDL.Guild.GetMyGuildInfo().guildId else return data.guildIdA ~= MDL.Guild.GetMyGuildInfo().guildId end end function UIGuildWarCampTopView:GetPlayerNameColor(playerName) if playerName == BattleDataGetter.GetPlayerName() then return UTL.Color.FormatGreenColor(playerName) else return UTL.Color.FormatTextByColor(UTL.Color.ModelNameColor.Blue, playerName) end end function UIGuildWarCampTopView:OnItemTriggerOccupyEnter(levelItemID,entity,isEnter) if entity._logicInitData.IsPlayerSelf then self.group_Occupy.gameObject:SetActive(true) self.curOccupyItemId = levelItemID self:StartRepeatFunc(self.UpdateOccupyInfo, 0.5, -1) self.preOccupationPercent = 0 self:ShowOccupyInfo(0,true) end end function UIGuildWarCampTopView:OnItemTriggerOccupyExit(levelItemID,entity,isEnter) if entity._logicInitData.IsPlayerSelf then self.group_Occupy.gameObject:SetActive(false) self:StopRepeatFunc(self.UpdateOccupyInfo) self.curOccupyItemId = nil end end function UIGuildWarCampTopView:UpdateOccupyInfo(deltaTime, timeSinceUpdate) self:ShowOccupyInfo(deltaTime) end function UIGuildWarCampTopView:ShowOccupyInfo(deltaTime,isInit) local levelItem = LevelItemManager.GetItemByID(self.curOccupyItemId) local curState, campID, occupationPercent = levelItem:GetStrongHoldInfo() if occupationPercent<1 or MDL.GuildWar.IsMiddleChongcheId(self.curOccupyItemId) then local imgOccupied = nil if campID == BattleDataGetter.GetMyCampID() then self.img_OccupiedBar_Red.gameObject:SetActive(false) self.img_OccupiedBar_Blue.gameObject:SetActive(true) imgOccupied = self.img_OccupiedBar_Blue else self.img_OccupiedBar_Red.gameObject:SetActive(true) self.img_OccupiedBar_Blue.gameObject:SetActive(false) imgOccupied = self.img_OccupiedBar_Red end imgOccupied.fillAmount = occupationPercent if isInit or self.preOccupationPercent >= 1 then local imagePath = MDL.GuildWar.GetOccupationBarImageResourceById(self.curOccupyItemId) UTL.Item.SetAtlasSprite(self.img_CampIcon, "UI_MiniMap", imagePath) self.img_MangonelHP.gameObject:SetActive(false) local name = MDL.GuildWar.GetElementName(BattleDataGetter.GetCurLevelType(),self.curOccupyItemId) self.txt_Name.text = name end else if isInit or self.preOccupationPercent < 1 then local imageCfg = MDL.GuildWar.GetMangonelImageResource(BattleDataGetter.GetMyCampID() == campID) UTL.Item.SetAtlasSprite(self.img_CampIcon, "UI_MiniMap", imageCfg.Main) UTL.Item.SetAtlasSprite(self.img_MangonelHP, "UI_MiniMap", imageCfg.Progress) self.img_MangonelHP.gameObject:SetActive(true) local name = MDL.GuildWar.GetElementName(BattleDataGetter.GetCurLevelType(),self.curOccupyItemId) self.txt_Name.text = name end local entity = MDL.GuildWar.GetToushicheEntity(self.curOccupyItemId) if entity then self.img_MangonelHP.fillAmount = FP.tonumberV1(entity:GetHp() / entity:GetMaxHp()) self.img_OccupiedBar_Red.gameObject:SetActive(false) self.img_OccupiedBar_Blue.gameObject:SetActive(false) else --占领不一定会立刻有投石车 --logging.error(LTAG.ERROR, "GWS : guildwarCampTop 没有找到阵地生的entity ,levelID = ",BattleDataGetter.GetLevelID(),",LevelItemID =", self.curOccupyItemId) end end self.preOccupationPercent = occupationPercent if occupationPercent<1 then if not self.playEffctTime or self.playEffctTime>=1 then self.effect_Occupy:PlayUIEffect() self.playEffctTime = 0 end self.playEffctTime = self.playEffctTime + deltaTime else self.effect_Occupy:StopUIEffect() end end function UIGuildWarCampTopView:SetTime() local time = BattleDataGetter.GetRemainTime() if time >= UTL.Time.TotalSecondsOneMinute then self.txt_battleTime.text = UTL.Time.FormatTimeSeconds(time) else if time > 10 then self.txt_CountDown.text = UTL.Time.FormatTimeSeconds(time) else if self.playId then self:PlayUIAnimation(self.playId) else self.playId = self:PlayUIAnimation("CountDown") end self.txt_CountDown.text = math.floor(time) end self.txt_battleTime.text = nil end end function UIGuildWarCampTopView:OnHeroDead(killer, deadEntity, assistPlayerIDList, assistHeroEntityIDList, relaxAssistPlayerIDList) local isAssist = false if not killer._logicInitData.IsPlayerSelf then local myPlayerID = BattleDataGetter.GetCurPlayerID() for i,v in ipairs(relaxAssistPlayerIDList) do if v == myPlayerID then isAssist = true break end end end if isAssist then -- k:击杀数 d:死亡数 a:助攻数 local assistNum = BattleDataGetter.GetGuildWar_MySelfHeroRelaxAssist() if assistNum then self:ShowSelfAssist(assistNum) end end end function UIGuildWarCampTopView:ShowSelfAssist(value) self.group_Support.gameObject:SetActive(true) self.txt_Num.text = value self:StartRepeatFunc(self.DelaySetActive, 5, 1) end function UIGuildWarCampTopView:DelaySetActive() self.group_Support.gameObject:SetActive(false) end return UIGuildWarCampTopView