--<* -- @Author: Saber -- @Description: 社团商城界面item --*> GuildShopItem = GuildShopItem or BaseClass(BaseItem) local GuildShopItem = GuildShopItem function GuildShopItem:__init(parent_wnd,prefab_asset,layer_name) self.base_file = "guild" self.layout_file = "GuildShopItem" self.parent_wnd = parent_wnd self.layer_name = layer_name self.limit_buy_str = { [GuildModel.ShopBuyType.NoLimit] = "不限购", [GuildModel.ShopBuyType.DayLimit] = "每日限购:", [GuildModel.ShopBuyType.WeekLimit] = "每周限购:", [GuildModel.ShopBuyType.RoleLimit] = "终生限购:", } self.shop_goods_id = nil self.shop_goods_priceType = nil self.shop_goods_price = nil self.model = GuildModel:getInstance() self:Load() end function GuildShopItem:Load_callback() self.nodes = { "bg:imgex", "price_con/cost_icon:img:obj", "buy_btn:obj", "item_con", "name:tmp", "price_con/price:tmp", "limit_buy_time:tmp", "locked:obj", "locked/lock_icon:obj", "locked/lock_flag:tmp", "item_red:img", -- "limit_bg:obj", } self:GetChildren(self.nodes) self.award_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con) self.award_item:SetItemSize(86, 86) self.award_item:SetVisible(false) self:AddEvents() if self.need_refreshData then self:UpdateView() self:UpdateItemRed() end end function GuildShopItem:AddEvents( ) local function click_event(target) if target == self.buy_btn_obj then if self.data and self.data.id and self.shop_goods_id then local data = { shop_data = { price = self.shop_goods_price, money_type = self.shop_goods_priceType, goods_id = self.shop_goods_id, quota_num = self.data.num, sold_out = self.data.buy_num, bind = false, quota_type = self.data.type, -- num = 1, discount = 100, is_guild_shop = true, buy_cfg_id = self.data.id }, } UIToolTipMgr:getInstance():AppendGoodsTips(self.shop_goods_id, x, y, nil, nil, data, true) end end end AddClickEvent(self.buy_btn_obj, click_event, LuaSoundManager.SOUND_UI.NONE) local function update_goods_num(vo) if self.data and self.data.id == vo.id then self:UpdateView() end end self:BindEvent(self.model, GuildModel.RefreshBuyGoodsItemEvt, update_goods_num) local function update_item_red(view_type) if view_type and view_type == Config.ConfigGuild.TabId.Shop then self:UpdateItemRed() end end self:BindEvent(self.model, GuildModel.UPDATE_RED_DOT_BY_TYPE, update_item_red) end function GuildShopItem:UpdateView( ) if self.data then -- 加载商品信息 local goods_cfg = stringtotable(self.data.cargo)[1] local type_Id, lock = GoodsModel:getInstance():GetMappingTypeId(goods_cfg[1], goods_cfg[2]) local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_Id) local goods_name = GoodsModel:getInstance():getGoodsName(type_Id) self.name_tmp.text = goods_name self.name_tmp.color = ColorUtil:GetGoodsColor(goodsVo.color) lua_resM:setImageSprite(self, self.bg_imgex, "shopOut_asset", "shop_item_color"..goodsVo.color, false) self.award_item:SetData(type_Id, goods_cfg[3], nil, nil, lock) self.award_item:SetVisible(true) self.shop_goods_id = type_Id local cost_cfg = stringtotable(self.data.cost)[1] self.shop_goods_priceType = cost_cfg[1] self.shop_goods_price = cost_cfg[3] -- 限购信息 local limit_buy_str = self.limit_buy_str[self.data.type] if self.data.type ~= GuildModel.ShopBuyType.NoLimit then limit_buy_str = string.format("%s%s/%s", limit_buy_str, self.data.num - self.data.buy_num > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, self.data.num - self.data.buy_num, self.data.num) -- limit_buy_str = limit_buy_str .. (self.data.num - self.data.buy_num) .. "/" .. self.data.num end self.limit_buy_time_tmp.text = limit_buy_str if self.data.lock_guild then -- 未达到社团等级 self.lock_flag_tmp.text = string.format("社团等级%s级解锁", self.data.guild_lv) self.cost_icon_obj:SetActive(false) self.price_tmp.text = "" self.limit_buy_time_tmp.text = "" self.award_item:SetGray(true) else self.lock_flag_tmp.text = "" -- 费用信息 if not self.data.can_buy then -- 限购商品买完 self.price_tmp.text = "已售完" self.price_tmp.color = ColorUtilValue.WHITE self.cost_icon_obj:SetActive(false) self.award_item:SetGray(true) self.bg_imgex.gray = true self.name_tmp.color = ColorUtilValue.GRAY_DARK else local icon_asset, icon_res = WordManager:GetCommonMoneyIcon(cost_cfg[1]) lua_resM:setImageSprite(self, self.cost_icon_img, icon_asset, icon_res) self.price_tmp.text = self.shop_goods_price self.price_tmp.color = ColorUtil:ConvertHexToRGBColor("#fdffc2") self.cost_icon_obj:SetActive(true) self.award_item:SetGray(false) self.bg_imgex.gray = false end end -- 锁定效果 self.lock_icon_obj:SetActive(self.data.lock_guild) self.locked_obj:SetActive(self.data.lock_guild) self.gameObject:SetActive(true) end end function GuildShopItem:SetData( data ) self.data = data if self.is_loaded then self.need_refreshData = false self:UpdateView() self:UpdateItemRed() else self.need_refreshData = true end end function GuildShopItem:UpdateItemRed( ) local bool = self.data and self.model:GetGuildShopSpecialItemRedById(self.data.id) or false self.item_red_img.enabled = bool end function GuildShopItem:__delete( ) if self.award_item then UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.award_item) self.award_item = nil end end