This commit is contained in:
CloudJ 2023-05-22 16:14:57 +08:00
parent 99fedebb96
commit aec28d95e8
13 changed files with 531 additions and 22 deletions

View File

@ -20,6 +20,7 @@ function DataManager:init()
self:initManager("DailyTaskData", "app/userdata/task/daily_task_data") self:initManager("DailyTaskData", "app/userdata/task/daily_task_data")
self:initManager("IdleData", "app/userdata/idle/idle_data") self:initManager("IdleData", "app/userdata/idle/idle_data")
-- self:initManager("SevenDayData", "app/userdata/activity/seven_day/seven_day_data") -- self:initManager("SevenDayData", "app/userdata/activity/seven_day/seven_day_data")
self:initManager("ShopData", "app/userdata/idle/shop_data")
end end
function DataManager:initManager(name, path) function DataManager:initManager(name, path)
@ -89,6 +90,7 @@ function DataManager:clear()
self.DailyTaskData:clear() self.DailyTaskData:clear()
self.IdleData:clear() self.IdleData:clear()
-- self.SevenDayData:clear() -- self.SevenDayData:clear()
self.ShopData:clear()
ModuleManager.TaskManager:clear() ModuleManager.TaskManager:clear()
end end
@ -120,6 +122,11 @@ function DataManager:initWithServerData(data)
self.DailyTaskData:init(data.task_daily) self.DailyTaskData:init(data.task_daily)
self.IdleData:init(data.idle) self.IdleData:init(data.idle)
-- self.SevenDayData:init(data.SevenDayData) -- self.SevenDayData:init(data.SevenDayData)
self.ShopData:initActGift(data.act) -- 礼包购买信息
self.ShopData:initMallDaily(data.mall_daily) -- 每日特惠
self.ShopData:initCommonDailyGoldGift(data.mall_idle) -- 常驻金币礼包
self.ShopData:initGrowUpGift(data.act_grow_up_gift) -- 成长礼包
self.ShopData:initLevelUpGift(data.act_level_up_gift) -- 助力礼包
self:scheduleGlobal() self:scheduleGlobal()
self:checkDataBind() self:checkDataBind()

View File

@ -1,10 +1,19 @@
local ShopConst = class("ShopConst", BaseModule) local ShopConst = class("ShopConst", BaseModule)
ShopConst.ACT_GIFT_TYPE = { -- ShopConst.ACT_GIFT_TYPE = {
FIRST_RECHARGE_GIFT = 1, -- 首冲 -- FIRST_RECHARGE_GIFT = 1, -- 首冲
COIN_GIFT = 2, -- 金币不足礼包 -- COIN_GIFT = 2, -- 金币不足礼包
BEGINNER_GIFT = 4, -- BEGINNER_GIFT = 4,
LEVEL_GIFT = 5, -- 助力礼包 -- LEVEL_GIFT = 5, -- 助力礼包
-- }
-- 服务器pb对应的类型
ShopConst.GIFT_TYPE = {
ACT_GIFT = 1,
GOLD_PIG = 2,
CHAPTER_GIFT = 3,
GROW_UP_GIFT = 4,
MALL_TREASURE = 5,
} }
ShopConst.ACT_GIFT_ID = { ShopConst.ACT_GIFT_ID = {

View File

@ -4,4 +4,34 @@ function ShopManager:showBoxHeroUI()
UIManager:showUI("app/ui/shop/box_hero_ui") UIManager:showUI("app/ui/shop/box_hero_ui")
end end
-- 购买每日特惠商品
function ShopManager:buyMallDailyGift(id)
-- TODOJ
-- if not DataManager.SevenDayData:getIsOpen() then
-- GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_DESC))
-- return
-- end
-- if DataManager.SevenDayData:getStepCollected(id) then
-- return
-- end
-- if not DataManager.SevenDayData:canClaimStepTask(id) then
-- return
-- end
-- local params = {id = id}
-- local responseData = {
-- rewards = {GFunc.getRewardTableByReward(DataManager.SevenDayData:getStepReward(id))},
-- Claimed = {
-- [id] = true
-- }
-- }
-- self:sendMessage(ProtoMsgType.FromMsgEnum.SevenDayRewardReq, params, responseData, self.claimStepRewardFinish, BIReport.ITEM_GET_TYPE.SEVEN_DAY_STEP_REWARD)
end
function ShopManager:buyMallDailyGiftFinish(result)
-- TODOJ
end
return ShopManager return ShopManager

