125 lines
3.4 KiB
Lua
125 lines
3.4 KiB
Lua
local BaseCell = require (GConst.TYPEOF_LUA_CLASS.BASE_CELL)
|
|
local ResourceCell = class("ResourceCell", BaseCell)
|
|
|
|
function ResourceCell:ctor()
|
|
|
|
end
|
|
|
|
function ResourceCell:init()
|
|
local uiMap = self:getUIMap()
|
|
|
|
self.resImg = uiMap['currency_cell.res_img']
|
|
self.addImg = uiMap['currency_cell.add_img']
|
|
self.numTx = uiMap['currency_cell.num_tx']
|
|
self.timeTx = uiMap['currency_cell.time_tx']
|
|
self.addTx = uiMap["currency_cell.add_tx"]
|
|
end
|
|
|
|
function ResourceCell:show(itemId, hideAddImg)
|
|
-- hideAddImg = hideAddImg or false
|
|
-- self:hide()
|
|
-- if not itemId then
|
|
-- return
|
|
-- end
|
|
-- self.baseObject:setActive(true)
|
|
-- self.num = nil
|
|
|
|
-- local obj = DataManager.BagData.ItemData:getItemById(itemId)
|
|
-- self.resImg:setSprite(obj:getIconRes())
|
|
|
|
-- self:unBindAll()
|
|
-- self:bind(obj, "isDirty", function(binder, value)
|
|
-- self:refreshTextRightNow()
|
|
-- end)
|
|
|
|
-- self.baseObject:removeClickListener()
|
|
|
|
-- self.timeTx:setVisible(false)
|
|
-- self.itemId = itemId
|
|
-- if itemId == GConst.ItemConst.ITEM_ID_GEM then
|
|
-- self.baseObject:addClickListener(function()
|
|
-- if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.SHOP, true) then
|
|
-- EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CHANGE_MAIN_CITY_PAGE, {page = 5, storeIdx = 4})
|
|
-- end
|
|
-- end)
|
|
-- self.addImg:setVisible(not hideAddImg)
|
|
-- elseif itemId == GConst.ItemConst.ITEM_ID_GOLD then
|
|
-- if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.SHOP, true) then
|
|
-- self.baseObject:addClickListener(function()
|
|
-- EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CHANGE_MAIN_CITY_PAGE, {page = 5, storeIdx = 2})
|
|
-- end)
|
|
-- end
|
|
-- self.addImg:setVisible(not hideAddImg)
|
|
-- else
|
|
-- self.addImg:setVisible(not hideAddImg)
|
|
-- end
|
|
-- self:refreshCurrencyAddTx(itemId, nil)
|
|
end
|
|
|
|
function ResourceCell:refreshCurrencyAddTx(itemId, bigNum)
|
|
-- if self.itemId == itemId then
|
|
-- if bigNum then
|
|
-- local obj = DataManager.BagData.ItemData:getItemById(self.itemId)
|
|
-- if obj:getItemType() == 6 then
|
|
-- self.addTx:setText("+" .. tostring(BigNumOpt.bigNum2Num(bigNum)))
|
|
-- else
|
|
-- self.addTx:setText("+" .. BigNumOpt.bigNum2Str(bigNum))
|
|
-- end
|
|
-- else
|
|
-- self.addTx:setText(nil)
|
|
-- end
|
|
-- end
|
|
end
|
|
|
|
function ResourceCell:updateTime()
|
|
if self.itemId then
|
|
--local curTime = DataManager.BagData:getTimelyItemRecoveryTime(self.itemId)
|
|
--if curTime <= 0 then
|
|
-- self.timeTx:setText("")
|
|
--else
|
|
-- self.timeTx:setText(GFunc.getTimeStrWithMS(curTime))
|
|
--end
|
|
end
|
|
end
|
|
|
|
function ResourceCell:hide()
|
|
self.baseObject:setActive(false)
|
|
end
|
|
|
|
function ResourceCell:setAnchoredPosition(x, y)
|
|
self.baseObject:setAnchoredPosition(x, y, 0)
|
|
end
|
|
|
|
function ResourceCell:getAnchoredPosition()
|
|
return self.baseObject:getAnchoredPosition()
|
|
end
|
|
|
|
function ResourceCell:refreshTextRightNow()
|
|
-- if not self.itemId then
|
|
-- return
|
|
-- end
|
|
-- local obj = DataManager.BagData.ItemData:getItemById(self.itemId)
|
|
-- local bigNum = obj:getBigNum()
|
|
-- if bigNum.value < 0 then
|
|
-- self.numTx:setText(0)
|
|
-- elseif obj:getItemType() == 6 then
|
|
-- self.numTx:setText(BigNumOpt.bigNum2Num(bigNum))
|
|
-- else
|
|
-- self.numTx:setText(BigNumOpt.bigNum2Str(bigNum))
|
|
-- end
|
|
end
|
|
|
|
function ResourceCell:refreshText()
|
|
if self.numTx == nil then
|
|
return
|
|
end
|
|
local text = self.numTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).text
|
|
self.numTx:setText("")
|
|
self.numTx:setText(text)
|
|
end
|
|
|
|
function ResourceCell:doScaleFlyImg()
|
|
GFunc.doScaleFlyImg(self.resImg)
|
|
end
|
|
|
|
return ResourceCell |