--通用活动道具获取界面 local UIGetActivityItemPanel = UIViewClass() local OnePageCount = 3 local ActivityLimitType = 99 --活动限购类型 --region ****************************** 数据 ******************************** --获取途径对应图标 local GetActivityTypeImagePath = ConstAssetPathConfig.GetActivityTypeImagePath local GetActivityTypeImageArray ={ [CTL.OperationActivity.GetActivityType.Login] = "hqtj_icon_dl.png", [CTL.OperationActivity.GetActivityType.Mission] = "hqtj_icon_rw.png", [CTL.OperationActivity.GetActivityType.Gift] = "hqtj_icon_lb.png", [CTL.OperationActivity.GetActivityType.Gold] = "hqtj_icon_yb.png", [CTL.OperationActivity.GetActivityType.DragonJade] = "hqtj_icon_ly.png", [CTL.OperationActivity.GetActivityType.Shop] = "hqtj_icon_dp.png", [CTL.OperationActivity.GetActivityType.Special] = "hqtj_icon_lb.png", } --获取途径按钮Ids local GetActivityTypeBtnIds={ [CTL.OperationActivity.GetActivityType.Login] = "登录领取", --登录奖励 (没配这个,先占位) [CTL.OperationActivity.GetActivityType.Mission] = "IDS_ActivityItem_Turn", --前往 [CTL.OperationActivity.GetActivityType.Gift] = "IDS_ActivityItem_Turn", --前往 [CTL.OperationActivity.GetActivityType.Gold] = "IDS_ActivityItem_Buy", --购买 [CTL.OperationActivity.GetActivityType.DragonJade] = "IDS_ActivityItem_Buy", --购买 [CTL.OperationActivity.GetActivityType.Shop] = "IDS_ActivityItem_Turn", --前往 [CTL.OperationActivity.GetActivityType.Special] = "IDS_ActivityItem_Turn", --前往 } --endregion ****************************** 数据 ******************************** --region ****************************** 生命周期方法 ******************************** function UIGetActivityItemPanel:OnOpened(context) self.activityId = 0 self.activityType = 0 --外面传递的数据 if context then self.itemId = context.itemId if context.activityId then self.activityId = context.activityId self.activityType = context.activityType self.customEndTime = context.customEndTime self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) end else logging.error(LTAG.ERROR,"UIGetActivityItemPanel context is nil") return end self:InitData() self:StartRepeatFunc(self.RefreshActivityTime, 1, -1) end function UIGetActivityItemPanel:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseView() end end end function UIGetActivityItemPanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIGetActivityItemPanel:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() end end function UIGetActivityItemPanel:OnCellInit(scrollRect, index, cellTable, data) local sourcesData = DataSheetManager.ItemSource:GetDataByID(data.sourceId) if not sourcesData then logging.error(LTAG.ERROR, "itemId为:", self.itemId, "的这个物品ItemSource表中没有ID为:", data.sourceId, "的数据!!!请策划检查!!!") return end UIUtils.SetLabel(cellTable.txt_Icon, data.desc) UIUtils.SetImageByAssetBundle(cellTable.cell_Icon, self:GetActivityTypeImagePath(sourcesData.Type)) local goodData = self:GetGoodsData(sourcesData.Type) --是否显示剩余次数 if self:IsShowLeftCount(goodData) then local max = MDL.PayMall.GetLimitedCount(goodData) --最大可购买次数 local ids = "IDS_ActivityItem_RemainingToday" --今日剩余 --活动限购 if goodData.LimitBuyType == ActivityLimitType then ids = "IDS_Store_HotActivity" end local currentLeftCount = self:GetCurrentLeftCount(goodData) local currentLeftCountColorString = "" if currentLeftCount > 0 then currentLeftCountColorString = UTL.Color.FormatTextByColor(UTL.Color.Green, currentLeftCount) else currentLeftCountColorString = UTL.Color.FormatTextByColor(UTL.Color.Red, currentLeftCount) end if goodData.LimitBuyType == ActivityLimitType then --活动限购 UIUtils.SetLabel(cellTable.txt_Time, string.format("%s%s/%s",UIUtils.GetLocalizedTxt(Const_IDS[ids]),currentLeftCountColorString,max) ) else --每日限购 UIUtils.SetLabel(cellTable.txt_Time, string.FormatByIdsId(Const_IDS[ids], currentLeftCountColorString, max)) end UIUtils.SetActive(cellTable.txt_Time,true) --龙玉或元宝需要判断是否可购买,不可购买时置灰 if self:IsCanBuy(sourcesData.Type,goodData) then cellTable.btn_Get:SetGray(false) UIUtils.SetActive(cellTable.mask,false) else cellTable.btn_Get:SetGray(true) UIUtils.SetActive(cellTable.mask,true) end else UIUtils.SetActive(cellTable.txt_Time,false) --其他情况活动结束置灰 if self:IsActivityNotEnd() then cellTable.btn_Get:SetGray(false) UIUtils.SetActive(cellTable.mask,false) else cellTable.btn_Get:SetGray(true) UIUtils.SetActive(cellTable.mask,true) end end --折扣显示 local discount = goodData and goodData.ItemDiscount or 100 if discount == 100 then --不显示折扣 UIUtils.SetActive(cellTable.img_Discount,false) elseif discount == 0 then --显示免费 UIUtils.SetActive(cellTable.img_Discount,true) UIUtils.SetLabel(cellTable.txt_Discount,UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store_Free)) else --显示折扣 UIUtils.SetActive(cellTable.img_Discount,true) UIUtils.SetLabel(cellTable.txt_Discount, UTL.String.GetDiscountStrByIdsId(discount)) end UIUtils.SetLabelText(cellTable.txt_Get, Const_IDS[GetActivityTypeBtnIds[sourcesData.Type]]) end function UIGetActivityItemPanel:OnCellClicked(scrollRect, index, cellTable, target, data) --活动结束提示,否则跳转 if not self:IsActivityNotEnd() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_ActivityItem_NotAtActivityTime"]) return end local sourcesData = DataSheetManager.ItemSource:GetDataByID(data.sourceId) local goodData = self:GetGoodsData(sourcesData.Type) --龙玉或元宝需要判断是否可购买 if self:IsShowLeftCount(goodData) and not self:IsCanBuy(sourcesData.Type,goodData) then return end --礼包类型要判断是否可显示 if not self:IsCanShowGift(sourcesData.Type) then return end CTL.OperationActivity.ExecuteSourceFunctionById(self.activityId,self.activityType,data.sourceId, self.itemId) self:CloseView() end --endregion ****************************** 生命周期方法 ******************************** --region ****************************** 自定义方法 ******************************** --获取图标路径 function UIGetActivityItemPanel:GetActivityTypeImagePath(type) local path = GetActivityTypeImagePath..GetActivityTypeImageArray[type] return path end --判断活动是否还未结束(即处在解锁并开放) function UIGetActivityItemPanel:IsActivityNotEnd() return CTL.OperationActivity.IsOperationActivityTypeOpen(self.activityType) end --获取当前可购买次数 function UIGetActivityItemPanel:GetCurrentLeftCount(goodData) if goodData == nil then return 0 end local maxLeftCount = MDL.PayMall.GetLimitedCount(goodData) local purchased = MDL.PayMall.GetPurchaseItemCount(goodData) return maxLeftCount - purchased end function UIGetActivityItemPanel:GetGoodsData(type) local moneyId if type == CTL.OperationActivity.GetActivityType.Gold then moneyId = MDL.Currency.CurrencyType.GoldIngot elseif type == CTL.OperationActivity.GetActivityType.DragonJade then moneyId = MDL.Currency.CurrencyType.DragonJade end if moneyId then for _, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.ItemID == self.itemId and v.MoneyID == moneyId then return v end end end return nil end --是否显示剩余次数 function UIGetActivityItemPanel:IsShowLeftCount(goodData) if goodData == nil then return false end if goodData.LimitBuyType == 0 then return false elseif goodData.LimitBuyNum == 0 then return false elseif goodData.LimitBuyType == ActivityLimitType then --活动限购也需要显示 return true elseif goodData.LimitBuyType ~= 1 then return false end return true end --获取活动结束时间 function UIGetActivityItemPanel:GetActivityEndTime() if self:GetActivityInfo() then if self.customEndTime then return self.customEndTime end return self:GetActivityInfo().endTime end return nil end --活动数据 function UIGetActivityItemPanel:GetActivityInfo() return MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) end function UIGetActivityItemPanel:IsCanShowGift(type) if type == CTL.OperationActivity.GetActivityType.Gift then local isCanShow = CTL.OperationActivity.IsCanShowGift(self.activityType) if isCanShow then return true else --号令天下不可购买礼包时要提示 if self.activityType == MDL.OperationActivity.ActivityType.BattlefieldMuster then CTL.Tips.AddTipsMsg(Const_IDS.IDS_BattlefieldMuster_WarZoneRankTips) end return false end end return true end --龙玉、元宝 当前是否可购买,不可购买的话,返回;如果是礼包,判断是否可购买 function UIGetActivityItemPanel:IsCanBuy(type,goodData) if type == CTL.OperationActivity.GetActivityType.Gold or type == CTL.OperationActivity.GetActivityType.DragonJade then if self:IsActivityNotEnd() and self:GetCurrentLeftCount(goodData) > 0 then return true end else return true end return false end function UIGetActivityItemPanel:InitData() UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS["IDS_Item_Source"]) self:RefreshActivityTime() self.LoopScroll:ClearCells() local sourceDatas = MDL.OperationActivity.GetActivityItemSourcesById(self.itemId,MDL.OperationActivity.GetHeroTypeId(self.activityType,self.activityId)) --限购次数用完的排到最后 local temp = {} local tempNoCount = {} for i, v in ipairs(sourceDatas) do local sourcesData = DataSheetManager.ItemSource:GetDataByID(v.sourceId) local goodData = self:GetGoodsData(sourcesData.Type) if self:IsShowLeftCount(goodData) then local currentLeftCount = self:GetCurrentLeftCount(goodData) if currentLeftCount > 0 then table.insert(temp,v) else table.insert(tempNoCount,v) end else table.insert(temp,v) end end for i, v in ipairs(tempNoCount) do table.insert(temp,v) end sourceDatas = temp for i, v in ipairs(sourceDatas) do self.LoopScroll:AddData(v, 0) end self.LoopScroll:MoveIndex(0); --子项数量小时,不拖拽 if self.LoopScroll.Count <= OnePageCount then self.LoopScroll:SetMovementType(LuaConst.MovementType.UnDrag) else self.LoopScroll:SetMovementType(LuaConst.MovementType.Elastic) end end --刷新活动剩余时间 function UIGetActivityItemPanel:RefreshActivityTime() if not self:IsActivityNotEnd() then UIUtils.SetLabel(self.txt_LeftTime, UTL.Color.FormatRedColor(UIUtils.GetLocalizedTxt(Const_IDS["IDS_ActivityItem_End"]))) self:StopRepeatFunc(self.RefreshActivityTime) else local duration = self:GetActivityEndTime() - UTL.Time.GetServerTimestamp() if duration <= 0 then UIUtils.SetLabel(self.txt_LeftTime, UTL.Color.FormatRedColor(UIUtils.GetLocalizedTxt(Const_IDS["IDS_ActivityItem_End"]))) self:StopRepeatFunc(self.RefreshActivityTime) return end local remainTimeStr = UTL.Time.FormatTimeForDayOrClock(duration) UIUtils.SetLabel(self.txt_LeftTime,remainTimeStr) end end --endregion ****************************** 自定义方法 ******************************** return UIGetActivityItemPanel