源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

454 行
19 KiB

  1. NiceGoodsTips = NiceGoodsTips or BaseClass(BaseView)
  2. local NiceGoodsTips = NiceGoodsTips
  3. --[[
  4. NiceGoodsTips.TabData = {
  5. [1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
  6. }
  7. --]]
  8. function NiceGoodsTips:__init()
  9. self.base_file = "common"
  10. self.layout_file = "NiceGoodsTips"
  11. self.layer_name = "Top"
  12. self.destroy_imm = true
  13. self.is_set_zdepth = true
  14. self.use_background = true --全屏界面默认使用这个参数
  15. self.click_bg_toClose = true
  16. self.hide_maincancas = false
  17. self.change_scene_close = true
  18. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  19. self.need_show_money = false --是否要显示顶部的金钱栏
  20. self.model = GoodsModel:getInstance()
  21. self.shop_model = ShopModel:getInstance()
  22. self.pos_x = 0
  23. self.pos_y = 0
  24. self.goods_vo = nil
  25. self.is_show_btn = nil
  26. self.mainVo = RoleManager.Instance.mainRoleInfo
  27. self.load_callback = function ()
  28. self:LoadSuccess()
  29. self:AddEvent()
  30. end
  31. self.open_callback = function ( )
  32. self:OpenSuccess()
  33. end
  34. self.destroy_callback = function ( )
  35. self:DestroySuccess()
  36. end
  37. end
  38. function NiceGoodsTips:Open(type_id, x, y, goods_vo, show_btn_list, parm_list)
  39. self.type_id = type_id
  40. self.is_show_btn = goods_vo ~= nil
  41. self.show_btn_list = show_btn_list
  42. self.parm_list = parm_list
  43. self.shop_data = parm_list and parm_list.shop_data or nil
  44. self.goods_vo = goods_vo or self.model:GetGoodsBasicByTypeId(type_id)
  45. self.pos_x = x
  46. self.pos_y = y
  47. BaseView.Open(self)
  48. end
  49. function NiceGoodsTips:LoadSuccess()
  50. local nodes = {
  51. "layout/base_con/attr_scroll","layout/base_con/line1:obj","layout/base_con/attr_scroll/Viewport/attr_con",
  52. "layout/base_con/designation_con:obj","layout/base_con/power_text:txt","layout/base_con/bg:raw",
  53. "layout/base_con/get_text:txt","layout/base_con/desc_text:txt","layout/base_con/name_text:txt","layout/base_con/limit_image:obj",
  54. ----------------------------
  55. "layout:obj","layout/base_con/designation_con/designation_image:obj:img",
  56. "layout/base_con/designation_con/designation_text:txt","layout/base_con/designation_con/designation_effect:obj",
  57. "layout/base_con/roleCon:obj","layout/btns_con:obj",
  58. --商城购买界面
  59. "layout/shop_con:obj",
  60. }
  61. self:GetChildren(nodes)
  62. self.shiyongBtn = self:GetChild("layout/btns_con/shiyongBtn").gameObject
  63. self.hechengBtn = self:GetChild("layout/btns_con/hechengBtn").gameObject
  64. self.chushouBtn = self:GetChild("layout/btns_con/chushouBtn").gameObject
  65. self.yulanBtn = self:GetChild("layout/btns_con/yulanBtn").gameObject
  66. self.storeBtn = self:GetChild("layout/btns_con/storeBtn").gameObject
  67. self.takeBtn = self:GetChild("layout/btns_con/takeBtn").gameObject
  68. self.splitBtn = self:GetChild("layout/btns_con/splitBtn").gameObject
  69. self.shelvesUpBtn = self:GetChild("layout/btns_con/shelvesUpBtn").gameObject
  70. self.shelvesDownBtn = self:GetChild("layout/btns_con/shelvesDownBtn").gameObject
  71. self.decomposeBtn = self:GetChild("layout/btns_con/decomposeBtn").gameObject
  72. self.oneKeyBuyBtn = self:GetChild("layout/btns_con/oneKeyBuyBtn").gameObject
  73. self.replaceBtn = self:GetChild("layout/btns_con/replaceBtn").gameObject
  74. self.dropBtn = self:GetChild("layout/btns_con/dropBtn").gameObject
  75. self.capsuleEggTakeBtn = self:GetChild("layout/btns_con/capsuleEggTakeBtn").gameObject
  76. self.btns_list = {
  77. self.shiyongBtn, self.hechengBtn, self.chushouBtn,
  78. self.yulanBtn, self.storeBtn, self.takeBtn, self.splitBtn,
  79. self.shelvesUpBtn, self.shelvesDownBtn,
  80. self.oneKeyBuyBtn, self.decomposeBtn, self.replaceBtn, self.dropBtn,self.capsuleEggTakeBtn
  81. }
  82. end
  83. function NiceGoodsTips:AddEvent()
  84. local function onClickBtnHandler(target)
  85. if (self.goods_vo and (self.is_show_btn or CapsuleEggModel:getInstance():IsShowCapsuleEggTakeOutBtn() or self:ForeceTriggerEvt())) then
  86. if target == self.shiyongBtn then
  87. if self.mainVo.level < self.goods_vo.level then
  88. Message.show("等级不足,无法使用")
  89. return
  90. end
  91. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.goods_vo.type_id)
  92. if basic.use_way and basic.use_way ~= "" then
  93. local use_table = stringtotable(basic.use_way)
  94. if use_table and use_table[1] and use_table[2] then
  95. --特殊参数处理
  96. local arg1, arg2
  97. if self.goods_vo.type_id == 102601 then --扩容钥匙
  98. local num = self.goods_vo.goods_num
  99. local open_count = math.max(math.floor(num / 2), 1)
  100. arg1 = self.goods_pos_type
  101. arg2 = open_count
  102. end
  103. OpenFun.Open(tonumber(use_table[1]), tonumber(use_table[2]), arg1, arg2)
  104. self:Close()
  105. return
  106. end
  107. end
  108. self:CheckSecondView()
  109. elseif target == self.hechengBtn then
  110. self:JumpComposeFunc()
  111. elseif target == self.chushouBtn then
  112. GlobalEventSystem:Fire(EventName.OPEN_SEll_VIEW, self.goods_vo)
  113. elseif target == self.storeBtn then
  114. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15003, self.goods_vo.goods_id, GoodsModel.GOODS_POS_TYPE.bag, GoodsModel.GOODS_POS_TYPE.warehouse)
  115. elseif target == self.takeBtn then
  116. GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT, 15003, self.goods_vo.goods_id, GoodsModel.GOODS_POS_TYPE.warehouse, GoodsModel.GOODS_POS_TYPE.bag)
  117. elseif target == self.splitBtn then
  118. BagModel:getInstance():Fire(BagModel.OPEN_BATHANDLE_VIEW, self.goods_vo, SplitView.TYPE.SPLIT)
  119. elseif target == self.yulanBtn then
  120. elseif target == self.shelvesUpBtn then
  121. elseif target == self.shelvesDownBtn then
  122. elseif target == self.oneKeyBuyBtn then
  123. elseif target == self.decomposeBtn then
  124. BagModel:getInstance():Fire(BagModel.OPEN_EQUIP_DECOMPOSE_VIEW, self.goods_vo)
  125. elseif target == self.dropBtn then
  126. BagModel:getInstance():Fire(BagModel.OPEN_BATHANDLE_VIEW, self.goods_vo, SplitView.TYPE.BAT_DROP)
  127. elseif target == self.replaceBtn then
  128. if self.goods_vo then
  129. local has_vo, main, sub = HorseModel:getInstance():CheckVoIsOnMaterialTab(self.goods_vo)
  130. if has_vo then
  131. local typ = (self.parm_list and self.parm_list.material_type and self.parm_list.material_type ~= 0) and self.parm_list.material_type or main
  132. local pos = (self.parm_list and self.parm_list.material_pos and self.parm_list.material_pos ~= 0) and self.parm_list.material_pos or sub
  133. HorseModel:getInstance():Fire(HorsePetEvent.SELECT_MATERIAL_VIEW, typ, true, pos)
  134. self:Close()
  135. return
  136. end
  137. end
  138. elseif target == self.capsuleEggTakeBtn then --龙神宝库临时仓库取出按钮
  139. local now_warehouse_selected_goods_id = CapsuleEggModel:getInstance():GetWarehouseNowSelectedGoodsId()
  140. CapsuleEggModel:getInstance():Fire(CapsuleEggConst.REQUEST_CCMD_EVENT,17008,now_warehouse_selected_goods_id)
  141. CapsuleEggModel:getInstance():ResetWarehouseNowSelectedGoodsId()
  142. end
  143. end
  144. self:Close()
  145. end
  146. AddClickEvent(self.shiyongBtn, onClickBtnHandler)
  147. AddClickEvent(self.hechengBtn, onClickBtnHandler)
  148. AddClickEvent(self.chushouBtn, onClickBtnHandler)
  149. AddClickEvent(self.storeBtn, onClickBtnHandler)
  150. AddClickEvent(self.takeBtn, onClickBtnHandler)
  151. AddClickEvent(self.splitBtn, onClickBtnHandler)
  152. AddClickEvent(self.yulanBtn, onClickBtnHandler)
  153. AddClickEvent(self.shelvesUpBtn, onClickBtnHandler)
  154. AddClickEvent(self.shelvesDownBtn, onClickBtnHandler)
  155. AddClickEvent(self.oneKeyBuyBtn, onClickBtnHandler)
  156. AddClickEvent(self.decomposeBtn, onClickBtnHandler)
  157. AddClickEvent(self.replaceBtn, onClickBtnHandler)
  158. AddClickEvent(self.dropBtn, onClickBtnHandler)
  159. AddClickEvent(self.capsuleEggTakeBtn,onClickBtnHandler)
  160. function on_close( )
  161. self:Close()
  162. end
  163. self:BindEvent(self.shop_model,ShopModel.CLOSE_SHOP_BUY_VIEW, on_close)
  164. end
  165. function NiceGoodsTips:OpenSuccess()
  166. self:UpdateView()
  167. end
  168. function NiceGoodsTips:UpdateView()
  169. if self.goods_vo == nil then return end
  170. local basic = self.model:GetGoodsBasicByTypeId(self.type_id)
  171. self.attr_list = {}
  172. self.designation_con_obj:SetActive(false)
  173. self.roleCon_obj:SetActive(false)
  174. if basic.type == GoodsModel.TYPE.DESIGNATION then
  175. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("designation_tip_bg"),true)
  176. local cfg = Config.Dsgt
  177. local designation_id = DesignationModel:GetInstance():GetDesignationIdByGoodsId(self.type_id)
  178. self.attr_list = stringtotable(cfg[designation_id].attr_list)
  179. local is_limit = DesignationModel:GetInstance():IsDesignationLimitTime(designation_id)
  180. self.limit_image_obj:SetActive(is_limit)
  181. self.designation_image_obj:SetActive(false)
  182. self.designation_effect_obj:SetActive(false)
  183. self.name_text_txt.text = ""
  184. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
  185. if cfg[designation_id].type == 1 then--文字称号(文字称号也用图片了)
  186. self.designation_image_obj:SetActive(true)
  187. lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetDesignImage(cfg[designation_id].id), true)
  188. self.designation_text_txt.text = ""
  189. elseif cfg[designation_id].type == 2 then--图片称号
  190. self.designation_image_obj:SetActive(true)
  191. lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetDesignImage(cfg[designation_id].id), true)
  192. self.designation_text_txt.text = ""
  193. elseif cfg[designation_id].type == 3 then--特效称号
  194. self.designation_image_obj:SetActive(true)
  195. local data = DesignationConst.DesignationData[cfg[designation_id].id] or DesignationConst.DesignationData[0]
  196. local action = cc.Animation.New(data,0.15)
  197. cc.ActionManager:getInstance():addAction(cc.RepeatForever.New(action),self.designation_image.transform)
  198. self.designation_text_txt.text = ""
  199. end
  200. self.designation_con_obj:SetActive(true)
  201. elseif basic.type == GoodsModel.TYPE.FASHION then
  202. local fashion_id,color_id = FashionModel:getInstance():GetFashionIdByGoodsId(self.type_id)
  203. local cur_cfg = Config.Fashionstarup[fashion_id.."@"..color_id.."@0"]
  204. if cur_cfg then
  205. self.attr_list = stringtotable(cur_cfg.attr_list)
  206. end
  207. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("fashion_tip_bg"),true)
  208. local is_limit = FashionModel:GetInstance():IsFashionLimitTime(fashion_id,color_id)
  209. self.limit_image_obj:SetActive(is_limit)
  210. self.roleCon_obj:SetActive(true)
  211. elseif basic.type == GoodsModel.TYPE.CHILDTOY then
  212. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("designation_tip_bg"),true)
  213. self.designation_con_obj:SetActive(true)
  214. self.designation_image_obj:SetActive(true)
  215. lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetChildHandbookIcon(basic.type_id), true)
  216. if DeepCopy(Config.Childtoynew)[basic.type_id] then
  217. self.attr_list = stringtotable(DeepCopy(Config.Childtoynew)[basic.type_id].attr_list)
  218. end
  219. end
  220. self.name_text_txt.text = basic.goods_name
  221. self.get_text_txt.text = basic.getway
  222. self.desc_text_txt.text = basic.intro
  223. self:SetBtnCon()
  224. self:UpdateAttrCon()
  225. if self.shop_data then
  226. self.shop_con_obj:SetActive(true)
  227. self:UpdateShopView()
  228. else
  229. self.shop_con_obj:SetActive(false)
  230. end
  231. end
  232. function NiceGoodsTips:UpdateAttrCon( )
  233. local attr_list = self.attr_list
  234. if not self.attr_list_com then
  235. self.attr_list_com = self:AddUIComponent(UI.ItemListCreator)
  236. end
  237. local child_names = {
  238. "num_text:txt","name_text:txt",
  239. }
  240. self.power_text_txt.text = GetFighting(attr_list)
  241. local function on_update( item,i,v )
  242. local _, name, _, val = WordManager:GetPropertyInfo(v[1], v[2])
  243. item.name_text_txt.text = name..""
  244. item.num_text_txt.text = val
  245. end
  246. local info = {
  247. data_list = attr_list,
  248. item_con = self.attr_con,
  249. prefab_ab_name = "common",
  250. prefab_res_name = "NiceGoodsAttrItem",
  251. item_width = 160,
  252. item_height = 34,
  253. space_x = 2,
  254. space_y = 2,
  255. start_x = 2,
  256. start_y = -2,
  257. scroll_view = self.attr_scroll,
  258. create_frequency = 0.05,
  259. is_scroll_back_on_update = false,
  260. child_names = child_names,
  261. on_update_item = function(item, i, v)
  262. on_update(item,i,v)
  263. end,
  264. }
  265. self.attr_list_com:UpdateItems(info)
  266. end
  267. function NiceGoodsTips:SetBtnCon( )
  268. local basic = self.model:GetGoodsBasicByTypeId(self.type_id)
  269. for i, v in pairs(self.btns_list) do
  270. v:SetActive(false)
  271. end
  272. local btns_list = {}
  273. if self.model:IsShowPreviewBtn(self.type_id) then
  274. table.insert(btns_list, self.yulanBtn)
  275. self.yulanBtn:SetActive(true)
  276. else
  277. self.yulanBtn:SetActive(false)
  278. end
  279. if self.is_show_btn then
  280. if (self.goods_vo.use > 0 or self.goods_vo.use_way ~= "") and self.mainVo.level >= self.goods_vo.level then
  281. table.insert(btns_list, self.shiyongBtn)
  282. end
  283. if basic.jump > 0 then--and self.mainVo.level >= self.goods_vo.level then
  284. table.insert(btns_list, self.jumpBtn)
  285. end
  286. if self.goods_vo.compose > 0 then
  287. table.insert(btns_list, self.hechengBtn)
  288. end
  289. if self.goods_vo.goods_num > 1 then
  290. table.insert(btns_list, self.splitBtn)
  291. end
  292. if self.goods_vo.sell > 0 then
  293. table.insert(btns_list, self.chushouBtn)
  294. end
  295. if MarketModel:getInstance():IsGoodsCanUpShelves(self.goods_vo) then
  296. table.insert(btns_list, self.shelvesUpBtn)
  297. end
  298. if basic and basic.drop == 1 then
  299. table.insert(btns_list, self.dropBtn)
  300. end
  301. end
  302. local hide_yulan_btn = false
  303. if GoodsModel:getInstance().show_warehouse == true and self.goods_vo.pos == GoodsModel.GOODS_POS_TYPE.bag then
  304. hide_yulan_btn = true
  305. btns_list = {self.storeBtn}
  306. elseif self.goods_vo.pos == GoodsModel.GOODS_POS_TYPE.warehouse then
  307. hide_yulan_btn = true
  308. btns_list = {self.takeBtn}
  309. elseif self.goods_vo.pos == GoodsModel.GOODS_POS_TYPE.hunt_store then
  310. hide_yulan_btn = true
  311. btns_list = {self.takeBtn}
  312. end
  313. if hide_yulan_btn then
  314. self.yulanBtn:SetActive(false)
  315. end
  316. if CapsuleEggModel:getInstance():IsShowCapsuleEggTakeOutBtn() then--龙神宝库扭蛋临时仓库显示取出按钮
  317. btns_list = {self.capsuleEggTakeBtn}
  318. end
  319. --自定义显示的按钮
  320. if self.show_btn_list then
  321. btns_list = self:ShowCustomBtns()
  322. end
  323. local btns_len = #btns_list
  324. self.btns_con_obj:SetActive(btns_len > 0)
  325. local local_index = 0
  326. local local_offset_h = 55
  327. for k, v in ipairs(btns_list) do
  328. local b = self.is_show_btn
  329. or CapsuleEggModel:getInstance():IsShowCapsuleEggTakeOutBtn()--龙神宝库仓库需要显示按钮
  330. v:SetActive(b)
  331. if b then
  332. print(v)
  333. SetAnchoredPosition(v.transform, 8, local_index * local_offset_h - 504)
  334. local_index = local_index + 1
  335. end
  336. end
  337. if not hide_yulan_btn then
  338. if self.goods_vo.type == 32 or self.goods_vo.type == 34 then
  339. self.yulanBtn:SetActive(true)
  340. end
  341. end
  342. end
  343. function NiceGoodsTips:CheckSecondView()
  344. if self.goods_vo.type == GoodsModel.TYPE.DESIGNATION then--称号类型物品直接发激活协议
  345. local designation_id = DesignationModel:GetInstance():GetDesignationIdByGoodsId(self.goods_vo.type_id)
  346. if designation_id ~= 0 then
  347. DesignationModel:GetInstance():Fire(DesignationModel.REQUEST_DESIGNATION, 41106, self.goods_vo.type_id, designation_id, 1)
  348. else
  349. Message.show("称号物品有点问题哦~请联系GM")
  350. end
  351. return
  352. elseif self.goods_vo.type == GoodsModel.TYPE.FASHION and self.goods_vo.subtype ~= GoodsModel.FASHION_LIMIT_SUB_TYPE then--时装体验卡物品不走这里的激活协议
  353. local fashion_id,color_id = FashionModel:getInstance():GetFashionIdByGoodsId(self.type_id)
  354. local cur_cfg = Config.Fashionstarup[fashion_id.."@"..color_id.."@0"]
  355. if cur_cfg then
  356. local pos = cur_cfg.pos_id
  357. FashionModel:GetInstance():Fire(FashionEvent.REQUEST_FASHION_PROTOCOL, 41306, pos, fashion_id, color_id)
  358. else
  359. Message.show("时装物品有点问题哦~请联系GM")
  360. end
  361. return
  362. end
  363. if self.goods_vo.use == 1 then
  364. if self.goods_vo.goods_num > 1 then
  365. BagModel:getInstance():Fire(BagModel.OPEN_BATHANDLE_VIEW, self.goods_vo, SplitView.TYPE.BAT_USE)
  366. else
  367. self.model:Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.goods_vo.goods_id, self.goods_vo.type_id, 1)
  368. end
  369. else
  370. self.model:Fire(GoodsModel.REQUEST_CCMD_EVENT, 15050, self.goods_vo.goods_id, self.goods_vo.type_id, 1)
  371. end
  372. end
  373. function NiceGoodsTips:ShowCustomBtns()
  374. local temp_list = {}
  375. for _, v in pairs(self.btns_list) do
  376. v:SetActive(false)
  377. end
  378. for _, v in pairs(self.show_btn_list) do
  379. if self[v] then
  380. table.insert(temp_list, self[v])
  381. end
  382. end
  383. return temp_list
  384. end
  385. function NiceGoodsTips:DestroySuccess( )
  386. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
  387. if self.change_count_id then
  388. self.addNumComponent:UnBind(self.change_count_id)
  389. self.change_count_id = nil
  390. self.addNumComponent:DeleteMe()
  391. self.addNumComponent = nil
  392. end
  393. if self.change_jin_id then
  394. self.mainVo:UnBind(self.change_jin_id)
  395. self.change_jin_id = nil
  396. end
  397. if self.change_lockJin_id then
  398. self.mainVo:UnBind(self.change_lockJin_id)
  399. self.change_lockJin_id = nil
  400. end
  401. if self.change_silver_id then
  402. self.mainVo:UnBind(self.change_silver_id)
  403. self.change_silver_id = nil
  404. end
  405. if self.score_change_event_id then
  406. GoodsModel:getInstance():UnBind(self.score_change_event_id)
  407. self.score_change_event_id = nil
  408. end
  409. if self.shop_view then
  410. self.shop_view:DeleteMe()
  411. self.shop_view = nil
  412. end
  413. end
  414. function NiceGoodsTips:UpdateShopView( )
  415. if not self.shop_view then
  416. self.shop_view = ShopBuySubView.New(self.shop_con)
  417. end
  418. self.shop_view:SetData(self.shop_data)
  419. self.shop_view:SetPosition(9,-141)
  420. end