---@class KLDailyDiamondRechargePanel:UIKmlLuaPanelBase ---@field view KLDailyDiamondRechargePanelView local KLDailyDiamondRechargePanel = class(UIKmlLuaPanelBase) local this =KLDailyDiamondRechargePanel function this:AsyncLoadUI() end ---创建时调用一次 function this:Init() self.selectItemInfoData = {} --选中数据保存 self.selectItemInfoObj = {} --选中勾选框保存 self.openSelectGIftId = 0 --打开giftId的自选框 self.selectItemInfoRewardIndex =0 --选中的具体道具 self.itemInfoList = {} GUI:DataListInitData(self.view.DailyPackItemList, function() return table.count(self.itemInfoList) end,function() end,function() end,function(realIndex) local discountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountImage') --左上角返利 local discountTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'discountText') --返利数值 local ItemPriceShowTextControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemPriceShowText') --价格标题 local limitBuyCountControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'limitBuyCount') --限制次数 local ItemInfoListControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'ItemInfoList') --奖励列表 local BuyBtnControl = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'daliyPackItemBuyBtn') --购买按钮 local redpoint = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'redpoint') --红点 local diamondImg = GUI:GetChildControl(self.view.DailyPackItemList,realIndex,'DiamondImg') --钻石 local info = self.itemInfoList[realIndex+1] local buycount = 0 --剩余次数 local totalcount = 0 buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(info.Countkey) if info.Diamonditem == 1 then GUI:Image_loadTexture(diamondImg, "10040001", "Atlas/TS_Common.spriteatlas") else GUI:Image_loadTexture(diamondImg, "10050001", "Atlas/TS_Common.spriteatlas") end --返利 if info.rebate and info.rebate>0 then GUI:setVisible(discountControl, true) GUI:Text_setString(discountTextControl, info.rebate.."%") else GUI:setVisible(discountControl, false) end GUI:setVisible(redpoint, false) GUI:AddOnClickEvent(BuyBtnControl, self, self.ItemBuyBtn, {info}) if info.canBuy then if info.Price == 0 then GUI:Button_setTitleText(BuyBtnControl, "领取") GUI:setVisible(redpoint, true) else GUI:Button_setTitleText(BuyBtnControl, "购买") end else GUI:Button_setTitleText(BuyBtnControl, "已购买") end if info.Price == 0 then GUI:setVisible(diamondImg, false) GUI:Text_setString(ItemPriceShowTextControl, "免费") else GUI:setVisible(diamondImg, true) GUI:Text_setString(ItemPriceShowTextControl, tostring(info.Price).."钻石") end GUI:Text_setString(limitBuyCountControl, "每日限购次数:"..(totalcount-buycount).."/"..totalcount) self:ItemUpdateFun(ItemInfoListControl,realIndex) end) self.selectRewardList = {} GUI:DataListInitData(self.view.selectItemInfoDataList, function() return table.count(self.selectRewardList) end,function() end,function() end,function(realIndex) local selectItem = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItem') --奖励模型 local selectItemTips = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemTips') --奖励模型 local selectItemNum = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemNum') --奖励数量 local iteminfogouImg = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'iteminfogouImg') --勾选 local selectItemInfoBtn = GUI:GetChildControl(self.view.selectItemInfoDataList,realIndex,'selectItemInfoBtn') --勾选按钮 local info = self.selectRewardList[realIndex+1] local ItemInfoTab={} if iteminfogouImg then ItemInfoTab ={ Index = realIndex+1, Obj = iteminfogouImg, } table.insert(self.selectItemInfoObj,ItemInfoTab) end GUI:setVisible(iteminfogouImg, false) GUI:Item_setItemId(selectItem, tostring(info.rewardId)) GUI:AddOnClickEvent(selectItemTips,self,function() SL:OpenTips(nil, info.rewardId) end) GUI:Text_setString(selectItemNum, tostring(info.rewarcount)) GUI:AddOnClickEvent(selectItemInfoBtn,self,self.selectItemIndexBtn,{ Index = info.rewardIndex}) end) GUI:setVisible(self.view.selectItemPanel, false) end function this:ItemUpdateFun(ItemInfoListControl,Index) local data = self.itemInfoList[Index + 1] local showRewards={} for k,v in ipairs(data.Rewards) do table.insert(showRewards,v) end local showRewardsCount = table.count(showRewards) if not table.isNullOrEmpty(data.Optionalreward) then showRewardsCount = showRewardsCount +1 end GUI:DataListInitData(ItemInfoListControl, function() return showRewardsCount end,function() end,function() end,function(realIndex) local ItemInfoSlotModel = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotModel') --模型 local ItemInfoSlotCount = GUI:GetChildControl(ItemInfoListControl,realIndex,'ItemInfoSlotCount') --数量 local selectItemBtn = GUI:GetChildControl(ItemInfoListControl,realIndex,'selectItemBtn') --模型 local itemInfoTips = GUI:GetChildControl(ItemInfoListControl,realIndex,'itemInfoTips') --模型Tips GUI:setVisible(selectItemBtn, false) GUI:setVisible(ItemInfoSlotModel, false) GUI:setVisible(ItemInfoSlotCount, false) GUI:setVisible(itemInfoTips, false) if showRewards[realIndex+1] then local itemdata = showRewards[realIndex+1] GUI:setVisible(ItemInfoSlotModel, true) GUI:setVisible(itemInfoTips, true) GUI:setVisible(ItemInfoSlotCount, true) GUI:Item_setItemId(ItemInfoSlotModel, itemdata[1]) if itemdata[1] == 10040001 or itemdata[1] == 10050001 then GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24") end GUI:AddOnClickEvent(itemInfoTips,self,function() SL:OpenTips(nil, itemdata[1]) end) GUI:Text_setString(ItemInfoSlotCount, tostring(itemdata[2])) else if data.canBuy then if self.selectItemInfoData[data.id] and self.selectItemInfoData[data.id]~=0 then --有选中的道具 GUI:setVisible(ItemInfoSlotModel, true) GUI:setVisible(itemInfoTips, true) GUI:setVisible(ItemInfoSlotCount, true) local selectInfo = InfoManager.dailyDiamondRechargeInfo:GetSelectRewardItem(data.id,self.selectItemInfoData[data.id])[1] GUI:Item_setItemId(ItemInfoSlotModel, selectInfo.rewardId) if selectInfo.rewardId == 10040001 or selectInfo.rewardId == 10050001 then GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24") end GUI:AddOnClickEvent(itemInfoTips,self,self.selectItemOpenBtn,{ data}) GUI:Text_setString(ItemInfoSlotCount,tostring(selectInfo.rewarcount)) else GUI:setVisible(selectItemBtn, true) end else if data.buyIndex >0 then --获取购买时的自选道具 GUI:setVisible(ItemInfoSlotModel, true) GUI:setVisible(itemInfoTips, true) GUI:setVisible(ItemInfoSlotCount, true) local selectInfo = InfoManager.dailyDiamondRechargeInfo:GetSelectRewardItem(data.id,data.buyIndex)[1] GUI:Item_setItemId(ItemInfoSlotModel, selectInfo.rewardId) if selectInfo.rewardId == 10040001 or selectInfo.rewardId == 10050001 then GUI:Model_setSrc(ItemInfoSlotModel, nil, nil, nil, nil, "24,24") end GUI:AddOnClickEvent(itemInfoTips,self,function() SL:OpenTips(nil, selectInfo.rewardId) end) GUI:Text_setString(ItemInfoSlotCount, tostring(selectInfo.rewarcount)) end end end GUI:AddOnClickEvent(selectItemBtn,self,self.selectItemOpenBtn,{ data}) end) GUI:DataListUpdateData(ItemInfoListControl) end ---注册UI事件和服务器消息 function this:RegistEvents() GUI:AddOnClickEvent(self.view.buyAllGift_btn, self, self.buyAllGift_btn) GUI:AddOnClickEvent(self.view.selectItemOkBtn, self, self.selectItemOkBtn) GUI:AddOnClickEvent(self.view.selectItemCloseBtn, self, self.selectItemCloseBtn) SL:RegisterLUAEvent(LUA_EVENT_DAILY_DIAMOND_RECHARGE_CHANGE, this.LUA_EVENT_DAILY_DIAMOND_RECHARGE_CHANGE, self) end --服务器发送礼包组消息后刷新礼包组的数据 function this:LUA_EVENT_DAILY_DIAMOND_RECHARGE_CHANGE() self:RefreshPanel() end --打开自选框 function this:selectItemOpenBtn(control, giftdata) self.openSelectGIftId = giftdata[1].id self.selectRewardList = InfoManager.dailyDiamondRechargeInfo:GetSelectRewardInfo(self.openSelectGIftId) if not table.isNullOrEmpty(self.selectRewardList) then self.selectItemInfoObj = {} GUI:setVisible(self.view.selectItemPanel, true) GUI:DataListUpdateData(self.view.selectItemInfoDataList) end end --关闭自选框 function this:selectItemCloseBtn() self.openSelectGIftId = 0 self.selectItemInfoRewardIndex = 0 GUI:setVisible(self.view.selectItemPanel, false) self:RefreshPanel() end --选中的自选框中的具体道具 function this:selectItemIndexBtn(control, data) for k,v in ipairs(self.selectItemInfoObj) do GUI:setVisible(v.Obj, false) end for k,v in ipairs(self.selectItemInfoObj) do if v.Index == data.Index then GUI:setVisible(v.Obj, true) self.selectItemInfoRewardIndex =data.Index end end end --确认选中的自选框中的具体道具 function this:selectItemOkBtn() GUI:setVisible(self.view.selectItemPanel, false) if self.selectItemInfoRewardIndex ~= 0 and self.openSelectGIftId ~=0 then self.selectItemInfoData[self.openSelectGIftId] = self.selectItemInfoRewardIndex end self:RefreshPanel() end ---列表的购买按钮 function this:ItemBuyBtn(control, data) local id = data[1].id local rechargeid = data[1].RechargeId if data[1].canBuy then if table.isNullOrEmpty(data[1].Optionalreward) then elseif self.selectItemInfoData[id] ==nil or self.selectItemInfoData[id] == 0 then SL:TipMessage( "请选中一个自选道具", 1, NoticeType.NoticeMid ) return end local tab = {} tab[id] = self.selectItemInfoData[id] local table = SL:GetConfig("cfg_recharge", tonumber(rechargeid)) GUIUtil.SDKPay(table,1,tab) else SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid ) end end ---一键购买 function this:buyAllGift_btn() local allbuyData = InfoManager.dailyDiamondRechargeInfo.DailyPackAllGiftData[1] if not allbuyData.canBuy then SL:TipMessage( "请勿重复购买", 1, NoticeType.NoticeMid ) return end local tab = {} for k,v in pairs(self.itemInfoList) do if v.Price~= 0 then if (table.isNullOrEmpty(v.Optionalreward)) then elseif self.selectItemInfoData[v.id] and self.selectItemInfoData[v.id]~=0 then tab[v.id] = self.selectItemInfoData[v.id] else SL:TipMessage( "还有礼包没有自选,无法一键购买", 1, NoticeType.NoticeMid ) return end end end if not InfoManager.dailyDiamondRechargeInfo:IsCanBuyAllGift() then SL:TipMessage( "已购买,无法购买", 1, NoticeType.NoticeMid ) return end local table = SL:GetConfig("cfg_recharge", tonumber(allbuyData.RechargeId)) GUIUtil.SDKPay(table,1,tab) end ---界面显示时调用一次 function this:Show() end ---创建或者刷新界面数据时调用 function this:Refresh() self:RefreshPanel() end function this:RefreshPanel() self.itemInfoList = {} local giftData = InfoManager.dailyDiamondRechargeInfo.DailyPackData if not table.isNullOrEmpty(giftData) then for k,v in ipairs(giftData) do local buycount = 0 --剩余次数 local totalcount = 0 buycount,totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(v.Countkey) if buycount < 1 then v.canBuy = false else v.canBuy = true end table.insert(self.itemInfoList, v) end end table.sort(self.itemInfoList,function (a,b) if a.canBuy == b.canBuy then return a.Price