This commit is contained in:
puxuan 2025-08-13 18:31:17 +08:00
parent 8b49352830
commit 7cbd4e8ddf
2 changed files with 80 additions and 35 deletions

View File

@ -112,9 +112,9 @@ function MainComp:init()
self.chapterPageBtnDescTxs[i] = uiMap["main_comp.middle_bg.page_btn_" .. i .. ".desc_tx"]
self.chapterPageBtnMaskImgs[i] = uiMap["main_comp.middle_bg.page_btn_" .. i .. ".mask_img"]
self.chapterPageBtns[i]:addClickListener(function()
local chapterId = DataManager.ChapterData:getChapterId()
local selChapterId = ((chapterId - 1) // CHAPTER_PAGE) * CHAPTER_PAGE + i
DataManager.ChapterData:setChapterId(selChapterId)
self.chapterStage = i
local chapterId = DataManager.ChapterData:getChapterCfgByPageAndStage(self.chapterPage, self.chapterStage)
DataManager.ChapterData:setChapterId(chapterId)
self:refresh()
end)
end
@ -135,13 +135,23 @@ function MainComp:init()
ModuleManager.DailyChallengeManager:showDailyChallengeUI()
end)
self.leftArrowBtn:addClickListener(function()
local chapterId = DataManager.ChapterData:getChapterId()
DataManager.ChapterData:setChapterId(chapterId - CHAPTER_PAGE)
self.chapterPage = self.chapterPage - 1
self.chapterList = DataManager.ChapterData:getChapterList(self.chapterPage)
if self.chapterStage > #self.chapterList then
self.chapterStage = #self.chapterList
end
local chapterId = DataManager.ChapterData:getChapterCfgByPageAndStage(self.chapterPage, self.chapterStage)
DataManager.ChapterData:setChapterId(chapterId)
self:refresh()
end)
self.rightArrowBtn:addClickListener(function()
local chapterId = DataManager.ChapterData:getChapterId()
DataManager.ChapterData:setChapterId(chapterId + CHAPTER_PAGE)
self.chapterPage = self.chapterPage + 1
self.chapterList = DataManager.ChapterData:getChapterList(self.chapterPage)
if self.chapterStage > #self.chapterList then
self.chapterStage = #self.chapterList
end
local chapterId = DataManager.ChapterData:getChapterCfgByPageAndStage(self.chapterPage, self.chapterStage)
DataManager.ChapterData:setChapterId(chapterId)
self:refresh()
end)
self.leftBtn:addClickListener(function()
@ -150,6 +160,9 @@ function MainComp:init()
self.rightBtn:addClickListener(function()
ModuleManager.SummonManager:showSummonMainUI()
end)
local chapterId = DataManager.ChapterData:getChapterId()
self.chapterPage = DataManager.ChapterData:getChapterPage(chapterId)
self.chapterStage = DataManager.ChapterData:getChapterStage(chapterId)
end
function MainComp:refresh()
@ -158,6 +171,7 @@ end
function MainComp:refreshChapter(force)
local chapterId = DataManager.ChapterData:getChapterId()
self.chapterList = DataManager.ChapterData:getChapterList(self.chapterPage)
self.currChapterId = chapterId
if self.currChapterId ~= chapterId or force then
self:refreshFightBtn()
@ -170,12 +184,10 @@ function MainComp:refreshChapter(force)
end
function MainComp:refreshChapterBtn()
local chapterId = DataManager.ChapterData:getChapterId()
local chapterMaxId = DataManager.ChapterData:getMaxChapterId()
local page = (chapterId - 1) // CHAPTER_PAGE
local maxPage = chapterMaxId // CHAPTER_PAGE
self.leftArrowBtn:setActive(page > 0)
self.rightArrowBtn:setActive(page < maxPage)
local chapterNewId = DataManager.ChapterData:getNewChapterId()
local maxPage = DataManager.ChapterData:getChapterPage(chapterNewId)
self.leftArrowBtn:setActive(self.chapterPage > 1)
self.rightArrowBtn:setActive(self.chapterPage < maxPage)
end
function MainComp:refreshFightBtn()
@ -189,17 +201,23 @@ end
function MainComp:refreshChapterInfo()
local chapterId = DataManager.ChapterData:getChapterId()
local chapterMaxId = DataManager.ChapterData:getMaxChapterId()
local idx = DataManager.ChapterData:getChapterIdIdx(chapterId)
for i = 1, CHAPTER_PAGE do
if idx == i then
self.chapterSelectImg:setAnchoredPositionX((i - 3) * 98)
if i <= #self.chapterList then
self.chapterPageBtns[i]:setActive(true)
if self.chapterStage == i then
self.chapterSelectImg:setAnchoredPositionX((i - 3) * 98)
end
self.chapterPageBtnDescTxs[i]:setText(i)
local selChapterId = DataManager.ChapterData:getChapterCfgByPageAndStage(self.chapterPage, i)
self.chapterPageBtnCheckImgs[i]:setActive(selChapterId <= chapterMaxId)
self.chapterPageBtnMaskImgs[i]:setActive(selChapterId > (chapterMaxId + 1))
else
self.chapterPageBtns[i]:setActive(false)
end
self.chapterPageBtnDescTxs[i]:setText(i)
local selChapterId = ((chapterId - 1) // CHAPTER_PAGE) * CHAPTER_PAGE + i
self.chapterPageBtnCheckImgs[i]:setActive(selChapterId <= chapterMaxId)
self.chapterPageBtnMaskImgs[i]:setActive(selChapterId > (chapterMaxId + 1))
end
self.fightBtn:setActive(chapterId <= chapterMaxId + 1)
local chapterI18NInfo = I18N:getConfig("chapter")[chapterId]
if chapterI18NInfo then
self.chapterTx:setText(chapterI18NInfo.name)

View File

@ -77,21 +77,6 @@ function ChapterData:setChapterId(chapterId)
self.data.chapterId = chapterId
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 + 1
return page
end
function ChapterData:getChapterIdByPageAndIdx(page, idx)
local chapterId = (page - 1) * CHAPTER_PAGE + idx
return chapterId
end
function ChapterData:getNextChapter(chapterId)
local chapterInfo = self:getChapterCfg()[chapterId]
if chapterInfo == nil then
@ -490,4 +475,46 @@ function ChapterData:getCacheTrailAtkInfo()
return self.trailAtkInfo
end
--@region 主线章节
function ChapterData:getChapterList(chapterPage)
if self.chapterCfgList == nil then
self.chapterCfgList = {}
local cfg = self:getChapterCfg()
for i, v in ipairs(cfg) do
v.chapterId = i
self.chapterCfgList[v.chapter] = self.chapterCfgList[v.chapter] or {}
table.insert(self.chapterCfgList[v.chapter], v)
end
end
if chapterPage then
return self.chapterCfgList[chapterPage]
end
return self.chapterCfgList
end
function ChapterData:getChapterCfgByPageAndStage(chapterPage, stage)
local cfg = self:getChapterList(chapterPage)
if not cfg[stage] then
return
end
return cfg[stage].chapterId
end
function ChapterData:getChapterPage(chapterId)
local info = self:getChapterCfg()[chapterId]
if info == nil then
return 1
end
return info.chapter
end
function ChapterData:getChapterStage(chapterId)
local info = self:getChapterCfg()[chapterId]
if info == nil then
return 1
end
return info.stage
end
--@endregion
return ChapterData