SupremeVipShopItem = SupremeVipShopItem or BaseClass(BaseItem)
|
|
local SupremeVipShopItem = SupremeVipShopItem
|
|
|
|
SupremeVipShopItem.Width = 146
|
|
SupremeVipShopItem.Height = 181
|
|
function SupremeVipShopItem:__init()
|
|
self.base_file = "supremeVip"
|
|
self.layout_file = "SupremeVipShopItem"
|
|
self.model = SupremeVipModel:getInstance()
|
|
self.mainVo = RoleManager:getInstance():GetMainRoleVo()
|
|
|
|
self.can_buy = false --是否能购买
|
|
|
|
self:Load()
|
|
end
|
|
|
|
function SupremeVipShopItem:Load_callback()
|
|
self.nodes = {
|
|
"awardCon:obj",
|
|
"limit:tmp",
|
|
"moneyIcon:obj:img",
|
|
"lock:obj", --神秘物品标志
|
|
"emptyClick:obj",
|
|
"price:tmp",
|
|
"name:tmp",
|
|
"lockTips:tmp",
|
|
"bg:img"
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
|
|
self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.awardCon, false)
|
|
self.awardItem:SetItemSize(62, 62)
|
|
self.awardItem:SetIsAct(true)
|
|
|
|
self:AddEvents()
|
|
if self.need_refreshData then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
|
|
function SupremeVipShopItem:AddEvents( )
|
|
local on_click = function(click_obj,x,y)
|
|
if self.emptyClick_obj == click_obj then --购买物品
|
|
-- if self.can_buy then
|
|
-- self.model:Fire(SupremeVipConst.REQUEST_CCMD_EVENT,45105,self.data.goods_id)
|
|
-- else
|
|
-- Message.show("已达到限购数量")
|
|
-- end
|
|
|
|
local limit_quota_type = 0
|
|
if self.limit_type == 1 then
|
|
limit_quota_type = 2
|
|
elseif self.limit_type == 2 then
|
|
limit_quota_type = 1
|
|
else
|
|
limit_quota_type = 0
|
|
end
|
|
local data = {
|
|
shop_data = {
|
|
price = self.money_cost,
|
|
money_type = self.money_type,
|
|
goods_id = self.data.goods_id,
|
|
quota_num = self.limit_num,
|
|
sold_out = self.sold_out,
|
|
bind = false,
|
|
quota_type = limit_quota_type,
|
|
-- num = 1,
|
|
discount = 100,
|
|
is_supreme_vip_shop = true,
|
|
},
|
|
}
|
|
UIToolTipMgr:getInstance():AppendGoodsTips(self.data.goods_id, x, y, nil, nil,data, true)
|
|
end
|
|
end
|
|
AddClickEvent(self.emptyClick_obj, on_click)
|
|
|
|
|
|
local function update_shop_item(vo)
|
|
for k,v in pairs(vo.goods_list) do
|
|
if v.goods_id == self.data.goods_id or vo.unlock_id == self.index then
|
|
self:UpdateView()
|
|
end
|
|
end
|
|
end
|
|
self:BindEvent(self.model, SupremeVipConst.UPDATE_SUPREME_VIP_SHOP_ITEM,update_shop_item)
|
|
end
|
|
|
|
function SupremeVipShopItem:UpdateView( )
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId( self.data.goods_id )
|
|
if goods_basic then
|
|
lua_resM:setImageSprite(self, self.bg_img, "kfActShopBgExtra_asset", "kf_shop_item_color"..goods_basic.color)
|
|
end
|
|
--判断自己是否在解锁序列中,如果不在,展示为神秘物品
|
|
local is_unlocked = self.model:IsInUnLockList(self.data.index)
|
|
if is_unlocked then
|
|
SetImageGray(self.bg_img,false)
|
|
-- self:SetVisible(true)
|
|
self:UpdateLimitTimes()
|
|
self:UpdateMoneyCon()
|
|
self:UpdateGoodsMsg()
|
|
else
|
|
-- self:SetVisible(false)
|
|
self.limit_tmp.text = ""
|
|
SetImageGray(self.bg_img,true)
|
|
self.lockTips_tmp.text = "<#ff203a>购买前一道具后解锁</color>"
|
|
self.emptyClick_obj:SetActive(false)
|
|
if self.awardItem then
|
|
self.awardItem:SetVisible(false)
|
|
end
|
|
self.name_tmp.text = "<#fdffc2>神秘道具</color>"
|
|
self.price_tmp.text = ""
|
|
self.moneyIcon_obj:SetActive(false)
|
|
self.lock_obj:SetActive(true)
|
|
end
|
|
end
|
|
|
|
--刷新限购次数
|
|
function SupremeVipShopItem:UpdateLimitTimes()
|
|
self.emptyClick_obj:SetActive(true)
|
|
|
|
local limit_cfg = stringtotable(self.data.limit_buy)
|
|
if limit_cfg and #limit_cfg ~= 0 then --限购
|
|
self.limit_type = limit_cfg[1][1]--限购类型 1日限购|2周限购|3终身限购
|
|
self.limit_num = limit_cfg[1][2]--限购数量
|
|
local limit_data = self.model:GetLimitShopData(self.data.goods_id)--限购信息
|
|
|
|
if limit_data then
|
|
self.sold_out = limit_data.count
|
|
if self.limit_num-limit_data.count > 0 then
|
|
self.limit_tmp.text = SupremeVipConst.ShopLimitType[self.limit_type].." "
|
|
.."<color=#2CF86F>"..self.limit_num-limit_data.count.."</color>/"..self.limit_num
|
|
else
|
|
self.limit_tmp.text = SupremeVipConst.ShopLimitType[self.limit_type].." "
|
|
.."<color=#ff203a>"..self.limit_num-limit_data.count.."</color>/"..self.limit_num
|
|
end
|
|
self.can_buy = self.limit_num-limit_data.count > 0
|
|
else
|
|
self.sold_out = 0
|
|
self.limit_tmp.text = SupremeVipConst.ShopLimitType[self.limit_type].." "
|
|
..self.limit_num.."/"..self.limit_num
|
|
self.can_buy = true
|
|
end
|
|
else -- 不限购
|
|
self.limit_tmp.text = ""
|
|
self.can_buy = true
|
|
end
|
|
end
|
|
|
|
--刷新货币信息
|
|
function SupremeVipShopItem:UpdateMoneyCon()
|
|
--货币类型 具体类型可看ConfigNotNormalGoods或Config.GoodsSubtype
|
|
--此处常用 1|彩钻 2|红钻 11|星钻
|
|
self.money_type = stringtotable(self.data.price)[1][1]
|
|
self.money_cost = stringtotable(self.data.price)[1][2]--需要花费
|
|
|
|
local is_level_enough = self.mainVo.level >= stringtotable(self.data.lv)[1]
|
|
|
|
if is_level_enough then
|
|
self.moneyIcon_obj:SetActive(true)
|
|
self.lockTips_tmp.text = ""
|
|
lua_resM:setImageSprite(self,self.moneyIcon_img,"common_asset","tyui_hb_"..self.money_type,true)
|
|
self.price_tmp.text = self.money_cost
|
|
else
|
|
self.emptyClick_obj:SetActive(false)
|
|
self.moneyIcon_obj:SetActive(false)
|
|
self.lockTips_tmp.text = stringtotable(self.data.lv)[1].."级解锁"
|
|
self.price_tmp.text = ""
|
|
end
|
|
SetAnchoredPositionX(self.moneyIcon,11-self.price_tmp.preferredWidth/2-18)
|
|
|
|
end
|
|
|
|
--刷新物品信息
|
|
function SupremeVipShopItem:UpdateGoodsMsg()
|
|
local bg_res = self.item_id%2 == 0 and "supremeVip_shop_top_2" or "supremeVip_shop_top_1"
|
|
self.lock_obj:SetActive(false)
|
|
local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.data.goods_id)
|
|
local goods_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id)
|
|
self.name_tmp.text = HtmlColorTxt(goods_name, ShopItem.ColorStr[goodsVo.color])
|
|
if self.awardItem then--设置awardItem
|
|
self.awardItem:SetVisible(true)
|
|
self.awardItem:SetData(self.data.goods_id)
|
|
end
|
|
end
|
|
|
|
function SupremeVipShopItem:SetData(data,item_id)
|
|
self.data = data
|
|
self.index = self.data.index
|
|
self.item_id = item_id
|
|
if self.is_loaded then
|
|
self.need_refreshData = false
|
|
self:UpdateView()
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function SupremeVipShopItem:__delete( )
|
|
if self.awardItem then
|
|
self.awardItem:ReleaseObj()
|
|
self.awardItem = nil
|
|
end
|
|
end
|