local UIOAPopDirectGiftPanel = UIViewClass() function UIOAPopDirectGiftPanel:OnOpened(context) self.activityType = context.activityType self.activityId = context.activityId self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) self:RegistSystemEvent(EventID.UI_DirectGift_GiftInfoUpdate, self.RefreshAllGift) self:RegistSystemEvent(EventID.UI_OperationActivity_DataChanged, self.RefreshAllGift) self:RegistSystemEvent(EventID.UI_Shop_RefreshShopInfo, self.RefreshAllGift) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshCells) self:RefreshAllGift() CTL.DirectGift.SaveNewDirectGiftInfo(nil, self.activityId) CTL.NewYear.OpenCurrencyPanel(CTL.NewYear.ViewName.UINewYearGiftMain, self.activityType, self.activityId, self.currency_Info) end function UIOAPopDirectGiftPanel:RefreshCells() self.loop_DirectGift:RefreshCells() end function UIOAPopDirectGiftPanel:RefreshAllGift() if self.loop_DirectGift.Count > 0 then self.loop_DirectGift:ClearCells() end ---把免费的直购礼包放在第一个位置 ---isAddFree标识现有的直购礼包的第一个是否是免费直购礼包 local isAddFree = false for i, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.Base, self.activityId) do if v.data.IsFree then self.loop_DirectGift:AddData(v, 0) isAddFree = true end break end for i, v in MDL.DirectGift.GetDirectGiftEnumerator(MDL.DirectGift.DirectGiftType.Base, self.activityId) do if not isAddFree or i >= 2 then self.loop_DirectGift:AddData(v, 0) end end end function UIOAPopDirectGiftPanel:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIOAPopDirectGiftPanel:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() end end function UIOAPopDirectGiftPanel:RefreshDirectGiftCell(cellTable, data) local sheetData = data.data local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.GiftID) local activityId = data.activityId if Localization.IsAllChinese() then cellTable.txt_Name.text = giftRewardData.Name else cellTable.scrollText_Name:SetText(giftRewardData.Name) end cellTable.txt_Rebate.text = UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate) local isFree = sheetData.IsFree if isFree then UIUtils.SetActive(cellTable.img_Icon, false) UIUtils.SetLabelText(cellTable.txt_BuyPrice, Const_IDS.IDS_Gift_Receive) else if CTL.NewYear.IsItemBuyGift(sheetData.GiftID) then UIUtils.SetActive(cellTable.img_Icon, true) local moneyId, moneyNum = CTL.NewYear.GetMoneyIdAndNum(sheetData.GiftID) UTL.Item.MoneyIcon(cellTable.img_Icon, moneyId) cellTable.txt_BuyPrice.text = UTL.Item.GetItemStockCount(moneyId) >= moneyNum and moneyNum or UTL.Color.FormatRedColor(moneyNum) else UIUtils.SetActive(cellTable.img_Icon, false) cellTable.txt_BuyPrice.text = MDL.Currency.GetFullyIAPPriceByIapID(giftRewardData.IapID) end end cellTable.btn_Buy:SetRedPoint(isFree) UIUtils.SetActive(cellTable.group_Rebate, not 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.FormatTextByColor("2e925a", 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 cellTable.group_Time:EndTimer() else cellTable.group_Time:SetDHMSStr( UIUtils.GetLocalizedTxt(Const_IDS.IDS_NewYearActivity_DirectGiftTimeHint_1), UIUtils.GetLocalizedTxt(Const_IDS.IDS_NewYearActivity_DirectGiftTimeHint_2), UIUtils.GetLocalizedTxt(Const_IDS.IDS_NewYearActivity_DirectGiftTimeHint_3), UIUtils.GetLocalizedTxt(Const_IDS.IDS_NewYearActivity_DirectGiftTimeHint_4) ) local startTime, endTime = MDL.DirectGift.GetGiftTimeStamp(data.info) local leftTime = endTime - UTL.Time.GetServerTimestamp() cellTable.group_Time:ResetAndBeginCustomTimer(false, leftTime, 0, nil) end if MDL.Currency.IsNotShowRechargeButton() then UIUtils.SetActive(cellTable.btn_Buy, false) end end function UIOAPopDirectGiftPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_DirectGift then self:RefreshDirectGiftCell(cellTable, data) end end function UIOAPopDirectGiftPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_DirectGift then if target == cellTable.btn_Buy then CTL.NewYear.OpenView(self.activityId, CTL.NewYear.ViewName.UINewYearGiftPopup, {activityType = MDL.OperationActivity.ActivityType.NewYear, activityId = self.activityId, data = data}) end end end return UIOAPopDirectGiftPanel