主界面箱子

This commit is contained in:
puxuan 2025-07-14 20:47:59 +08:00
parent 0f782300da
commit 35440839e9
7 changed files with 185 additions and 8 deletions

View File

@ -13,6 +13,10 @@ function MaincityManager:showModuleUnlockUI()
UIManager:showUI("app/ui/main_city/module_unlock_ui", {chapterId = chapterId}) UIManager:showUI("app/ui/main_city/module_unlock_ui", {chapterId = chapterId})
end end
function MaincityManager:showChapterBoxUI(chapterId)
UIManager:showUI("app/ui/main_city/chapter_box_ui", {chapterId = chapterId})
end
-- 从登录界面第一次进入主城 -- 从登录界面第一次进入主城
function MaincityManager:firstEnterMainCity() function MaincityManager:firstEnterMainCity()
if (EDITOR_MODE or not Platform:getIsPublishChannel()) and LocalData:getTutorialSkip() > 0 then if (EDITOR_MODE or not Platform:getIsPublishChannel()) and LocalData:getTutorialSkip() > 0 then

View File

@ -0,0 +1,56 @@
local ChapterBoxCell = class("ChapterBoxCell", BaseCell)
function ChapterBoxCell:init()
local uiMap = self:getUIMap()
self.titleTx = uiMap["cell.title_tx"]
self.claimBtn = uiMap["cell.claim_btn"]
self.claimBtnTx = uiMap["cell.claim_btn.text"]
self.claimImg = uiMap["cell.claim_img"]
self.claimImgTx = uiMap["cell.claim_img.text"]
self.rewardCells = {}
for i = 1, 2 do
self.rewardCells[i] = CellManager:addCellComp(uiMap["cell.reward_cell_" .. i], GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
end
self.claimImgTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_DONE))
self.claimBtn:addClickListener(function()
ModuleManager.ChapterManager:openBox(self.chapterId, self.idx)
end)
end
function ChapterBoxCell:refresh(chapterId, idx)
local list = DataManager.ChapterData:getChapterBoxRewardList(chapterId)
local rewardCfg = list[idx]
if rewardCfg == nil then
return
end
self.chapterId = chapterId
self.idx = idx
self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.GET_REWARDS_DESC, idx))
local hadGot = DataManager.ChapterData:getChapterBoxRewardGot(chapterId, idx)
if hadGot then
self.claimBtn:setActive(false)
self.claimImg:setActive(true)
else
self.claimBtn:setActive(true)
self.claimImg:setActive(false)
if DataManager.ChapterData:boxCanGet(chapterId, idx) then
self.claimBtn:setTouchEnable(true)
self.claimBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_blue_1")
self.claimBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM))
else
self.claimBtn:setTouchEnable(false)
self.claimBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_1")
self.claimBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM))
end
end
for i = 1, 2 do
self.rewardCells[i]:refreshByConfig(rewardCfg[i], hadGot, hadGot)
end
end
return ChapterBoxCell

View File

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

View File

