local UICountryPopupContribute = UIViewClass() local MaxCount = DataSheetManager.ConstData:GetDataByID("CountryDonateResourceDailyLimit").IntValue local MaxRankRecord = DataSheetManager.ConstData:GetDataByID("CountryDonateRankRecord").IntValue local InputMaxCount = 99 function UICountryPopupContribute:OnOpened(context) self:RegistSystemEvent(EventID.UI_Country_DonateRankRefresh, self.OnUpdateListInfo) self:RegistSystemEvent(EventID.UI_Country_DonateEvent, self.DonateEvent) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshCost) self:RegistSystemEvent(EventID.Country_OnGetDonatePanelInfo, self.OnUpdateListInfo) self:RegistSystemEvent(EventID.Country_OnCountryDonate, self.OnCountryDonate) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshCost) self.curShowTDValue = true self.enoughCout = true self.todayDonateNum = 0 UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Country_CountryDonate) self:InitDonateData() self.curShowCount = 1 MDL.Country.CountryGetDonatePanelInfoReq() end function UICountryPopupContribute:OnCountryDonate(msg) self.myTodayRank = msg.myTodayRank self.myTotalRank = msg.myTotalRank self.todayDonateNum = msg.TodayDonateNum self.maxCount = self.canDonateDataMax - self.myDonateCount self:ShowRank() self:SetTodayDonateNum() end function UICountryPopupContribute:OnUpdateListInfo(msg) self.curShowCount = 1 self.todayRankList = msg.TodayRankInfo self.totalRankList = msg.TotalRankInfo self.myTodayRank = msg.myTodayRank self.myTotalRank = msg.myTotalRank self.todayDonateNum = msg.TodayDonateNum self.myDonateCount = msg.TodayDonateTimes or 0 self.maxCount = self:GetShowMaxCount() self:ShowRank() self:SetTodayDonateNum() self:RefreshBtnState() end function UICountryPopupContribute:GetShowMaxCount() local maxCostCount = self:GetMaxCostCount(self.myDonateCount) local canCount = self.canDonateDataMax - self.myDonateCount if canCount > maxCostCount then return maxCostCount > 0 and maxCostCount or 1 end return maxCostCount end function UICountryPopupContribute:InitDonateData() self.canDonateDataMax = 0 local data = nil for i, v in DataSheetManager.CountryDonate:GetEnumerator() do self.canDonateDataMax = v.MaxNum data = v end self.maxCount = self.canDonateDataMax UTL.Item.ItemIconWithoutBg(self.group_CostNum.icon_Get, data.CostType) UTL.Item.ItemIconWithoutBg(self.group_GetNum1.icon_Get, data.Reward_Table[1].RewardType) UTL.Item.ItemIconWithoutBg(self.group_GetNum2.icon_Get, data.Reward_Table[2].RewardType) UTL.Item.ItemIconWithoutBg(self.icon_CountryMoney, data.Reward_Table[1].RewardType) self.group_CostNum.txt_Tpye.text = UTL.Item.GetItemName(data.CostType) self.group_GetNum1.txt_Tpye.text = UTL.Item.GetItemName(data.Reward_Table[1].RewardType) self.group_GetNum2.txt_Tpye.text = UTL.Item.GetItemName(data.Reward_Table[2].RewardType) self.donateId = data.CostType end function UICountryPopupContribute:GetMaxCostCount(startCount) local donateId = 0 for i, v in DataSheetManager.CountryDonate:GetEnumerator() do donateId = v.CostType break end local hasCount = CTL.Bag.GetHasCountByItemCfgID(donateId) local costCount = 0 for i, v in DataSheetManager.CountryDonate:GetEnumerator() do for count = v.MinNum, v.MaxNum do if startCount < count then costCount = costCount + v.CostValue if costCount > hasCount then return count - 1 - startCount end end end end return self.canDonateDataMax - startCount end function UICountryPopupContribute:GetDonateRewardByCount(count) local rewardCount1 = 0 local rewardCount2 = 0 local costCount = 0 for i, v in DataSheetManager.CountryDonate:GetEnumerator() do if v.MaxNum > count then local count = count + 1 - v.MinNum rewardCount1 = rewardCount1 + v.Reward_Table[1].RewardValue * count rewardCount2 = rewardCount2 + v.Reward_Table[2].RewardValue * count costCount = costCount + v.CostValue * count break end local count = v.MaxNum - v.MinNum + 1 rewardCount1 = rewardCount1 + v.Reward_Table[1].RewardValue * count rewardCount2 = rewardCount2 + v.Reward_Table[2].RewardValue * count costCount = costCount + v.CostValue * count end return rewardCount1, rewardCount2, costCount end function UICountryPopupContribute:SetDonateReward() local rewardCount1, rewardCount2, costCount = self:GetDonateRewardByCount(self.curShowCount + self.myDonateCount) local oldrewardCount1, oldrewardCount2, oldcostCount = self:GetDonateRewardByCount(self.myDonateCount) local realCount = rewardCount1 - oldrewardCount1 self.enoughCurrency = false if realCount + self.todayDonateNum > MaxCount then realCount = MaxCount - self.todayDonateNum self.enoughCurrency = true end self.group_GetNum1.txt_CostNum.text = realCount self.group_GetNum2.txt_CostNum.text = rewardCount2 - oldrewardCount2 self.group_CostNum.txt_CostNum.text = costCount - oldcostCount self.curGetCountryCurrency = realCount local hasCount = CTL.Bag.GetHasCountByItemCfgID(self.donateId) if hasCount < costCount - oldcostCount then self.itemNotEnough = true self.group_CostNum.txt_CostNum.text = UTL.Color.FormatRedColor(costCount - oldcostCount) else self.itemNotEnough = false self.group_CostNum.txt_CostNum.text = costCount - oldcostCount end end function UICountryPopupContribute:RefreshCost() self.maxCount = self:GetShowMaxCount() self:SetTodayDonateNum() self:RefreshBtnState() end function UICountryPopupContribute:ShowRank() local list = self:GetSortList() self.loopScroll_Contribute:ClearCells() if #list == 0 then self.group_Empty01.gameObject:SetActive(true) self.group_Own.gameObject:SetActive(true) self:SetSelfInfo(nil) else local selfData = nil self.group_Empty01.gameObject:SetActive(false) self.group_Own.gameObject:SetActive(true) local length = DataSheetManager.ConstData:GetDataByID("GuildDonateRankShow").IntValue for i, v in ipairs(list) do if length >= i then if v.donateNum > 0 then self.loopScroll_Contribute:AddData(v, 0) end end end if self.loopScroll_Contribute.Count == 0 then self.group_Empty01.gameObject:SetActive(true) end self:SetSelfInfo() end end function UICountryPopupContribute:GetSortList() local list = nil if self.curShowTDValue then list = self.todayRankList table.sort(list, function(a, b) return a.index < b.index end) else list = self.totalRankList table.sort(list, function(a, b) return a.index < b.index end) end return list end function UICountryPopupContribute:SetSelfInfo(data) local data = nil if self.curShowTDValue then data = self.myTodayRank else data = self.myTotalRank end if data == nil or data.donateNum == 0 then UIUtils.SetActive(self.txt_Name, false) self.sprite_Rank.gameObject:SetActive(false) self.txt_Score.text = nil UIUtils.SetActive(self.group_Empty02, true) return end UIUtils.SetActive(self.group_Empty02, false) UIUtils.SetActive(self.txt_Name, true) if data.index <= 3 then UTL.Item.SetAtlasSprite(self.sprite_Rank, "UI_Battle", "bd_zs_0" .. data.index) self.sprite_Rank.gameObject:SetActive(true) self.txt_Rank.text = nil else self.sprite_Rank.gameObject:SetActive(false) self.txt_Rank.text = data.index end self.txt_Name.text = BattleDataGetter.GetPlayerName() self.txt_Score.text = data.donateNum end function UICountryPopupContribute:OnValueChanged(comp, index) if comp == self.toggle_TopGroup then if index == 0 then self.curShowTDValue = true self:ShowRank() elseif index == 1 then self.curShowTDValue = false self:ShowRank() end end end function UICountryPopupContribute:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UICountryPopupContribute:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.event_Plus then self.curShowCount = self.curShowCount + 1 self.txt_NumSelect.text = self.curShowCount self:RefreshBtnState() elseif comp == self.event_Minus then self.curShowCount = self.curShowCount - 1 self:RefreshBtnState() elseif comp == self.event_Max then if self.maxCount == 0 then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Country_DonateDailyLimitTip) else self.curShowCount = self.maxCount > InputMaxCount and InputMaxCount or self.maxCount self:RefreshBtnState() end elseif comp == self.bg_NumSelect then if not self.keyBoardView then local inputCount = self.maxCount > InputMaxCount and InputMaxCount or self.maxCount self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), { parentView = self, scale = 0.8, x = 384, y = 148, minNum = 1, maxNum = inputCount }) end elseif comp == self.btn_Contribute then if self.itemNotEnough then local consumeItemData = DataSheetManager.ItemData:GetDataByID(self.donateId) CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Guild_CommonFail1, UIUtils.GetLocalizedTxt(Const_IDS[consumeItemData.Name])) return end if self.enoughCurrency then local str = string.FormatByIdsId(Const_IDS.IDS_Country_DonateDailyLimitConfirm, self.group_GetNum2.txt_Tpye.text) UTL.MessageBox.ShowOKCancelBox("", str, function() MDL.Country.CountryDonateReq(self.donateId, self.curShowCount) end ) else MDL.Country.CountryDonateReq(self.donateId, self.curShowCount) end end end function UICountryPopupContribute:ExcuteKeyBoardBack(count, paramData) self.curShowCount = count self:RefreshBtnState() end function UICountryPopupContribute:CloseKeyBoardView() self.keyBoardView:CloseView() self.keyBoardView = nil end function UICountryPopupContribute:RefreshBtnState() self.txt_NumSelect.text = self.curShowCount local inputCount = self.maxCount > InputMaxCount and InputMaxCount or self.maxCount self.event_Plus:SetGray(self.curShowCount >= inputCount, false); self.event_Max:SetGray(self.curShowCount >= inputCount, false); self.event_Minus:SetGray(self.curShowCount <= 1, false); self:SetDonateReward() end function UICountryPopupContribute:OnCellInit(scrollRect, index, cellTable, data) local state = index % 2 UIUtils.SetActive(cellTable.sprite_Bg1.gameObject, state == 0) UIUtils.SetActive(cellTable.sprite_Bg2.gameObject, state == 1) if index <= 2 then UTL.Item.SetAtlasSprite(cellTable.sprite_Rank, "UI_Battle", "bd_zs_0" .. index + 1) UIUtils.SetActive(cellTable.sprite_Rank.gameObject, true) cellTable.txt_Rank.text = nil elseif index <= MaxRankRecord then UIUtils.SetActive(cellTable.sprite_Rank.gameObject, false) cellTable.txt_Rank.text = index + 1 else cellTable.txt_Rank.text = "--" end cellTable.txt_Name.text = data.playerName if self.curShowTDValue then cellTable.txt_Score.text = data.donateNum else cellTable.txt_Score.text = data.donateNum end end function UICountryPopupContribute:SetTodayDonateNum() if MaxCount == self.todayDonateNum then self.txt_LimitNum.text = UTL.Color.FormatRedColor(self.todayDonateNum) .. "/" .. MaxCount else self.txt_LimitNum.text = self.todayDonateNum .. "/" .. MaxCount end local maxPlayerCount = DataSheetManager.ConstData:GetDataByID("CountryDonateDailyNum").IntValue if maxPlayerCount <= self.myDonateCount then self.max_State:SetState(1) self.bg_NumSelect.interactable = false self.curShowCount = 0 self:RefreshBtnState() else self.max_State:SetState(0) end end return UICountryPopupContribute