97 lines
2.4 KiB
Lua
97 lines
2.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)
|
|
|
|
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_GOLD then
|
|
-- self.addImg:setVisible(not hideAddImg)
|
|
-- else
|
|
-- self.addImg:setVisible(not hideAddImg)
|
|
-- end
|
|
self.addImg:setVisible(false) -- 没有来源,直接隐藏
|
|
end
|
|
|
|
function ResourceCell:updateTime()
|
|
if self.itemId then
|
|
local curTime = DataManager.BagData:getTimelyItemRecoveryTime(self.itemId)
|
|
if curTime <= 0 then
|
|
self.timeTx:setText(GConst.EMPTY_STRING)
|
|
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 count = obj:getNum()
|
|
if count < 0 then
|
|
self.numTx:setText("0")
|
|
elseif obj:getItemType() == GConst.ItemConst.ITEM_ID_VIT then
|
|
self.numTx:setText(GFunc.num2Str(count) .. "/" .. DataManager.PlayerData:getMaxVit())
|
|
else
|
|
self.numTx:setText(GFunc.num2Str(count))
|
|
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(GConst.EMPTY_STRING)
|
|
self.numTx:setText(text)
|
|
end
|
|
|
|
function ResourceCell:doScaleFlyImg()
|
|
GFunc.doScaleFlyImg(self.resImg)
|
|
end
|
|
|
|
return ResourceCell |