-- <*
|
|
-- @Author: Saber
|
|
-- @Description: 藏宝图 限时商城界面节点item(收纳商品)
|
|
-- *>
|
|
TreasureMapStorageShopItem = TreasureMapStorageShopItem or BaseClass(BaseItem)
|
|
local TreasureMapStorageShopItem = TreasureMapStorageShopItem
|
|
|
|
function TreasureMapStorageShopItem:__init(parent_wnd,prefab_asset,layer_name)
|
|
self.base_file = "treasureMap"
|
|
self.layout_file = "TreasureMapShopItem"
|
|
self.parent_wnd = parent_wnd
|
|
self.layer_name = layer_name
|
|
self.need_show_leftime = true
|
|
self.model = TreasureMapModel:getInstance()
|
|
self:Load()
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:Load_callback()
|
|
local nodes = {
|
|
"bg:obj:img",
|
|
"left_time_icon:obj",
|
|
"item_con",
|
|
"reddot:obj",
|
|
"name:tmp",
|
|
"price_con/price:tmp", "price_con/old_price:tmp", "price_con/delete_icon:obj",
|
|
"day_limit:tmp",
|
|
"left_time:tmp",
|
|
}
|
|
self:GetChildren(nodes)
|
|
-- 使用的是原先的商城界面,改成类名方便搜索 --
|
|
self.transform.name = "TreasureMapStorageShopItem"
|
|
|
|
self.delete_icon_obj:SetActive(false)
|
|
self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_con)
|
|
self.awardItem:SetItemSize(78, 78)
|
|
self.awardItem:SetAnchoredPosition(0, 0)
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:AddEvents( )
|
|
local function click_event(target)
|
|
if target == self.bg_obj then
|
|
if self.data.rest_num > 0 and self.goods_id and self.price_type and self.price then
|
|
local data = {
|
|
shop_data = {
|
|
price = self.price,
|
|
money_type = self.price_type,
|
|
goods_id = self.goods_id,
|
|
quota_num = self.data.max_num,
|
|
sold_out = self.data.max_num - self.data.rest_num,
|
|
quota_type = 1,
|
|
is_tm_storage_shop = true,
|
|
shop_expire_time = self.data.expire_time,
|
|
discount = 100,
|
|
reward_id = self.data.reward_id,
|
|
reward_index = self.data.index,
|
|
},
|
|
}
|
|
UIToolTipMgr:getInstance():AppendGoodsTips(self.goods_id, x, y, nil, nil, data, true)
|
|
else
|
|
Message.show("该物品已售罄", "fault")
|
|
end
|
|
end
|
|
end
|
|
AddClickEvent(self.bg_obj, click_event)
|
|
|
|
local function updateRestNum(vo) -- 更新剩余商品个数
|
|
if self.data and
|
|
self.data.expire_time == vo.expire_time and
|
|
self.data.reward_id == vo.reward_id and
|
|
self.data.index == vo.index then -- 通过这几个属性可以锁定一个道具
|
|
self:UpdateLeftNum(vo.rest_num, vo.max_num)
|
|
self:StartLeftTimeFunc()
|
|
end
|
|
end
|
|
self:BindEvent(self.model, TreasureMapConst.UPDATE_STORAGE_SHOP_DATA, updateRestNum)
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:SetData( data )
|
|
self.data = data
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:UpdateView( )
|
|
self:UpdateBasicData()
|
|
self:UpdateLeftNum(self.data.rest_num, self.data.max_num)
|
|
self:StartLeftTimeFunc()
|
|
end
|
|
|
|
-- 获取配置,加载基础数据
|
|
function TreasureMapStorageShopItem:UpdateBasicData( )
|
|
local cfg = Config.Treasuremapdoor[self.data.reward_id]
|
|
if not cfg then return end
|
|
local reward_data = stringtotable(cfg.rewards)
|
|
local reward_cfg
|
|
for k, v in pairs(reward_data) do
|
|
if v[1] == self.data.index then
|
|
reward_cfg = v
|
|
break
|
|
end
|
|
end
|
|
if not reward_cfg then return end
|
|
local goods_Id, lock = GoodsModel:getInstance():GetMappingTypeId(reward_cfg[2][1][1], reward_cfg[2][1][2])
|
|
self.awardItem:SetData(goods_Id, reward_cfg[2][1][3], nil, nil, lock)
|
|
self.name_tmp.text = GoodsModel:getInstance():getGoodsName(goods_Id)
|
|
-- 缓存物品id
|
|
self.goods_id = goods_Id
|
|
local price_type = reward_cfg[2][2] == "gold" and 1 or 2
|
|
self.price_type = price_type
|
|
self.price = reward_cfg[2][3]
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:UpdateLeftNum(rest_num, max_num)
|
|
SetImageGray(self.bg_img, rest_num <= 0)
|
|
self.day_limit_tmp.text = string.format("限购<color=%s>%s</color>/%s",
|
|
rest_num > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, rest_num, max_num)
|
|
self.price_tmp.text = rest_num > 0
|
|
and WordManager:GetMoneyFaceStr(self.price_type) .. self.price
|
|
or string.format("<color=%s>已售完</color>", ColorUtil.GRAY_DARK)
|
|
self.need_show_leftime = rest_num > 0
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:StartLeftTimeFunc( )
|
|
self:ClearLeftTimeFunc()
|
|
if self.need_show_leftime then
|
|
local function left_time_func()
|
|
local left_time = self.data.expire_time - TimeUtil:getServerTime()
|
|
if left_time > 0 then
|
|
self.left_time_tmp.text = string.format("<color=%s>%s</color>", ColorUtil.GREEN_DARK, TimeUtil:convertTimeWithoutHour(left_time))
|
|
else
|
|
self.left_time_tmp.text = string.format("<color=%s>已超时</color>", ColorUtil.RED_DARK)
|
|
self:ClearLeftTimeFunc()
|
|
end
|
|
end
|
|
self.left_time_icon_obj:SetActive(true)
|
|
left_time_func()
|
|
self.left_time_func_id = GlobalTimerQuest:AddPeriodQuest(left_time_func, 0.5, -1)
|
|
else
|
|
self.left_time_icon_obj:SetActive(false)
|
|
self.left_time_tmp.text = ""
|
|
end
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:ClearLeftTimeFunc( )
|
|
if self.left_time_func_id then
|
|
GlobalTimerQuest:CancelQuest(self.left_time_func_id)
|
|
self.left_time_func_id = nil
|
|
end
|
|
end
|
|
|
|
function TreasureMapStorageShopItem:__delete( )
|
|
if self.awardItem then
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
|
|
self.awardItem = nil
|
|
end
|
|
|
|
self:ClearLeftTimeFunc()
|
|
end
|