|
|
- EmpowerShopItem = EmpowerShopItem or BaseClass(BaseItem)
-
- function EmpowerShopItem:__init(parent_wnd, prefab_asset, layer_name)
- self.base_file = "empower"
- self.layout_file = "EmpowerShopItem"
- self.layer_name = layer_name
- self.is_delay_callback = true
- --self.model = ShopModel:getInstance()
- self.mainVo = RoleManager.Instance.mainRoleInfo
- self.model = EmpowerModel:GetInstance()
- self.itemInfo = nil
- self.image_gray_list = {}
- self.gray_mat = ShaderTools.gray_mat
-
- self.condition_str = nil
- self.is_show_cond = false
- self.is_show_vip_cond = false
- self:Load()
- end
-
- function EmpowerShopItem:Load_callback()
- self.nodes = {
- "bg:img","item_con",
- "discount_con/discount_text:tmp","name_text:tmp","price_con/price_text:tmp",
- "lock_text:tmp","price_con:obj","price_con/money_icon:imgex",
- "discount_con:obj:img","limit_text:tmp","click_con:obj","red_dot:obj","line:img","descrb_text:tmp",
- }
- self:GetChildren(self.nodes)
-
- -- self.descrb_text_shadow = self:GetChild("descrb_text"):GetComponent("Shadow")
-
- self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
- self.awardItem:SetItemSize(86, 86)
- if self.need_refreshData then
- self:SetData(self.data, self.index, self.isChangeItem)
- end
- self:InitEvent()
- end
-
- function EmpowerShopItem:InitEvent()
- local function onBtnClickHandler(target, x, y)
- if self.isChangeItem then
- --Message.show("self.data.goods_id:",self.data.goods_id)
- -- local ok = function ( )
- -- self.model:Fire(EmpowerConst.EMPOWER_REQ_EVENT, 41408, self.data.goods_id)
- -- end
-
- -- local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.data.goods_id)
- -- local goods_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, false)
- -- goods_name = string.format("<color=%s>%s</color>", ShopItem.ColorStr[goodsVo.color],goods_name)
-
- -- -- local price = WordManager:GetMoneyFaceStr(self.data.money_type) .. HtmlColorTxt( self.data.price, ColorUtil.GREEN_DARK)
- -- local str = string.format('确认兑换 %s 吗?', goods_name)
- -- Alert.show(str, Alert.Type.Two,ok)
-
- local data = {
- shop_data = {
- price = 1,
- money_type = EmpowerConst.EmpowerMoneyId,
- discount = 100,
- goods_id = self.data.goods_id,
- num = 1,
- quota_type = 0,
- is_empower_exchange_shop = true,
- limit_num = 99,
- money_id = 270013,
- },
- }
- UIToolTipMgr:getInstance():AppendGoodsTips(self.data.goods_id, x, y, nil, nil, data, true)
- else
- --Message.show("self.index:",self.index)
- if self.data and self.data.is_pay == 0 then
- self.model:Fire(EmpowerConst.EMPOWER_REQ_EVENT, 41406,self.index)
- else
- local data = {
- shop_data = {
- price = self.data.price,
- money_type = self.data.money_type,
- discount = 100,
- goods_id = self.data.goods_id,
- num = self.data.num,
- quota_type = 0,
- is_empower_shop = true,
- limit_num = 1,
- item_index = self.index,
- },
- }
- UIToolTipMgr:getInstance():AppendGoodsTips(self.data.goods_id, x, y, nil, nil, data, true)
- end
- end
- end
- AddClickEvent(self.click_con_obj, onBtnClickHandler, 2)
- end
-
- function EmpowerShopItem:ClickCallFun(target)
- if not self.data then return end
- end
-
- function EmpowerShopItem:SetData(data, index, isChangeItem)
- self.data = data
- self.index = index
- self.isChangeItem = isChangeItem
- if self.is_loaded then
- -- local shop_cfg = Config.Shop
- -- if shop_cfg[data.key_id] then
- -- local tips = shop_cfg[data.key_id].tips
- -- if tips >= 1 then
- -- lua_resM:setImageSprite(self, self.hot_image_img, "shop_asset", "shop_tip"..tips)
- -- end
- -- self.hot_image_obj:SetActive(tips >= 1)
- -- end
-
- --[[ local name_color =
- {
- [1] = "#58e8c4",
- [2] = "#69d0ff",
- [3] = "#efafff",
- [4] = "#ffc076",
- [5] = "#ff96a1",
- [6] = "#ffec6b",
- }]]
-
- self.need_refreshData = false
- local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(data.goods_id)
- if goodsVo == nil then
- LogError("EmpowerShopItem:SetItemInfo : goodsVo is nil, goods_id is "..data.goods_id)
- return
- end
-
- -- local function call_back( )
- -- self:SetVisible(true)
- -- end
- -- lua_resM:setImageSprite(self, self.line_img, "common_asset", "shop_item_color"..goodsVo.color, false, call_back)
- -- 背景图
- local function call_back( )
- self:SetVisible(true)
- end
- lua_resM:setImageSprite(self, self.bg_img, "shopOut_asset", "shop_item_color"..goodsVo.color, false, call_back)
-
- -- 数量提示
- local equip_pos = EquipModel:getInstance():GetShopGoodsIdEquipPos( tonumber(data.goods_id) )
- if equip_pos then
- local need_num = EquipModel:getInstance():GetRedEquipShopCostlimitNum(equip_pos)
- local has_num = GoodsModel:getInstance():GetTypeGoodsNum(data.goods_id)
- local color = need_num <= has_num and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK
- self.limit_text_tmp.text = string.format('升品需求 %s/%s', HtmlColorTxt( has_num, color), need_num)
- end
-
-
- self.awardItem:SetData(data.goods_id, data.num, nil, nil, data.bind, nil, nil, self.isChangeItem)
- local goods_name = GoodsModel:getInstance():getGoodsName(data.goods_id, false)
- self.name_text_tmp.text = string.format("<color=%s>%s</color>", ShopItem.ColorStr[goodsVo.color],goods_name)
-
- self.price_text_tmp.text = data.price --round(data.price * data.discount / 100)
-
- if data.is_pay == 0 then
- self.price_text_tmp.text = HtmlColorTxt( " 免费", ColorUtil.GREEN_DARK)
- self.money_icon.gameObject:SetActive(false)
- else
- self.money_icon.gameObject:SetActive(true)
- end
- SetSizeDeltaX(self.price_text, self.price_text_tmp.preferredWidth)
- -- self.discount_text_tmp.text = (data.discount / 10) .. "折"
- self.discount_text_tmp.text = data.discount .. "折"
- self.discount_con_obj:SetActive(data.discount ~= 0 and self.is_show_cond == false)
- self:SetMoneyIcon()
- self:SetItemGary(data.is_gray)
-
- if data.is_pay == 0 and data.state == 0 then
- self.red_dot_obj:SetActive(true)
- else
- self.red_dot_obj:SetActive(false)
- end
-
- else
- self.need_refreshData = true
- return
- end
- end
-
-
-
- -- 加载货币图标
- function EmpowerShopItem:SetMoneyIcon()
- if not self.data or not self.data.money_type then return end
- local asset, source = WordManager:GetCommonMoneyIcon(self.data.money_type)
- if self.data.money_type == EmpowerConst.EmpowerMoneyId then
- self.money_icon.transform.sizeDelta = co.TableXY(26,21)
- else
- self.money_icon.transform.sizeDelta = co.TableXY(40,40)
- end
- lua_resM:setImageSprite(self, self.money_icon_imgex, asset, source)
- end
-
- function EmpowerShopItem:SetItemGary(bool)
- local mat = bool and self.gray_mat or nil
- self.bg_img.material = mat
- --self.awardItem:SetGray(bool)
- --self.money_icon_imgex.gray = bool
-
- --self.discount_con_img.material = mat
- -- self.priceCon_bg.material = mat
-
- if bool then
- self.money_icon.gameObject:SetActive(false)
- self.descrb_text_tmp.color = Color(78/255,78/255,78/255)
- -- self.descrb_text_shadow.effectColor = Color(195/255,195/255,195/255,1)
- if self.isChangeItem then
- -- self.descrb_text_tmp.text = "已兑换"
- self.price_text_tmp.text = " 已兑换"
- else
- -- self.descrb_text_tmp.text = "已购买"
- self.price_text_tmp.text = " 已购买"
- end
- else
- self.descrb_text_tmp.color = Color(143/255,53/255,13/255)
- -- self.descrb_text_shadow.effectColor = Color(255/255,244/255,170/255,1)
- if self.isChangeItem then
- self.descrb_text_tmp.text = "兑换"
- else
- self.descrb_text_tmp.text = "购买"
- end
- end
-
-
-
-
- --[[local is_sale_out = self.data.quota_num - self.data.sold_out > 0
- local color = is_sale_out and ColorUtil.GREEN or ColorUtil.RED
- if bool then
- self.price.text = "<color=#979696>"..round(self.data.price * self.data.discount / 100).."</color>"
- if self.condition_str and self.is_show_vip_cond then
- self.OthercondTxt.text = "<color=#ffffff>"..self.condition_str.."</color>"
- end
- else
- self.price.text = "<color=#835741>"..round(self.data.price * self.data.discount / 100).."</color>"
- if self.condition_str and self.is_show_vip_cond then
- self.OthercondTxt.text = self.condition_str
- end
- end]]
- end
-
- function EmpowerShopItem:__delete()
- if self.awardItem then
- UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
- self.awardItem = nil
- end
- end
|