local UIOACommonDirectGiftPanel = UIViewClass() function UIOACommonDirectGiftPanel: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.RefreshPanel) self:RegistSystemEvent(EventID.UI_Shop_RefreshShopInfo, self.RefreshAllGift) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshCells) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS[context.Title or "IDS_GoldHeroActivity_All_Title"]) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self:RefreshPanel() CTL.DirectGift.SaveNewDirectGiftInfo(nil, self.activityId) if self.activityType == MDL.OperationActivity.ActivityType.GoldenHero then CTL.GoldenHeroMain.OpenCurrencyPanel(MDL.GoldenHeroMain.GetHeroTypeByActivityId(self.activityId), self.__viewClassPath, self.currency_Info, {activityType = self.activityType, activityId = self.activityId, title = "IDS_DrawCard_Title_QuickBuy"}) elseif self.activityType == MDL.OperationActivity.ActivityType.SuperGold then CTL.SuperGoldMain.OpenCurrencyPanel(MDL.SuperGoldMain.GetHeroTypeByActivityId(self.activityId), self.__viewClassPath, self.currency_Info, {activityType = self.activityType, activityId = self.activityId, title = "IDS_DrawCard_Title_QuickBuy"}) end end function UIOACommonDirectGiftPanel:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseView(true) end end end function UIOACommonDirectGiftPanel:RefreshPanel() self:RefreshAllGift() if self.activityType == MDL.OperationActivity.ActivityType.SuperGold then local heroType = MDL.SuperGoldMain.GetHeroTypeByActivityId(self.activityId) local modeData = DataSheetManager.SuperGoldActivityModeData:GetDataByHeroType(heroType) local extraEndTime = modeData.TotalRankPreTime * UTL.Time.TotalSecondsOneHour local endTimeNum = MDL.SuperGoldMain.GetEndFuncTime(self.activityId) - extraEndTime if UTL.Time.GetServerTimestamp() > endTimeNum then UIUtils.SetLabelText(self.txt_TimeOutTips, Const_IDS.IDS_GoldHeroActivity_RankTip) UIUtils.SetActive(self.txt_TimeOutTips, true) end end end function UIOACommonDirectGiftPanel:RefreshCells() self.loop_DirectGift:RefreshCells() end function UIOACommonDirectGiftPanel: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 if self.activityType == MDL.OperationActivity.ActivityType.GoldenHero then for i, v in DataSheetManager.DrawItemGoodsData:GetEnumerator() do local goodData = MDL.OperationActivity.StoreGoodsData:GetDataByID(v.GoodsID) if not CTL.PayMall.IsSoldOut(goodData) then self.loop_DirectGift:AddData({data = v, notDirectGift = true}, 0) end end elseif self.activityType == MDL.OperationActivity.ActivityType.Turntable then for i, v in DataSheetManager.CasinoItemGoodsData:GetEnumerator() do local goodData = MDL.OperationActivity.StoreGoodsData:GetDataByID(v.GoodsID) if not CTL.PayMall.IsSoldOut(goodData) then self.loop_DirectGift:AddData({data = v, notDirectGift = true}, 0) end end elseif self.activityType == MDL.OperationActivity.ActivityType.SuperGold then for i, v in DataSheetManager.SuperDrawItemGoodsData:GetEnumerator() do local goodData = MDL.OperationActivity.StoreGoodsData:GetDataByID(v.GoodsID) if not CTL.PayMall.IsSoldOut(goodData) then self.loop_DirectGift:AddData({data = v, notDirectGift = true}, 0) end end 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 self.state_OACommonDirectGift:SetState(self.loop_DirectGift.Count == 0 and 1 or 0) end function UIOACommonDirectGiftPanel:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) end function UIOACommonDirectGiftPanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIOACommonDirectGiftPanel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() end end function UIOACommonDirectGiftPanel:RefreshDirectGiftCell(cellTable, data) local sheetData = data.data local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.GiftID) local activityId = data.activityId cellTable.txt_GiftName.text = giftRewardData.Name cellTable.txt_Rebate.text = UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate) 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 local isFree = sheetData.IsFree if isFree then UIUtils.SetLabelText(cellTable.txt_BuyPrice, Const_IDS.IDS_Gift_Receive) else cellTable.txt_BuyPrice.text = MDL.Currency.GetFullyIAPPriceByIapID(giftRewardData.IapID) end cellTable.btn_Buy:SetRedPoint(isFree) UIUtils.SetActive(cellTable.group_Icon, false) UIUtils.SetActive(cellTable.img_Rebate, not isFree) UIUtils.SetActive(cellTable.txt_Integral, 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.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 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) end --奖励物品显示 local rewardTable = giftRewardData.Reward_Table cellTable.state_Item:SetState(#rewardTable > 3 and 0 or 1) if #rewardTable > 3 then for i, rewardData in ipairs(rewardTable) do local contentItem = cellTable.Content[i] if not contentItem then contentItem = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, cellTable.Item.gameObject) end UTL.Item.SetItemCell(contentItem, rewardData.RewardID, rewardData.RewardNum) UIUtils.SetActive(contentItem.gameObject, true) end for i = #rewardTable + 1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false) end else for i, v in ipairs(cellTable.group_Item) do local rewardData = rewardTable[i] if rewardData then UIUtils.SetActive(v.gameObject.transform.parent, true) UTL.Item.SetItemCell(v, rewardData.RewardID, rewardData.RewardNum) else UIUtils.SetActive(v.gameObject.transform.parent, false) end end end UIUtils.SetLocalizationImage(cellTable.img_New, "zr_msz_new.png") cellTable.img_New:SetNativeSize() UIUtils.SetActive(cellTable.img_New, CTL.DirectGift.IsDirectGiftShowNew(activityId, data.giftId)) if MDL.Currency.IsNotShowRechargeButton() then UIUtils.SetActive(cellTable.btn_Buy, false) end end function UIOACommonDirectGiftPanel:RefreshGoodCell(cellTable, data) local sheetData = data.data local goodsId = sheetData.GoodsID local goodData = MDL.OperationActivity.StoreGoodsData:GetDataByID(goodsId) UIUtils.SetLabelText(cellTable.txt_GiftName, Const_IDS[sheetData.GoodsName]) cellTable.txt_Rebate.text = UTL.String.GetDiscountStrByIdsId(goodData.ItemDiscount) UIUtils.SetActive(cellTable.img_Rebate, goodData.ItemDiscount < 100) UIUtils.SetImageByAssetBundle(cellTable.img_Gift, sheetData.GoodsPic) UIUtils.SetActive(cellTable.giftTimer, false) cellTable.btn_Buy:SetRedPoint(false) --奖励物品显示 cellTable.state_Item:SetState(1) UTL.Item.SetItemCell(cellTable.group_Item[1], goodData.ItemID, goodData.ItemNum) UIUtils.SetActive(cellTable.group_Item[1].gameObject.transform.parent, true) for i = 2, #cellTable.group_Item do UIUtils.SetActive(cellTable.group_Item[i].gameObject.transform.parent, false) end local canBuy = not CTL.PayMall.IsSoldOut(goodData) local isLimit, limitStr = CTL.PayMall.IsLimitedGood(goodData) UIUtils.SetActive(cellTable.img_PurchaseLimitBg, isLimit and canBuy) if isLimit and canBuy then if goodData.LimitBuyType == LuaConst.LimitBuyType.Forever then UIUtils.SetLabelText(cellTable.lab_PurchaseLimit, Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) else cellTable.lab_PurchaseLimit.text = CTL.PayMall.GetLimitedTitle(goodData) end cellTable.txt_PurchaseLimit.text = limitStr end if MDL.Currency.GetMoneyCount(goodData.MoneyID) < goodData.BuyPrice then cellTable.txt_BuyPrice.text = UTL.Color.FormatRedColor(goodData.BuyPrice) else cellTable.txt_BuyPrice.text = goodData.BuyPrice end UIUtils.SetLabelText(cellTable.lab_PurchaseLimit, Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) UTL.Item.MoneyIcon(cellTable.img_Icon, goodData.MoneyID) UIUtils.SetActive(cellTable.group_Icon, true) UIUtils.SetActive(cellTable.txt_Integral, false) UIUtils.SetActive(cellTable.img_New, false) end function UIOACommonDirectGiftPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_DirectGift then if data.notDirectGift then self:RefreshGoodCell(cellTable, data) else self:RefreshDirectGiftCell(cellTable, data) end end end function UIOACommonDirectGiftPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_DirectGift then if data.notDirectGift then if target == cellTable.btn_Buy then local goodData = MDL.OperationActivity.StoreGoodsData:GetDataByID(data.data.GoodsID) if MDL.Currency.GetMoneyCount(goodData.MoneyID) < goodData.BuyPrice then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_GoldActivity_DrawItemGoods_Hint1) return end CTL.PayMall.OpenPayMallPopUp(goodData, self.activityId, self.activityType, data.data.GoodsName) else for i, v in ipairs(cellTable.group_Item) do if v.event_Click == target then local goodData = MDL.OperationActivity.StoreGoodsData:GetDataByID(data.data.GoodsID) UTL.ItemTips.ShowCommonTipsById(goodData.ItemID) break end end end else 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.group_Item) do if v.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 for i, v in ipairs(cellTable.Content) do if v.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 end return UIOACommonDirectGiftPanel