View File

@ -43,7 +43,7 @@ function CoinSellCell:refresh()
local actGiftId = 20102 local actGiftId = 20102
local cfgInfo = ConfigManager:getConfig("act_gift")[actGiftId] local cfgInfo = ConfigManager:getConfig("act_gift")[actGiftId]
-- 超值 -- 超值
self.offText:setText(tostring(cfgInfo.value * 100) .. "%") self.offText:setText(tostring(cfgInfo.value) .. "%")
-- 限购 -- 限购
self.limitText:setText("限购" .. tostring(cfgInfo.limit) .. "次TD") -- TODOJ self.limitText:setText("限购" .. tostring(cfgInfo.limit) .. "次TD") -- TODOJ
-- 标题 -- 标题

View File

@ -1,10 +1,79 @@
local GemCell = class("GemCell", BaseCell) local GemCell = class("GemCell", BaseCell)
function GemCell:init() function GemCell:init()
local uiMap = self:getUIMap() local uiMap = self.baseObject:genAllChildren()
self.bg = uiMap["gem_cell.bg"]
self.icon = uiMap["gem_cell.icon"]
self.nameText = uiMap["gem_cell.num"]
self.priceText = uiMap["gem_cell.price"]
self.doubleNode = uiMap["gem_cell.double_bg"]
self.doubleDesc = uiMap["gem_cell.double_bg.desc"]
self.doubleText = uiMap["gem_cell.double_bg.num"]
self.doubleImg = uiMap["gem_cell.double_bg.icon"]
self.doubleOriginText = uiMap["gem_cell.double_bg.origin_num"]
self.doubleOriginLine = uiMap["gem_cell.double_bg.line"]
self.adNode = uiMap["gem_cell.ad"]
self.adImg = uiMap["gem_cell.ad.image"]
self.adText = uiMap["gem_cell.ad.desc"]
self.sellOutText = uiMap["gem_cell.sell_out"]
self.sellOutText:setText("已购买TD") -- TODOJ
end end
function GemCell:refresh(index, info) function GemCell:refresh(id, cfgInfo, bought, clickCallback)
local rechargeId = cfgInfo.recharge_id
local reward = cfgInfo.reward[1]
local limit = cfgInfo.limit or 0
local adMaxTimes = cfgInfo.daily or 0
local isFree = rechargeId == nil
local hasDoubleTimes = bought < limit
local leftDoubleTimes = limit - bought
if isFree then -- 免费广告
self.adNode:setVisible(true)
self.price:setVisible(false)
GFunc.setAdsSprite(self.adImg)
local adLeftCount = adMaxTimes - bought
if adLeftCount > 0 then
self.adText:setText("免费(" .. tostring(adLeftCount) .. ")TD") -- TODOJ
GFunc.centerImgAndTx(self.adImg, self.adText, 20)
self.sellOutText:setVisible(false)
self:getBaseObject():addRedPoint(95, 130, 0.5)
else
self.adNode:setVisible(false)
self.sellOutText:setVisible(true)
self:getBaseObject():removeRedPoint()
end
else -- 付费
self.adNode:setVisible(false)
self.price:setVisible(true)
if hasDoubleTimes then -- 有双倍效果
self.doubleNode:setVisible(true)
self.doubleDesc:setText("剩余次数:" .. tostring(leftDoubleTimes) .. "TD") -- TODOJ
self.doubleText:setText("+" .. tostring(reward.num * 2))
GFunc.centerImgAndTx(self.doubleImg, self.doubleText, 20)
self.doubleOriginText:setText(reward.num)
else
self.doubleNode:setVisible(false)
end
end
self.nameText:setText(reward.num)
self.priceText:setText(GFunc.getFormatPrice(rechargeId))
if clickCallback then
self:addClickListener(function()
clickCallback(cfgInfo.id)
end)
end
end
function GemCell:setVisible(visible)
self.baseObject:setVisible(visible)
end end
return GemCell return GemCell

