源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.9 KiB

  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 圣物兑换界面商品节点
  4. -- *>
  5. PsionicExchangeItem = PsionicExchangeItem or BaseClass(BaseItem)
  6. local PsionicExchangeItem = PsionicExchangeItem
  7. PsionicExchangeItem.ColorStr = {
  8. [1] = "#58e8c4",
  9. [2] = "#69d0ff",
  10. [3] = "#efafff",
  11. [4] = "#ffc076",
  12. [5] = "#ff96a1",
  13. [6] = "#ffec6b",
  14. }
  15. function PsionicExchangeItem:__init(parent_wnd,prefab_asset,layer_name)
  16. self.base_file = "psionic"
  17. self.layout_file = "PsionicExchangeItem"
  18. self.parent_wnd = parent_wnd
  19. self.layer_name = layer_name
  20. self.have_num = 0
  21. self.is_enough = true -- 材料足够兑换
  22. self.model = PsionicModel:getInstance()
  23. self.goods_model = GoodsModel:getInstance()
  24. self:Load()
  25. end
  26. function PsionicExchangeItem:Load_callback()
  27. local nodes = {
  28. "bg:img",
  29. "add_btn:obj",
  30. "price_icon:img",
  31. "item_con",
  32. "need_num:tmp",
  33. "name:tmp",
  34. "exchange_lb:obj"
  35. }
  36. self:GetChildren(nodes)
  37. self.award_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_con)
  38. self.award_item:SetItemSize(78, 78)
  39. self.award_item:SetAnchoredPosition(0, 0)
  40. self.award_item:SetVisible(false)
  41. self:AddEvents()
  42. if self.need_refreshData then
  43. self:UpdateView()
  44. end
  45. end
  46. function PsionicExchangeItem:AddEvents( )
  47. local function click_event(target, x, y)
  48. if target == self.exchange_lb_obj then -- 兑换按钮
  49. self:OnExchangeBtnClick(x, y)
  50. elseif target == self.add_btn_obj then -- 添加按钮
  51. if self.cost_cfg then
  52. local cost_goods_id = self.cost_cfg[2]
  53. UIToolTipMgr:getInstance():AppendGoodsTips(cost_goods_id, x, y, nil, nil, nil, nil, true)
  54. end
  55. end
  56. end
  57. AddClickEvent(self.exchange_lb_obj, click_event)
  58. AddClickEvent(self.add_btn_obj, click_event)
  59. -- 背包更新或者兑换成功时刷新节点扣费数据
  60. local function update_goods_num(tab_id)
  61. if not tab_id or tab_id == PsionicConst.TabId.PExchange then
  62. self:UpdateCostData()
  63. end
  64. end
  65. self:BindEvent(self.model, PsionicConst.UPDATE_RED_BY_TABID, update_goods_num)
  66. -- self:BindEvent(self.model, PsionicConst.UPDATE_PSIONIC_ADVANCE_GOODSNUM, update_goods_num)
  67. -- self:BindEvent(self.model, PsionicConst.EXCHANGE_SUCCEED, update_goods_num)
  68. end
  69. function PsionicExchangeItem:SetData( cfg_data )
  70. self.cfg_data = cfg_data
  71. self.cost_cfg = cfg_data and self.cfg_data.cost and stringtotable(self.cfg_data.cost)[1] or nil
  72. if self.is_loaded then
  73. self.need_refreshData = false
  74. self:UpdateView()
  75. else
  76. self.need_refreshData = true
  77. end
  78. end
  79. function PsionicExchangeItem:UpdateView( )
  80. self:UpdateBasicData()
  81. self:UpdateCostData()
  82. end
  83. -- 加载基础数据
  84. function PsionicExchangeItem:UpdateBasicData( )
  85. if not self.cfg_data or not self.cost_cfg then return end
  86. -- 加载节点样式
  87. local goodsVo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.cfg_data.goodsid)
  88. -- lua_resM:setImageSprite(self, self.name_bg_img, "common_asset", "shop_item_color"..goodsVo.color, false)
  89. self.award_item:SetData(self.cfg_data.goodsid)
  90. self.award_item:SetVisible(true)
  91. self.name_tmp.text = HtmlColorTxt(Trim(goodsVo.goods_name), ShopItem.ColorStr[goodsVo.color])
  92. lua_resM:setImageSprite(self, self.bg_img, "shopOut_asset", "shop_item_color"..goodsVo.color, false)
  93. lua_resM:setOutsideImageSprite(self, self.price_icon_img, GameResPath.GetGoodsIcon(self.cost_cfg[2]), false)
  94. end
  95. function PsionicExchangeItem:UpdateCostData( )
  96. if not self.cfg_data then return end
  97. self.have_num = self.goods_model:GetTypeGoodsNum(self.cost_cfg[2])
  98. self.is_enough = self.have_num >= self.cost_cfg[3]
  99. self.need_num_tmp.text = string.format("<color=%s>%s</color>/%s",
  100. self.is_enough and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK,
  101. self.have_num, self.cost_cfg[3])
  102. -- self.ex_btn_imgex.gray = not is_enough
  103. -- self.ex_btn_lb_tmp.color = ColorUtil:ConvertHexToRGBColor(is_enough and "8F350D" or "4e4e4e")
  104. -- self.ex_btn_lb_outline.effectColor = ColorUtil:ConvertHexToRGBColor(is_enough and "FFF799" or "DBDBDB")
  105. end
  106. function PsionicExchangeItem:OnExchangeBtnClick(x, y)
  107. if self.cost_cfg and self.is_enough then
  108. local data = {
  109. shop_data = {
  110. price = self.cost_cfg[3],
  111. money_id = self.cost_cfg[2],
  112. goods_id = self.cfg_data.goodsid,
  113. quota_type = 0,
  114. discount = 100,
  115. is_psionic_shop = true,
  116. sort = self.cfg_data.sort,
  117. },
  118. }
  119. UIToolTipMgr:getInstance():AppendGoodsTips(self.cfg_data.goodsid, x, y, nil, nil, data, true)
  120. else
  121. Message.show("兑换所需的材料不足", "fault")
  122. end
  123. end
  124. function PsionicExchangeItem:__delete( )
  125. end