local UICountrySalaryReward = UIViewClass() local MaxCount = DataSheetManager.ConstData:GetDataByID("CountrySpoilApplyLimit").IntValue local CountrySpoilJoinLimit = DataSheetManager.ConstData:GetDataByID("CountrySpoilJoinLimit").IntValue local Imgtopbg = ConstAssetPathConfig.ItemBg local MaxBuyCount = 99 local CountrySalaryReward = "CountrySalaryReward" local function SortFunc(a, b) if a.MyApplyRank > 0 and b.MyApplyRank > 0 then if a.CountryRewardNum == b.CountryRewardNum then local rewardDataA = DataSheetManager.CountryRewards:GetDataByID(a.CountryRewardID) local rewardDataB = DataSheetManager.CountryRewards:GetDataByID(b.CountryRewardID) return rewardDataA.sortID > rewardDataB.sortID else return a.CountryRewardNum > b.CountryRewardNum end elseif b.MyApplyRank > 0 then return false elseif a.MyApplyRank > 0 then return true else if a.CountryRewardNum > 0 then return a.CountryRewardNum > b.CountryRewardNum else if a.CountryRewardNum == b.CountryRewardNum then local rewardDataA = DataSheetManager.CountryRewards:GetDataByID(a.CountryRewardID) local rewardDataB = DataSheetManager.CountryRewards:GetDataByID(b.CountryRewardID) if rewardDataA.RewardType == rewardDataB.RewardType then return rewardDataA.sortID > rewardDataB.sortID else return rewardDataA.RewardType < rewardDataB.RewardType end else return false end end end return false end function UICountrySalaryReward:OnOpened(context) --self:InitRewardList() MDL.Country.CountrySalarySpoilsItemInfoReq() self:RegistSystemEvent(EventID.Country_OnSalarySpoilsApplyInfo, self.OnSalarySpoilsApplyInfo) self:RegistSystemEvent(EventID.Country_OnGetSalarySpoilsItemInfo, self.OnGetSalarySpoilsItemInfo) self:RegistSystemEvent(EventID.Country_OnCountrySalaryBuy, self.OnCountrySalaryBuy) self:RegistSystemEvent(EventID.Country_SalaryGiveOut, self.OnSalaryGiveOut) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshCost) local desc6, timeStr6 = UTL.Time.GetDateDescAndTime({[1] = 1}) if GameAppInfo.IsVietnamPackage() then self.txt.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyIntro, desc6 .. " " .. timeStr6) else self.txt.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyIntro, desc6..timeStr6) end end function UICountrySalaryReward:OnSalaryGiveOut() MDL.Country.CountrySalarySpoilsItemInfoReq() end function UICountrySalaryReward:RefreshCost() self.group_Scroll:RefreshCells(true) end function UICountrySalaryReward:OnGetSalarySpoilsItemInfo(list) local tempList = {} self.myTotalApplyCount = 0 for i,v in ipairs(list) do table.insert(tempList, v) if v.MyApplyRank > 0 then self.myTotalApplyCount = self.myTotalApplyCount + 1 end end table.sort(tempList, SortFunc) self.group_Scroll:ReloadAll(tempList) self.group_Scroll:SelectIndex(0) self.spoilsItemList = tempList end function UICountrySalaryReward:OnButtonClicked(comp) if comp == self.event_Apply then if self.myTotalApplyCount == MaxCount then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Stockroom_ApplyNumLimit) elseif self.itemNotEnough then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS["IDS_DrawCard_Tip_LackItem"], UTL.Item.GetItemDataSpliceByType(self.curCostId).Name)) else self:ApplyItem() end elseif comp == self.btn_Record then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountrySalaryRecord) elseif comp == self.event_CancelApply then local itemName = UTL.Item.GetItemDataSpliceByType(self.curCostId).Name local str = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyCancelConfirm, self.curCostNum, itemName) UTL.MessageBox.ShowOKCancelBox("", str, function() MDL.Country.CountrySalarySpoilsCancelApplyReq(self.curRewardId) end ) elseif comp == self.group_BuyItem.event_Minus then self.curBuyCount = self.curBuyCount - 1 self:RefreshCount(self.curBuyCount) elseif comp == self.group_BuyItem.event_Plus then self.curBuyCount = self.curBuyCount + 1 self:RefreshCount(self.curBuyCount) elseif comp == self.group_BuyItem.event_Max then if self.canBuyMaxCount == 0 then self:RefreshCount(1) elseif self.canBuyMaxCount > MaxBuyCount then self:RefreshCount(MaxBuyCount) else self:RefreshCount(self.canBuyMaxCount) end elseif comp == self.group_BuyItem.event_Buy then if self.itemNotEnough then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS["IDS_DrawCard_Tip_LackItem"], UTL.Item.GetItemDataSpliceByType(self.curCostId).Name)) else MDL.Country.CountrySalaryBuyReq(self.curRewardId, self.curBuyCount) end elseif comp == self.group_BuyItem.event_Count then if not self.keyBoardView then local _, _, availablePurchaseCount = CTL.PayMall.IsLimitedGood(self.curGoodsData) self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, x = 731, y = 110, minNum = 1, maxNum = self.canBuyMaxCount}) end end end function UICountrySalaryReward:ExcuteKeyBoardBack(count) self:RefreshCount(count) end function UICountrySalaryReward:CloseKeyBoardView() self.keyBoardView:CloseView() self.keyBoardView = nil end function UICountrySalaryReward:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.group_Scroll then self.curRewardId = data.CountryRewardID local rewardData = DataSheetManager.CountryRewards:GetDataByID(data.CountryRewardID) if rewardData.RewardType == 2 then self:ShowRankInfo(rewardData, data) elseif rewardData.RewardType == 3 then self:ShowBuyInfo(rewardData, data) else logging.error(LTAG.ERROR, "错误 不应该显示3类型奖励") end end end function UICountrySalaryReward:ShowRankInfo(rewardData, data) MDL.Country.CountrySalarySpoilsApplyInfoReq(rewardData.ID) local guildInfo = MDL.Guild.GetMyGuildInfo() local canApplyTime = CountrySpoilJoinLimit - (UTL.Time.GetServerTimestamp() - guildInfo.joinGuildTime) if canApplyTime <= 0 or guildInfo.joinGuildTime > UTL.Time.GetServerTimestamp() then if data.MyApplyRank > 0 then UIUtils.SetActive(self.event_Apply, false) UIUtils.SetActive(self.event_CancelApply, true) else UIUtils.SetActive(self.event_Apply, true) UIUtils.SetActive(self.event_CancelApply, false) self.event_Apply:SetGray(self.myTotalApplyCount == MaxCount, true) end self.lab_ApplyNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyLimit, self.myTotalApplyCount, MaxCount) else CTL.Country.SetCdTime(self.lab_Time, canApplyTime, Const_IDS.IDS_Stockroom_ApplyTimeLimit) UIUtils.SetActive(self.event_Apply, false) UIUtils.SetActive(self.event_CancelApply, false) self.lab_ApplyNum.text = nil self:StartRepeatFunc(self.RefreshSelect, canApplyTime + 1, 1) end local rewardData = DataSheetManager.CountryRewards:GetDataByID(data.CountryRewardID) UTL.Item.SetItemCell(self.ItemDetails, rewardData.ItemID) local hasCount = CTL.Bag.GetHasCountByItemCfgID(rewardData.CostItem) if hasCount < rewardData.CostNum then self.itemNotEnough = true else self.itemNotEnough = false end self.curCostId = rewardData.CostItem self.curCostNum = rewardData.CostNum UIUtils.SetActive(self.group_BuyItem.gameObject, false) UIUtils.SetActive(self.group_ItemDetails, true) end function UICountrySalaryReward:RefreshSelect() self.group_Scroll:RefreshCells(true) end function UICountrySalaryReward:ShowBuyInfo(rewardData, data) UIUtils.SetActive(self.group_BuyItem.gameObject, true) UIUtils.SetActive(self.group_ItemDetails, false) local guildInfo = MDL.Guild.GetMyGuildInfo() local collection = self.group_BuyItem local canApplyTime = CountrySpoilJoinLimit - (UTL.Time.GetServerTimestamp() - guildInfo.joinGuildTime) if canApplyTime <= 0 or guildInfo.joinGuildTime > UTL.Time.GetServerTimestamp() then self.lab_ApplyNum.text = nil UIUtils.SetActive(collection.group_NumSelect, true) UIUtils.SetActive(collection.event_Buy, true) UIUtils.SetActive(collection.event_Count, true) self.curCostId = rewardData.CostItem self.curCostNum = rewardData.CostNum self.itemMaxCount = MaxBuyCount local itemData = DataSheetManager.ItemData:GetDataByID(rewardData.ItemID) --道具名称 local colorBg = DataSheetManager.QualityColor:GetDataByID(itemData.Color).EquipFragmentComposeBase local colorPrint = DataSheetManager.QualityColor:GetDataByID(itemData.Color).EquipRefineIcon UIUtils.SetImageByAssetBundle(collection.img_Print, string.format(Imgtopbg, colorPrint)) UTL.Item.SetItemCell(collection.ItemDetails, rewardData.ItemID, rewardData.ItemNum) self:RefreshCount(1) else CTL.Country.SetCdTime(self.lab_Time, canApplyTime, Const_IDS.IDS_Stockroom_BuyTimeLimit) UIUtils.SetActive(collection.group_NumSelect, false) UIUtils.SetActive(collection.event_Buy, false) UIUtils.SetActive(collection.event_Count, false) self.lab_ApplyNum.text = nil self:StartRepeatFunc(self.RefreshSelect, canApplyTime + 1, 1) end end function UICountrySalaryReward:RefreshCount(count) self.curBuyCount = count local hasCount = CTL.Bag.GetHasCountByItemCfgID(self.curCostId) self.canBuyMaxCount = math.floor(hasCount / self.curCostNum) if self.canBuyMaxCount > self.itemMaxCount then self.canBuyMaxCount = self.itemMaxCount end if count == 1 and hasCount < self.curCostNum * count then UIUtils.SetLabel(self.group_BuyItem.txt_NumSelect, UTL.Color.FormatRedColor(1)) UIUtils.SetLabel(self.group_BuyItem.txt_NumCost, UTL.Color.FormatRedColor(self.curCostNum)) self.itemNotEnough = true else self.itemNotEnough = false UIUtils.SetLabel(self.group_BuyItem.txt_NumCost,self.curCostNum * count) UIUtils.SetLabel(self.group_BuyItem.txt_NumSelect, self.curBuyCount) end UTL.Item.ItemIconWithoutBg(self.group_BuyItem.DetailMoneyIcon, self.curCostId) UIUtils.SetComponentGray(self.group_BuyItem.event_Minus, false) UIUtils.SetComponentGray(self.group_BuyItem.event_Plus, false) UIUtils.SetComponentGray(self.group_BuyItem.event_Max, false) self.group_BuyItem.event_Plus:SetGray(false) self.group_BuyItem.event_Minus:SetGray(false) self.group_BuyItem.event_Max:SetGray(false) if count <= 1 then self.group_BuyItem.event_Minus:SetGray(true) UIUtils.SetComponentGray(self.group_BuyItem.event_Minus, true) end if count >= self.canBuyMaxCount or count == MaxBuyCount then self.group_BuyItem.event_Plus:SetGray(true) self.group_BuyItem.event_Max:SetGray(true) UIUtils.SetComponentGray(self.group_BuyItem.event_Plus, true) end end function UICountrySalaryReward:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.group_Scroll then local rewardData = DataSheetManager.CountryRewards:GetDataByID(data.CountryRewardID) UTL.Item.SetItemCell(cellTable.Item, rewardData.ItemID, rewardData.ItemNum > 1 and rewardData.ItemNum or nil) cellTable.txt_Cost.text = data.CountryRewardNum local itemData = DataSheetManager.ItemData:GetDataByID(rewardData.ItemID) --道具名称 local colorText = UTL.Color.FormatQualityText(UTL.Item.GetItemDataSpliceByType(rewardData.ItemID).Name, itemData.Color) UIUtils.SetLabel(cellTable.txt_ItemName, colorText) if rewardData.RewardType == 3 then cellTable.state_ItemType:SetState(1) cellTable.Num1.text = nil cellTable.RankNum.text = nil cellTable.lab_Num.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_GoodsNum, UIUtils.GetLocalizedTxt(Const_IDS.IDS_Stockroom_Enough)) else cellTable.lab_Num.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_GoodsNum, data.CountryRewardNum) if data.MyApplyRank > 0 then cellTable.RankNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyRank, data.MyApplyRank) cellTable.Num1.text = nil else cellTable.Num1.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ListNum, data.ApplyRankNum) cellTable.RankNum.text = nil end cellTable.state_ItemType:SetState(0) end UTL.Item.MoneyIcon(cellTable.icon_Cost, rewardData.CostItem) local hasCount = CTL.Bag.GetHasCountByItemCfgID(rewardData.CostItem) if hasCount < rewardData.CostNum then cellTable.txt_Cost.text = UTL.Color.FormatRedColor(rewardData.CostNum) self.itemNotEnough = true else cellTable.txt_Cost.text = rewardData.CostNum self.itemNotEnough = false end UIUtils.SetActive(cellTable.img_Purchasable, false) elseif scrollRect == self.group_players then CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHead, data.PortraitId) cellTable.lab_Name.text = data.Name cellTable.txt_CE.text = data.Power cellTable.Num.text = index + 1 end end function UICountrySalaryReward:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.group_Scroll and target == cellTable.Item.event_Click then local rewardData = DataSheetManager.CountryRewards:GetDataByID(data.CountryRewardID) UTL.ItemTips.ShowCommonTipsById(rewardData.ItemID) end end function UICountrySalaryReward:OnSalarySpoilsApplyInfo(spoilsApplyItemList, isApply, count) self.group_players:ReloadAll(spoilsApplyItemList) UIUtils.SetActive(self.group_Empty, #spoilsApplyItemList == 0) if isApply == true then UIUtils.SetActive(self.event_Apply, false) UIUtils.SetActive(self.event_CancelApply, true) self.myTotalApplyCount = self.myTotalApplyCount + 1 for i, v in ipairs(self.spoilsItemList) do if v.CountryRewardID == self.curRewardId then v.MyApplyRank = count v.ApplyRankNum = #spoilsApplyItemList self.group_Scroll:UpdateIndex(i - 1, v) break end end self.lab_ApplyNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyLimit, self.myTotalApplyCount, MaxCount) elseif isApply == false then UIUtils.SetActive(self.event_Apply, true) UIUtils.SetActive(self.event_CancelApply, false) self.myTotalApplyCount = self.myTotalApplyCount - 1 for i, v in ipairs(self.spoilsItemList) do if v.CountryRewardID == self.curRewardId then v.MyApplyRank = 0 v.ApplyRankNum = #spoilsApplyItemList self.group_Scroll:UpdateIndex(i - 1, v) self.group_Scroll:SelectIndex(i - 1) break end end self.lab_ApplyNum.text = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyLimit, self.myTotalApplyCount, MaxCount) end self.event_Apply:SetGray(self.myTotalApplyCount == MaxCount, true) end function UICountrySalaryReward:OnCountrySalaryBuy() self:RefreshCount(1) end function UICountrySalaryReward:ApplyItem() local timeValue = PersistentData.PlayerData:Get(CountrySalaryReward, 0) if timeValue > 0 and UTL.Time.IsTimestampCrossDay(timeValue) then PersistentData.PlayerData:Remove(CountrySalaryReward) timeValue = PersistentData.PlayerData:Get(CountrySalaryReward, 0) end if timeValue <= 0 then local itemName = UTL.Item.GetItemDataSpliceByType(self.curCostId).Name local str = string.FormatByIdsId(Const_IDS.IDS_Stockroom_ApplyConfirm, itemName, self.curCostNum) UTL.MessageBox.ShowOKCancelToggleBox(nil, str, UIUtils.GetLocalizedTxt(Const_IDS.IDS_WarZoneAuction_27), -- 确认按钮回调 function() MDL.Country.CountrySalarySpoilsApplyReq(self.curRewardId) end, -- 勾选框回调 function(isOn) if isOn then PersistentData.PlayerData:Set(CountrySalaryReward, UTL.Time.GetServerTimestamp(), true) else PersistentData.PlayerData:Remove(CountrySalaryReward) end end) else MDL.Country.CountrySalarySpoilsApplyReq(self.curRewardId) end end return UICountrySalaryReward