local UICountryPopupSalary = UIViewClass() local RewardIds = DataSheetManager.ConstData:GetDataByID("CountryWarSpoilReward").IntListValue local RewardPoolIDS = {"RewardPoolID1", "RewardPoolID2", "RewardPoolID3", "RewardPoolID4"} function UICountryPopupSalary:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Country_WarSpoilPreview) self.clickItemDict = {} self.curBattleIndex = 1 self.UICommonPopUp.loop_Tab:AddData("IDS_Country_EpicWarSpoil", 0) self.UICommonPopUp.loop_Tab:AddData("IDS_Country_NormalWarSpoil", 0) self.UICommonPopUp.loop_Tab:SelectIndex(0) end function UICountryPopupSalary:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UICountryPopupSalary:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UICountryPopupSalary:OnCellInit(scrollRect, index, cellTable, data) if self.scroll_Reward_1 == scrollRect then local excelData = DataSheetManager.CountryWarSpoil:GetDataByID(data) self:SetReward(cellTable, excelData.RewardPoolID1, excelData.RewardPoolID2, 1) cellTable.state_Rank:SetState(index) cellTable.state_Bg:SetState(index % 2) elseif scrollRect == self.scroll_Reward_2 then self:InitBattleRewardCell(cellTable, data) cellTable.state_Rank:SetState(index) cellTable.state_Bg:SetState(index % 2) else UIUtils.SetLabelText(cellTable.txt_Name_Nomal, Const_IDS[data]) UIUtils.SetLabelText(cellTable.txt_Name_Selected, Const_IDS[data]) UIUtils.SetActive(cellTable.img_Arrow, false) UIUtils.SetActive(cellTable.img_ArrowS, false) end end function UICountryPopupSalary:OnCellClicked(scrollRect, index, cellTable, target, data) if self.clickItemDict[target] then UTL.ItemTips.ShowCommonTipsById(self.clickItemDict[target]) elseif scrollRect == self.scroll_Reward_2 then if target == cellTable.btn_Click then UTL.ItemTips.ShowCommonTipsById(data) end end end function UICountryPopupSalary:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.UICommonPopUp.loop_Tab then if index == 0 then UIUtils.SetActive(self.group_1, true) UIUtils.SetActive(self.group_2, false) self:ShowGuildReward() elseif index == 1 then UIUtils.SetActive(self.group_1, false) UIUtils.SetActive(self.group_2, true) self:ShowBattleReward() end end end function UICountryPopupSalary:SetReward(cellTable, reward1, reward2, collectionIndex) local rewardPool1 = DataSheetManager.CountrySeasonGuildRewardPool:GetDataByID(reward1) local rewardPool2 = DataSheetManager.CountrySeasonGuildRewardPool:GetDataByID(reward2) self:SetSingleReward(cellTable, cellTable.itemGroup[1], rewardPool1.AssignRward_Table) self:SetSingleReward(cellTable, cellTable.itemGroup[2], rewardPool2.AssignRward_Table) end function UICountryPopupSalary:SetSingleReward(cellTable, collection, itemTable) local sortItems = {} for i, v in ipairs(itemTable) do local rewardData = DataSheetManager.CountryRewards:GetDataByID(v.AssignRwardID) for _, item in ipairs(sortItems) do if item.id == rewardData.ItemID then item.count = item.count + v.AssignRwardPortion break end end table.insert(sortItems, {id = rewardData.ItemID, count = v.AssignRwardPortion, ItemImage = rewardData.ItemImage}) end for i, item in ipairs(sortItems) do local obj = collection[i] if obj == nil then obj = self:InstantiateCellCollection(cellTable.cell.gameObject, collection, self.icon_Template.gameObject) UIUtils.SetActive(obj.gameObject, true) end self.clickItemDict[obj.btn] = item.id UTL.Item.SetItemCell(obj.item, item.id, item.count) if not string.isNilOrEmpty(item.ItemImage) then UIUtils.SetImageByAssetBundle(obj.img_trade, item.ItemImage) UIUtils.SetActive(obj.img_tradeBg, true) else UIUtils.SetActive(obj.img_tradeBg, false) end end for i = #sortItems + 1, #collection do local obj = cellTable.group_Item[i] UIUtils.SetActive(obj.gameObject, false) end end function UICountryPopupSalary:OnValueChanged(comp, value) if comp == self.toggle_Group then self.curBattleIndex = value + 1 self.scroll_Reward_2:RefreshCells(false) end end function UICountryPopupSalary:ShowGuildReward() if self.scroll_Reward_1.Count == 0 then for i = 1, 4 do self.scroll_Reward_1:AddData(i, 0) end end end local function SortItem(a, b) local itemDataA = DataSheetManager.ItemData:GetDataByID(a) local itemDataB = DataSheetManager.ItemData:GetDataByID(b) if itemDataA.Quality == itemDataB.Quality then return a > b else return itemDataA.Quality >itemDataB.Quality end end function UICountryPopupSalary:ShowBattleReward1() if self.scroll_Reward_2.Count == 0 then local itemIds = {} for i,v in ipairs(RewardIds) do local reward = DataSheetManager.CountrySeasonGuildRewardPool:GetDataByID(v) for _, item in ipairs(reward.QueueRward_Table) do local id = DataSheetManager.CountryRewards:GetDataByID(item.QueueRwardID).ItemID if not table.containValue(itemIds, id) then table.insert(itemIds, id) end end end table.sort(itemIds, SortItem) for i,v in ipairs(itemIds) do self.scroll_Reward_2:AddData(v, 0) end end end function UICountryPopupSalary:ShowBattleReward(poolIndex) if self.scroll_Reward_2.Count == 0 then self.curBattleIndex = 1 for _, data in DataSheetManager.CountryWarSpoil:GetEnumerator() do self.scroll_Reward_2:AddData(data, 0) end end end function UICountryPopupSalary:InitBattleRewardCell(cellTable, data) local rewardId = data[RewardPoolIDS[self.curBattleIndex]] local rewardPool1 = DataSheetManager.CountrySeasonGuildRewardPool:GetDataByID(rewardId) local sortItems = {} for i, v in ipairs(rewardPool1.QueueRward_Table) do local rewardData = DataSheetManager.CountryRewards:GetDataByID(v.QueueRwardID) for _, item in ipairs(sortItems) do if item.id == rewardData.ItemID then item.count = item.count + v.QueueRwardPortion break end end table.insert(sortItems, {id = rewardData.ItemID, count = v.QueueRwardPortion , path = rewardData.ItemImage}) end for i, item in ipairs(sortItems) do local obj = cellTable.group_Item[i] if obj == nil then obj = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.group_Item, self.itemTemplate.gameObject) UIUtils.SetActive(obj.gameObject, true) end UIUtils.SetActive(obj.gameObject, true) self.clickItemDict[obj.item.event_Click] = item.id UTL.Item.SetItemCell(obj.item, item.id, item.count) end for i = #sortItems + 1, #cellTable.group_Item do local obj = cellTable.group_Item[i] UIUtils.SetActive(obj.gameObject, false) end end return UICountryPopupSalary