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

150 lines
4.9 KiB

  1. TreasureHouseTaskItem = TreasureHouseTaskItem or BaseClass(BaseItem)
  2. local TreasureHouseTaskItem = TreasureHouseTaskItem
  3. function TreasureHouseTaskItem:__init()
  4. self.base_file = "treasureHouse"
  5. self.layout_file = "TreasureHouseTaskItem"
  6. self.model = TreasureHouseModel:GetInstance()
  7. self:Load()
  8. end
  9. function TreasureHouseTaskItem:Load_callback()
  10. self.nodes = {
  11. "btn:obj:imgex", "goods_image:img", "desc_text:tmp", "cost_image:img:obj", "num_text:tmp", "bg", "cost_text:tmp",
  12. "btn/btn_red:obj", "btn/btn_text:tmp",
  13. }
  14. self:GetChildren(self.nodes)
  15. self:AddEvents()
  16. if self.need_refreshData then
  17. self:UpdateView()
  18. end
  19. end
  20. function TreasureHouseTaskItem:AddEvents( )
  21. local function on_click( )
  22. if self.server_data then--有服务端的话 就要看看状态
  23. if self.server_data.state == 0 then--未完成
  24. if not self.is_buy then
  25. local link = stringtotable(self.data.link) or {}
  26. if TableSize(link) > 0 then
  27. OpenFun.Open(link[1],link[2])
  28. end
  29. else--购买的走购买协议
  30. if self.buy_type == 1 then--彩钻购买的
  31. if GoodsModel:getInstance():IsJinEnough(self.buy_cost) then
  32. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
  33. else
  34. local qc_data = {
  35. price = self.buy_cost,
  36. }
  37. GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
  38. end
  39. else
  40. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
  41. end
  42. end
  43. elseif self.server_data.state == 1 then--已完成
  44. if not self.is_buy then
  45. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10404, self.data.id)
  46. else
  47. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
  48. end
  49. elseif self.server_data.state == 2 then--已领取
  50. Message.show("今天已经完成这个任务了哦", "fault")
  51. end
  52. else
  53. if not self.is_buy then
  54. local link = stringtotable(self.data.link) or {}
  55. if TableSize(link) > 0 then
  56. OpenFun.Open(link[1],link[2])
  57. end
  58. else--购买的走购买协议
  59. self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10405, self.data.id)
  60. end
  61. end
  62. end
  63. AddClickEvent(self.btn_obj, on_click)
  64. end
  65. function TreasureHouseTaskItem:UpdateView( )
  66. local desc = Trim(self.data.desc)
  67. local details = stringtotable(self.data.details)
  68. local cur_num = 0
  69. local num = GoodsModel:getInstance():GetTypeGoodsNum(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
  70. local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( TreasureHouseConst.TREASURE_HOUSE_TICKET_ID ).goods_icon
  71. lua_resM:setOutsideImageSprite(self,self.goods_image_img,GameResPath.GetGoodsIcon(goods_icon),false)
  72. local color_str = ColorUtil.RED_DARK
  73. self.num_text_tmp.text = 1
  74. if details[1] == "buy" then--如果是购买类型的 就要显示购买
  75. self.is_buy = true
  76. self.buy_cost = details[2][1][3]
  77. self.buy_type = details[2][1][1]
  78. cur_num = self.data.daily_max
  79. color_str = ColorUtil.GREEN_DARK
  80. self.btn_text_tmp.text = "购买"
  81. self.cost_image_obj:SetActive(true)
  82. lua_resM:setOutsideImageSprite(self,self.cost_image_img,GameResPath.GetGoodsIcon(details[2][1][2]),false)
  83. self.cost_text_tmp.text = self.buy_cost
  84. SetAnchoredPositionY(self.btn, 14)
  85. else
  86. self.btn_text_tmp.text = "去完成"
  87. self.is_buy = false
  88. self.cost_image_obj:SetActive(false)
  89. self.cost_text_tmp.text = ""
  90. SetAnchoredPositionY(self.btn, 0)
  91. end
  92. local str = string.format("%s(%s/%s)", desc, HtmlColorTxt(cur_num, color_str), self.data.daily_max)
  93. self.btn_red_obj:SetActive(false)
  94. self.btn_imgex.gray = false
  95. if self.server_data then
  96. local num = self.server_data.times
  97. if self.is_buy then
  98. if num == self.data.daily_max then
  99. color_str = ColorUtil.RED_DARK
  100. else
  101. color_str = ColorUtil.GREEN_DARK
  102. end
  103. else
  104. if num == self.data.daily_max then
  105. color_str = ColorUtil.GREEN_DARK
  106. end
  107. end
  108. str = string.format("%s(%s/%s)", desc, HtmlColorTxt(num, color_str), self.data.daily_max)
  109. self.btn_red_obj:SetActive(self.server_data.state == 1)
  110. self.btn_imgex.gray = self.server_data.state == 2
  111. if self.server_data.state == 2 then
  112. SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  113. self.btn_text_tmp.text = "已完成"
  114. elseif self.server_data.state == 1 then
  115. self.btn_text_tmp.text = "完成"
  116. SetTMPSharedMaterial(self.btn_text_tmp,ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
  117. end
  118. end
  119. self.desc_text_tmp.text = str
  120. end
  121. function TreasureHouseTaskItem:SetData(index, data )
  122. self.index = index
  123. self.data = data
  124. if self.is_loaded then
  125. self.need_refreshData = false
  126. self:UpdateView()
  127. else
  128. self.need_refreshData = true
  129. end
  130. end
  131. function TreasureHouseTaskItem:SetServerData( data )
  132. self.server_data = data
  133. if self.is_loaded then
  134. self.need_refreshData = false
  135. self:UpdateView()
  136. else
  137. self.need_refreshData = true
  138. end
  139. end
  140. function TreasureHouseTaskItem:__delete( )
  141. end