源战役客户端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

247 líneas
8.1 KiB

hace 4 semanas
  1. EmpowerShopItem = EmpowerShopItem or BaseClass(BaseItem)
  2. function EmpowerShopItem:__init(parent_wnd, prefab_asset, layer_name)
  3. self.base_file = "empower"
  4. self.layout_file = "EmpowerShopItem"
  5. self.layer_name = layer_name
  6. self.is_delay_callback = true
  7. --self.model = ShopModel:getInstance()
  8. self.mainVo = RoleManager.Instance.mainRoleInfo
  9. self.model = EmpowerModel:GetInstance()
  10. self.itemInfo = nil
  11. self.image_gray_list = {}
  12. self.gray_mat = ShaderTools.gray_mat
  13. self.condition_str = nil
  14. self.is_show_cond = false
  15. self.is_show_vip_cond = false
  16. self:Load()
  17. end
  18. function EmpowerShopItem:Load_callback()
  19. self.nodes = {
  20. "bg:img","item_con",
  21. "discount_con/discount_text:tmp","name_text:tmp","price_con/price_text:tmp",
  22. "lock_text:tmp","price_con:obj","price_con/money_icon:imgex",
  23. "discount_con:obj:img","limit_text:tmp","click_con:obj","red_dot:obj","line:img","descrb_text:tmp",
  24. }
  25. self:GetChildren(self.nodes)
  26. -- self.descrb_text_shadow = self:GetChild("descrb_text"):GetComponent("Shadow")
  27. self.awardItem = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
  28. self.awardItem:SetItemSize(86, 86)
  29. if self.need_refreshData then
  30. self:SetData(self.data, self.index, self.isChangeItem)
  31. end
  32. self:InitEvent()
  33. end
  34. function EmpowerShopItem:InitEvent()
  35. local function onBtnClickHandler(target, x, y)
  36. if self.isChangeItem then
  37. --Message.show("self.data.goods_id:",self.data.goods_id)
  38. -- local ok = function ( )
  39. -- self.model:Fire(EmpowerConst.EMPOWER_REQ_EVENT, 41408, self.data.goods_id)
  40. -- end
  41. -- local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.data.goods_id)
  42. -- local goods_name = GoodsModel:getInstance():getGoodsName(self.data.goods_id, false)
  43. -- goods_name = string.format("<color=%s>%s</color>", ShopItem.ColorStr[goodsVo.color],goods_name)
  44. -- -- local price = WordManager:GetMoneyFaceStr(self.data.money_type) .. HtmlColorTxt( self.data.price, ColorUtil.GREEN_DARK)
  45. -- local str = string.format('确认兑换 %s 吗?', goods_name)
  46. -- Alert.show(str, Alert.Type.Two,ok)
  47. local data = {
  48. shop_data = {
  49. price = 1,
  50. money_type = EmpowerConst.EmpowerMoneyId,
  51. discount = 100,
  52. goods_id = self.data.goods_id,
  53. num = 1,
  54. quota_type = 0,
  55. is_empower_exchange_shop = true,
  56. limit_num = 99,
  57. money_id = 270013,
  58. },
  59. }
  60. UIToolTipMgr:getInstance():AppendGoodsTips(self.data.goods_id, x, y, nil, nil, data, true)
  61. else
  62. --Message.show("self.index:",self.index)
  63. if self.data and self.data.is_pay == 0 then
  64. self.model:Fire(EmpowerConst.EMPOWER_REQ_EVENT, 41406,self.index)
  65. else
  66. local data = {
  67. shop_data = {
  68. price = self.data.price,
  69. money_type = self.data.money_type,
  70. discount = 100,
  71. goods_id = self.data.goods_id,
  72. num = self.data.num,
  73. quota_type = 0,
  74. is_empower_shop = true,
  75. limit_num = 1,
  76. item_index = self.index,
  77. },
  78. }
  79. UIToolTipMgr:getInstance():AppendGoodsTips(self.data.goods_id, x, y, nil, nil, data, true)
  80. end
  81. end
  82. end
  83. AddClickEvent(self.click_con_obj, onBtnClickHandler, 2)
  84. end
  85. function EmpowerShopItem:ClickCallFun(target)
  86. if not self.data then return end
  87. end
  88. function EmpowerShopItem:SetData(data, index, isChangeItem)
  89. self.data = data
  90. self.index = index
  91. self.isChangeItem = isChangeItem
  92. if self.is_loaded then
  93. -- local shop_cfg = Config.Shop
  94. -- if shop_cfg[data.key_id] then
  95. -- local tips = shop_cfg[data.key_id].tips
  96. -- if tips >= 1 then
  97. -- lua_resM:setImageSprite(self, self.hot_image_img, "shop_asset", "shop_tip"..tips)
  98. -- end
  99. -- self.hot_image_obj:SetActive(tips >= 1)
  100. -- end
  101. --[[ local name_color =
  102. {
  103. [1] = "#58e8c4",
  104. [2] = "#69d0ff",
  105. [3] = "#efafff",
  106. [4] = "#ffc076",
  107. [5] = "#ff96a1",
  108. [6] = "#ffec6b",
  109. }]]
  110. self.need_refreshData = false
  111. local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(data.goods_id)
  112. if goodsVo == nil then
  113. LogError("EmpowerShopItem:SetItemInfo : goodsVo is nil, goods_id is "..data.goods_id)
  114. return
  115. end
  116. -- local function call_back( )
  117. -- self:SetVisible(true)
  118. -- end
  119. -- lua_resM:setImageSprite(self, self.line_img, "common_asset", "shop_item_color"..goodsVo.color, false, call_back)
  120. -- 背景图
  121. local function call_back( )
  122. self:SetVisible(true)
  123. end
  124. lua_resM:setImageSprite(self, self.bg_img, "shopOut_asset", "shop_item_color"..goodsVo.color, false, call_back)
  125. -- 数量提示
  126. local equip_pos = EquipModel:getInstance():GetShopGoodsIdEquipPos( tonumber(data.goods_id) )
  127. if equip_pos then
  128. local need_num = EquipModel:getInstance():GetRedEquipShopCostlimitNum(equip_pos)
  129. local has_num = GoodsModel:getInstance():GetTypeGoodsNum(data.goods_id)
  130. local color = need_num <= has_num and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK
  131. self.limit_text_tmp.text = string.format('升品需求 %s/%s', HtmlColorTxt( has_num, color), need_num)
  132. end
  133. self.awardItem:SetData(data.goods_id, data.num, nil, nil, data.bind, nil, nil, self.isChangeItem)
  134. local goods_name = GoodsModel:getInstance():getGoodsName(data.goods_id, false)
  135. self.name_text_tmp.text = string.format("<color=%s>%s</color>", ShopItem.ColorStr[goodsVo.color],goods_name)
  136. self.price_text_tmp.text = data.price --round(data.price * data.discount / 100)
  137. if data.is_pay == 0 then
  138. self.price_text_tmp.text = HtmlColorTxt( " 免费", ColorUtil.GREEN_DARK)
  139. self.money_icon.gameObject:SetActive(false)
  140. else
  141. self.money_icon.gameObject:SetActive(true)
  142. end
  143. SetSizeDeltaX(self.price_text, self.price_text_tmp.preferredWidth)
  144. -- self.discount_text_tmp.text = (data.discount / 10) .. "折"
  145. self.discount_text_tmp.text = data.discount .. ""
  146. self.discount_con_obj:SetActive(data.discount ~= 0 and self.is_show_cond == false)
  147. self:SetMoneyIcon()
  148. self:SetItemGary(data.is_gray)
  149. if data.is_pay == 0 and data.state == 0 then
  150. self.red_dot_obj:SetActive(true)
  151. else
  152. self.red_dot_obj:SetActive(false)
  153. end
  154. else
  155. self.need_refreshData = true
  156. return
  157. end
  158. end
  159. -- 加载货币图标
  160. function EmpowerShopItem:SetMoneyIcon()
  161. if not self.data or not self.data.money_type then return end
  162. local asset, source = WordManager:GetCommonMoneyIcon(self.data.money_type)
  163. if self.data.money_type == EmpowerConst.EmpowerMoneyId then
  164. self.money_icon.transform.sizeDelta = co.TableXY(26,21)
  165. else
  166. self.money_icon.transform.sizeDelta = co.TableXY(40,40)
  167. end
  168. lua_resM:setImageSprite(self, self.money_icon_imgex, asset, source)
  169. end
  170. function EmpowerShopItem:SetItemGary(bool)
  171. local mat = bool and self.gray_mat or nil
  172. self.bg_img.material = mat
  173. --self.awardItem:SetGray(bool)
  174. --self.money_icon_imgex.gray = bool
  175. --self.discount_con_img.material = mat
  176. -- self.priceCon_bg.material = mat
  177. if bool then
  178. self.money_icon.gameObject:SetActive(false)
  179. self.descrb_text_tmp.color = Color(78/255,78/255,78/255)
  180. -- self.descrb_text_shadow.effectColor = Color(195/255,195/255,195/255,1)
  181. if self.isChangeItem then
  182. -- self.descrb_text_tmp.text = "已兑换"
  183. self.price_text_tmp.text = " 已兑换"
  184. else
  185. -- self.descrb_text_tmp.text = "已购买"
  186. self.price_text_tmp.text = " 已购买"
  187. end
  188. else
  189. self.descrb_text_tmp.color = Color(143/255,53/255,13/255)
  190. -- self.descrb_text_shadow.effectColor = Color(255/255,244/255,170/255,1)
  191. if self.isChangeItem then
  192. self.descrb_text_tmp.text = "兑换"
  193. else
  194. self.descrb_text_tmp.text = "购买"
  195. end
  196. end
  197. --[[local is_sale_out = self.data.quota_num - self.data.sold_out > 0
  198. local color = is_sale_out and ColorUtil.GREEN or ColorUtil.RED
  199. if bool then
  200. self.price.text = "<color=#979696>"..round(self.data.price * self.data.discount / 100).."</color>"
  201. if self.condition_str and self.is_show_vip_cond then
  202. self.OthercondTxt.text = "<color=#ffffff>"..self.condition_str.."</color>"
  203. end
  204. else
  205. self.price.text = "<color=#835741>"..round(self.data.price * self.data.discount / 100).."</color>"
  206. if self.condition_str and self.is_show_vip_cond then
  207. self.OthercondTxt.text = self.condition_str
  208. end
  209. end]]
  210. end
  211. function EmpowerShopItem:__delete()
  212. if self.awardItem then
  213. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
  214. self.awardItem = nil
  215. end
  216. end