local UISceneQuizRank = UIViewClass() local RankType = { Preliminary = true, Final = false, } function UISceneQuizRank:OnOpened(context) self.activityId = MDL.SceneQuiz.CurActivityID self.rankType = context.rankType self:RegistSystemEvent(EventID.UI_SceneQuiz_AnswerRank, self.RefreshPlayerRankData) self:RegistSystemEvent(EventID.UI_SceneQuiz_MyInfoRefresh, self.UpdateIsFinals) self.txt_RankInfo.text = nil if self.rankType == RankType.Preliminary then self.state_Title:SetState(0) UIUtils.SetLabelText(self.lab_Quiz, Const_IDS.IDS_SceneQuiz_RankHint_5) MDL.SceneQuiz.SceneQuizGetInfoReq() elseif self.rankType == RankType.Final then self.state_Title:SetState(1) UIUtils.SetLabelText(self.lab_Quiz, Const_IDS.IDS_SceneQuiz_RankHint_3) end self.temp_ItemObj = self.temp_Item.gameObject MDL.SceneQuiz.SceneQuizGetAnswerRankReq(self.rankType) end function UISceneQuizRank:UpdateIsFinals() if MDL.SceneQuiz.GetIsFinal() then UIUtils.SetLabelText(self.txt_RankInfo, Const_IDS.IDS_SceneQuiz_PreliminaryHint_2) else UIUtils.SetLabelText(self.txt_RankInfo, Const_IDS.IDS_SceneQuiz_PreliminaryHint_3) end end function UISceneQuizRank:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UISceneQuizRank:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() if LevelManager.IsSceneQuizTown() then MDL.Level.SendRoleLeaveFubenFromSetting() end else for i, v in ipairs(self.group_SelfRank.content) do if v.item.event_Click == comp then UTL.ItemTips.ShowCommonTipsById(self.rewardData[i].Item) break end end end end function UISceneQuizRank:RefreshPlayerRankData(rankDatas, selfRankDataIndex, rankType) if rankType == self.rankType then if self.loop_Rank.Count > 0 then self.loop_Rank:ClearCells() end for index, rankData in ipairs(rankDatas) do self.loop_Rank:AddData(rankData, 0) end local myData = rankDatas[selfRankDataIndex] if self.rankType == RankType.Final then if myData then UIUtils.SetActive(self.group_SelfRank.gameObject, true) self:RefreshRankCell(self.group_SelfRank, myData, selfRankDataIndex) else UIUtils.SetActive(self.group_SelfRank.gameObject, false) end else UIUtils.SetActive(self.group_SelfRank.gameObject, true) self:RefreshRankCell(self.group_SelfRank, myData, selfRankDataIndex) end end end function UISceneQuizRank:RefreshRankCell(cell, data, index, cellObj) if data then --押注情况 if self.rankType == RankType.Final then if CTL.SceneQuiz.IfBetByAcId(data.acid) then if index == 1 then cell.state_Bet:SetState(0) else cell.state_Bet:SetState(1) end else cell.state_Bet:SetState(2) end else cell.state_Bet:SetState(2) end --排名 if index <= 3 then cell.state_RankIcon:SetState(index) else cell.state_RankIcon:SetState(0) cell.txt_Rank.text = index end cell.txt_Name.text = data.name local serverId, serverName = CTL.CrossServer.GetServerIDAndServerNameByServerID(data.serverId) cell.txt_Server.text = serverId .. "-" .. serverName cell.txt_QuizNum.text = data.param self.rewardData = self:GetRewardData(data.param, index) if self.rewardData then self:SetRewardInfo(self.rewardData, cell.content, cellObj) UIUtils.SetActive(cell.content.gameObject, true) else UIUtils.SetActive(cell.content.gameObject, false) end if cell.lab_None then cell.lab_None.text = nil end else --自己未上榜的情况 UIUtils.SetActive(cell.content.gameObject, false) cell.state_RankIcon:SetState(0) UIUtils.SetLabelText(cell.txt_Rank, Const_IDS.IDS_GoldHeroActivity_SynergyBoss_NewHint6) cell.txt_Name.text = BattleDataGetter.GetPlayerName() local serverId, serverName = CTL.CrossServer.GetServerIDAndServerNameByServerID(MDL.Login.GetServerShowId()) cell.txt_Server.text = serverId .. "-" .. serverName cell.txt_QuizNum.text = "-" if cell.lab_None then UIUtils.SetLabelText(cell.lab_None,Const_IDS.IDS_SceneQuiz_RankHint_11) end end end function UISceneQuizRank:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Rank then self:RefreshRankCell(cellTable, data, index + 1, cellTable.cell.gameObject) end end function UISceneQuizRank:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Rank then for i, v in ipairs(cellTable.content) do if v.item.event_Click == target then local reward = self:GetRewardData(data.param, index + 1) UTL.ItemTips.ShowCommonTipsById(reward[i].Item) break end end end end function UISceneQuizRank:GetRewardData(param, rank) if self.rankType == RankType.Preliminary then for i, v in DataSheetManager.SceneQuizPreliminaryReward:GetEnumerator() do if param >= v.Score1 then return v.Reward_Table end end elseif self.rankType == RankType.Final then for i, v in DataSheetManager.SceneQuizFinalReward:GetEnumerator() do if rank <= v.Rank1 and rank >= v.Rank2 then return v.Reward_Table end end end end function UISceneQuizRank:SetRewardInfo(rewardData, content, cellObj) if rewardData == nil then for i = 1, #content do local item = content[i] UIUtils.SetActive(item.gameObject, false) end return end for i, v in ipairs(rewardData) do local item = content[i] if item == nil then if cellObj then item = self:InstantiateCellCollection(cellObj, content, self.temp_ItemObj) else item = self:InstantiateCollection(content, self.temp_ItemObj) end end UIUtils.SetActive(item.gameObject, true) UTL.Item.SetItemCell(item.item, v.Item, v.ItemNum) end for i = #rewardData + 1, #content do local item = content[i] UIUtils.SetActive(item.gameObject, false) end end return UISceneQuizRank