源战役客户端
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.

263 regels
9.6 KiB

4 weken geleden
  1. MarketFocusItem = MarketFocusItem or BaseClass(BaseItem)
  2. local MarketFocusItem = MarketFocusItem
  3. function MarketFocusItem:__init()
  4. self.base_file = "market"
  5. self.layout_file = "MarketFocusItem"
  6. self.model = MarketModel:GetInstance()
  7. self:Load()
  8. end
  9. function MarketFocusItem:Load_callback()
  10. self.nodes = {
  11. "time_text:tmp","one_price_text:tmp","auction_price_text:tmp","focus_btn:obj:img","my_price_text:tmp",
  12. "buy_btn:obj:imgex","auction_btn/auction_btn_text:tmp","auction_btn:obj:imgex","name_text:tmp","item_con",
  13. "show_image:obj","my_icon:obj","my_image:obj","one_image:obj","auction_image:obj","my_text:tmp:obj",
  14. "focus_text:tmp", "buy_btn/buy_btn_text:tmp",
  15. }
  16. self:GetChildren(self.nodes)
  17. self.awardItem = UIObjPool:PopItem(UIObjPool.UIType.AwardItem,self.item_con)
  18. self.awardItem:SetEnableClick(false)
  19. self.awardItem:SetItemSize(78, 78)
  20. self:AddEvents()
  21. if self.need_refreshData then
  22. self:UpdateView()
  23. end
  24. end
  25. function MarketFocusItem:AddEvents( )
  26. function on_click( target )
  27. if target == self.focus_btn_obj then
  28. if self.is_like then
  29. self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15511, self.data.id)
  30. else
  31. self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15510, self.data.id)
  32. end
  33. elseif target == self.auction_btn_obj then
  34. if self.is_my_sales then
  35. Message.show("不能购买自己的商品哦~")
  36. return
  37. end
  38. if self.no_auction_price then
  39. Message.show("该商品不能竞拍购买哦~")
  40. else
  41. self.model:Fire(MarketModel.OPEN_MARKET_BUY_VIEW, self.data, MarketModel.AUCTION_PRICE_TYPE)
  42. end
  43. elseif target == self.buy_btn_obj then
  44. if self.is_my_sales then
  45. Message.show("不能购买自己的商品哦~")
  46. return
  47. end
  48. if self.no_one_price then
  49. Message.show("该商品不能一口价购买哦~")
  50. else
  51. self.model:Fire(MarketModel.OPEN_MARKET_BUY_VIEW, self.data, MarketModel.ONE_PRICE_TYPE)
  52. end
  53. end
  54. end
  55. AddClickEvent(self.buy_btn_obj, on_click)
  56. AddClickEvent(self.focus_btn_obj, on_click)
  57. AddClickEvent(self.auction_btn_obj, on_click)
  58. local function onBtnClickHandler(target, x, y)
  59. if target == self.gameObject then
  60. local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.data.type_id)
  61. if goods_vo.type == GoodsModel.TYPE.EQUIP then
  62. UIToolTipMgr:getInstance():AppendEquipTips(self.data.type_id, x, y, self.data, nil, nil, {"buyBtn"},"market_buy")
  63. else
  64. local can_auction = self.model:IsGoodsCanAuction(self.data.type_id) and self.can_auction
  65. local can_buy_one = self.model:IsGoodsCanBuyOnePrice(self.data.type_id)
  66. if can_auction and can_buy_one then
  67. UIToolTipMgr:getInstance():AppendGoodsTips(self.data.type_id, x, y, self.data, {"marketBuyBtn","marketActionBtn"}, nil, true)
  68. elseif can_auction and not can_buy_one then
  69. UIToolTipMgr:getInstance():AppendGoodsTips(self.data.type_id, x, y, self.data, {"marketActionBtn"}, nil, true)
  70. elseif can_buy_one and not can_auction then
  71. UIToolTipMgr:getInstance():AppendGoodsTips(self.data.type_id, x, y, self.data, {"marketBuyBtn"}, nil, true)
  72. end
  73. end
  74. end
  75. end
  76. AddClickEvent(self.gameObject, onBtnClickHandler)
  77. local function on_price_up( id, price )
  78. if self.data.id == id then
  79. self.data.price = price
  80. self:UpdateView()
  81. end
  82. end
  83. self:BindEvent(self.model, MarketModel.UPDATE_ONE_GOODS_BY_PRICE_UP, on_price_up)
  84. end
  85. function MarketFocusItem:UpdateView( )
  86. self.name_text_tmp.text = GoodsModel:getInstance():getGoodsName(self.data.type_id,true)
  87. local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.data.type_id)
  88. self.is_my_sales = self.data.role_id == RoleManager.Instance.mainRoleInfo.role_id
  89. if goods_vo.buyout_price == 0 then
  90. self.one_price_text_tmp.text = ""
  91. self.no_one_price = true
  92. else
  93. self.one_price_text_tmp.text = self.data.get_price
  94. self.no_one_price = false
  95. end
  96. if goods_vo.trade_price == 0 then
  97. self.auction_price_text_tmp.text = ""
  98. self.no_auction_price = true
  99. else
  100. if self.data.aution_num > 0 then--出过价的要变色
  101. self.auction_price_text_tmp.text = HtmlColorTxt(self.data.price, ColorUtil.YELLOW_DARK)
  102. self.my_text_tmp.text = "该商品正在竞价中"
  103. else
  104. self.auction_price_text_tmp.text = self.data.price
  105. end
  106. self.no_auction_price = false
  107. end
  108. local market_show_time = goods_vo.market_show_time
  109. local equip_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.data)
  110. equip_data.equip_key = "EquipView"
  111. GoodsModel:getInstance():SetBaseInfo(equip_data.goods_vo)
  112. equip_data.goods_vo.is_market = true
  113. self.awardItem:SetData(self.data.type_id, self.data.goods_num, nil, equip_data)
  114. local can_tip, flag = EquipModel:getInstance():EquipCanShowGoodsTip(equip_data.goods_vo)
  115. self.awardItem:ChangeEquipState(flag)
  116. if self.data.up_time + market_show_time > TimeUtil:getServerTime( ) then
  117. self.rest_time = self.data.up_time + market_show_time - TimeUtil:getServerTime( )
  118. self.is_show_time = true
  119. else
  120. self.rest_time = self.data.end_time - TimeUtil:getServerTime( )
  121. self.is_show_time = false
  122. end
  123. self.is_like = self.data.is_like == 1 and true or false
  124. if self.is_like then
  125. lua_resM:setImageSprite(self, self.focus_btn_img, "market_asset", "market_icon1",true)
  126. self.focus_text_tmp.text = "已关注"
  127. else
  128. lua_resM:setImageSprite(self, self.focus_btn_img, "market_asset", "market_icon2",true)
  129. self.focus_text_tmp.text = "关注"
  130. end
  131. self.focus_btn_obj:SetActive(goods_vo.market_show_time > 0)
  132. SetAnchoredPositionY(self.name_text, goods_vo.market_show_time > 0 and 20 or 0)
  133. if self.is_show_time then
  134. self.focus_text_tmp.text = "开拍提醒"
  135. else
  136. if goods_vo.market_show_time > 0 then
  137. self.focus_text_tmp.text = (self.is_like) and "取消关注" or "关注"
  138. else
  139. self.focus_text_tmp.text = ""
  140. end
  141. end
  142. self.can_auction = true
  143. if self.data.role_id > 655 and self.data.sell_type == 2 and not self.no_one_price then --公会拍卖玩家上架且有一口价的不能竞拍
  144. self.can_auction = false
  145. end
  146. self.show_image_obj:SetActive(self.is_show_time)
  147. if self.no_one_price or self.is_my_sales then
  148. self.buy_btn_imgex.gray = true
  149. SetTMPSharedMaterial(self.buy_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  150. else
  151. self.buy_btn_imgex.gray = self.is_show_time
  152. if self.is_show_time then
  153. SetTMPSharedMaterial(self.buy_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  154. else
  155. SetTMPSharedMaterial(self.buy_btn_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
  156. end
  157. end
  158. if self.no_auction_price then
  159. self.auction_btn_imgex.gray = true
  160. SetTMPSharedMaterial(self.auction_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  161. else
  162. self.auction_btn_imgex.gray = self.is_show_time or not self.can_auction
  163. if self.is_show_time or not self.can_auction then
  164. SetTMPSharedMaterial(self.auction_btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  165. else
  166. SetTMPSharedMaterial(self.auction_btn_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkBlueBtn)
  167. end
  168. end
  169. -- self.my_price_text_tmp.text = self.data.my_price > 0 and self.data.my_price or ""
  170. -- if self.data.my_price == self.data.price and self.data.price > 0 then
  171. -- self.auction_btn_text_tmp.text = "出价最高"
  172. -- self.my_text_tmp.text = "您的出价"
  173. -- self:SetMyPriceConVisible(true)
  174. -- lua_resM:setImageSprite(self, self.my_image_img, "market_asset", "market_item5", true)
  175. -- else
  176. -- self.my_text_tmp.text = "您的出价"
  177. -- self:SetMyPriceConVisible(self.data.my_price > 0)
  178. -- lua_resM:setImageSprite(self, self.my_image_img, "market_asset", "market_item15", true)
  179. -- end
  180. self.auction_btn_text_tmp.text = "竞价"
  181. if self.data.my_price == self.data.price and self.data.price > 0 then
  182. self.my_text_tmp.text = "亲,目前您的出价最高"
  183. elseif self.data.my_bid == 1 then
  184. self.my_text_tmp.text = HtmlColorTxt("您的出价已被超过", ColorUtil.RED_DARK)
  185. end
  186. self:SetMyPriceConVisible(self.data.my_price > 0 or self.data.aution_num > 0)
  187. if not self.time_str then
  188. self:UpdateTime()
  189. end
  190. end
  191. function MarketFocusItem:UpdateTime( )
  192. self.time_str = "MarketFocusItem"..self.index
  193. if self.rest_time>0 then
  194. local function time_callback( ... )
  195. self.rest_time = self.rest_time - 1
  196. if self.rest_time>=0 then
  197. self.time_text_tmp.text = TimeUtil:convertTime(self.rest_time)
  198. else
  199. if self.is_show_time then--如果是公示期到了,就刷新一下时间
  200. self:UpdateView()
  201. else
  202. self.time_text_tmp.text = HtmlColorTxt("已到期", ColorUtil.RED_DARK)
  203. self.model:DeleteFuncCallBack(self.time_str)
  204. self.time_str = nil
  205. end
  206. end
  207. end
  208. self.model:SetFuncCallBack(time_callback, self.time_str)
  209. else
  210. if self.is_show_time then--如果是公示期到了,就刷新一下时间
  211. self:UpdateView()
  212. else
  213. self.time_text_tmp.text = HtmlColorTxt("已到期", ColorUtil.RED_DARK)
  214. self.model:DeleteFuncCallBack(self.time_str)
  215. self.time_str = nil
  216. end
  217. end
  218. end
  219. function MarketFocusItem:SetData(index, data )
  220. self.index = index
  221. self.data = data
  222. if self.is_loaded then
  223. self.need_refreshData = false
  224. self:UpdateView()
  225. else
  226. self.need_refreshData = true
  227. end
  228. end
  229. function MarketFocusItem:SetMyPriceConVisible( bool )
  230. -- self.my_image_obj:SetActive(bool)
  231. -- self.my_icon_obj:SetActive(bool)
  232. -- self.my_text_obj:SetActive(bool)
  233. self.my_image_obj:SetActive(bool)
  234. self.my_text_obj:SetActive(bool)
  235. self.my_icon_obj:SetActive(false)
  236. end
  237. function MarketFocusItem:__delete( )
  238. if self.time_str then
  239. self.model:DeleteFuncCallBack(self.time_str)
  240. end
  241. if self.awardItem then
  242. UIObjPool:PushItem(UIObjPool.UIType.AwardItem, self.awardItem)
  243. self.awardItem = nil
  244. end
  245. if self.on_update_view_id then
  246. self.model:UnBind(self.on_update_view_id)
  247. self.on_update_view_id = nil
  248. end
  249. end