local UIChangAnSiegeReward = UIViewClass() local TabIds = { Const_IDS.IDS_SiegeCity_Reward_VictoryOrFailure_1, Const_IDS.IDS_SiegeCity_Reward_ContinuousOccupy_1, Const_IDS.IDS_SiegeCity_Reward_Personal_1, Const_IDS.IDS_SiegeCity_Reward_PersonalRank_1, Const_IDS.IDS_SiegeCity_CommandReward, } function UIChangAnSiegeReward:OnOpened(context) self.mainPanelInfo = context self.State_Tab:SetState(0) for _,v in ipairs(TabIds) do self.loop_CASLeftRewardTab:AddData(v, 0) end self.loop_CASLeftRewardTab:SelectIndex(0) self:RefreshVictoryOrFail() end function UIChangAnSiegeReward:RefreshVictoryOrFail() local victoryCountryRewardCfgId = DataSheetManager.ConstData:GetDataByID("SiegeCityVictoryCountryReward").IntValue local victoryCountryRewardList = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(victoryCountryRewardCfgId).Item_Table for _,v in ipairs(victoryCountryRewardList) do self.group_Tab1.Loop_CASVictory:AddData(v, 0) end local victoryRewardCfgId = DataSheetManager.ConstData:GetDataByID("SiegeCityVictoryReward").IntValue local victoryRewardList = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(victoryRewardCfgId).Item_Table for _,v in ipairs(victoryRewardList) do self.group_Tab1.Loop_CASVictory:AddData(v, 0) end local failCountryCfgId = DataSheetManager.ConstData:GetDataByID("SiegeCityfailCountryReward").IntValue local failCountryRewardList = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(failCountryCfgId).Item_Table for _,v in ipairs(failCountryRewardList) do self.group_Tab1.Loop_CASFail:AddData(v, 0) end local failCfgId = DataSheetManager.ConstData:GetDataByID("SiegeCityfailReward").IntValue local failRewardList = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(failCfgId).Item_Table for _,v in ipairs(failRewardList) do self.group_Tab1.Loop_CASFail:AddData(v, 0) end end function UIChangAnSiegeReward:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() end end function UIChangAnSiegeReward:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_CASLeftRewardTab then UIUtils.SetLabelText(cellTable.txt_UnselectedTabName, data) UIUtils.SetLabelText(cellTable.txt_SelectedTabName, data) elseif scrollRect == self.group_Tab1.Loop_CASVictory or scrollRect == self.group_Tab1.Loop_CASFail then UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) elseif scrollRect == self.group_Tab2.Loop_CASTab2 then UIUtils.SetActive(cellTable.img_Issued, data.SiegeCityOccupyMuchTimes <= self.mainPanelInfo.ContinuousOccupy) UIUtils.SetLabel(cellTable.txt_ContinuousOccupation, string.FormatByIdsId(Const_IDS.IDS_SiegeCity_Reward_ContinuousOccupy_2, data.SiegeCityOccupyMuchTimes)) local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityOccupyMuchReward).Item_Table self:SetCellRewards(rewardData, cellTable) elseif scrollRect == self.group_Tab3.Loop_CASTab3 then local mySinglePoint = self.mainPanelInfo.contribution if mySinglePoint >= data.PointSingleValueBegin and mySinglePoint <= data.PointSingleValueEnd then self.singleContributionIndex = index UIUtils.SetActive(cellTable.img_MyGear, true) UIUtils.SetLabelText(cellTable.txt_MyGear, Const_IDS.IDS_SiegeCity_Reward_Personal_3) else UIUtils.SetActive(cellTable.img_MyGear, false) end local mySinglePointStr if mySinglePoint >= data.PointSingleValueBegin then mySinglePointStr = UTL.Color.FormatGreenColor(mySinglePoint) else mySinglePointStr = UTL.Color.FormatRedColor(mySinglePoint) end local str = UIUtils.GetLocalizedTxt(Const_IDS.IDS_SiegeCity_Reward_Personal_2).. mySinglePointStr .. "/" ..data.PointSingleValueBegin UIUtils.SetLabel(cellTable.txt_PersonalContribution, str) local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityPointSingleReward).Item_Table self:SetCellRewards(rewardData, cellTable) elseif scrollRect == self.group_Tab4.Loop_CASTab4 then local mySingleRank = self.mainPanelInfo.rank if mySingleRank >= data.RankBegin and mySingleRank <= data.RankEnd then self.singleRankIndex = index UIUtils.SetActive(cellTable.img_MyRank, true) UIUtils.SetLabelText(cellTable.txt_MyRank, Const_IDS.IDS_SiegeCity_Reward_PersonalRank_4) else UIUtils.SetActive(cellTable.img_MyRank, false) end local myRankStr if data.RankBegin == data.RankEnd then myRankStr = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_Reward_PersonalRank_2, data.RankBegin) else myRankStr = string.FormatByIdsId(Const_IDS.IDS_SiegeCity_Reward_PersonalRank_2, data.RankBegin .. "~".. data.RankEnd) end UIUtils.SetLabel(cellTable.txt_ContinuousOccupation, myRankStr) local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityPointRankReward).Item_Table self:SetCellRewards(rewardData, cellTable) elseif scrollRect == self.group_Tab5.Loop_CASTab then self:InitCommandCell(index, cellTable, data) end end function UIChangAnSiegeReward:InitCommandCell(index, cellTable, data) local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityCommanderReward).Item_Table self:SetCellRewards(rewardData, cellTable) UIUtils.SetLabel(cellTable.txt_ContinuousOccupation, string.FormatByIdsId(Const_IDS[data.TaskDes], data.TaskParam)) end function UIChangAnSiegeReward:SetCellRewards(rewardData, cellTable) for i, reward in ipairs(rewardData) do local item = cellTable.Content[i] if not item then item = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, self.cell_CASReward.gameObject) end UTL.Item.SetItemCell(item.item, reward.ItemID, reward.ItemNum) UIUtils.SetActive(item.gameObject, true) end for i = #rewardData + 1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false) end end function UIChangAnSiegeReward:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loop_CASLeftRewardTab then self.State_Tab:SetState(index) if index == 1 then self:RefreshContinuousOccupy() elseif index == 2 then self:RefreshPersonal() elseif index == 3 then self:RefreshPersonalRank() elseif index == 4 then self:RefreshCommandReward() end end end function UIChangAnSiegeReward:RefreshContinuousOccupy() local maxOccupyTimes = self.mainPanelInfo.maxContinuousOccupy UIUtils.SetLabel(self.group_Tab2.txt_SeasonOccupy, string.FormatByIdsId(Const_IDS.IDS_SiegeCity_Reward_ContinuousOccupy_3, maxOccupyTimes)) local curOccupyTimes = self.mainPanelInfo.ContinuousOccupy UIUtils.SetLabel(self.group_Tab2.txt_CurrentOccupation, string.FormatByIdsId(Const_IDS.IDS_SiegeCity_Reward_ContinuousOccupy_4, curOccupyTimes)) self.group_Tab2.Loop_CASTab2:ClearCells() for i,v in DataSheetManager.SiegeCityOccupyMuchReward:GetEnumerator() do self.group_Tab2.Loop_CASTab2:AddData(v, 0) end end function UIChangAnSiegeReward:RefreshPersonal() self.group_Tab3.Loop_CASTab3:ClearCells() for i,v in DataSheetManager.SiegeCityPointSingleReward:GetEnumerator() do self.group_Tab3.Loop_CASTab3:AddData(v, 0) end self.group_Tab3.Loop_CASTab3:MoveIndex(self.singleContributionIndex or 0) end function UIChangAnSiegeReward:RefreshPersonalRank() self.group_Tab4.Loop_CASTab4:ClearCells() for i,v in DataSheetManager.SiegeCityPointRankReward:GetEnumerator() do self.group_Tab4.Loop_CASTab4:AddData(v, 0) end self.group_Tab4.Loop_CASTab4:MoveIndex(self.singleRankIndex or 0) end function UIChangAnSiegeReward:RefreshCommandReward() self.group_Tab5.Loop_CASTab:ClearCells() for i,v in DataSheetManager.SiegeCityCommanderReward:GetEnumerator() do self.group_Tab5.Loop_CASTab:AddData(v, 0) end end function UIChangAnSiegeReward:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.group_Tab1.Loop_CASVictory or scrollRect == self.group_Tab1.Loop_CASFail then UTL.ItemTips.ShowCommonTipsById(data.ItemID) elseif scrollRect == self.group_Tab2.Loop_CASTab2 then local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityOccupyMuchReward).Item_Table self:OnClickRewardItem(target, cellTable, rewardData) elseif scrollRect == self.group_Tab3.Loop_CASTab3 then local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityPointSingleReward).Item_Table self:OnClickRewardItem(target, cellTable, rewardData) elseif scrollRect == self.group_Tab4.Loop_CASTab4 then local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityPointRankReward).Item_Table self:OnClickRewardItem(target, cellTable, rewardData) elseif scrollRect == self.group_Tab5.Loop_CASTab then local rewardData = DataSheetManager.SiegeCityRewardRepeat:GetDataByID(data.SiegeCityCommanderReward).Item_Table self:OnClickRewardItem(target, cellTable, rewardData) end end function UIChangAnSiegeReward:OnClickRewardItem(target, cellTable, rewardData) for i = 1, #cellTable.Content do if cellTable.Content[i].item.event_Click == target then UTL.ItemTips.ShowCommonTipsById(rewardData[i].ItemID) end end end return UIChangAnSiegeReward