local UIOACommonGiftBase = UIViewClass() local IAP_SCORE_ID = 30 local TabSound = {"UI_active_treasure" ,"UI_foundation"} local TimeColorCode = "FFFFFF" function UIOACommonGiftBase:OnCreated() self.selectedTab = 0 self.FirstGiftInfo = nil self.overTimeStamp = nil self.PageCfg = { {IDS = "IDS_Monopoly_GiftBag_Title", GiftType = MDL.DirectGift.DirectGiftType.StageUnlock, isInit = false, isShowRp = false, isShow = true}, {IDS = "IDS_Monopoly_GiftBag_Title2", GiftType = MDL.DirectGift.DirectGiftType.Base, isInit = false, isShowRp = false, isShow = true} } end function UIOACommonGiftBase:OnOpened(context) self:Init(context) end function UIOACommonGiftBase:Init(context) self.activityId = context.activityId self.activityType = context.activityType self:RegistSystemEvent(EventID.UI_DirectGift_GiftInfoUpdate, self.UpdatePage) for i, v in ipairs (self.PageCfg) do v.isInit = false if v.GiftType == MDL.DirectGift.DirectGiftType.Base and not self:IsShowDirectGiftBaseType() then v.isShow = false else v.isShow = true self.TabScroll:AddData(v, 0) end end self.playSound = false self.TabScroll:SelectIndex(self.selectedTab) self.playSound = true self:RefreshPage() self:RefreshRP() self:SetCdTimerStr() self:RefreshGiftTime() end function UIOACommonGiftBase:SetCdTimerStr() local timeStr_1 = string.FormatByIdsKey("IDS_Monopoly_LastTime", string.FormatByIdsKey("IDS_HorseActivity_TimeWithColor_1", TimeColorCode)) local timeStr_2 = string.FormatByIdsKey("IDS_Monopoly_LastTime", string.FormatByIdsKey("IDS_HorseActivity_TimeWithColor_2", TimeColorCode, TimeColorCode, TimeColorCode)) local timeStr_3 = string.FormatByIdsKey("IDS_Monopoly_LastTime", string.FormatByIdsKey("IDS_HorseActivity_TimeWithColor_4", TimeColorCode, TimeColorCode)) local timeStr_4 = string.FormatByIdsKey("IDS_Monopoly_LastTime", string.FormatByIdsKey("IDS_HorseActivity_TimeWithColor_4", TimeColorCode, TimeColorCode)) self.GiftPanel.group_Time:SetDHMSStr(timeStr_1, timeStr_2, timeStr_3, timeStr_4) self.PackagePanel.group_Time:SetDHMSStr(timeStr_1, timeStr_2, timeStr_3, timeStr_4) end function UIOACommonGiftBase:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIOACommonGiftBase:IsActivityOpen() -- 先判断服务器开启状态GM --if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Monopoly) then -- return false --end local info = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) return info and CTL.OperationActivity.IsOperationActivityOpen(info) end --检测活动时间相关逻辑,可以子类自定义,用于充值和领取之前判断 function UIOACommonGiftBase:IsCheckActivityTime() return true end function UIOACommonGiftBase:ActivityCloseFunc() self:CloseView() end function UIOACommonGiftBase:OnClickDetail() logging.error(LTAG.ERROR, "UIOACommonGiftBase:OnClickDetail()此方法应被重写!不应该出现此LOG,请检查!!!") end function UIOACommonGiftBase:OnClickBuy() self:UpdateFirstGiftInfo() if self.FirstGiftInfo then if not self:IsActivityOpen() then return end if not self:IsCheckActivityTime() then return end local sheetData = self.FirstGiftInfo.data if sheetData then if sheetData.IsFree then MDL.DirectGift.DirectGiftGetFreeAwardReq(self.activityId, self.FirstGiftInfo.data.giftId) else 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 MDL.Currency.GetOrderIDReq(iap, MDL.Currency.PayType.DirectGift, self.FirstGiftInfo.giftId, self.activityId, self.activityType) end end end end function UIOACommonGiftBase:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.GiftPanel.btn_RewardDetail then self:OnClickDetail() elseif comp == self.GiftPanel.btn_Buy then self:OnClickBuy() end end function UIOACommonGiftBase:SetDiscount(cellTable, giftRewardData) -- txt_Num UIUtils.SetActive(cellTable.group_Discount, giftRewardData.Rebate ~= 0) UIUtils.SetLabel(cellTable.txt_Num, UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate)) UIUtils.SetLabelText(cellTable.lab_Discount, Const_IDS.IDS_Monopoly_GiftBag_OnSale) UIUtils.SetActive(cellTable.lab_Discount, Localization.IsAllChinese()) end function UIOACommonGiftBase:ShowGiftCell(cellTable, data) local sheetData = data.data -- 折扣 local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.GiftID) self:SetDiscount(cellTable, giftRewardData) -- 奖励 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, 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 -- 价格 UIUtils.SetActive(cellTable.btn_Buy.gameObject, not sheetData.IsFree and not MDL.Currency.IsNotShowRechargeButton()) UIUtils.SetActive(cellTable.btn_Get.gameObject, sheetData.IsFree and not MDL.Currency.IsNotShowRechargeButton()) if not sheetData.IsFree then UIUtils.SetLabel(cellTable.txt_Prices, MDL.Currency.GetFullyIAPPriceByIapID(giftRewardData.IapID)) end -- 限购 if sheetData.LimitType == LuaConst.LimitBuyType.NoLimit then UIUtils.SetActive(cellTable.lab_Limit, false) else UIUtils.SetActive(cellTable.lab_Limit, true) local titleLimit = sheetData.LimitType == LuaConst.LimitBuyType.Forever and UIUtils.GetLocalizedTxt(Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) or CTL.PayMall.GetLimitedTitleText(sheetData.LimitType) local hasBuyCount = MDL.DirectGift.GetGiftBuyingCount(self.activityId, sheetData.HotPackageID) local limitNumText = sheetData.TimesLimit - hasBuyCount if hasBuyCount < sheetData.TimesLimit then limitNumText = UTL.Color.FormatGreenColor(limitNumText) else limitNumText = UTL.Color.FormatRedColor(limitNumText) end UIUtils.SetLabel(cellTable.lab_Limit, titleLimit .. limitNumText .. "/" .. sheetData.TimesLimit) end -- 积分 UIUtils.SetActive(cellTable.txt_Points, false) if not sheetData.IsFree then local iapStringId = giftRewardData.IapID for _, v in DataSheetManager.IAP:GetEnumerator() do if v.IapID == iapStringId then for _, item in ipairs (v.Item_Condition_Table) do if item.GetID == IAP_SCORE_ID then UIUtils.SetActive(cellTable.txt_Points, true) UIUtils.SetLabel(cellTable.txt_Points, string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_TotalTopUp_Score_Tips_Giftbag"]), item.GetAmount)) break end end break end end end end function UIOACommonGiftBase:OnClickBuyInGiftCell(data) if not self:IsActivityOpen() then return end if not self:IsCheckActivityTime() then return end local sheetData = data.data if sheetData then if sheetData.IsFree then MDL.DirectGift.DirectGiftGetFreeAwardReq(self.activityId, data.giftId) else 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 MDL.Currency.GetOrderIDReq(iap, MDL.Currency.PayType.DirectGift, data.giftId, self.activityId, self.activityType) end end end function UIOACommonGiftBase:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.TabScroll then UIUtils.SetLabelText(cellTable.txt_UnSelectedTabName, Const_IDS[data.IDS]) UIUtils.SetLabelText(cellTable.txt_SelectedTabName, Const_IDS[data.IDS]) UIUtils.SetActive(cellTable.img_RedPoint, data.isShowRp) elseif scrollRect == self.GiftPanel.scroll_Reward then UTL.Item.SetItemCell(cellTable.item, data.RewardID, data.RewardNum) elseif scrollRect == self.PackagePanel.GiftScroll then self:ShowGiftCell(cellTable, data) end end function UIOACommonGiftBase:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.TabScroll then if self.playSound then CTL.Sound.PlayGameSound(TabSound[index + 1]) end if self.selectedTab ~= index then self.selectedTab = index self.playSound = false self.TabScroll:RefreshCells() self.playSound = true self:RefreshPage() end elseif scrollRect == self.GiftPanel.scroll_Reward then if target == cellTable.item.event_Click then UTL.ItemTips.ShowCommonTipsById(data.RewardID) end elseif scrollRect == self.PackagePanel.GiftScroll then if target == cellTable.btn_Buy or target == cellTable.btn_Get then self:OnClickBuyInGiftCell(data) else 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 function UIOACommonGiftBase:UpdatePage() -- 刷新数据 for _, v in pairs (self.PageCfg) do v.isInit = false end -- 判断是否显示直购基础页签 if self:IsShowDirectGiftBaseType() ~= self.PageCfg[2].isShow then self.PageCfg[2].isShow = self:IsShowDirectGiftBaseType() if self.PageCfg[2].isShow then self.TabScroll:InsertData(1, self.PageCfg[2], 0) else self.TabScroll:RemoveIndex(1) if self.selectedTab == 1 then self.selectedTab = 0 end self.TabScroll:SelectIndex(self.selectedTab) end end self:RefreshPage() self:RefreshRP() end function UIOACommonGiftBase:RefreshRP() self:UpdateFirstGiftInfo() local sheetData = self.FirstGiftInfo and self.FirstGiftInfo.data or nil local showRp = false if self.FirstGiftInfo then local giftCount = MDL.DirectGift.GetGiftBuyingCount(self.FirstGiftInfo.activityId, self.FirstGiftInfo.giftId) if sheetData and sheetData.IsFree and self.FirstGiftInfo.state == MDL.DirectGift.GiftStateEnum.Available and (sheetData.LimitType == LuaConst.LimitBuyType.NoLimit or sheetData.TimesLimit - giftCount > 0) then showRp = true end end self.PageCfg[1].isShowRp = showRp self.PageCfg[2].isShowRp = false for _, v in MDL.DirectGift.GetDirectGiftEnumerator(self.PageCfg[2].GiftType, self.activityId) do if v.data then local sheetData = v.data if sheetData and sheetData.IsFree and v.state == MDL.DirectGift.GiftStateEnum.Available and (sheetData.LimitType == LuaConst.LimitBuyType.NoLimit or sheetData.TimesLimit - MDL.DirectGift.GetGiftBuyingCount(v.activityId, v.giftId) > 0) then self.PageCfg[2].isShowRp = true break end end end self.playSound = false self.TabScroll:RefreshCells() self.playSound = true end function UIOACommonGiftBase:RefreshPage() UIUtils.SetActive(self.GiftPanel.DetailPanel, false) self.PageState:SetState(self.selectedTab) local cfg = self.PageCfg[self.selectedTab + 1] if not cfg.isInit then cfg.isInit = true if self.selectedTab == 0 then self.GiftPanel.scroll_Reward:ClearCells() self:UpdateFirstGiftInfo() local cfg = self.PageCfg[self.selectedTab + 1] if self.FirstGiftInfo then UIUtils.SetActive(self.GiftPanel.btn_Buy, true and not MDL.Currency.IsNotShowRechargeButton()) UIUtils.SetActive(self.GiftPanel.lab_SoldOut, false) local sheetData = self.FirstGiftInfo.data local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(sheetData.GiftID) if not giftRewardData then logging.error(LTAG.ERROR, "运营活动配置表hotGiftInfo没有ID为", sheetData.GiftID, "的数据,请检查配置!!!") end -- 折扣 UIUtils.SetActive(self.GiftPanel.group_Discount, giftRewardData.Rebate ~= 0) UIUtils.SetLabel(self.GiftPanel.txt_DiscountPercent, UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate)) UIUtils.SetLabelText(self.GiftPanel.lab_Discount, Const_IDS.IDS_Monopoly_GiftBag_OnSale) UIUtils.SetActive(self.GiftPanel.lab_Discount, Localization.IsAllChinese()) -- 价格 if sheetData.IsFree then UIUtils.SetLabelText(self.GiftPanel.txt_Prices, Const_IDS.IDS_Gift_Receive) else UIUtils.SetLabel(self.GiftPanel.txt_Prices, MDL.Currency.GetFullyIAPPriceByIapID(giftRewardData.IapID)) end -- 剩余购买次数 if sheetData.LimitType == LuaConst.LimitBuyType.NoLimit then UIUtils.SetActive(self.GiftPanel.group_Remain, false) else UIUtils.SetActive(self.GiftPanel.group_Remain, true) local titleLimit = sheetData.LimitType == LuaConst.LimitBuyType.Forever and UIUtils.GetLocalizedTxt(Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) or CTL.PayMall.GetLimitedTitleText(sheetData.LimitType) local giftCount = MDL.DirectGift.GetGiftBuyingCount(self.FirstGiftInfo.activityId, self.FirstGiftInfo.giftId) local limitNumText = sheetData.TimesLimit - giftCount if self.FirstGiftInfo.state == MDL.DirectGift.GiftStateEnum.Available then limitNumText = UTL.Color.FormatGreenColor(limitNumText) elseif self.FirstGiftInfo.state == MDL.DirectGift.GiftStateEnum.ShowLimited then limitNumText = UTL.Color.FormatRedColor(limitNumText) end UIUtils.SetLabel(self.GiftPanel.txt_RemainCount, titleLimit .. limitNumText .. "/" .. sheetData.TimesLimit) end -- 时间 if sheetData.TimeType == MDL.OperationActivity.TimeType.Forever then UIUtils.SetActive(self.GiftPanel.group_Time, false) else UIUtils.SetActive(self.GiftPanel.group_Time, true) end -- 奖励 for i, rewardData in ipairs(giftRewardData.Reward_Table) do self.GiftPanel.scroll_Reward:AddData(rewardData, 0) end -- 积分 UIUtils.SetActive(self.GiftPanel.txt_Points, false) if not sheetData.IsFree then local iapStringId = giftRewardData.IapID for _, v in DataSheetManager.IAP:GetEnumerator() do if v.IapID == iapStringId then for _, item in ipairs (v.Item_Condition_Table) do if item.GetID == IAP_SCORE_ID then UIUtils.SetActive(self.GiftPanel.txt_Points, true) UIUtils.SetLabel(self.GiftPanel.txt_Points, string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_TotalTopUp_Score_Tips_Giftbag"]), item.GetAmount)) break end end break end end end else -- 卖完 local lastGiftInfo for _, v in MDL.OperationActivity.DirectGiftData[self.activityType]:GetEnumeratorByActivityID(self.activityId) do if v.HotPackageType == cfg.GiftType then if not lastGiftInfo or lastGiftInfo.HotPackageID < v.HotPackageID then lastGiftInfo = v end end end if lastGiftInfo then -- 时间 if lastGiftInfo.TimeType == MDL.OperationActivity.TimeType.Forever then UIUtils.SetActive(self.GiftPanel.group_Time, false) else UIUtils.SetActive(self.GiftPanel.group_Time, true) end -- 奖励 local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(lastGiftInfo.GiftID) for i, rewardData in ipairs(giftRewardData.Reward_Table) do self.GiftPanel.scroll_Reward:AddData(rewardData, 0) end local giftRewardData = MDL.OperationActivity.CommonGiftReward:GetDataByID(lastGiftInfo.GiftID) -- 折扣 UIUtils.SetActive(self.GiftPanel.group_Discount, giftRewardData.Rebate ~= 0) UIUtils.SetLabel(self.GiftPanel.txt_DiscountPercent, UTL.String.GetDiscountStrByIdsId(giftRewardData.Rebate)) UIUtils.SetLabelText(self.GiftPanel.lab_Discount, Const_IDS.IDS_Monopoly_GiftBag_OnSale) UIUtils.SetActive(self.GiftPanel.lab_Discount, Localization.IsAllChinese()) UIUtils.SetActive(self.GiftPanel.btn_Buy, false) UIUtils.SetActive(self.GiftPanel.lab_SoldOut, true) UIUtils.SetLabelText(self.GiftPanel.lab_SoldOut, Const_IDS["IDS_GuildShop_SoldOut"]) -- 限购 if lastGiftInfo.LimitType == LuaConst.LimitBuyType.NoLimit then UIUtils.SetActive(self.GiftPanel.group_Remain, false) else UIUtils.SetActive(self.GiftPanel.group_Remain, true) local titleLimit = lastGiftInfo.LimitType == LuaConst.LimitBuyType.Forever and UIUtils.GetLocalizedTxt(Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) or CTL.PayMall.GetLimitedTitleText(data.LimitType) local hasBuyCount = MDL.DirectGift.GetGiftBuyingCount(self.activityId, lastGiftInfo.HotPackageID) local limitNumText = lastGiftInfo.TimesLimit - hasBuyCount if hasBuyCount < lastGiftInfo.TimesLimit then limitNumText = UTL.Color.FormatGreenColor(limitNumText) else limitNumText = UTL.Color.FormatRedColor(limitNumText) end UIUtils.SetLabel(self.GiftPanel.txt_RemainCount, titleLimit .. limitNumText .. "/" .. lastGiftInfo.TimesLimit) end -- 积分 UIUtils.SetActive(self.GiftPanel.txt_Points, false) if not lastGiftInfo.IsFree then local iapStringId = giftRewardData.IapID for _, v in DataSheetManager.IAP:GetEnumerator() do if v.IapID == iapStringId then local scoreNum = 0 for _, item in ipairs (v.Item_Condition_Table) do if item.GetID == IAP_SCORE_ID then UIUtils.SetActive(self.GiftPanel.txt_Points, true) UIUtils.SetLabel(self.GiftPanel.txt_Points, string.format(UIUtils.GetLocalizedTxt(Const_IDS["IDS_TotalTopUp_Score_Tips_Giftbag"]), item.GetAmount)) break end end break end end end end end elseif self.selectedTab == 1 then self.PackagePanel.GiftScroll:ClearCells() for _, v in MDL.DirectGift.GetDirectGiftEnumerator(cfg.GiftType, self.activityId) do self.PackagePanel.GiftScroll:AddData(v, 0) end end end end function UIOACommonGiftBase:UpdateFirstGiftInfo() self.FirstGiftInfo = nil for _, v in MDL.DirectGift.GetDirectGiftEnumerator(self.PageCfg[1].GiftType, self.activityId) do self.FirstGiftInfo = v break end end function UIOACommonGiftBase:RefreshGiftTime() if not self:IsActivityOpen() then self.GiftPanel.group_Time:EndTimer() self.PackagePanel.group_Time:EndTimer() self:ActivityCloseFunc() else local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) local leftTimes = activityInfo.endTime - UTL.Time.GetServerTimestamp() self.GiftPanel.group_Time:ResetAndBeginCustomTimer(false, leftTimes, 0, nil) self.PackagePanel.group_Time:ResetAndBeginCustomTimer(false, leftTimes, 0, nil) end end function UIOACommonGiftBase:IsShowDirectGiftBaseType() for _, v in MDL.DirectGift.GetDirectGiftEnumerator(self.PageCfg[2].GiftType, self.activityId) do return true end return false end return UIOACommonGiftBase