View File

@ -9,7 +9,7 @@ function GemSellCell:init()
self.cellHeight = 0 self.cellHeight = 0
local cellHeight = nil local cellHeight = nil
local cfg = ConfigManager:getConfig("mall_treasure") local cfg = ConfigManager:getConfig("mall_treasure")
for i = 1, 12 do for i = 1, 9 do
local cell = uiMap["gem_sell_cell.cell_" .. i] local cell = uiMap["gem_sell_cell.cell_" .. i]
if cellHeight == nil then if cellHeight == nil then
local w, h = cell:fastGetSizeDelta() local w, h = cell:fastGetSizeDelta()
@ -32,7 +32,11 @@ end
function GemSellCell:refresh() function GemSellCell:refresh()
local cfg = ConfigManager:getConfig("mall_treasure") local cfg = ConfigManager:getConfig("mall_treasure")
for k, v in ipairs(self.cells) do for k, v in ipairs(self.cells) do
v:refresh(k, cfg[k]) local id = k -- 目前配置表结构如此
local buyCount = DataManager.ShopData:getActGiftBuyCount(GConst.ShopConst.GIFT_TYPE.MALL_TREASURE, id)
v:refresh(id, cfg[id], buyCount, function(id)
self:onClickGift(id)
end)
end end
end end
@ -48,4 +52,8 @@ function GemSellCell:setVisible(visible)
self.baseObject:setVisible(visible) self.baseObject:setVisible(visible)
end end
function GemSellCell:onClickGift(id)
Logger.logHighlight("Click id:%s", id) -- TODOJ
end
return GemSellCell return GemSellCell

View File

@ -1,10 +1,71 @@
local GoldCell = class("GoldCell", BaseCell) local GoldCell = class("GoldCell", BaseCell)
function GoldCell:init() function GoldCell:init()
local uiMap = self:getUIMap() local uiMap = self.baseObject:genAllChildren()
self.bg = uiMap["gold_cell.bg"]
self.icon = uiMap["gold_cell.icon"]
self.nameText = uiMap["gold_cell.num"]
self.costNode = uiMap["gold_cell.cost"]
self.costImg = uiMap["gold_cell.cost.icon"]
self.costText = uiMap["gold_cell.cost.num"]
self.adNode = uiMap["gold_cell.ad"]
self.adImg = uiMap["gold_cell.ad.image"]
self.adText = uiMap["gold_cell.ad.desc"]
self.descText = uiMap["gold_cell.desc"]
self.sellOutText = uiMap["gold_cell.sell_out"]
self.sellOutText:setText("已购买TD") -- TODOJ
end end
function GoldCell:refresh(index, info) function GoldCell:refresh(id, cfgInfo)
local idleTime = cfgInfo.idel_time
local cost = cfgInfo.cost
local adMaxTimes = cfgInfo.daily or 0
local goldNum = DataManager.ShopData:getCommonDailyCoinNum(idleTime)
local isFree = adMaxTimes > 0
if isFree then -- 免费广告
self.adNode:setVisible(true)
self.costNode:setVisible(false)
GFunc.setAdsSprite(self.adImg)
local bought = DataManager.ShopData:getCommonDailyCoinAdBuyCount() -- 金币礼包购买次数
local adLeftCount = adMaxTimes - bought
if adLeftCount > 0 then
self.adText:setText("免费(" .. tostring(adLeftCount) .. ")TD") -- TODOJ
GFunc.centerImgAndTx(self.adImg, self.adText, 20)
self.sellOutText:setVisible(false)
self:getBaseObject():addRedPoint(95, 130, 0.5)
else
self.adNode:setVisible(false)
self.sellOutText:setVisible(true)
self:getBaseObject():removeRedPoint()
end
else -- 付费
self.adNode:setVisible(false)
self.costNode:setVisible(true)
self.costText:setText(tostring(cost.num))
GFunc.centerImgAndTx(self.costImg, self.costText, 20)
end
self.nameText:setText(GFunc.num2Str(goldNum))
self.descText:setText("金币礼包:" .. tostring(id) .. "TD") -- TODOJ
self:addClickListener(function()
self:onClickGift(cfgInfo.id)
end)
end
function GoldCell:setVisible(visible)
self.baseObject:setVisible(visible)
end
function GoldCell:onClickGift(id)
Logger.logHighlight("onClick:%s", id)
end end
return GoldCell return GoldCell

