local UIDirectGiftPanel = UIViewClass() local DirectGiftSoldOutTimeHint = DataSheetManager.ConstData:GetDataByID("DirectGiftSoldOutTimeHint").IntValue local EventSystem = require('Event/EventSystem') function UIDirectGiftPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_DirectGift_GiftInfoUpdate, self.RefreshAllGift) self.activityType = MDL.OperationActivity.ActivityType.DirectGift self.welfareId = context.welfareId self:RefreshAllGift() CTL.DirectGift.SaveNewDirectGiftInfo(self.welfareId) EventSystem.Dispatch(EventID.UI_PayMall_RefreshRedPoint) local desc1, timeStr1 = UTL.Time.GetDateDescAndTime({[1] = 1}) local desc2, timeStr2 = UTL.Time.GetDateDescAndTime({[1] = 2}) local desc3, timeStr3 = UTL.Time.GetDateDescAndTime({[1] = 3}) if GameAppInfo.IsVietnamPackage() then UIUtils.SetLabel(self.txt_Tips, string.FormatByIdsId(Const_IDS.IDS_Store_StoreTips, timeStr1.." "..desc1, timeStr2.." "..desc2, timeStr3.." "..desc3)) else UIUtils.SetLabel(self.txt_Tips, string.FormatByIdsId(Const_IDS.IDS_Store_StoreTips, desc1..timeStr1, desc2..timeStr2, desc3..timeStr3)) end end function UIDirectGiftPanel:RefreshAllGift() if self.loop_DirectGift.Count > 0 then self.loop_DirectGift:ClearCells() end ---需要在界面中把loop的全部加载打开,因为在初始化完“新”的标识以后,数据就会改变,如果等滑动过去再执行init方法,显示就不正确了。 for i, v in MDL.DirectGift.GetNormalDirectGiftEnumerator(self.welfareId) do self.loop_DirectGift:AddData(v, 0) end self.state_DirectGift:SetState(self.loop_DirectGift.Count == 0 and 1 or 0) --没有礼包了,刷新商城页面 if self.loop_DirectGift.Count == 0 then EventSystem.Dispatch(EventID.UI_PayMall_RefreshTab) end end function UIDirectGiftPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_DirectGift then local sheetData = data.data local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.GiftID) local activityId = data.activityId local amount = MDL.Currency.GetIAPRewardAmountBy(giftRewardData.IapID) UIUtils.SetActive(cellTable.txt_Integral, amount and true or false) if amount then UIUtils.SetLabel(cellTable.txt_Integral, string.FormatByIdsId(Const_IDS["IDS_TotalTopUp_Score_Tips_Giftbag"], amount)) end cellTable.txt_GiftName.text = giftRewardData.Name cellTable.txt_Rebate.text = UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate) if sheetData.IsFree then UIUtils.SetLabelText(cellTable.txt_BuyPrice, Const_IDS.IDS_Gift_Receive) else cellTable.txt_BuyPrice.text = MDL.Currency.GetFullyIAPPriceByIapID(giftRewardData.IapID) end UIUtils.SetActive(cellTable.img_Rebate, not sheetData.IsFree) UIUtils.SetActive(cellTable.txt_Integral, not sheetData.IsFree) UIUtils.SetImageByAssetBundle(cellTable.img_Gift, sheetData.HotPackagePic) --限购显示 if sheetData.LimitType == LuaConst.LimitBuyType.NoLimit then UIUtils.SetActive(cellTable.img_PurchaseLimitBg, false) cellTable.state_Gift:SetState(0) else UIUtils.SetActive(cellTable.img_PurchaseLimitBg, true) if sheetData.LimitType == LuaConst.LimitBuyType.Forever then UIUtils.SetLabelText(cellTable.lab_PurchaseLimit, Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) else cellTable.lab_PurchaseLimit.text = CTL.PayMall.GetLimitedTitleText(sheetData.LimitType) end local limitNumText = (sheetData.TimesLimit - MDL.DirectGift.GetGiftBuyingCount(activityId, data.giftId)) .. "/" .. sheetData.TimesLimit if data.state == MDL.DirectGift.GiftStateEnum.Available then cellTable.state_Gift:SetState(0) limitNumText = UTL.Color.FormatGreenColor(limitNumText) elseif data.state == MDL.DirectGift.GiftStateEnum.ShowLimited then cellTable.state_Gift:SetState(1) cellTable.lab_SoldOut.text = CTL.PayMall.GetLimitedSoldoutText(sheetData.LimitType) limitNumText = UTL.Color.FormatRedColor(limitNumText) end cellTable.txt_PurchaseLimit.text = limitNumText end --剩余时间 if sheetData.TimeType == MDL.OperationActivity.TimeType.Forever then UIUtils.SetActive(cellTable.img_AboutFinish, false) cellTable.giftTimer:EndTimer() else local dayText = UTL.Color.FormatGreenColor(UIUtils.GetLocalizedTxt(Const_IDS.IDS_OfficialPrivilege_BuffShow)) local redClockText = UTL.Color.FormatRedColor("{0}:{1}") cellTable.giftTimer:SetDHMSStr(dayText, UTL.Color.FormatRedColor("{0}:{1}:{2}"), redClockText, redClockText) local startTime, endTime = MDL.DirectGift.GetGiftTimeStamp(data.info) local leftTime = endTime - UTL.Time.GetServerTimestamp() cellTable.giftTimer:ResetAndBeginCustomTimer(false, leftTime, 0, nil) UIUtils.SetActive(cellTable.img_AboutFinish, leftTime <= DirectGiftSoldOutTimeHint) end --奖励物品显示 local rewardTable = giftRewardData.Reward_Table for i, rewardData in ipairs(rewardTable) do local contentItem = cellTable.Content[i] if not contentItem then contentItem = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, self.Item.gameObject) end UTL.Item.SetItemCell(contentItem.ItemCell, rewardData.RewardID, nil)--此处不显示道具数量 --道具名字带品质色 local itemData = DataSheetManager.ItemData:GetDataByID(rewardData.RewardID) if itemData then UIUtils.SetLabel(contentItem.txt_ItemName, UTL.Item.GetItemColorName(rewardData.RewardID)) end --道具数量 UIUtils.SetLabel(contentItem.txt_ItemNum, "X"..rewardData.RewardNum) UIUtils.SetActive(contentItem.gameObject, true) end for i = #rewardTable + 1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false) end UIUtils.SetLocalizationImage(cellTable.img_New, "zr_msz_new.png") cellTable.img_New:SetNativeSize() local durationOfNew = UTL.Time.GetServerTimestamp() - data.info.startTime - UTL.Time.TotalSecondsOneDay * 2 if durationOfNew > 0 then UIUtils.SetActive(cellTable.img_New, false) else UIUtils.SetActive(cellTable.img_New, true) end if MDL.Currency.IsNotShowRechargeButton() then UIUtils.SetActive(cellTable.btn_Buy, false) end UIUtils.SetActive(cellTable.img_DiscountPrice, self:IsShowDiscountPriceFlag()) end end function UIDirectGiftPanel:IsShowDiscountPriceFlag() local guojiaPackageTypeID = DataSheetManager.ConstData:GetDataByID("GuojiaPackageTypeID").IntListValue if table.containValue(guojiaPackageTypeID, self.welfareId) then local specialPackageLabelTime = DataSheetManager.ConstData:GetDataByID("SpecialPackageLabelTime").IntListValue local startTime = UTL.Time.GetConfigTimestampById(specialPackageLabelTime[1]) local endTime = UTL.Time.GetConfigTimestampById(specialPackageLabelTime[2]) local nowTime = UTL.Time.GetServerTimestamp() return startTime <= nowTime and endTime >= nowTime end return false end function UIDirectGiftPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_DirectGift then if target == cellTable.btn_Buy then if data.data.IsFree then MDL.DirectGift.DirectGiftGetFreeAwardReq(data.activityId, data.giftId) return end local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(data.data.GiftID) local iapStringId = giftRewardData.IapID local iap for _, v in DataSheetManager.IAP:GetEnumerator() do if v.IapID == iapStringId then iap = v.Index break end end if iap then MDL.Currency.GetOrderIDReq(iap, MDL.Currency.PayType.DirectGift, data.giftId, data.activityId, self.activityType) else logging.error(LTAG.ERROR, "iap not found", iapStringId) end else for i, v in ipairs(cellTable.Content) do if v.ItemCell.event_Click == target then local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(data.data.GiftID) local rewardTable = giftRewardData.Reward_Table UTL.ItemTips.ShowCommonTipsById(rewardTable[i].RewardID) break end end end end end return UIDirectGiftPanel