187 lines
6.0 KiB
Lua
187 lines
6.0 KiB
Lua
local IdleDropUI = class("IdleDropUI", BaseUI)
|
|
|
|
function IdleDropUI:isFullScreen()
|
|
return false
|
|
end
|
|
|
|
function IdleDropUI:getPrefabPath()
|
|
return "assets/prefabs/ui/idle/idle_drop_ui.prefab"
|
|
end
|
|
|
|
function IdleDropUI:ctor()
|
|
self.itemList = {}
|
|
self.refreshIntervalTime = GFunc.getConstValue("idle_exp_drop_time")
|
|
self.canRefreshReward = false
|
|
end
|
|
|
|
function IdleDropUI:onLoadRootComplete()
|
|
local uiMap = self.root:genAllChildren()
|
|
self.uiMap = uiMap
|
|
uiMap["idle_drop_ui.bg.title_text"]:setText("临时文本:挂机奖励")
|
|
uiMap["idle_drop_ui.bg.desc_tx_1"]:setText("临时文本:章节越高,收益越大")
|
|
self.timeTx = uiMap["idle_drop_ui.bg.time_tx"]
|
|
|
|
local goldPerHour = GFunc.num2Str(DataManager.IdleData:getGoldPerHour())
|
|
local expPerHour = GFunc.num2Str(DataManager.IdleData:getExpPerHour())
|
|
uiMap["idle_drop_ui.bg.bg_1.desc"]:setText("临时文本:" .. goldPerHour .. "/小时")
|
|
uiMap["idle_drop_ui.bg.bg_2.desc"]:setText("临时文本:" .. expPerHour .. "/小时")
|
|
|
|
uiMap["idle_drop_ui.bg.desc_tx_2"]:setText("临时文本:最长挂机16小时")
|
|
self.quickBtn = uiMap["idle_drop_ui.bg.quick_btn"]
|
|
self.quickBtn:addClickListener(function()
|
|
ModuleManager.IdleManager:showIdleQuickDropUI()
|
|
end)
|
|
uiMap["idle_drop_ui.bg.quick_btn.text"]:setText("临时文本:快速挂机")
|
|
self.getBtn = uiMap["idle_drop_ui.bg.get_btn"]
|
|
self.getBtn:addClickListener(function()
|
|
self.lastRefreshTime = Time:getServerTime()
|
|
ModuleManager.IdleManager:getIdleRewrad()
|
|
end)
|
|
uiMap["idle_drop_ui.bg.get_btn.text"]:setText("临时文本:领取")
|
|
uiMap["idle_drop_ui.bg.close_btn"]:addClickListener(function()
|
|
self:closeUI()
|
|
end)
|
|
|
|
self:initRewards()
|
|
self:bindData()
|
|
self:refreshCD()
|
|
self:scheduleGlobal(function()
|
|
self:refreshCD()
|
|
end, 1)
|
|
end
|
|
|
|
function IdleDropUI:initRewards()
|
|
self.scrollRect = self.uiMap["idle_drop_ui.bg.scroll_rect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
|
|
self.scrollRect:addInitCallback(function()
|
|
return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
|
|
end)
|
|
self.scrollRect:addRefreshCallback(function(index, cell)
|
|
cell:refreshByConfig(self.itemList[index])
|
|
end)
|
|
self.scrollRect:clearCells()
|
|
self.scrollRect:setTotalCount(0)
|
|
end
|
|
|
|
function IdleDropUI:bindData()
|
|
self:bind(DataManager.IdleData, "dirty", function()
|
|
self:onRefresh()
|
|
self.canRefreshReward = true
|
|
end)
|
|
end
|
|
|
|
function IdleDropUI:onRefresh()
|
|
self:refreshRewards()
|
|
self:refreshBtns()
|
|
end
|
|
|
|
function IdleDropUI:refreshRewards()
|
|
for i = 1, #self.itemList do
|
|
table.remove(self.itemList)
|
|
end
|
|
local rewards = DataManager.IdleData:getIdleRewards()
|
|
for _, item in pairs(rewards) do
|
|
if item.num > 0 then
|
|
table.insert(self.itemList, item)
|
|
end
|
|
end
|
|
if #self.itemList > 1 then
|
|
-- 道具类型从低到高>道具ID从低到高>品质从高到低
|
|
local cfg = ConfigManager:getConfig("item")
|
|
local infoA
|
|
local infoB
|
|
table.sort(self.itemList, function(a, b)
|
|
infoA = cfg[a.id]
|
|
infoB = cfg[b.id]
|
|
if infoA.type == infoB.type then
|
|
if infoA.qlt == infoB.qlt then
|
|
return infoA.qlt > infoB.qlt
|
|
else
|
|
return a.id < b.id
|
|
end
|
|
else
|
|
return infoA.type < infoB.type
|
|
end
|
|
end)
|
|
end
|
|
if self.scrollRect:getTotalCount() ~= #self.itemList then -- 打开界面的时候定位到当前可领取的最低等级奖励,如果没有则定位到当前等级
|
|
self.scrollRect:refillCells(#self.itemList)
|
|
else
|
|
self.scrollRect:updateAllCell()
|
|
end
|
|
end
|
|
|
|
function IdleDropUI:refreshBtns()
|
|
if #self.itemList > 0 then
|
|
self.getBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_green_2")
|
|
self.getBtn:setTouchEnable(true)
|
|
else
|
|
self.getBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_2")
|
|
self.getBtn:setTouchEnable(false)
|
|
end
|
|
local quickTimes = DataManager.IdleData:getQuickIdleTimes()
|
|
if quickTimes > 0 then
|
|
self.quickBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_yellow_2")
|
|
self.quickBtn:setTouchEnable(true)
|
|
self:addQuickBtnRedPoint()
|
|
else
|
|
self.quickBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_2")
|
|
self.quickBtn:setTouchEnable(false)
|
|
self:removeQuickBtnRedPoint()
|
|
end
|
|
end
|
|
|
|
function IdleDropUI:refreshCD()
|
|
local time = Time:getServerTime() - DataManager.IdleData:getLastDropTime()
|
|
local idleMaxTime = DataManager.IdleData:getIdleMaxTime()
|
|
if time >= idleMaxTime and #self.itemList > 0 then
|
|
self:addGetBtnRedPoint()
|
|
self.timeTx:setText(Time:formatNumTime(idleMaxTime))
|
|
else
|
|
self:removeGetBtnRedPoint()
|
|
self.timeTx:setText(Time:formatNumTime(time))
|
|
end
|
|
if self.lastRefreshTime == nil then
|
|
self.lastRefreshTime = Time:getServerTime()
|
|
elseif Time:getServerTime() - self.lastRefreshTime > self.refreshIntervalTime then
|
|
if not self.canRefreshReward then
|
|
return
|
|
end
|
|
self.canRefreshReward = false
|
|
self.lastRefreshTime = Time:getServerTime()
|
|
ModuleManager.IdleManager:getIdleShowRewrad()
|
|
end
|
|
end
|
|
|
|
function IdleDropUI:addGetBtnRedPoint()
|
|
if self.getBtnRedPoint == true then
|
|
return
|
|
end
|
|
self.getBtnRedPoint = true
|
|
self.getBtn:addRedPoint(94, 42, 0.8)
|
|
end
|
|
|
|
function IdleDropUI:removeGetBtnRedPoint()
|
|
if self.getBtnRedPoint == false then
|
|
return
|
|
end
|
|
self.getBtnRedPoint = false
|
|
self.getBtn:removeRedPoint()
|
|
end
|
|
|
|
function IdleDropUI:addQuickBtnRedPoint()
|
|
if self.quickBtnRedPoint == true then
|
|
return
|
|
end
|
|
self.quickBtnRedPoint = true
|
|
self.quickBtn:addRedPoint(94, 42, 0.8)
|
|
end
|
|
|
|
function IdleDropUI:removeQuickBtnRedPoint()
|
|
if self.quickBtnRedPoint == false then
|
|
return
|
|
end
|
|
self.quickBtnRedPoint = false
|
|
self.quickBtn:removeRedPoint()
|
|
end
|
|
|
|
return IdleDropUI |