View File

@ -0,0 +1,93 @@
local HotCell = class("HotCell", BaseCell)
function HotCell:init()
local uiMap = self.baseObject:genAllChildren()
self.bg = uiMap["hot_cell.bg"]
self.icon = uiMap["hot_cell.icon"]
self.nameText = uiMap["hot_cell.num"]
self.adNode = uiMap["hot_cell.ad"]
self.adImg = uiMap["hot_cell.ad.image"]
self.adText = uiMap["hot_cell.ad.desc"]
self.costNode = uiMap["hot_cell.ad.cost"]
self.costImg = uiMap["hot_cell.ad.cost.icon"]
self.costText = uiMap["hot_cell.ad.cost.num"]
self.heroNode = uiMap["hot_cell.hero"]
self.heroCell = CellManager:addCellComp(uiMap["hot_cell.hero.hero_cell"], GConst.TYPEOF_LUA_CLASS.HERO_CELL)
self.heroNumText = uiMap["hot_cell.hero.num_tx"]
self.sellOutText = uiMap["hot_cell.sell_out"]
self.sellOutText:setText("已购买TD") -- TODOJ
end
function HotCell:refresh(data, clickCallback)
local id = data.id
local index = data.good_index
local bought = data.bought
local cfgInfo = ConfigManager:getConfig("mall_daily")[id]
local reward = cfgInfo.good[index]
local cost = cfgInfo.cost[index]
local isHeroReward = ConfigManager:getConfig("hero")[reward.id] ~= nil
local isAdCost = cost ~= nil
if isHeroReward then
self.icon:setVisible(false)
self.heroNode:setVisible(true)
self.heroCell:refreshWithCfgId(reward.id)
self.heroNumText:setText(reward.num)
self.nameText:setText(ModuleManager.ItemManager:getItemName(reward.id))
else
self.icon:setVisible(false)
self.heroNode:setVisible(true)
self.icon:setSprite(GFunc.getIconRes(cost.id))
self.nameText:setText(cost.num)
end
if isAdCost then -- 广告商品
self.adNode:setVisible(true)
self.costNode:setVisible(false)
GFunc.setAdsSprite(self.adImg)
local adLeftCount = DataManager.ShopData:getMallDailyFirstItemAdMaxCount() - bought
if adLeftCount > 0 then
self.adText:setText("免费(" .. tostring(adLeftCount) .. ")TD") -- TODOJ
GFunc.centerImgAndTx(self.adImg, self.adText, 20)
self.sellOutText:setVisible(false)
self:getBaseObject():addRedPoint(95, 130, 0.5)
else
self.adNode:setVisible(false)
self.sellOutText:setVisible(true)
self:getBaseObject():removeRedPoint()
end
else -- (2,3)金币(4,5,6)钻石商品
self.adNode:setVisible(false)
self.costNode:setVisible(true)
local leftCount = DataManager.ShopData:getMallDailyGoodsMaxCount() - bought
if leftCount > 0 then
self.costImg:setSprite(GFunc.getIconRes(cost.id))
self.costText:setText(cost.num)
GFunc.centerImgAndTx(self.costImg, self.costText, 20)
self.sellOutText:setVisible(false)
else
self.costNode:setVisible(false)
self.sellOutText:setVisible(true)
end
end
if clickCallback then
self:addClickListener(function()
clickCallback(cfgInfo.id)
end)
end
end
function HotCell:setVisible(visible)
self.baseObject:setVisible(visible)
end
return HotCell

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f0d28230c07310f42b57246a5307c8f1
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}

View File

