local UIDragonArteryBattleInfo = UIViewClass() local INTERVAL_UPDATE_TIME = 1 --倒计时显示的时间间隔 local INTERVAL_UPDATE_POINT = 2 --查询积分的时间间隔 local BATTLE_TIME_REMAIN_WARN = 30 --战斗区的倒计时时间 local EventSystem = require("Event/EventSystem") function UIDragonArteryBattleInfo:OnCreated() self.txt_Num_1.text = 1 self.txt_Num_2.text = 2 self.txt_Num_3.text = 3 self.txt_Num_4.text = 4 end function UIDragonArteryBattleInfo:OnOpened(context) self:RegistSystemEvent(EventID.UIBattle_DragonArtery_DragonArteryPlayerChanged, self.OnDragonArteryPlayerChanged) self:RegistSystemEvent(EventID.UIBattle_MainPlayerFightModeChanged, self.OnFightModeChanged) self.waitAreaTotalTime = DataSheetManager.ConstData:GetDataByID("DragonArteryPeaceTime").IntValue + CTL.DragonArtery.GetRegisterAreaTime() self.progressRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBossProgress)) self.comboViewRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleCombo), { isShowComboType = LuaConst.ComboType.IsKillHero }) self.killInfoNoticeViewRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleKillInfoNotice), {compareCamp = true}) self:OnFightModeChanged(BattleDataGetter.GetFightMode()) self.txt_LeftTimeWarn.text = nil self.winTotalFrame = DataSheetManager.ConstData:GetDataByID("DragonArteryWinTime").IntValue * LuaConst.LogicFrameRate--持有图腾的胜利时长,单位为帧数 self.myCountry = BattleDataGetter.GetDragonArteryMyKingdom() self.myCountryRankIndex = 1 --我的国家排行 self:StartRepeatFunc(self.UpdateTimeShow, INTERVAL_UPDATE_TIME, 0) if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DragonArteryWaitingArea) then UIUtils.SetLabelText(self.lab_Time, Const_IDS.IDS_DragonArtey_LastTime2) self:UpdateCountryPoints() UIUtils.SetLabelText(self.lab_RankTitle, Const_IDS.IDS_DragonArtey_TimeToBattle) else UIUtils.SetLabelText(self.lab_Time, Const_IDS.IDS_DragonArtey_LastTime) self:UpdateCountryPoints() self:StartRepeatFunc(self.UpdateCountryPoints, INTERVAL_UPDATE_POINT, 0) local targetEntity = BattleDataGetter.GetDragonArteryEntity() if targetEntity == nil then UIUtils.SetLabelText(self.lab_RankTitle, Const_IDS.IDS_DragonArtey_GetTotem) else self:OnDragonArteryPlayerChanged(targetEntity, targetEntity:GetPlayerID()) end end end function UIDragonArteryBattleInfo:OnFightModeChanged(pkModel) if pkModel == LuaConst.EFightMode.PEACE then self.state_Mode:SetState(0) elseif pkModel == LuaConst.EFightMode.TEAM_GUILD then self.state_Mode:SetState(1) end end function UIDragonArteryBattleInfo:OnDragonArteryPlayerChanged(entity, playerID) self:StopRepeatFunc(self.CountWithDragonArtery) if entity == nil then self.lab_RankTitle.text = nil self.dragonArteryCountryName = nil return end self.dragonArteryPlayerName = BattleDataGetter.GetPlayerNameByPlayerID(playerID) --这个是跟服务器约定死了的,在龙脉战里,对应国家的玩家一定是固定的campID local dragonArteryCountryId = entity:GetCampID() self.dragonArteryCountryName = UTL.String.GetCountryName(dragonArteryCountryId) self:CountWithDragonArtery() self:StartRepeatFunc(self.CountWithDragonArtery, 1, 0) self.dragonArteryCountryId = dragonArteryCountryId self:UpdateCountryPoints() end function UIDragonArteryBattleInfo:CountWithDragonArtery() local leftWinFrame = self.winTotalFrame - BattleDataGetter.GetDragonArteryPlayerComboFrame() if leftWinFrame > 0 then --剩余持有时长大于玩法剩余时间时,修改提示 local endFrame = self:GetLevelRemainTime() * LuaConst.LogicFrameRate if leftWinFrame >= endFrame then UIUtils.SetLabelText(self.lab_RankTitle, Const_IDS.IDS_DragonArtey_EndWin) else if self.dragonArteryCountryId == MDL.Country.GetMyCountryId() then self.lab_RankTitle.text = string.FormatByIdsId(Const_IDS.IDS_DragonArtey_HaveTotemWin2, self.dragonArteryCountryName, self.dragonArteryPlayerName, UTL.Time.FormatTimeByFrameCount(leftWinFrame)) else self.lab_RankTitle.text = string.FormatByIdsId(Const_IDS.IDS_DragonArtey_HaveTotemWin, self.dragonArteryCountryName, self.dragonArteryPlayerName, UTL.Time.FormatTimeByFrameCount(leftWinFrame)) end end else self:StopRepeatFunc(self.CountWithDragonArtery) self.lab_RankTitle.text = nil end end function UIDragonArteryBattleInfo:GetCountryScoreRank() local firstPoint, firstCountry = 0 local secondPoint, secondCountry = 0 local thirdPoint, thirdCountry = 0 local fourthPoint, fourthCountry = 0 for country = LuaConst.Kingdom.Wei, LuaConst.Kingdom.Qun do local point = BattleDataGetter.GetDragonArteryKingdomScore(country) or 0 if firstCountry == nil or point > firstPoint then fourthPoint = thirdPoint fourthCountry = thirdCountry thirdPoint = secondPoint thirdCountry = secondCountry secondPoint = firstPoint secondCountry = firstCountry firstPoint = point firstCountry = country elseif secondCountry == nil or (point > secondPoint and point <= firstPoint) then fourthPoint = thirdPoint fourthCountry = thirdCountry thirdPoint = secondPoint thirdCountry = secondCountry secondPoint = point secondCountry = country elseif thirdCountry == nil or (point > thirdPoint and point <= secondPoint) then fourthPoint = thirdPoint fourthCountry = thirdCountry thirdPoint = point thirdCountry = country else fourthPoint = point fourthCountry = country end end return firstCountry, secondCountry, thirdCountry, fourthCountry end function UIDragonArteryBattleInfo:SetCountryName(txt, country) if country == self.myCountry then txt.text = UTL.Color.FormatGreenColor(UTL.String.GetCountryName(country)) else UTL.String.SetCountryName(txt, country) end end function UIDragonArteryBattleInfo:RefreshMyCountryRank(firstCountry, secondCountry, thirdCountry, fourthCountry) if firstCountry == self.myCountry then if self.myCountryRankIndex ~= 1 then EventSystem.Dispatch(EventID.UI_DragonArtery_RefreshKingdomRankIndex, 1) end self.myCountryRankIndex = 1 elseif secondCountry == self.myCountry then if self.myCountryRankIndex ~= 2 then EventSystem.Dispatch(EventID.UI_DragonArtery_RefreshKingdomRankIndex, 2) end self.myCountryRankIndex = 2 elseif thirdCountry == self.myCountry then if self.myCountryRankIndex ~= 3 then EventSystem.Dispatch(EventID.UI_DragonArtery_RefreshKingdomRankIndex, 3) end self.myCountryRankIndex = 3 elseif fourthCountry == self.myCountry then if self.myCountryRankIndex ~= 4 then EventSystem.Dispatch(EventID.UI_DragonArtery_RefreshKingdomRankIndex, 4) end self.myCountryRankIndex = 4 end end --更新国家排名和积分显示 function UIDragonArteryBattleInfo:UpdateCountryPoints() local firstCountry, secondCountry, thirdCountry, fourthCountry = self:GetCountryScoreRank() self:RefreshMyCountryRank(firstCountry, secondCountry, thirdCountry, fourthCountry) if self.dragonArteryCountryName == nil then UIUtils.SetActive(self.group_None, true) UIUtils.SetActive(self.group_Owner, false) self:SetCountryName(self.txt_CountryNoTotem_1, firstCountry) self:SetCountryName(self.txt_CountryNoTotem_2, secondCountry) self:SetCountryName(self.txt_CountryNoTotem_3, thirdCountry) self:SetCountryName(self.txt_CountryNoTotem_4, fourthCountry) else UIUtils.SetActive(self.group_None, false) UIUtils.SetActive(self.group_Owner, true) self.txt_CountryWithTotem_1.text = CTL.Country.GetCountryName(self.dragonArteryCountryId) if self.dragonArteryCountryId == firstCountry then self.txt_Rank1.text = 1 self.txt_Rank2.text = 2 self.txt_Rank3.text = 3 self.txt_Rank4.text = 4 self:SetCountryName(self.txt_CountryWithTotem_2, secondCountry) self:SetCountryName(self.txt_CountryWithTotem_3, thirdCountry) self:SetCountryName(self.txt_CountryWithTotem_4, fourthCountry) elseif self.dragonArteryCountryId == secondCountry then self.txt_Rank1.text = 2 self.txt_Rank2.text = 1 self.txt_Rank3.text = 3 self.txt_Rank4.text = 4 self:SetCountryName(self.txt_CountryWithTotem_2, firstCountry) self:SetCountryName(self.txt_CountryWithTotem_3, thirdCountry) self:SetCountryName(self.txt_CountryWithTotem_4, fourthCountry) elseif self.dragonArteryCountryId == thirdCountry then self.txt_Rank1.text = 3 self.txt_Rank2.text = 1 self.txt_Rank3.text = 2 self.txt_Rank4.text = 4 self:SetCountryName(self.txt_CountryWithTotem_2, firstCountry) self:SetCountryName(self.txt_CountryWithTotem_3, secondCountry) self:SetCountryName(self.txt_CountryWithTotem_4, fourthCountry) else self.txt_Rank1.text = 4 self.txt_Rank2.text = 1 self.txt_Rank3.text = 2 self.txt_Rank4.text = 3 self:SetCountryName(self.txt_CountryWithTotem_2, firstCountry) self:SetCountryName(self.txt_CountryWithTotem_3, secondCountry) self:SetCountryName(self.txt_CountryWithTotem_4, thirdCountry) end end if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DragonArtery) then self.txt_PersonalPoints.text = BattleDataGetter.GetDragonArteryPlayerScore(BattleDataGetter.GetCurPlayerID()) else self.txt_PersonalPoints.text = 0 end end function UIDragonArteryBattleInfo:GetLevelRemainTime() if BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.DragonArteryWaitingArea) then --备战区不是同步的,不能直接用关卡剩余时间 return self.waitAreaTotalTime - CTL.Activities.GetOpenedActivityPassedTime(LuaConst.ActivityType.DragonArtery) else return BattleDataGetter.GetRemainTime() end end --更新时间显示 function UIDragonArteryBattleInfo:UpdateTimeShow() local time = self:GetLevelRemainTime() self.txt_Time.text = UTL.Time.FormatTimeSeconds(time) if time <= BATTLE_TIME_REMAIN_WARN then self.txt_LeftTimeWarn.text = math.floor(time) end if time <= 0 then self:StopRepeatFunc(self.UpdateTimeShow) end end function UIDragonArteryBattleInfo:OnButtonClicked(comp) if comp == self.btn_Score then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDragonArterySummaryInfoPanel, { rankIndex = self.myCountryRankIndex }) elseif comp == self.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.DragonArtery, params = { UTL.Time.GetShowTimeBySeconds(DataSheetManager.ConstData:GetDataByID("DragonArteryWinTime").IntValue) } }) elseif comp == self.btn_Setting then UIManager.OpenView(Const_UI_Lua.UIEnum.UISettingMainPanel) end end return UIDragonArteryBattleInfo