--- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by admin. --- DateTime: 2024/11/5 13:41 ---@class UIDailyPackRechargeInfo UIDailyPackRechargeInfo = class() local this = UIDailyPackRechargeInfo function this:ctor() end function this:Reset() end function this:Init() self:InitData() self:RegistMessages() self.DailyPackAllData = SL:GetConfigTable("cfg_DailyGiftPack") self.DailyPackData = {} self.DailyPackAllGiftData={} end function this:InitData() end function this:RegistMessages() SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RECHARGE_ACTION, self.RES_RECHARGE_ACTION, self) SL:RegisterLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_COUNT_CHANGE, this.LUA_EVENT_DAILYPACK_RECHARGE_COUNT_CHANGE, self) end --服务器发送礼包组消息后刷新礼包组的数据 function this:RES_RECHARGE_ACTION(_, message) if tonumber(message.type)~=4 then --类型4 return end self.DailyPackData = {} self.DailyPackAllGiftData = {} if message then local itemInfo = {} local itemCountInfo = {} local keynum = 0 local buycount = 0 --剩余次数 local totalcount = 0 for k , v in ipairs(self.DailyPackAllData) do if v.Packagetype == tonumber(message.data.group) and this:IsOpenJudge(v.conditionid) then itemInfo = {} itemInfo.id = v.id itemInfo.Price = v.Price itemInfo.Packagetype = v.Packagetype itemInfo.conditionid = v.conditionid itemInfo.Limited =tonumber(v.Limited) itemInfo.Rewards = v.Rewards itemInfo.Optionalreward = v.Optionalreward itemInfo.rebate = v.rebate itemInfo.purchase = v.purchase itemInfo.buyIndex = 0 itemInfo.canBuy = true itemInfo.RechargeId = 0 itemInfo.Countkey = 0 buycount = 0 totalcount = 0 for key,value in pairs(message.data.countInfo) do keynum = tonumber(key) itemCountInfo = SL:GetConfig('cfg_recharge',keynum) if itemCountInfo.parameter == v.id then itemInfo.RechargeId = keynum itemInfo.Countkey = itemCountInfo.Countkey itemInfo.buyIndex = value buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(itemCountInfo.Countkey) if buycount < 1 then itemInfo.canBuy = false end break end end if v.purchase ~= 0 then table.insert(self.DailyPackData,itemInfo) else table.insert(self.DailyPackAllGiftData,itemInfo) end end end end local isDailyPackRedPoint = false for k,v in pairs(self.DailyPackData) do if v.Price== 0 and v.canBuy then isDailyPackRedPoint = true end end InfoManager.mainRechargeInfo:RefreshMainRechargeRedPoint("tog_DailyPack",isDailyPackRedPoint) SL:onLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_CHANGE) end --Count刷新 function this:LUA_EVENT_DAILYPACK_RECHARGE_COUNT_CHANGE() local isDailyPackRedPoint = false local buycount = 0 --剩余次数 local totalcount = 0 for k,v in pairs(self.DailyPackData) do buycount = 0 totalcount = 0 v.canBuy = true buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey) if buycount < 1 then v.canBuy = false end if v.Price== 0 and v.canBuy then isDailyPackRedPoint = true end end InfoManager.mainRechargeInfo:RefreshMainRechargeRedPoint("tog_DailyPack",isDailyPackRedPoint) SL:onLUAEvent(LUA_EVENT_DAILYPACK_RECHARGE_CHANGE) end function this:IsOpenJudge(condition) local isShow = condition == "" or ConditionManager.Check4D(condition) ---if else 可特殊处理页签显示隐藏 return isShow end --是否能够一键购买 function this:IsCanBuyAllGift() if table.isNullOrEmpty(self.DailyPackData) then return false end local buycount = 0 --剩余次数 local totalcount = 0 for k,v in ipairs(self.DailyPackData) do buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey) if v.Price~= 0 and ((not v.canBuy) or buycount ~=totalcount) then return false end end return true end --获取一键购买原价 function this:GetAllBuyOriginPrice() local price = 0 local buycount = 0 --剩余次数 local totalcount = 0 for k,v in ipairs(self.DailyPackData) do totalcount = 0 buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey) price = price +(v.Price * totalcount) end return price end --获取giftid自选道具 function this:GetSelectRewardInfo(giftid) local itemInfo = {} local tab = {} local index = 0 for k,v in ipairs(self.DailyPackData) do if v.id == giftid and (not table.isNullOrEmpty(v.Optionalreward))then for key,value in ipairs(v.Optionalreward) do index = index +1 tab={ rewardId = value[1], rewarcount = value[2], rewardIndex = index } table.insert(itemInfo,tab) end end end return itemInfo end --获取giftid上index自选道具 function this:GetSelectRewardItem(giftid,Index) local itemInfo = {} local tab = {} local index = 0 for k,v in ipairs(self.DailyPackData) do if v.id == giftid and (not table.isNullOrEmpty(v.Optionalreward))then for key,value in ipairs(v.Optionalreward) do index = index +1 if index == Index then tab={ rewardId = value[1], rewarcount = value[2], rewardIndex = index } table.insert(itemInfo,tab) break end end end end return itemInfo end --获取0元礼包是否已经买过--红点 function this:GetSelectRewardInfo(giftid) local itemInfo = {} local tab = {} local index = 0 for k,v in ipairs(self.DailyPackData) do if v.id == giftid and (not table.isNullOrEmpty(v.Optionalreward))then for key,value in ipairs(v.Optionalreward) do index = index +1 tab={ rewardId = value[1], rewarcount = value[2], rewardIndex = index } table.insert(itemInfo,tab) end end end return itemInfo end