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