local UISyncFourCountryWarBattlePanel = UIViewClass() local SyncFourCountryInitialPointsPerPerson = DataSheetManager.ConstData:GetDataByID("SyncFourCountryInitialPointsPerPerson").IntValue local HideTime = 7 local SyncFourCountryCompetitionDuration = DataSheetManager.ConstData:GetDataByID("SyncFourCountryCompetitionDuration").IntValue function UISyncFourCountryWarBattlePanel:OnOpened(context) self.hideLoopKill = {} self.allHide = true self.scoreList = {} self.firstCellPosX, self.firstCellPosY = self.loop_Kill[3].gameObject.transform:GetAnchoredPosition() self.hideLoopRemind = {} self.allRemindHide = true self.firstRemindCellPosX, self.firstRemindCellPosY = self.loop_Remind[2].gameObject.transform:GetAnchoredPosition() for i = 1, MDL.Country.CountryType.Qun do self:InitCampPlayers(self.group_Heads[i], BattleDataGetter.GetEntityListOfCampId(i), i) end self:RegistSystemEvent(EventID.UI_FourCountryWar_ScoreChange, self.UpdateScore) self:RegistSystemEvent(EventID.UI_FourCountryWar_PlayerBattleMsg, self.ShowRemindScoreMsg) self:RegistSystemEvent(EventID.After_Hero_Dead, self.OnHeroEntityDead) self:RegistSystemEvent(EventID.UI_SyncSolo_OpenCountDownPanel , self.OnOpenCountDownPanel) self.txt_Kill.text = BattleDataGetter.GetPlayerKillNum(BattleDataGetter.GetCurPlayerID()) self.txt_Die.text = BattleDataGetter.GetPlayerDeadHeroCount(BattleDataGetter.GetCurPlayerID()) local scoreStr = UTL.Color.FormatTextByColor("efd449", BattleDataGetter.GetFourCountryScoreOfPlayerID(BattleDataGetter.GetCurPlayerID())) self.txt_Score.text = string.FormatByIdsId(Const_IDS.IDS_RankOptimization_Score, scoreStr) UIUtils.SetActive(self.img_TimeBg, false) self:OnUpdateFun() self:StartRepeatFunc(self.OnUpdateFun, 1) self:RegistSystemEvent(EventID.SDK_OnVoiceRoomStateChange, self.RefreshVoiceUI) if not GameAppInfo.IsJapanesePackage() then if CTL.VoiceRoom.IsInVoiceRoom(MDL.VoiceRoom.VoiceRoomType.Room_SyncFourCountry) then self:RefreshVoiceUI() else MDL.VoiceRoom.VoiceCallStateReq(MDL.VoiceRoom.VoiceRoomType.Room_SyncFourCountry) end else UIUtils.SetActive(self.group_Right, false) end end function UISyncFourCountryWarBattlePanel:OnButtonClicked(obj) if obj == self.event_ListenIn then --收听 local listen, call = CTL.VoiceRoom.IsEnabledListener(), CTL.VoiceRoom.IsEnabledMicrophone() listen = not listen MDL.VoiceRoom.VoiceCallSetStateReq(MDL.VoiceRoom.VoiceRoomType.Room_SyncFourCountry, call, listen) if listen then CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_Listening"]) CTL.Sound.PlayGameSound("UI_voice_system") else CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_NotListening"]) CTL.Sound.PlayGameSound("UI_invalid") end elseif obj == self.event_OpenMic then --麦克风 local listen, call = CTL.VoiceRoom.IsEnabledListener(), CTL.VoiceRoom.IsEnabledMicrophone() call = not call MDL.VoiceRoom.VoiceCallSetStateReq(MDL.VoiceRoom.VoiceRoomType.Room_SyncFourCountry, call, listen) if call then CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_NotSpeakingBtn"]) CTL.Sound.PlayGameSound("UI_voice_system") else CTL.Tips.AddTipsMsg(Const_IDS["IDS_WarChannel_SpeakingBtn"]) CTL.Sound.PlayGameSound("UI_invalid") end end end function UISyncFourCountryWarBattlePanel:OnUpdateFun(deltaTime, timeSinceUpdate) local curTimer = BattleDataGetter.GetRemainTime() if curTimer > SyncFourCountryCompetitionDuration then self.txt_TimeCount.text = UTL.Time.FormatTimeBySeconds(curTimer - SyncFourCountryCompetitionDuration) UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(SyncFourCountryCompetitionDuration)) if not self.openCountDownPanel then UIUtils.SetActive(self.img_TimeBg, true) end elseif curTimer < 0 then UIUtils.SetLabel(self.txt_Time, nil) else UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(curTimer)) if not self.openCountDownPanel then self:OnOpenCountDownPanel() end end end function UISyncFourCountryWarBattlePanel:OnOpenCountDownPanel() UIUtils.SetActive(self.img_TimeBg, false) self.openCountDownPanel = true end function UISyncFourCountryWarBattlePanel:OnHeroEntityDead(entity) self.txt_Kill.text = BattleDataGetter.GetPlayerKillNum(BattleDataGetter.GetCurPlayerID()) self.txt_Die.text = BattleDataGetter.GetPlayerDeadHeroCount(BattleDataGetter.GetCurPlayerID()) if entity._logicInitData.IsPlayerSelf then UIManager.OpenView(Const_UI_Lua.UIEnum.UISyncTeamPVPRevive) end end function UISyncFourCountryWarBattlePanel:UpdateScore(entity, scoreDelta, playerScore, countryScore, reason) for i = 1, MDL.Country.CountryType.Qun do local score = FP.tonumberV1(BattleDataGetter.GetFourCountryScoreOfCountryId(i)) if score ~= self.scoreList[i] or self.scoreList[i] == nil then self.scoreList[i] = score local countryData = DataSheetManager.CountryBase:GetDataByID(i) self.group_Heads[i].lab_Integral.text = UIUtils.GetLocalizedTxt(Const_IDS[countryData.CountryName]) .. ":" .. score local entityList = BattleDataGetter.GetEntityListOfCampId(i) for j, v in ipairs(entityList) do if v == entity then self.group_Heads[i].scores[j].text = playerScore break end end end end local maxScore = 0 local maxCountryId = 1 for i, v in ipairs(self.scoreList) do if maxScore < v then maxCountryId = i maxScore = v end end for i, v in ipairs(self.group_Heads) do UIUtils.SetActive(v.img_Winner, maxCountryId == i) end if entity == BattleDataGetter.GetCurEntity() then self.txt_Score.text = string.FormatByIdsId(Const_IDS.IDS_RankOptimization_Score, UTL.Color.FormatTextByColor("efd449", playerScore)) if reason == LuaConst.EFourCountryScoreChangeReason.KILL or reason == LuaConst.EFourCountryScoreChangeReason.DEATH then self:ShowKillScoreMsg({score = FP.tonumberV1(scoreDelta), reason = reason}) elseif reason == LuaConst.EFourCountryScoreChangeReason.COIN or reason == LuaConst.EFourCountryScoreChangeReason.OCCUPY then self:ShowKillScoreMsg({score = scoreDelta, reason = reason}) end end end function UISyncFourCountryWarBattlePanel:InitCampPlayers(collection, entityList, countryId) local playerCollection = { collection.group_Player1, collection.group_Player2, collection.group_Player3 } for i, v in ipairs(entityList) do local subViewContext = {} subViewContext.playerID = v:GetPlayerID() subViewContext.mainHeroId = v:GetCharacterID() subViewContext.campId = v:GetCampID() if v.components.adjutant.AdjutantEntity then subViewContext.subHeroId = CTL.HeroSelect.GetHeroIdByFuJiangRelate(v.components.adjutant.AdjutantEntity:GetCharacterID()) else subViewContext.subHeroId = 1 end subViewContext.ImgBloodPath = self:GetBloodImgPath(subViewContext.playerID, v:GetCampID()) if playerCollection[i] == nil then logging.error(LTAG.ERROR,"错误 队伍人数超过3人 countryId", countryId, " index :", i) else playerCollection[i]:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIHeadSquareCommon), subViewContext) end end for i, v in ipairs(collection.scores) do v.text = SyncFourCountryInitialPointsPerPerson end UIUtils.SetActive(collection.img_Winner, false) UIUtils.SetActive(collection.group_OurSide, countryId == BattleDataGetter.GetMyCampID()) end function UISyncFourCountryWarBattlePanel:GetBloodImgPath(playerId, campId) if playerId == BattleDataGetter.GetCurPlayerID() then return ConstAssetPathConfig.FriendPath elseif campId == BattleDataGetter.GetMyCampID() then return ConstAssetPathConfig.AssetPath211 else return ConstAssetPathConfig.Path45 end end function UISyncFourCountryWarBattlePanel:RefreshVoiceUI() UIUtils.SetActive(self.group_Right, true) local listen, call = CTL.VoiceRoom.IsEnabledListener(), CTL.VoiceRoom.IsEnabledMicrophone() self.img_ListenIn:SetState(listen and 1 or 0) self.img_OpenMic:SetState(call and 1 or 0) end function UISyncFourCountryWarBattlePanel:OnUIAnimationStoped(id) --动画结束 显示手指 聚焦特效等 if 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:InitScoreCell(self.loop_Kill[3], msg) self.loop_Kill[3].gameObject.transform:SetAnchoredPosition(self.firstCellPosX, self.firstCellPosY) self.loop_Kill[3].gameObject:SetActive(true) self.firstId = self:PlayUIAnimation(ConstAssetPathConfig.Path46, self.loop_Kill[3].gameObject.transform, true) self.hideLoopKill[self.loop_Kill[3]] = UTL.Time.GetLocalTimestamp() end elseif self.firstId == id then self:PlayNext() elseif self.remindPlayId == id then if self.curRemindShowMsgs and #self.curRemindShowMsgs > 0 then local cell1 = self.loop_Remind[1] local cell2 = self.loop_Remind[2] self.loop_Remind[1] = cell2 self.loop_Remind[2] = cell1 local msg = table.remove(self.curRemindShowMsgs, 1) self:InitBattleMsgCell(self.loop_Remind[2], msg) self.loop_Remind[2].gameObject.transform:SetAnchoredPosition(self.firstRemindCellPosX, self.firstRemindCellPosY) self.loop_Remind[2].gameObject:SetActive(true) self.firstRemindId = self:PlayUIAnimation(ConstAssetPathConfig.Path46, self.loop_Remind[2].gameObject.transform, true) self.hideLoopRemind[self.loop_Kill[2]] = UTL.Time.GetLocalTimestamp() end elseif self.firstRemindId == id then self:PlayRemindNext() end end function UISyncFourCountryWarBattlePanel:PlayNext() if self.curShowMsgs and #self.curShowMsgs > 0 then self.playing = true --击杀动画 已经显示的上移 腾出位置给新的显示动画 if self.hideLoopKill[self.loop_Kill[2]] then self:PlayUIAnimation(ConstAssetPathConfig.AssetPath213, self.loop_Kill[2].gameObject.transform) self.hideLoopKill[self.loop_Kill[2]] = UTL.Time.GetLocalTimestamp() end self.killPlayId = self:PlayUIAnimation(ConstAssetPathConfig.AssetPath213, self.loop_Kill[3].gameObject.transform, true) self.loop_Kill[1].gameObject:SetActive(false) self.hideLoopKill[self.loop_Kill[3]] = UTL.Time.GetLocalTimestamp() else self.playing = false end end function UISyncFourCountryWarBattlePanel: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 UISyncFourCountryWarBattlePanel:ShowKillScoreMsg(msg) if self.allHide then local cell = self.loop_Kill[3] self:InitScoreCell(cell, msg) cell.gameObject:SetActive(true) --第一次显示 播放最下层信息动画 self.firstId = self:PlayUIAnimation(ConstAssetPathConfig.Path46, 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 UISyncFourCountryWarBattlePanel:InitScoreCell(cell, msg) if msg.score < 0 then local deathStr = "("..UTL.Color.GetColorfulText("ff4545", "IDS_GuildWar_PlayerDeath")..")" cell.txt_Name02.text = deathStr..UTL.Color.FormatTextByColor("ff4545",msg.score) else if msg.reason == LuaConst.EFourCountryScoreChangeReason.KILL then local killStr = "("..UTL.Color.GetColorfulText("efd449", "IDS_GuildWar_PlayerKill")..")" cell.txt_Name02.text = killStr..UTL.Color.FormatTextByColor("69e856","+"..msg.score) else cell.txt_Name02.text = UTL.Color.FormatTextByColor("69e856","+"..msg.score) end end end --战斗消息Remind Loop function UISyncFourCountryWarBattlePanel:PlayRemindNext() if self.curRemindShowMsgs and #self.curRemindShowMsgs > 0 then self.remindPlaying = true --战斗消息动画 已经显示的上移 腾出位置给新的显示动画 self.remindPlayId = self:PlayUIAnimation(ConstAssetPathConfig.AssetPath213, self.loop_Remind[2].gameObject.transform, true) self.loop_Remind[1].gameObject:SetActive(false) self.hideLoopRemind[self.loop_Remind[2]] = UTL.Time.GetLocalTimestamp() else self.remindPlaying = false end end function UISyncFourCountryWarBattlePanel:HideLoopRemind() for k, v in pairs(self.hideLoopRemind) do if v then local time = UTL.Time.GetLocalTimestamp() - v if time >= HideTime then self:PlayUIAnimation(ConstAssetPathConfig.AssetPath112, k.gameObject.transform) self.hideLoopRemind[k] = nil end end end if not next(self.hideLoopRemind) then self.allRemindHide = true end end function UISyncFourCountryWarBattlePanel:ShowRemindScoreMsg(msg) if self.allRemindHide then local cell = self.loop_Remind[2] self:InitBattleMsgCell(cell, msg) cell.gameObject:SetActive(true) --第一次显示 播放最下层信息动画 self.firstRemindId = self:PlayUIAnimation(ConstAssetPathConfig.Path46, self.loop_Remind[2].gameObject.transform, true) self.hideLoopRemind[self.loop_Remind[2]] = UTL.Time.GetLocalTimestamp() self.remindPlaying = true self.allRemindHide = false self:StartRepeatFunc(self.HideLoopRemind, 1, -1) else self.curRemindShowMsgs = self.curRemindShowMsgs or {} table.insert(self.curRemindShowMsgs, msg) if not self.remindPlaying then self:PlayRemindNext() end end end function UISyncFourCountryWarBattlePanel:InitBattleMsgCell(cell, msg) cell.txt_Name01.text = msg end return UISyncFourCountryWarBattlePanel