local UIOAPopDirectGiftView = UIViewClass() local ChangeItemCountSpeed = 0.3 local timeHintText = UIUtils.GetLocalizedTxt(Const_IDS.IDS_NewYearActivity_DirectGiftTimeHint_5) local function StringFormat(ids) return string.format(timeHintText, UIUtils.GetLocalizedTxt(Const_IDS[ids])) end function UIOAPopDirectGiftView:OnOpened(context) self.activityId = context.activityId self.activityType = context.activityType self.data = context.data self.txt_Time:SetDHMSStr(StringFormat("IDS_NewYearActivity_DirectGiftTimeHint_1"), StringFormat("IDS_NewYearActivity_DirectGiftTimeHint_2"), StringFormat("IDS_NewYearActivity_DirectGiftTimeHint_3"), StringFormat("IDS_NewYearActivity_DirectGiftTimeHint_4")) --一个脚本应用于多个不同版本界面,有可能使用了模板,作不同处理 self.isUseTemplate = self.UICommonPopUp ~= nil if self.isUseTemplate then UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, context.Title or Const_IDS.IDS_NewYearActivity_DirectGiftHint_3) CTL.NewYear.SetCommonTitle(self.activityId, CTL.NewYear.ViewTitle.GiftPopupTitle, self.UICommonPopUp) end self._currentBuyCount = 1 self.isUseGameMoney = CTL.NewYear.IsItemBuyGift(self.data.data.GiftID) self:RefreshGiftInfo() UIUtils.SetActive(self.group_NumSelect, self.isUseGameMoney) UIUtils.SetActive(self.img_Icon, self.isUseGameMoney) if self.isUseGameMoney then self:InitNumParams() self:RefreshBuyCount() end CTL.NewYear.OpenCurrencyPanel(CTL.NewYear.ViewName.UINewYearGiftPopup, self.activityType, self.activityId, self.currency_Info) end function UIOAPopDirectGiftView:OnBackButtonPressed() if self.isUseTemplate then self:OnButtonClicked(self.UICommonPopUp.btn_Close) else self:OnButtonClicked(self.btn_Close) end end function UIOAPopDirectGiftView:OnButtonClicked(comp) if (self.isUseTemplate and comp == self.UICommonPopUp.btn_Close) or (comp == self.btn_Close) then self:CloseView() elseif comp == self.btn_Max then self:OnClickMax() elseif comp == self.event_Count then if not self.keyBoardView then self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, x = 250, y = 150, minNum = 1, maxNum = self.maxCount}, nil, nil); end elseif comp == self.btn_Buy then self:OnClickBuy() end end function UIOAPopDirectGiftView:OnClickBuy() local sheetData = self.data.data local giftId = self.data.giftId if self.isUseGameMoney then self._currentBuyCount = tonumber(self.txt_Num.text) if self._currentBuyCount > self.maxCount then CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldActivity_DrawItemGoods_Hint1) else MDL.DirectGift.DirectGiftGetFreeAwardReq(self.activityId, giftId, self._currentBuyCount) self:CloseView() end else if sheetData.IsFree then MDL.DirectGift.DirectGiftGetFreeAwardReq(self.activityId, giftId) self:CloseView() return end local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.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, giftId, self.activityId, self.activityType) self:CloseView() else logging.error(LTAG.ERROR, "iap not found", iapStringId) end end end function UIOAPopDirectGiftView:RefreshGiftInfo() local sheetData = self.data.data local isFree = sheetData.IsFree local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.GiftID) self.txt_Name.text = giftRewardData.Name self.txt_Rebate.text = UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate) UIUtils.SetActive(self.txt_Integral, not isFree) if isFree then UIUtils.SetActive(self.img_Integral, false) UIUtils.SetActive(self.group_Price, false) UIUtils.SetLabelText(self.lab_Buy, Const_IDS.IDS_Gift_Receive) else UIUtils.SetActive(self.group_Price, true) UIUtils.SetLabelText(self.lab_Buy, Const_IDS.IDS_BUTTON_BUY) if self.isUseGameMoney then UIUtils.SetActive(self.img_Icon, true) self.moneyId, self.moneyNum = CTL.NewYear.GetMoneyIdAndNum(sheetData.GiftID) UTL.Item.MoneyIcon(self.img_Icon, self.moneyId) UIUtils.SetActive(self.img_Integral, false) self.txt_Integral.text = "" self.txt_BuyPrice.text = UTL.Item.GetItemStockCount(self.moneyId) >= self.moneyNum and self.moneyNum or UTL.Color.FormatRedColor(self.moneyNum) else UIUtils.SetActive(self.img_Integral, true) UIUtils.SetActive(self.img_Icon, false) self.txt_BuyPrice.text = MDL.Currency.GetFullyIAPPriceByIapID(giftRewardData.IapID) local amount = MDL.Currency.GetIAPRewardAmountBy(giftRewardData.IapID) if amount then UIUtils.SetLabel(self.txt_Integral, string.FormatByIdsId(Const_IDS.IDS_TotalTopUp_Score_Tips_Giftbag, amount)) end end end self.btn_Buy:SetRedPoint(isFree) UIUtils.SetActive(self.group_Rebate, not isFree) UIUtils.SetImageByAssetBundle(self.img_Gift, sheetData.HotPackagePic) --剩余时间 if sheetData.TimeType == MDL.OperationActivity.TimeType.Forever then self.txt_Time:EndTimer() else local startTime, endTime = MDL.DirectGift.GetGiftTimeStamp(self.data.info) local leftTime = endTime - UTL.Time.GetServerTimestamp() self.txt_Time:ResetAndBeginCustomTimer(false, leftTime, 0, nil) end --限购显示 if sheetData.LimitType == LuaConst.LimitBuyType.NoLimit then UIUtils.SetActive(self.img_PurchaseLimitBg, false) else UIUtils.SetActive(self.img_PurchaseLimitBg, true) if sheetData.LimitType == LuaConst.LimitBuyType.Forever then UIUtils.SetLabelText(self.lab_PurchaseLimit, Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) else self.lab_PurchaseLimit.text = CTL.PayMall.GetLimitedTitleText(sheetData.LimitType) end local limitNumText = (sheetData.TimesLimit - MDL.DirectGift.GetGiftBuyingCount(self.activityId, self.data.giftId)) .. "/" .. sheetData.TimesLimit if self.data.state == MDL.DirectGift.GiftStateEnum.Available then limitNumText = UTL.Color.FormatGreenColor(limitNumText) elseif self.data.state == MDL.DirectGift.GiftStateEnum.ShowLimited then self.lab_SoldOut.text = CTL.PayMall.GetLimitedSoldoutText(sheetData.LimitType) limitNumText = UTL.Color.FormatRedColor(limitNumText) end self.txt_PurchaseLimit.text = limitNumText end if MDL.Currency.IsNotShowRechargeButton() then UIUtils.SetActive(self.btn_Buy, false) end --礼包物品显示 local rewardTable = giftRewardData.Reward_Table if self.loop_GiftContent.Count > 0 then self.loop_GiftContent:ClearCells() end for i, rewardData in ipairs(rewardTable) do self.loop_GiftContent:AddData(rewardData, 0) end end function UIOAPopDirectGiftView:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_GiftContent then UTL.Item.SetItemCell(cellTable.Item, data.RewardID, data.RewardNum) local itemData = DataSheetManager.ItemData:GetDataByID(data.RewardID) UIUtils.SetLabelText(cellTable.txt_ItemName, Const_IDS[itemData.Name]) end end function UIOAPopDirectGiftView:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_GiftContent then if target == cellTable.Item.event_Click then UTL.ItemTips.ShowCommonTipsById(data.RewardID) end end end function UIOAPopDirectGiftView:InitNumParams() --按住的状态 self._pressPlus = false self._pressMinus = false self:RegistTriggerEvent(self.btn_Plus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Plus, UIEventTriggerType.PointerUp) self:RegistTriggerEvent(self.btn_Minus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Minus, UIEventTriggerType.PointerUp) local sheetData = self.data.data UTL.Item.MoneyIcon(self.img_Icon, self.moneyId) self.maxCount = math.floor(MDL.Currency.GetMoneyCount(self.moneyId) / self.moneyNum) if not sheetData.LimitType ~= LuaConst.LimitBuyType.NoLimit then local availableCount = sheetData.TimesLimit - MDL.DirectGift.GetGiftBuyingCount(self.activityId, self.data.giftId) self.maxCount = math.min(availableCount, self.maxCount) end self._currentBuyCount = 1 end function UIOAPopDirectGiftView:RefreshBuyCount() self.btn_Plus:SetGray(self._currentBuyCount >= self.maxCount) self.btn_Max:SetGray(self._currentBuyCount >= self.maxCount) self.btn_Minus:SetGray(self._currentBuyCount <= 1) if self._currentBuyCount > self.maxCount then self._currentBuyCount = self.maxCount self._pressPlus = false self:StopRepeatFunc(self.OnUpdate) end if self._currentBuyCount < 1 then self._currentBuyCount = 1 self._pressMinus = false self:StopRepeatFunc(self.OnUpdate) end self.txt_Num.text = self._currentBuyCount local canCostCount = self.moneyNum * self._currentBuyCount self.txt_BuyPrice.text = UTL.Item.GetItemStockCount(self.moneyId) >= canCostCount and canCostCount or UTL.Color.FormatRedColor(canCostCount) end function UIOAPopDirectGiftView:OnClickMax() self._currentBuyCount = self.maxCount self:RefreshBuyCount() end function UIOAPopDirectGiftView:OnClickPlus() if self._currentBuyCount < self.maxCount then self._currentBuyCount = self._currentBuyCount + 1 end self:RefreshBuyCount() end function UIOAPopDirectGiftView:OnClickMinus() if self._currentBuyCount > 1 then self._currentBuyCount = self._currentBuyCount - 1 end self:RefreshBuyCount() end function UIOAPopDirectGiftView:OnPointerDown(comp, eventData) if comp == self.btn_Plus then self:OnClickPlus() self:OnPressPlus() elseif comp == self.btn_Minus then self:OnClickMinus() self:OnPressMinus() end end function UIOAPopDirectGiftView:OnPointerUp(comp, eventData) if comp == self.btn_Plus then self:OnPressPlusStop() elseif comp == self.btn_Minus then self:OnPressMinusStop() end end function UIOAPopDirectGiftView:OnPressPlus() self._pressPlus = true self:StartRepeatFunc(self.OnUpdate, ChangeItemCountSpeed, 0) end function UIOAPopDirectGiftView:PlusItemCount() self._currentBuyCount = self._currentBuyCount + 1 self:RefreshBuyCount() end function UIOAPopDirectGiftView:OnPressPlusStop() self._pressPlus = false self:StopRepeatFunc(self.OnUpdate) end function UIOAPopDirectGiftView:OnPressMinus() self._pressMinus = true self:StartRepeatFunc(self.OnUpdate, ChangeItemCountSpeed, 0) end function UIOAPopDirectGiftView:MinusItemCount() self._currentBuyCount = self._currentBuyCount - 1 self:RefreshBuyCount() end function UIOAPopDirectGiftView:OnPressMinusStop() self._pressMinus = false self:StopRepeatFunc(self.OnUpdate) end function UIOAPopDirectGiftView:ExcuteKeyBoardBack(count, param) self._currentBuyCount = count self:RefreshBuyCount() end function UIOAPopDirectGiftView:CloseKeyBoardView() self.keyBoardView:CloseView() self.keyBoardView = nil end --检测按钮按住 function UIOAPopDirectGiftView:OnUpdate(deltaTime, timeSineUpdate) if not self._pressPlus and not self._pressMinus then return end if self._pressPlus then self:PlusItemCount() end if self._pressMinus then self:MinusItemCount() end end return UIOAPopDirectGiftView