PGRData/Script/matrix/xentity/xpurchase/XPurchaseRecommendManager.lua
2024-09-01 22:49:41 +02:00

88 lines
No EOL
2.9 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local XPurchaseRecommend = require("XEntity/XPurchase/XPurchaseRecommend")
local XPurchaseRecommendManager = XClass(nil, "XPurchaseRecommendManager")
---@class XPurchaseRecommendManager
function XPurchaseRecommendManager:Ctor()
self.RecommendConfigDic = {}
end
-- { XPurchaseRecommend, XPurchaseRecommend }
function XPurchaseRecommendManager:GetRecommends()
local result = {}
local configs = self:GetPurchaseRecommendConfigs()
for _, config in ipairs(configs) do
---@type XPurchaseRecommend
local purchaseRecommend = XPurchaseRecommend.New(config.Id)
--[[
local package = purchaseRecommend:GetPurchasePackage()
local skipSteps = purchaseRecommend:GetSkipSteps()
-- 拿不到礼包数据同时跳转步骤为0直接跳过
if XTool.IsTableEmpty(package) and #skipSteps <= 0 then
goto continue
end
]]
-- 时间已经过去,直接跳过
if not purchaseRecommend:GetIsInTime() then
goto continue
end
-- v1.31增加配置显示条件
if config.ConditionId and config.ConditionId ~= 0 and not XConditionManager.CheckCondition(config.ConditionId) then
goto continue
end
if config.IsLockShow or not purchaseRecommend:GetIsSellOut() then
table.insert(result, purchaseRecommend)
end
:: continue ::
end
return result
end
function XPurchaseRecommendManager:CheckHasRecommend()
return #self:GetRecommends() > 0
end
function XPurchaseRecommendManager:RequestServerData(cb)
local uiTypes = XPurchaseConfigs.GetUiTypesByUiPurchaseTopType(XPurchaseConfigs.UiPurchaseTopType.Recommend)
XDataCenter.PurchaseManager.GetPurchaseListRequest(uiTypes, cb)
end
function XPurchaseRecommendManager:GetIsShowRedPoint()
local recommends = self:GetRecommends()
for _, value in pairs(recommends) do
if value:GetIsShowRedPoint() then
return true
end
end
return false
end
function XPurchaseRecommendManager:AddOrModifyRecommendConfigs(addOrModifyConfigs)
if addOrModifyConfigs == nil then return end
for _, config in pairs(addOrModifyConfigs) do
self.RecommendConfigDic[config.Id] = config
end
end
function XPurchaseRecommendManager:DeleteRecommendConfigs(removeIds)
if removeIds == nil then return end
for _, id in ipairs(removeIds) do
self.RecommendConfigDic[id] = nil
end
end
function XPurchaseRecommendManager:GetPurchaseRecommendConfig(id)
return self.RecommendConfigDic[id]
end
function XPurchaseRecommendManager:GetPurchaseRecommendConfigs()
local result = {}
for _, config in pairs(self.RecommendConfigDic) do
table.insert(result, config)
end
table.sort(result, function(aConfig, bConfig)
return aConfig.Id < bConfig.Id
end)
return result
end
return XPurchaseRecommendManager