local UIGuildWarPastScoreList = UIViewClass() local guild_war_enum = require 'Proto/guild_war_enum_pb' local RankStr = "%s %s" -------------------- 系統函數 ---------------------------------- function UIGuildWarPastScoreList:OnOpened() self:RegistSystemEvent(EventID.UI_GuildWarPastScoreList_Refresh, self.RefreshPanel) self.selectIssue = 1 self.selectGroup = 0 self.firstEndIndex = -1 UIUtils.SetLabel(self.txt_MyGuildName, MDL.Guild.GetMyGuildInfo() and MDL.Guild.GetMyGuildInfo().guildName or "") MDL.GuildWar.RequestHistoryRecord() end function UIGuildWarPastScoreList:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIGuildWarPastScoreList:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() end end function UIGuildWarPastScoreList:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.Loop_Score_Terms then local isSelected = self.selectIssue == index + 1 UIUtils.SetActive(cellTable.img_BackgroundFrame_Selected, isSelected) cellTable.UIState_Tern:SetState(isSelected and 1 or 0) UIUtils.SetLabel(cellTable.txt_Term, string.FormatByIdsId(Const_IDS["IDS_GuildWar_ScheduleTitle"], data.issue)) elseif scrollRect == self.loop_Score_RewardRank then UIUtils.SetActive(cellTable.img_RewardBackground_Bright, index % 2 == 0) UIUtils.SetActive(cellTable.img_RewardBackground_Dark, index % 2 ~= 0) UIUtils.SetLabelText(cellTable.txt_Rank, (self.firstEndIndex ~= -1 and index <= self.firstEndIndex) and Const_IDS["IDS_GuildWar_Round1"] or Const_IDS["IDS_GuildWar_Round2"]) local guildRedShowInfo = data.guildRed.guildName..string.FormatByIdsId(Const_IDS["IDS_CrossSever_SeverSuffixText1"], CTL.CrossServer.GetServerIDAndServerNameByServerID(data.guildRed.zoneInfo.serverId)) local guildBlueShowInfo = data.guildBlue.guildName..string.FormatByIdsId(Const_IDS["IDS_CrossSever_SeverSuffixText1"], CTL.CrossServer.GetServerIDAndServerNameByServerID(data.guildBlue.zoneInfo.serverId)) UIUtils.SetLabel(cellTable.txt_PlayerName_1, data.guildRed.guildName) if CTL.GuildWar.IsShowCrossServerUI() then UIUtils.SetLabel(cellTable.txt_PlayerName_1, guildRedShowInfo) end UIUtils.SetLabel(cellTable.txt_PlayerName_2, not string.isNilOrEmpty(data.guildBlue.guildName) and data.guildBlue.guildName or UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_NoRival"])) if CTL.GuildWar.IsShowCrossServerUI() then UIUtils.SetLabel(cellTable.txt_PlayerName_2, not string.isNilOrEmpty(data.guildBlue.guildName) and guildBlueShowInfo or UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_NoRival"]) ) end if data.Result == 0 then UIUtils.SetLabel(cellTable.txt_Winner, nil) else if CTL.GuildWar.IsShowCrossServerUI() then UIUtils.SetLabel(cellTable.txt_Winner, data.Result == 1 and guildRedShowInfo or guildBlueShowInfo) else UIUtils.SetLabel(cellTable.txt_Winner, data.Result == 1 and data.guildRed.guildName or data.guildBlue.guildName) end end UIUtils.SetActive(cellTable.btn_DetailInfo, not string.isNilOrEmpty(data.guildBlue.guildName) and self.selectGroup + 1 ~= guild_war_enum.Leisure) end end function UIGuildWarPastScoreList:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.Loop_Score_Terms then if self.selectIssue - 1 == index then return end local oldIndex = self.selectIssue - 1 self.selectIssue = index + 1 self.Loop_Score_Terms:UpdateIndex(oldIndex) self:RefreshInfo() self:RefreshMyResult() elseif scrollRect == self.loop_Score_RewardRank then if target == cellTable.btn_DetailInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildWarHistoryPanel, data ,Const_UI_Lua.UIEnum.UIGuildWarSummaryPanel) end end end function UIGuildWarPastScoreList:OnValueChanged(comp, value) if comp == self.toggle_TopGroup then if self.selectGroup ~= value then self.selectGroup = value self:RefreshInfo() end end end ------------------------------------------------------------------- function UIGuildWarPastScoreList:RefreshPanel(msg) if not msg or #msg == 0 then return end self.historyRecords = msg self:RefreshInfo() self:RefreshMyResult() end function UIGuildWarPastScoreList:RefreshMyResult() if not self.historyRecords then return end local records = self.historyRecords[self.selectIssue] local myGuildId = MDL.Guild.GetMyGuildInfo().guildId local rankStr = nil if records and records.groupMatchInfo and #records.groupMatchInfo > 0 then for i, v in ipairs (records.groupMatchInfo) do local winCount = 0 local isContainMy = false local roundTwoRivalGuildId = nil if v.matchInfoSecond and #v.matchInfoSecond > 0 then for _, record in ipairs (v.matchInfoSecond) do if record.guildRed.guildId == myGuildId or record.guildBlue.guildId == myGuildId then isContainMy = true roundTwoRivalGuildId = record.guildRed.guildId == myGuildId and record.guildBlue.guildId or record.guildRed.guildId if (record.guildRed.guildId == myGuildId and record.Result == 1) or (record.guildBlue.guildId == myGuildId and record.Result == 2) then winCount = winCount + 1 end end end end if v.matchInfoFirst and #v.matchInfoFirst > 0 then for _, record in ipairs (v.matchInfoFirst) do if record.guildRed.guildId == myGuildId or record.guildBlue.guildId == myGuildId then isContainMy = true if (record.guildRed.guildId == myGuildId and record.Result == 1) or (record.guildBlue.guildId == myGuildId and record.Result == 2) then winCount = winCount + 1 end end end end if isContainMy then if i == guild_war_enum.Leisure then if winCount == 0 then rankStr = string.format(RankStr, UIUtils.GetLocalizedTxt(Const_IDS[CTL.GuildWar.GroupName[i]]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_Win0"])) elseif winCount == 1 then rankStr = string.format(RankStr, UIUtils.GetLocalizedTxt(Const_IDS[CTL.GuildWar.GroupName[i]]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_Win1"])) else rankStr = string.format(RankStr, UIUtils.GetLocalizedTxt(Const_IDS[CTL.GuildWar.GroupName[i]]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_Win2"])) end else if winCount == 2 then rankStr = string.format(RankStr, UIUtils.GetLocalizedTxt(Const_IDS[CTL.GuildWar.GroupName[i]]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_No1"])) elseif winCount == 0 then rankStr = string.format(RankStr, UIUtils.GetLocalizedTxt(Const_IDS[CTL.GuildWar.GroupName[i]]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_No4"])) else -- 判断第二场对手 local isWinRound1 = true local isWinRound2 = true if v.matchInfoSecond and #v.matchInfoSecond > 0 then for _, record in ipairs (v.matchInfoSecond) do if record.guildRed.guildId == roundTwoRivalGuildId or record.guildBlue.guildId == roundTwoRivalGuildId then isWinRound2 = (record.guildRed.guildId == roundTwoRivalGuildId and record.Result == 1) or (record.guildBlue.guildId == roundTwoRivalGuildId and record.Result == 2) end end end if v.matchInfoFirst and #v.matchInfoFirst > 0 then for _, record in ipairs (v.matchInfoFirst) do if record.guildRed.guildId == roundTwoRivalGuildId or record.guildBlue.guildId == roundTwoRivalGuildId then isWinRound1 = (record.guildRed.guildId == roundTwoRivalGuildId and record.Result == 1) or (record.guildBlue.guildId == roundTwoRivalGuildId and record.Result == 2) end end end if isWinRound1 and isWinRound2 then rankStr = string.format(RankStr, UIUtils.GetLocalizedTxt(Const_IDS[CTL.GuildWar.GroupName[i]]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_No2"])) else rankStr = string.format(RankStr, UIUtils.GetLocalizedTxt(Const_IDS[CTL.GuildWar.GroupName[i]]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_No3"])) end end end break end end end UIUtils.SetLabel(self.txt_MyMark, rankStr or UIUtils.GetLocalizedTxt(Const_IDS["IDS_GuildWar_NotJoinBattle"])) end function UIGuildWarPastScoreList:RefreshInfo() if not self.historyRecords or #self.historyRecords == 0 then return end if self.Loop_Score_Terms.Count == 0 then for _, v in ipairs (self.historyRecords) do self.Loop_Score_Terms:AddData(v, 0) end end self.loop_Score_RewardRank:ClearCells() local records = self.historyRecords[self.selectIssue] self.firstEndIndex = -1 if records and records.groupMatchInfo then local groupRecord = records.groupMatchInfo[self.selectGroup + 1] if groupRecord then if groupRecord.matchInfoFirst and #groupRecord.matchInfoFirst > 0 then for _, v in ipairs (groupRecord.matchInfoFirst) do self.firstEndIndex = self.firstEndIndex + 1 self.loop_Score_RewardRank:AddData(v, 0) end end if groupRecord.matchInfoSecond and #groupRecord.matchInfoSecond > 0 then for i, v in ipairs (groupRecord.matchInfoSecond) do self.loop_Score_RewardRank:AddData(v, 0) end end end end self.Loop_Score_Terms:UpdateIndex(self.selectIssue - 1) self.toggle_TopGroup:SelectIndex(self.selectGroup) UIUtils.SetActive(self.section_Empty, self.loop_Score_RewardRank.Count == 0) end return UIGuildWarPastScoreList