c1_lua/lua/app/ui/idle/idle_drop_ui.lua
2023-05-17 22:27:58 +08:00

178 lines
6.1 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.rewardList = {}
end
function IdleDropUI:onReshow()
-- self:refreshBtn()
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()
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: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.list[index])
end)
self.scrollRect:clearCells()
self.scrollRect:refillCells(#self.rewardList)
end
-- function IdleDropUI:_display()
-- local uiMap = self.root:genAllChildren()
-- uiMap["idle_drop_ui.bg.title"]:setText(I18N:getGlobalText(I18N.GlobalConst.HANG_UP_DESC))
-- uiMap["idle_drop_ui.bg.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.HANG_UP_DESC_1))
-- uiMap["idle_drop_ui.bg.desc_2"]:setText(I18N:getGlobalText(I18N.GlobalConst.HANG_UP_DESC_3, Time:formatNumTime(GFunc.getConstIntValue("idle_maxtime"))))
-- uiMap["idle_drop_ui.bg.btn_1.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.HANG_UP_DESC_5))
-- uiMap["idle_drop_ui.bg.btn_2.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.GET_DESC))
-- uiMap["idle_drop_ui.bg.bg_1.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.HANG_UP_DESC_4, self.coinPerHour))
-- uiMap["idle_drop_ui.bg.bg_2.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.HANG_UP_DESC_4, self.expPerHour))
-- self:_refreshScrollRect()
-- self:refreshBtn()
-- self.canRefreshReward = true
-- end
-- function IdleDropUI:_addListeners()
-- local uiMap = self.root:genAllChildren()
-- self.root:addClickListener(function()
-- self:closeUI()
-- ModuleManager.IdleManager:getIdleRewrad()
-- end)
-- uiMap["idle_drop_ui.bg.close_img"]:addClickListener(function()
-- self:closeUI()
-- ModuleManager.IdleManager:getIdleRewrad()
-- end)
-- uiMap["idle_drop_ui.bg.btn_1"]:addClickListener(function()
-- ModuleManager.IdleManager:showIdleQuickDropUI()
-- end)
-- uiMap["idle_drop_ui.bg.btn_2"]:addClickListener(function()
-- ModuleManager.IdleManager:getIdleRewrad()
-- end)
-- -- self:bind(DataManager.HangUpData, "isDirty", function()
-- -- self.list = DataManager.HangUpData:getCacheRewards()
-- -- self:_refreshScrollRect()
-- -- self.canRefreshReward = true
-- -- end)
-- end
function IdleDropUI:refreshCD()
local time = Time:getServerTime() - DataManager.IdleData:getLastDropTime()
local idleMaxTime = DataManager.IdleData:getIdleMaxTime()
if time >= idleMaxTime 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 > GFunc.getConstIntValue("exp_drop_time") then
-- if not self.canRefreshReward then
-- return
-- end
-- self.canRefreshReward = false
-- self.lastRefreshTime = Time:getServerTime()
-- ModuleManager.HangUpManager:getHangUpShowRewrad()
-- 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
-- function IdleDropUI:refreshBtn()
-- local uiMap = self.root:genAllChildren()
-- local btn = uiMap["idle_drop_ui.bg.btn_1"]
-- if self:canAd() or self:canDiamond() then
-- btn:addRedPoint(85, 36, 0.5)
-- else
-- btn:removeRedPoint()
-- end
-- end
-- function IdleDropUI:canAd()
-- return GFunc.getConstIntValue("idle_drop_fast_times_1") > DataManager.HangUpData:getAdCount()
-- end
-- function IdleDropUI:canDiamond()
-- return GFunc.getConstIntValue("idle_drop_fast_times_2") > DataManager.HangUpData:getDiamondCount()
-- end
return IdleDropUI