local UIWorldBossBattleRank = UIViewClass() local tonumberV1 = FP.tonumberV1 local ceil = math.ceil -- 此类是 UICountryWorldBossBattleRank 基类,改动的时候需要注意不要影响 子类的功能 --------------------------- UIWorldBossBattleRank.ItemState = { MySelf = -1, Normal = 0, AttackPlayer = 1, --主动攻击 BeAttacked = 2, --被攻击 } function UIWorldBossBattleRank:OnOpened(context) self.DownTeamLeaderNameList = {} -- 是否展开协助者列表 self.loopDataList = {} self.loopPrefabIndexs = {} self.MyRank = -1 self.worldBossBattle = context.parent self:RegistSystemEvent(EventID.UI_WorldBoss_PlayHelpEffect, self.PlayHelpEffect) self:RegistSystemEvent(EventID.UI_WorldBoss_UpdateDamageInfo, self.UpdateDamageInfo) self:RegistSystemEvent(EventID.UI_WorldBoss_My_Assistant_Kill, self.RefreshBattlePlayerList) -- 刷新击杀数量 self.obi_state:SetState(1) self:InitPanel() self:InitMyInfo() self:UpdateDamageInfo(true) end function UIWorldBossBattleRank:OnButtonClicked(comp) if comp == self.btn_ArrowClose then self.obi_state:SetState(0) elseif comp == self.btn_ArrowOpen then self.obi_state:SetState(1) elseif comp == self.btn_Setting then UIManager.OpenView(Const_UI_Lua.UIEnum.UISettingMainPanel) elseif comp == self.btn_Exit then CTL.Setting.BackToTown() elseif comp == self.event_SeekHelp then self:OnClickHelp() end end function UIWorldBossBattleRank:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.LoopScroll_Battle then if data.assistantName then -- 协助者 颜色 local myPlayerInfo = BattleDataGetter.GetPlayerInfo(BattleDataGetter.GetCurPlayerID()) local assistantPlayerInfo = BattleDataGetter.GetPlayerInfo(data.playerID) if assistantPlayerInfo.acid == myPlayerInfo.acid then -- 自己-绿色 UIUtils.SetLabel(cellTable.txt_Name, UTL.Color.FormatGreenColor(data.assistantName)) UIUtils.SetLabel(cellTable.txt_KillNum, UTL.Color.FormatGreenColor(data.killCount)) elseif self.worldBossBattle:IsAssistantNeedRedColorByPlayerID(data.playerID, true, false) then -- 敌人 -红色 UIUtils.SetLabel(cellTable.txt_Name, UTL.Color.FormatRedColor(data.assistantName)) UIUtils.SetLabel(cellTable.txt_KillNum, UTL.Color.FormatRedColor(data.killCount)) elseif self.worldBossBattle:IsAssistantNeedRedColorByPlayerID(data.playerID, false, true) then -- 变蓝的情况 UIUtils.SetLabel(cellTable.txt_Name, UTL.Color.FormatTextByColor(UTL.Color.ModelNameColor.Blue, data.assistantName)) UIUtils.SetLabel(cellTable.txt_KillNum, UTL.Color.FormatTextByColor(UTL.Color.ModelNameColor.Blue, data.killCount)) else -- 默认-白色 UIUtils.SetLabel(cellTable.txt_Name, UTL.Color.FormatWhiteColor(data.assistantName)) UIUtils.SetLabel(cellTable.txt_KillNum, UTL.Color.FormatWhiteColor(data.killCount)) end else local cellData = data.info local damage = tonumberV1(cellData.damage) local realIndex = data.index --根据索引值的背景条显示 UIUtils.SetLabel(cellTable.txt_Rank, realIndex) if realIndex == 1 and damage > 0 then UIUtils.SetActive(cellTable.img_FirstRank.gameObject, true) else UIUtils.SetActive(cellTable.img_FirstRank.gameObject, false) end cellTable.state_BG:SetState(realIndex % 2 == 0 and 0 or 1) -- 背景图片隔行使用同一个 local assistantList = self.worldBossBattle:GetAssistantListByTeamID(data.info.teamId) if assistantList == nil or #assistantList <= 0 then cellTable.state_Arrow:SetState(2) elseif self.DownTeamLeaderNameList[cellData.teamId] then cellTable.state_Arrow:SetState(1) else cellTable.state_Arrow:SetState(0) end local playerName = cellData.teamLeaderName if MDL.Team.IsTeamId(cellData.teamId) then playerName = string.FormatByIdsId(Const_IDS["IDS_Team_WorldBoss_Team"], playerName) end local curState local curDamage = self:GetDamageShow(damage) if cellData.teamId == BattleDataGetter.GetMyTeamID() then -- 自己绿色 curState = UIWorldBossBattleRank.ItemState.MySelf playerName = UTL.Color.FormatGreenColor(playerName) curDamage = UTL.Color.FormatGreenColor(curDamage) elseif self.worldBossBattle:IsNeedRedColorByTeamID(cellData.teamId, true, false) then -- 变红的情况 playerName = UTL.Color.FormatRedColor(playerName) curDamage = UTL.Color.FormatRedColor(curDamage) elseif self.worldBossBattle:IsNeedRedColorByTeamID(cellData.teamId, false, true) then -- 变蓝的情况 playerName = UTL.Color.FormatTextByColor(UTL.Color.ModelNameColor.Blue, playerName) curDamage = UTL.Color.FormatTextByColor(UTL.Color.ModelNameColor.Blue, curDamage) else playerName = UTL.Color.FormatWhiteColor(playerName) curDamage = UTL.Color.FormatWhiteColor(curDamage) end if self.needResetCount then self.PlayerNameList[realIndex] = playerName UIUtils.SetLabel(cellTable.txt_Name, playerName) self.PlayerDamageList[realIndex] = curDamage UIUtils.SetLabel(cellTable.txt_Score, curDamage) self.PlayerStateList[realIndex] = curState else --相同信息不重复设置 local lastPlayerName = self.PlayerNameList[realIndex] if lastPlayerName ~= playerName then self.PlayerNameList[realIndex] = playerName UIUtils.SetLabel(cellTable.txt_Name, playerName) end local lastDamage = self.PlayerDamageList[realIndex] if lastDamage ~= curDamage then self.PlayerDamageList[realIndex] = curDamage UIUtils.SetLabel(cellTable.txt_Score, curDamage) end local lastState = self.PlayerStateList[realIndex] if lastState ~= curState then self.PlayerStateList[realIndex] = curState end end end end end function UIWorldBossBattleRank:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.LoopScroll_Battle then if data.info then -- 帮助者没有info if self.DownTeamLeaderNameList[data.info.teamId] then self.DownTeamLeaderNameList[data.info.teamId] = false else self.DownTeamLeaderNameList[data.info.teamId] = true end end self:UpdateDamageInfo(true) end end function UIWorldBossBattleRank:OnUpdateFun(deltaTime, timeSinceUpdate) -- 求助CD if self.helpTimer then self.helpTimer = self.helpTimer - deltaTime if self.helpTimer <= 0 then self:HelpCDOver() end end end --------------------------- function UIWorldBossBattleRank:InitPanel() self.PlayerNameList = {} self.PlayerDamageList = {} self.PlayerStateList = {} self.MyDamage = -1 UIUtils.SetLabelText(self.lab_TeamDamage, Const_IDS.IDS_WorldBoss_TeamDamage) UIUtils.SetLabel(self.txt_NameMine, BattleDataGetter.GetPlayerName()) end function UIWorldBossBattleRank:InitMyInfo() local playerInfo = BattleDataGetter.GetPlayerInfo(BattleDataGetter.GetCurPlayerID()) if playerInfo.fighterType == LuaConst.BattleMemberType.Chase_Player then -- 仇杀者 self.obi_mineState:SetState(3) elseif playerInfo.fighterType == LuaConst.BattleMemberType.Assistant then -- 协助者 self.obi_mineState:SetState(2) elseif playerInfo.wbRewardLeft <= 0 then -- 剩余次数用完 self.obi_mineState:SetState(1) else self.obi_mineState:SetState(0) UIUtils.SetActive(self.img_FirstRankMine.gameObject, false) UIUtils.SetLabel(self.txt_ScoreMine, 0) end if playerInfo.fighterType == LuaConst.BattleMemberType.Assistant then -- 协助者 -- 自己作为协助者,默认能看到协助目标的协助者名单 local assisAimPlayerInfo = BattleDataGetter.GetPlayerInfoByAcid(playerInfo.assisAimAcid) self.DownTeamLeaderNameList[assisAimPlayerInfo.teamId] = true elseif playerInfo.fighterType == LuaConst.BattleMemberType.Account_Hero or playerInfo.fighterType == LuaConst.BattleMemberType.Called_Player then -- 自己作为参与者,默认展开自己的协助者名单 local playerInfo = BattleDataGetter.GetPlayerInfo(BattleDataGetter.GetCurPlayerID()) self.DownTeamLeaderNameList[playerInfo.teamId] = true end end --请求协助 --请求协助后,按钮变灰色,倒计时开始,按钮不可用 function UIWorldBossBattleRank:OnClickHelp() local value = MDL.WorldBoss.GetIsAttacked() --是否被人攻击过 if MDL.WorldBoss.WorldBossSeekHelp(true, value and MDL.WorldBoss.HelpType.Attacked or MDL.WorldBoss.HelpType.Normal, "") then self.effect_Help:StopUIEffect() self:StartRepeatFunc(self.OnUpdateFun, 1) self.event_SeekHelp:SetGray(true, false) self.helpTimer = DataSheetManager.ConstData:GetDataByID("WorldBossSeekHelpCD").IntValue self.lab_HelpTimeCD:ResetAndBeginCustomTimer(false, self.helpTimer, 0, UIUtils.GetLocalizedTxt(Const_IDS["IDS_TeamUI_Myteam_RecruitingTime"]), 1) end end -- 请求协助CD 结束 function UIWorldBossBattleRank:HelpCDOver() self:StopRepeatFunc(self.OnUpdateFun) self.event_SeekHelp:SetGray(false, true) self.helpTimer = nil self.lab_HelpTimeCD:EndTimer() end function UIWorldBossBattleRank:PlayHelpEffect() self.effect_Help:PlayUIEffect() end function UIWorldBossBattleRank:UpdateDamageInfo(isForce) local infoList = BattleDataGetter.GetDamageList() local infoCount = #infoList if infoCount == 0 and not isForce then return end local cellCount = self.LoopScroll_Battle.Count -- 长度不一致,需要重新设置每一个Item if cellCount ~= infoCount then self.needResetCount = true else self.needResetCount = false end self:RefreshBattlePlayerList() local myInfo = nil local myRank = 0 for i = 1, infoCount do if myInfo == nil and infoList[i].teamId == BattleDataGetter.GetMyTeamID() then myInfo = infoList[i] myRank = i break end end -- 更新自身信息 if myInfo then local damage = BattleDataGetter.GetDamageOfPlayer(BattleDataGetter.GetCurPlayerID()) damage = damage and tonumberV1(damage) or 0 if myRank ~= self.MyRank then self.MyRank = myRank UIUtils.SetLabel(self.txt_RankMine, myRank) end if myRank == 1 then UIUtils.SetActive(self.img_FirstRankMine.gameObject, true) else UIUtils.SetActive(self.img_FirstRankMine.gameObject, false) end local damageStr = self:GetDamageShow(damage) if self.MyDamage ~= damageStr then self.MyDamage = damageStr UIUtils.SetLabel(self.txt_ScoreMine, damageStr) end else self.MyRank = -1 UIUtils.SetLabel(self.txt_RankMine, "") UIUtils.SetActive(self.img_FirstRankMine.gameObject, false) UIUtils.SetLabel(self.txt_ScoreMine, 0) end end function UIWorldBossBattleRank:RefreshBattlePlayerList() if self.obi_state.CurState ~= 1 then return end -- 如果列表不是打开的则不刷新 local infoList = BattleDataGetter.GetDamageList() table.clearArray(self.PlayerNameList) table.clearArray(self.PlayerDamageList) table.clearArray(self.PlayerStateList) table.clearArray(self.loopDataList) table.clearArray(self.loopPrefabIndexs) self:ReloadRankList(infoList) end function UIWorldBossBattleRank:ReloadRankList(infoList) for index, info in ipairs(infoList) do table.insert(self.loopDataList, {info = info, index = index}) table.insert(self.loopPrefabIndexs, 0) if self.DownTeamLeaderNameList[info.teamId] then local assistantList = self.worldBossBattle:GetAssistantListByTeamID(info.teamId) for _,assistant in ipairs(assistantList) do table.insert(self.loopDataList, assistant) table.insert(self.loopPrefabIndexs, 1) end end end self.LoopScroll_Battle:ReloadAll(self.loopDataList, self.loopPrefabIndexs) end function UIWorldBossBattleRank:GetDamageShow(damage) return UTL.String.GetCountStr(ceil(damage)) end return UIWorldBossBattleRank