源战役客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

307 строки
11 KiB

1 месяц назад
  1. GetGoodsItem = GetGoodsItem or BaseClass(BaseItem)
  2. function GetGoodsItem:__init()
  3. self.base_file = "common"
  4. self.layout_file = "GetGoodsItem"
  5. self.is_delay_callback = true
  6. self.can_buy = false
  7. self.model = BagModel:getInstance()
  8. self.need_refresh = false
  9. self.is_default_get_way = false
  10. self.show_type = false
  11. self.get_des_id = 0
  12. self:Load()
  13. end
  14. function GetGoodsItem:Load_callback()
  15. local nodes = {
  16. "buy_group/goods_name:tmp",
  17. "item_con:obj",
  18. "go_group/way_name:tmp",
  19. "bg", "go_group/go:obj",
  20. "buy_group/price_type:img",
  21. "buy_group/buy:obj:imgex",
  22. "buy_group:obj",
  23. "buy_group/price_num:tmp",
  24. "buy_group/goods_from:tmp",
  25. "icon:img:obj",
  26. "go_group:obj",
  27. "is_special:obj",
  28. "buy_group/buy/buy_text:tmp",
  29. "go_group/get_des:tmp",
  30. }
  31. self:GetChildren(nodes)
  32. self:InitEvent()
  33. if self.need_refresh then
  34. self:SetData(self.data, self.type_id, self.callback)
  35. end
  36. end
  37. function GetGoodsItem:InitEvent()
  38. local function onBtnClickHandler(target)
  39. if target == self.go_obj then
  40. self:GoFunc()
  41. elseif target == self.buy_obj then
  42. if self.shop_config and self.can_buy and self.total_cost then
  43. if self.show_type == "shop" then
  44. if self.shop_config.money_type == 1 or self.shop_config.money_type == 2 then
  45. local function ok_callback( ... )
  46. ShopModel:getInstance():Fire(ShopModel.BUY_GOODS, self.shop_config.key_id, 1)
  47. end
  48. local function toggle_function( flag )
  49. self.model.bag_quick_buy_toggle = flag
  50. end
  51. local function use_function( toggle_tip_data,call_fun_sum )
  52. print('Cat:GetGoodsItem.lua[54] self.model.bag_quick_buy_toggle', self.model.bag_quick_buy_toggle)
  53. if not self.model.bag_quick_buy_toggle then
  54. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  55. else
  56. call_fun_sum()
  57. end
  58. end
  59. local function recharge_open_call_back()
  60. self.model:Fire(BagModel.CLOSE_EQUIP_ITEM_GET_WAY_TIPS)
  61. end
  62. local buy_tip_data = {
  63. gold_type = self.shop_config.money_type,--货币类型
  64. cost_price = self.total_cost,--消耗金额
  65. ok_callback = ok_callback,--成功
  66. toggle_function = toggle_function,--多选
  67. togglePriceStr = string.format("<color=#fdffc2>%s</color> 购买商品",self.total_cost),--提示语
  68. use_function = use_function,--最终调用
  69. recharge_open_call_back = recharge_open_call_back,
  70. }
  71. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  72. else
  73. ShopModel:getInstance():Fire(ShopModel.BUY_GOODS, self.shop_config.key_id, 1)
  74. end
  75. else
  76. self.model:Fire(BagModel.CLOSE_EQUIP_ITEM_GET_WAY_TIPS)
  77. local temp_cfg = Config.Shop[self.shop_config.key_id]
  78. GlobalEventSystem:Fire(EventName.OPEN_SHOP_VIEW, temp_cfg.shop_type, temp_cfg.sub_type, temp_cfg.goods_id, nil, true)
  79. end
  80. else
  81. Message.show("当前商品已售空,请耐心等待补货")
  82. end
  83. end
  84. end
  85. AddClickEvent(self.go_obj, onBtnClickHandler)
  86. AddClickEvent(self.buy_obj, onBtnClickHandler)
  87. local function buy_suceess()
  88. self.shop_config = self:GetShopData(self.type_id, self.data)
  89. self:CheckCanBuy(self.shop_config)
  90. end
  91. self:BindEvent(ShopModel:getInstance(),ShopModel.UPDATE_GOODS_LIST, buy_suceess)
  92. end
  93. function GetGoodsItem:GoFunc()
  94. if self.is_default_get_way then
  95. Message.show("请前往运营活动")
  96. return
  97. end
  98. GlobalEventSystem:Fire(EventName.GOODS_TOOLS_TIPS_GO_TO_EVENT)
  99. if self.callback then
  100. self.callback()
  101. end
  102. if self.data[1] == "153" then --商城 ,是商城有可能有s第三个页签的处理
  103. OpenFun.Open(self.data[1], self.data[2], self.data[4])
  104. elseif self.data[1] == "151" then
  105. ComposeModel:getInstance():TryComposeJump(self.type_id)
  106. elseif self.data[1] == "610" and self.data[2] == "2" then -- 经验副本需要特殊处理,关闭所有的上层打开界面
  107. DailyModel:getInstance():Fire(DailyModel.OPEN_DAILY_COMMON_TIP_VIEW, false)
  108. OpenFun.Open(self.data[1], self.data[2])
  109. else
  110. OpenFun.Open(self.data[1], self.data[2])
  111. end
  112. end
  113. function GetGoodsItem:SetData(data, type_id, callback)
  114. self.data = data
  115. self.type_id = type_id
  116. self.callback = callback
  117. self.show_type = false
  118. if not self.data then return end
  119. if self.is_loaded then
  120. local cfg = OpenFun.GetFunCfg(self.data[1], self.data[2])
  121. self.get_des_id = self.data[6] and tonumber(self.data[6]) or 0
  122. self.is_default_get_way = false
  123. if cfg then
  124. local show_type = self.data[3] or "normal"
  125. local is_special = self.data[5] or "0"
  126. self.show_type = show_type
  127. self.shop_config = self:GetShopData(self.type_id, self.data)
  128. if self.shop_config then
  129. self.go_group_obj:SetActive(false)
  130. self.buy_group_obj:SetActive(true)
  131. self.item_con_obj:SetActive(true)
  132. self.icon_obj:SetActive(false)
  133. if not self.icon_item then
  134. self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
  135. self.icon_item:SetItemSize(62, 62)
  136. self.icon_item:ChangeCountVisible(false)
  137. --self.icon_item:SetEnableClick(false)
  138. end
  139. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.type_id)
  140. self.icon_item:SetData(self.type_id)
  141. self.goods_name_tmp.text = Language.substitute("<color={0}>{1}</color>", WordManager.GetGoodsColor(basic.color, false), Trim(basic.goods_name))
  142. self.price_num_tmp.text = tostring(round(self.shop_config.price * self.shop_config.discount/ 100))
  143. self:CheckCanBuy(self.shop_config)
  144. local asset, source = WordManager:GetCommonMoneyIcon(self.shop_config.money_type)
  145. lua_resM:setImageSprite(self, self.price_type_img, asset, source,false)
  146. if show_type == "shop" then
  147. -- SetAnchoredPosition(self.price_num, -83, -14)
  148. -- SetAnchoredPosition(self.price_type, -47, -14)
  149. -- SetAnchoredPosition(self.buy, 70, 19)
  150. self.goods_from_tmp.text = ""
  151. self.price_num_tmp.color = ColorUtil:ConvertHexToRGBColor("#ffffff")
  152. else --"show_two"
  153. local mid = 112
  154. local w = self.price_num_tmp.preferredWidth + 36
  155. -- SetAnchoredPosition(self.price_num, mid - w / 2 + 34, 22)
  156. -- SetAnchoredPosition(self.price_type, mid - w / 2, 22)
  157. -- SetAnchoredPosition(self.buy, 70, 0)
  158. self.goods_from_tmp.text = ""
  159. self.price_num_tmp.color = ColorUtil:ConvertHexToRGBColor("#ffffff")
  160. end
  161. else
  162. self.go_group_obj:SetActive(true)
  163. self.buy_group_obj:SetActive(false)
  164. if self.data[8] then -- 存在传入剩余次数的数据时,显示剩余次数
  165. self.way_name_tmp.text = self.data[8] == -1 and "次数不限"
  166. or string.format("剩余 <color=%s>%s</color> 次", self.data[8] > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, self.data[8])
  167. else
  168. self.way_name_tmp.text = cfg.name
  169. end
  170. local show_cfg = self.data[3] or ""
  171. local show_type_id = 0
  172. if show_cfg and show_cfg ~= "" then
  173. local str_list = Split(show_cfg, "_")
  174. if #str_list >= 2 then
  175. if str_list[1] == "goods" then
  176. show_type_id = tonumber(str_list[2])
  177. end
  178. end
  179. end
  180. if show_type == "normal" then
  181. self.item_con_obj:SetActive(false)
  182. self.icon_obj:SetActive(true)
  183. lua_resM:setImageSprite(self,self.icon_img,"activityIcon_asset",cfg.icon_res, false)
  184. SetSizeDelta(self.icon,62,62)
  185. else --"goods"
  186. self.item_con_obj:SetActive(true)
  187. self.icon_obj:SetActive(false)
  188. if not self.icon_item then
  189. self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.item_con)
  190. self.icon_item:SetItemSize(62, 62)
  191. self.icon_item:ChangeCountVisible(false)
  192. --self.icon_item:SetEnableClick(false)
  193. end
  194. self.icon_item:SetData(show_type_id == 0 and self.type_id or show_type_id)
  195. end
  196. self:SetGoodGetDes()
  197. end
  198. if self.icon_item then
  199. if is_special == "1" then
  200. self.icon_item:SetNumLimitVisible(true, 16)
  201. else
  202. self.icon_item:SetNumLimitVisible(false)
  203. end
  204. end
  205. else
  206. self.is_default_get_way = true
  207. self.go_group_obj:SetActive(true)
  208. self.buy_group_obj:SetActive(false)
  209. self.way_name_tmp.text = "运营活动"
  210. lua_resM:setImageSprite(self,self.icon_img,"activityIcon_asset","icon_99_1", false)
  211. self:SetGoodGetDes()
  212. end
  213. else
  214. self.need_refresh = true
  215. end
  216. end
  217. function GetGoodsItem:__delete()
  218. if self.icon_item then
  219. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.icon_item)
  220. self.icon_item = nil
  221. end
  222. end
  223. function GetGoodsItem:SetGoodGetDes()
  224. if self.get_des_id then
  225. local cfg = GoodsConst.GetWayDes[self.get_des_id]
  226. if cfg then
  227. SetAnchoredPositionY(self.way_name, 15)
  228. local str = ChuanWenManager:getInstance():FormatColorTag2(cfg.des, false)
  229. self.get_des_tmp.text = str
  230. else
  231. SetAnchoredPositionY(self.way_name, 3)
  232. end
  233. else
  234. SetAnchoredPositionY(self.way_name, 3)
  235. end
  236. end
  237. function GetGoodsItem:GetShopData(type_id, data)
  238. local shop_config = nil
  239. if type_id and data and data[1] and data[2] and data[3] and (data[3] == "shop" or data[3] == "shoptwo") then
  240. local list = ShopModel:getInstance():GetGoodsListInfo(tonumber(data[2]))
  241. for k,v in pairs(list) do
  242. for kk,vv in pairs(v) do
  243. if self.type_id == vv.goods_id then
  244. shop_config = vv
  245. break
  246. end
  247. end
  248. if shop_config then
  249. break
  250. end
  251. end
  252. end
  253. return shop_config
  254. end
  255. function GetGoodsItem:CheckCanBuy(shop_data)
  256. self.can_buy = false
  257. self.sold_out = false
  258. if shop_data then
  259. local limit_left_num = nil
  260. if shop_data.quota_type > 0 then
  261. local left_num = shop_data.quota_num - shop_data.sold_out
  262. left_num = left_num > 0 and left_num or 0
  263. limit_left_num = left_num
  264. else
  265. limit_left_num = nil
  266. end
  267. price = round(shop_data.price * shop_data.discount / 100)
  268. local money_num = GoodsModel:getInstance():GetGoodsNumFromType(shop_data.money_type)
  269. local limit_num = money_num / price
  270. limit_num = math.floor(limit_num)
  271. if limit_left_num then--如果是限购 先对比
  272. limit_num = limit_num > limit_left_num and limit_left_num or limit_num
  273. end
  274. limit_num = limit_num > 0 and limit_num or 1
  275. self.can_buy = limit_num > 0
  276. self.sold_out = limit_left_num ~= nil and limit_left_num == 0
  277. self.buy_imgex.gray = self.sold_out
  278. if self.sold_out then
  279. self.buy_text_tmp.text =HtmlColorTxt("已售完", "#ffffff")
  280. SetTMPSharedMaterial(self.buy_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  281. else
  282. self.total_cost = price
  283. self.buy_text_tmp.text = HtmlColorTxt(self.show_type == "shop" and "购买" or "前往购买", "#ffffff")
  284. SetTMPSharedMaterial(self.buy_text_tmp, ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn)
  285. end
  286. end
  287. end