@ -0,0 +1,73 @@
local ChapterBoxUI = class("ChapterBoxUI", BaseUI)
function ChapterBoxUI:isFullScreen()
return false
end
function ChapterBoxUI:getPrefabPath()
return "assets/prefabs/ui/main_city/chapter_box_ui.prefab"
end
function ChapterBoxUI:ctor(params)
self.chapterId = params.chapterId
-- local chapterId = DataManager.ChapterData:getChapterId()
-- local chapterMaxId = DataManager.ChapterData:getMaxChapterId()
-- local idx = DataManager.ChapterData:getChapterIdIdx(chapterId)
end
function ChapterBoxUI:onLoadRootComplete()
local uiMap = self.root:genAllChildren()
uiMap["chapter_box_ui.bg.close_btn"]:addClickListener(function()
self:closeUI()
end)
self.selImg = uiMap["chapter_box_ui.bg.sel_img"]
self.maxWaveTx = uiMap["chapter_box_ui.bg.max_wave_tx"]
-- uiMap["chapter_box_ui.bg.title_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_TRIAL_DESC_1))
uiMap["chapter_box_ui.bg.title_tx"]:setText("通关奖励")
self.page = DataManager.ChapterData:getChapterIdPage(self.chapterId)
self.pageIdx = DataManager.ChapterData:getChapterIdIdx(self.chapterId)
self.chapterTxs = {}
for i = 1, 5 do
self.chapterTxs[i] = uiMap["chapter_box_ui.bg.chapter_tx_" .. i]
self.chapterTxs[i]:addClickListener(function()
if self.pageIdx == i then
return
end
self.pageIdx = i
self:onRefresh()
end)
end
self.scrollRect = uiMap["chapter_box_ui.bg.scrollrect"]
self.scrollRectComp = self.scrollRect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
self.scrollRectComp:addInitCallback(function()
return "app/ui/main_city/cell/chapter_box_cell"
end)
self.scrollRectComp:addRefreshCallback(function(index, cell)
cell:refresh(self.chapterId, index)
end)
self.scrollRectComp:setTotalCount(0)
self:bind(DataManager.ChapterData, "isDirty", function()
self:onRefresh()
end)
end
function ChapterBoxUI:onRefresh()
self.chapterId = DataManager.ChapterData:getChapterIdByPageAndIdx(self.page, self.pageIdx)
for i = 1, 5 do
self.chapterTxs[i]:setText(self.page .. "-" .. i)
end
self.selImg:setAnchoredPositionX((self.pageIdx - 3) * 118)
local list = DataManager.ChapterData:getChapterBoxRewardList(self.chapterId)
self.scrollRectComp:refillCells(#list)
self.maxWaveTx:setText(I18N:getGlobalText(I18N.GlobalConst.CHAPTER_DESC_1, DataManager.ChapterData:getChapterMaxWave(self.chapterId)))
end
return ChapterBoxUI

View File

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

View File

@ -118,7 +118,16 @@ function MainComp:init()
self:refresh() self:refresh()
end) end)
end end
-- MaincityManager:showChapterBoxUI(chapterId)
uiMap["main_comp.middle_bg.box_btn"]:addClickListener(function()
local chapterId = DataManager.ChapterData:getChapterId()
ModuleManager.MaincityManager:showChapterBoxUI(chapterId)
end)
uiMap["main_comp.middle_bg.info_btn"]:addClickListener(function()
local chapterId = DataManager.ChapterData:getChapterId()
ModuleManager.MaincityManager:showChapterBoxUI(chapterId)
end)
uiMap["main_comp.arena_btn"]:addClickListener(function() uiMap["main_comp.arena_btn"]:addClickListener(function()
ModuleManager.ArenaManager:reqArenaInfo(true) ModuleManager.ArenaManager:reqArenaInfo(true)
end) end)
@ -181,7 +190,7 @@ end
function MainComp:refreshChapterInfo() function MainComp:refreshChapterInfo()
local chapterId = DataManager.ChapterData:getChapterId() local chapterId = DataManager.ChapterData:getChapterId()
local chapterMaxId = DataManager.ChapterData:getMaxChapterId() local chapterMaxId = DataManager.ChapterData:getMaxChapterId()
local idx = (chapterId - 1) % CHAPTER_PAGE + 1 local idx = DataManager.ChapterData:getChapterIdIdx(chapterId)
for i = 1, CHAPTER_PAGE do for i = 1, CHAPTER_PAGE do
if idx == i then if idx == i then
self.chapterSelectImg:setAnchoredPositionX((i - 3) * 98) self.chapterSelectImg:setAnchoredPositionX((i - 3) * 98)

View File

@ -2,6 +2,7 @@ local ChapterData = class("ChapterData", BaseData)
ChapterData.MIN_CHAPTER_ID = 1 ChapterData.MIN_CHAPTER_ID = 1
local MIN_CHAPTER_ID = ChapterData.MIN_CHAPTER_ID local MIN_CHAPTER_ID = ChapterData.MIN_CHAPTER_ID
local CHAPTER_PAGE = 5
function ChapterData:ctor() function ChapterData:ctor()
self.data.chapterId = MIN_CHAPTER_ID self.data.chapterId = MIN_CHAPTER_ID
@ -76,6 +77,21 @@ function ChapterData:setChapterId(chapterId)
self.data.chapterId = chapterId self.data.chapterId = chapterId
end end
function ChapterData:getChapterIdIdx(chapterId)
local idx = (chapterId - 1) % CHAPTER_PAGE + 1
return idx
end
function ChapterData:getChapterIdPage(chapterId)
local page = (chapterId - 1) // CHAPTER_PAGE
return page
end
function ChapterData:getChapterIdByPageAndIdx(page, idx)
local chapterId = page * CHAPTER_PAGE + idx
return chapterId
end
function ChapterData:getNextChapter(chapterId) function ChapterData:getNextChapter(chapterId)
local chapterInfo = self:getChapterCfg()[chapterId] local chapterInfo = self:getChapterCfg()[chapterId]
if chapterInfo == nil then if chapterInfo == nil then
@ -174,16 +190,15 @@ function ChapterData:boxCanGet(chapterId, index)
return needWave <= curMaxWave return needWave <= curMaxWave
end end
function ChapterData:getChapterBoxRewards(chapterId, index) function ChapterData:getChapterBoxRewardList(chapterId)
chapterId = chapterId or self:getChapterId() local list = {}
if not self:getChapterBoxNum(chapterId, index) then
return
end
local cfg = self:getChapterCfg()[chapterId] local cfg = self:getChapterCfg()[chapterId]
if cfg then if cfg then
return cfg["box_reward_" .. index] for i = 1, 3 do
table.insert(list, cfg["box_reward_" .. i])
end
end end
return list
end end
function ChapterData:getChapterMaxWave(chapterId) function ChapterData:getChapterMaxWave(chapterId)