@ -1,4 +1,6 @@
local HotSellCell = class("HotSellCell", BaseCell) local HotSellCell = class("HotSellCell", BaseCell)
local HOT_CELL = "app/ui/shop/cell/hot_cell"
local CELL_COUNT = 6
function HotSellCell:init() function HotSellCell:init()
local uiMap = self.baseObject:genAllChildren() local uiMap = self.baseObject:genAllChildren()
@ -9,17 +11,55 @@ function HotSellCell:init()
end) end)
self.timeTx = uiMap["hot_sell_cell.time_tx"] self.timeTx = uiMap["hot_sell_cell.time_tx"]
self.cells = { self.cells = {}
uiMap["hot_sell_cell.cell_1"], for i = 1, CELL_COUNT do
uiMap["hot_sell_cell.cell_2"], local cellObj = uiMap["hot_sell_cell.cell_" .. i]
uiMap["hot_sell_cell.cell_3"], local cell = cellObj:addLuaComponent(HOT_CELL)
uiMap["hot_sell_cell.cell_4"], table.insert(self.cells, cell)
uiMap["hot_sell_cell.cell_5"], end
uiMap["hot_sell_cell.cell_6"],
} self.refreshBtn = uiMap["hot_sell_cell.refresh_btn"]
self.refreshAdImg = uiMap["hot_sell_cell.refresh_btn.ad_img"]
self.refreshGemImg = uiMap["hot_sell_cell.refresh_btn.gem_img"]
self.refreshText = uiMap["hot_sell_cell.refresh_btn.desc"]
self.refreshBtn:addClickListener(function()
self:onClickRefresh()
end)
end end
function HotSellCell:refresh() function HotSellCell:refresh()
local goods = DataManager.ShopData:getMallDailyGoods()
local freeRefreshCount = DataManager.ShopData:getMallDailyAdLeftCount() -- 免费刷新次数
local gemRefreshCount = DataManager.ShopData:getMallDailyDiamondLeftCount() -- 钻石刷新次数
local gemRefreshCost = DataManager.ShopData:getMallDailyDiamondResetCost() -- 钻石刷新消耗
if freeRefreshCount > 0 then
self.refreshBtn:setVisible(true)
self.refreshAdImg:setVisible(true)
GFunc.setAdsSprite(self.refreshAdImg)
self.refreshGemImg:setVisible(false)
self.refreshText:setText("刷新TD") -- TODOJ
elseif gemRefreshCount > 0 then
self.refreshBtn:setVisible(true)
self.refreshAdImg:setVisible(false)
self.refreshGemImg:setVisible(true)
self.refreshText:setText(gemRefreshCost)
else
self.refreshBtn:setVisible(false)
end
local goodsCount = goods and #goods or 0
for i = 1, CELL_COUNT do
if i <= goodsCount then
self.cells[i]:setVisible(true)
self.cells[i]:refresh(goods[i], function(id)
self:onClickGift(id)
end)
else
self.cells[i]:setVisible(false)
end
end
end end
function HotSellCell:getCellHeight() function HotSellCell:getCellHeight()
@ -34,4 +74,22 @@ function HotSellCell:setVisible(visible)
self.baseObject:setVisible(visible) self.baseObject:setVisible(visible)
end end
function HotSellCell:onClickGift(id)
Logger.logHighlight("Click id:%s", id) -- TODOJ
end
function HotSellCell:onClickRefresh()
local freeRefreshCount = DataManager.ShopData:getMallDailyAdLeftCount() -- 免费刷新次数
local gemRefreshCount = DataManager.ShopData:getMallDailyDiamondLeftCount() -- 钻石刷新次数
local gemRefreshCost = DataManager.ShopData:getMallDailyDiamondResetCost() -- 钻石刷新消耗
if freeRefreshCount > 0 then
-- TODOJ
elseif gemRefreshCount > 0 then
if GFunc.checkCost(GConst.ItemConst.ITEM_ID_GEM, gemRefreshCost, true) then
-- TODOJ
end
end
end
return HotSellCell return HotSellCell

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 563addd520dbcd0449b37156cd903f9d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,146 @@
local ShopData = class("ShopData", BaseData)
function ShopData:ctor()
self.data.isDirty = false
end
function ShopData:clear()
end
-- 通用礼包部分 **********************************************************************************************
-- 初始化购买的礼包
function ShopData:initActGift(act)
act = act or {}
self.gifts = act.gifts or {}
-- 转为map结构
for _, gift in ipairs(self.gifts) do
local giftType = gift.act_type
local giftId = gift.id
local buyCount = gift.buy_count
local latestBuyTime = gift.latest_buy_at -- 最后一次购买时间
local latestOrderUuid = gift.latest_order_uuid -- 正在支付的订单ID
if not self.giftMap then
self.giftMap = {}
end
if not self.giftMap[giftType] then
self.giftMap[giftType] = {}
end
self.giftMap[giftType][giftId] = gift
end
end
-- 已购买的礼包
function ShopData:getActGifts()
return self.gifts
end
function ShopData:getActGiftMap()
return self.giftMap
end
function ShopData:getActGiftMapByType(actType)
return self.giftMap and self.giftMap[actType]
end
function ShopData:getActGiftDetailData(actType, actId)
if self.giftMap then
if self.giftMap[actType] then
return self.giftMap[actType][actId]
end
end
return nil
end
-- 获得一个礼包的已购次数
function ShopData:getActGiftBuyCount(actType, actId)
local data = self:getActGiftDetailData(actType, actId)
if data then
return data.latest_buy_at
end
return 0
end
-- 通用礼包结束 ----------------------------------------------------------------------------------------------
-- 每日特惠部分 **********************************************************************************************
-- 初始化每日特惠
function ShopData:initMallDaily(mallDaily)
mallDaily = mallDaily or {}
self.mallDailyAdResetCount = mallDaily.ad_reset_Count or 0
self.mallDailyDiamondResetCount = mallDaily.diamond_reset_Count or 0
self.mallDailyGoods = mallDaily.goods or {} -- {id,good_index,bought}
end
function ShopData:getMallDailyAdResetCount()
return self.mallDailyAdResetCount
end
function ShopData:getMallDailyAdLeftCount()
return 1 - self.mallDailyAdResetCount -- TODOJ 目前无配置表
end
function ShopData:getMallDailyDiamondResetCount()
return self.mallDailyDiamondResetCount
end
function ShopData:getMallDailyDiamondLeftCount()
return 1 - self.mallDailyDiamondResetCount -- TODOJ 目前无配置表
end
function ShopData:getMallDailyGoods()
return self.mallDailyGoods
end
function ShopData:getMallDailyDiamondResetCost()
return 30 -- TODOJ 目前无配置表
end
-- 每日特惠 广告商品最大购买次数
function ShopData:getMallDailyFirstItemAdMaxCount()
return 5 -- TODOJ 目前无配置表
end
-- 每日特惠 常规商品最大购买次数
function ShopData:getMallDailyGoodsMaxCount()
return 1 -- TODOJ 目前无配置表
end
-- 每日特惠结束 ----------------------------------------------------------------------------------------------
-- 常驻金币礼包 **********************************************************************************************
function ShopData:initCommonDailyGoldGift(mallIdle)
mallIdle = mallIdle or {}
self.commonDailyGoldBuyCount = mallIdle[1] or 0 -- 已购的金币广告礼包次数
end
function ShopData:getCommonDailyCoinAdBuyCount()
return self.commonDailyGoldBuyCount
end
-- 金币礼包当前每小时挂机奖励
function ShopData:getCommonDailyCoinNum(time)
local constCfg = ConfigManager:getConfig("const")
local coinPerTime = constCfg.idle_gold_drop_time.value
local chapterId = DataManager.ChapterData:getMaxChapterId()
local cfg = ConfigManager:getConfig("chapter")[chapterId]
if cfg then
return math.floor(cfg.idle_gold * (time // coinPerTime))
else
return 0
end
end
-- 常驻金币礼包结束 ----------------------------------------------------------------------------------------------
-- 初始化成长礼包
function ShopData:initGrowUpGift(growUpGift)
end
-- 初始化助力礼包
function ShopData:initLevelUpGift(levelUpGift)
end
return ShopData

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fa421edcddf5a9644af17695224e8a5f
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3}