From 3dbfc8458c3990066befa95fb2b0420e3a01a240 Mon Sep 17 00:00:00 2001 From: Fang Date: Fri, 1 Sep 2023 17:45:29 +0800 Subject: [PATCH] review --- .../fourteen_day/fourteen_day_exchange_ui.lua | 6 +- .../fourteen_day/fourteen_day_gift_ui.lua | 2 +- .../fourteen_day/fourteen_day_task_ui.lua | 2 - .../fourteen_day/fourteen_day_data.lua | 89 ++++++++++--------- 4 files changed, 49 insertions(+), 50 deletions(-) diff --git a/lua/app/ui/activity/fourteen_day/fourteen_day_exchange_ui.lua b/lua/app/ui/activity/fourteen_day/fourteen_day_exchange_ui.lua index c7b3cd6e..5b2f9c77 100644 --- a/lua/app/ui/activity/fourteen_day/fourteen_day_exchange_ui.lua +++ b/lua/app/ui/activity/fourteen_day/fourteen_day_exchange_ui.lua @@ -31,8 +31,7 @@ function FourteenDayExchangeUI:onLoadRootComplete() self.txNum = uiMap["fourteen_day_exchange_ui.content.item.tx_num"] self.btnAdd = uiMap["fourteen_day_exchange_ui.content.item"] - self.exchangeList = DataManager.FourteenDayData:getExchangeShowIds() - + self.exchangeList = DataManager.FourteenDayData:getExchangeShowIdsSort() self.txTitle:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_FOURTEEN_TITLE_3)) self.txDesc:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_FOURTEEN_DESC_9)) @@ -40,7 +39,7 @@ function FourteenDayExchangeUI:onLoadRootComplete() return "app/ui/activity/fourteen_day/cell/fourteen_day_exchange_cell" end) self.scrollrectComp:addRefreshCallback(function(index, cell) - cell:refresh(self.exchangeList[index]) + cell:refresh(self.exchangeList[index].id) end) self.scrollrectComp:clearCells() self.scrollrectComp:refillCells(#self.exchangeList) @@ -59,6 +58,7 @@ end function FourteenDayExchangeUI:onRefresh() DataManager.FourteenDayData:onShowExchangeView() + self.exchangeList = DataManager.FourteenDayData:getExchangeShowIdsSort() self.txNum:setText(DataManager.FourteenDayData:getExchangeItemNum()) self.scrollrectComp:updateAllCell() diff --git a/lua/app/ui/activity/fourteen_day/fourteen_day_gift_ui.lua b/lua/app/ui/activity/fourteen_day/fourteen_day_gift_ui.lua index 37982fff..6854fe52 100644 --- a/lua/app/ui/activity/fourteen_day/fourteen_day_gift_ui.lua +++ b/lua/app/ui/activity/fourteen_day/fourteen_day_gift_ui.lua @@ -34,7 +34,7 @@ function FourteenDayGiftUI:onLoadRootComplete() return "app/ui/activity/fourteen_day/cell/fourteen_day_gift_cell" end) self.scrollrectComp:addRefreshCallback(function(index, cell) - cell:refresh(self.giftList[index]) + cell:refresh(self.giftList[index].id) end) self.btnClose:addClickListener(function() diff --git a/lua/app/ui/activity/fourteen_day/fourteen_day_task_ui.lua b/lua/app/ui/activity/fourteen_day/fourteen_day_task_ui.lua index 603a3318..c9f42293 100644 --- a/lua/app/ui/activity/fourteen_day/fourteen_day_task_ui.lua +++ b/lua/app/ui/activity/fourteen_day/fourteen_day_task_ui.lua @@ -72,8 +72,6 @@ end function FourteenDayTaskUI:onRefresh() self.taskStage = DataManager.FourteenDayData:getStageTaskId(self.curStage) self.taskList = DataManager.FourteenDayData:getStageSubTaskIdsSort(self.curStage) - Logger.printTable(self.curStage) - Logger.printTable(self.taskList) self.scrollrectComp:clearCells() self.scrollrectComp:refillCells(#self.taskList) diff --git a/lua/app/userdata/activity/fourteen_day/fourteen_day_data.lua b/lua/app/userdata/activity/fourteen_day/fourteen_day_data.lua index 1a95375b..ed7228a6 100644 --- a/lua/app/userdata/activity/fourteen_day/fourteen_day_data.lua +++ b/lua/app/userdata/activity/fourteen_day/fourteen_day_data.lua @@ -10,7 +10,6 @@ function FourteenDayData:ctor() end function FourteenDayData:clear() - self.data.isDirty = false DataManager:unregisterCrossDayFunc("FourteenDayData") DataManager:unregisterTryOpenFunc("FourteenDayData") end @@ -22,10 +21,12 @@ end function FourteenDayData:init(data) data = data or GConst.EMPTY_TABLE - Logger.logHighlight("新手14天乐数据初始化") - Logger.printTable(data) + if EDITOR_MODE then + Logger.logHighlight("新手14天乐数据初始化") + Logger.printTable(data) + end - self.openTs = data.open_at // 1000 + self.openTs = data.open_at and data.open_at // 1000 or 0 self.activeDays = data.active_days or 0-- 活动开启后的登陆天数、阶段数 self.bountyStatus = data.funds self.tasksStatus = data.tasks @@ -46,10 +47,9 @@ function FourteenDayData:init(data) if not self:isActiveTime() then return end - Logger.logHighlight("14天乐跨天") + -- Logger.logHighlight("14天乐跨天") self.activeDays = self.activeDays + 1 - self:getExchangeShowIds() self:setDirty() end) -- 注册任务进度监听 @@ -417,8 +417,8 @@ end -- 是否有兑换红点 function FourteenDayData:hasExchangeRedPoint() local isFullUnlock = true - for index, id in ipairs(self:getExchangeShowIds()) do - if not self:isExchangeUnlock(id) then + for index, data in ipairs(self:getExchangeShowIdsSort()) do + if not self:isExchangeUnlock(data.id) then isFullUnlock = false break end @@ -441,31 +441,34 @@ function FourteenDayData:getExchangeCfg() end -- 获取显示的id列表 -function FourteenDayData:getExchangeShowIds() - local unlock = {} - local lock = {} - local soldOut = {} - for id, data in ipairs(self:getExchangeCfg()) do - if self:getExchangeRemainTime(id) <= 0 then - table.insert(soldOut, id) - elseif not self:isExchangeUnlock(id) then - table.insert(lock, id) - else - table.insert(unlock, id) - end - end - table.sort(unlock) - table.sort(lock) - table.sort(soldOut) +function FourteenDayData:getExchangeShowIdsSort() + local result = {} + local ids = table.keys(self:getExchangeCfg()) + for index, id in ipairs(ids) do + local sort = id + 10000000000 - return table.addArray(unlock, table.addArray(lock, soldOut)) + if self:isExchangeUnlock(id) then + sort = sort - 10000000 + end + + if self:getExchangeRemainTime(id) > 0 then + sort = sort - 10000 + end + table.insert(result, {id = id, sort = sort}) + end + + table.sort(result, function (a, b) + return a.sort < b.sort + end) + + return result end -- 获取兑换所需最小道具数 function FourteenDayData:getExchangeMinNum() local minExchange - for index, id in ipairs(self:getExchangeShowIds()) do - local temp = self:getExchangeCostNum(id) + for index, data in ipairs(self:getExchangeShowIdsSort()) do + local temp = self:getExchangeCostNum(data.id) if minExchange == nil or minExchange > temp then minExchange = temp end @@ -520,7 +523,6 @@ function FourteenDayData:onReceivedExchangeReward(id) end self.exchangeStatus[id] = self.exchangeStatus[id] + 1 - self:getExchangeShowIds() self:setDirty() end @@ -547,27 +549,26 @@ end function FourteenDayData:getGiftIdsSort() local gifts = DataManager.ShopData:getGiftsByType(PayManager.PURCHARSE_ACT_TYPE.FOURTEEN_DAY_GIFT) - local free = {} - local unSoldOut = {} - local soldOut = {} + local result = {} + local ids = table.keys(gifts) + for index, id in ipairs(ids) do + local sort = id + 10000000000 - for id, data in pairs(gifts) do - if data.recharge_id then - if self:getGiftRemainTime(id) > 0 then - table.insert(unSoldOut, id) - else - table.insert(soldOut, id) - end - else - table.insert(free, id) + if self:isFreeGift(id) then + sort = sort - 10000000 end + + if self:getGiftRemainTime(id) > 0 then + sort = sort - 10000 + end + table.insert(result, {id = id, sort = sort}) end - table.sort(free) - table.sort(unSoldOut) - table.sort(soldOut) + table.sort(result, function (a, b) + return a.sort < b.sort + end) - return table.addArray(free, table.addArray(unSoldOut, soldOut)) + return result end -- 礼包剩余购买次数