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

441 lines
13 KiB

  1. EquipItem = EquipItem or BaseClass(BaseItem)
  2. function EquipItem:__init(parent_wnd, prefab_asset, layer_name, is_bag)
  3. self.base_file = "bag"
  4. self.layout_file = "EquipItem"
  5. self.is_delay_callback = true
  6. self.is_bag = is_bag or false --is_bag 是否用于背包界面中
  7. self.model = EquipModel:getInstance()
  8. self.mainVo = RoleManager.Instance.mainRoleInfo
  9. self.only_show_strength_tag = false --是否仅显示可精炼标识
  10. self.pos_type = false
  11. self.pos_type_visible = false
  12. self.default_conta_show = false
  13. self.series = false
  14. self.bg_alpha = 1
  15. self.showing_effect = false
  16. self.will_show_effect = false
  17. self.init_guide_event = false
  18. --self.use_local_view = true
  19. self:Load()
  20. end
  21. function EquipItem:Load_callback()
  22. self.equip_conta,self.canStren,self.effect_con = GetChildTransforms(self.transform,
  23. {
  24. "equip_conta","canStren", "effect_con"
  25. })
  26. self.strengthText,self.stren = GetChildTexts (self.transform,
  27. {
  28. "strengthText","stren"
  29. })
  30. self.default_conta,self.red_dot,self.selectBg,self.canStrenObj, self.can_buy_obj = GetChildGameObjects (self.transform,
  31. {
  32. "default_conta","red_dot","selectBg","canStren", "can_buy"
  33. })
  34. self.pos_type_img, self.default_conta_img = GetChildImages (self.transform,
  35. {
  36. "pos_type", "default_conta"
  37. })
  38. local nodes = {
  39. "can_buy:img"
  40. }
  41. self:GetChildren(nodes)
  42. self.stren.text = ""
  43. self.icon_item = AwardItem.New(self.equip_conta)
  44. -- self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.equip_conta)
  45. self.icon_item:SetItemSize(78,78)
  46. -- self.icon_item:SetAnchoredPosition(0,0)
  47. if self.style_cache then
  48. self:SetEquipStyle(self.style_cache)
  49. self.style_cache = nil
  50. end
  51. if self.need_refreshData then
  52. self:SetData(self.data)
  53. self:SetPosType(self.pos_type, self.pos_type_visible, self.series, self.default_conta_show)
  54. self:SetBgAlpha(self.bg_alpha)
  55. self:WillShowEffect(self.will_show_effect)
  56. end
  57. if self.need_set_ring_show then
  58. self:SetRingShow()
  59. end
  60. self.icon_item:SetEnableClick(false)
  61. self.icon_item.ClickCallFun = function (target,target2,x,y) --覆盖AwardItem 的点击方法
  62. self:ClickHandler(target2,x,y)
  63. end
  64. self:AddToStageHandler()
  65. self:InitEvent()
  66. end
  67. function EquipItem:InitEvent()
  68. local function click_fun(target,x,y)
  69. if self.pos_type == EquipModel.EquipType.Weapon then
  70. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_SUIT_ACTIVE,4)
  71. if helpVo then
  72. GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
  73. end
  74. end
  75. self:ClickHandler(target,x,y)
  76. end
  77. AddClickEvent(self.gameObject, click_fun)
  78. local select_fun = function (goods_vo)
  79. if self.data and goods_vo then
  80. if self.is_bag == false then
  81. if self.data.goods_id == goods_vo.goods_id then
  82. self:SetSelect(true)
  83. else
  84. self:SetSelect(false)
  85. end
  86. end
  87. end
  88. end
  89. self.event_id = self.model:Bind(EquipModel.EQUIP_ITEM_BE_CLICK, select_fun)
  90. local change_dynamic = function (goods_id)
  91. if self.data then
  92. if self.data.goods_id == goods_id then
  93. self:SetData(self.data, self.only_show_strength_tag)
  94. end
  95. end
  96. end
  97. self.dynamic_event_id = GlobalEventSystem:Bind(GoodsModel.CHANGE_GOODS_DYNAMIC,change_dynamic)
  98. --发生改变时,判断是否进行提示
  99. local update_red_func = function ()
  100. self:SetRedPoint()
  101. end
  102. self.change_tong_id = self.mainVo:BindOne("tong", update_red_func)
  103. local function RedDotRefresh( )
  104. if self.is_open_ring then
  105. self.icon_item:SetRedDot(MateModel:GetInstance():GetShipRedDot(false))
  106. end
  107. end
  108. self:BindEvent(MateModel:GetInstance(), MateConst.RedDotRefresh, RedDotRefresh)
  109. end
  110. function EquipItem:ClickHandler(target,x,y)
  111. if self.data then
  112. if self.is_bag == false then
  113. self.model:Fire(EquipModel.EQUIP_ITEM_BE_CLICK, self.data)
  114. else
  115. UIToolTipMgr:getInstance():AppendEquipTips(self.data.type_id, x, y, self.data)
  116. end
  117. else
  118. if self.is_open_ring then
  119. UIToolTipMgr:getInstance():AppendEquipTips(self.ring_equip_id, x, y)
  120. -- UIToolTipMgr:getInstance():AppendMarriageTips(self.ring_info, x, y)
  121. else
  122. local ui_tf = panelMgr:GetParent("UI").transform
  123. local pos = ui_tf:InverseTransformPoint(self.transform.position)
  124. local w = ScreenWidth
  125. local h = ScreenHeight
  126. pos.x = w / 2 + pos.x
  127. pos.y = h / 2 + pos.y
  128. local key = self.pos_type .. "@" .. self.series .. "@" .. self.pos_type
  129. local cfg = Config.Equipmentempty[key]
  130. if cfg then
  131. BagModel:getInstance():Fire(BagModel.EQUIP_ITEM_GET_WAY_TIPS, cfg,pos.x,pos.y)
  132. else
  133. print(">>>>> unfinfd config Equipmentempty ", self.pos_type, self.series )
  134. end
  135. end
  136. end
  137. end
  138. function EquipItem:SetData(data, only_show_strength_tag)
  139. self.data = data
  140. self.only_show_strength_tag = only_show_strength_tag
  141. if self.is_loaded then
  142. self.need_refreshData = false
  143. --设置装备
  144. local callback = function (dynamic)
  145. if self.data and self.data.goods_id == dynamic.goods_id then
  146. if self.gameObject == nil then return end
  147. if self.data.type_id ~= dynamic.type_id then
  148. self.data.type_id = dynamic.type_id
  149. GoodsModel:getInstance():SetBaseInfo(self.data)
  150. end
  151. self.dynamic = dynamic
  152. self:SetDynamic(self.dynamic)
  153. self:ShowCanStrength(self.data.type_id)
  154. if self.icon_item then
  155. self.icon_item:SetVisible(true)
  156. local stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.data)
  157. stren_data.equip_key = "EquipView"
  158. stren_data.is_find = true
  159. local hide_color_effect = false
  160. if self.pos_type == EquipModel.EquipType.Guard or self.pos_type == EquipModel.EquipType.Fetter then
  161. hide_color_effect = true
  162. end
  163. self.icon_item:SetData(self.data.type_id, self.data.goods_num, self.dynamic.color,stren_data,nil,nil,nil,nil,nil,hide_color_effect)
  164. --是否过期装备
  165. if self.data.expire_time and self.data.expire_time~=0 and self.data.expire_time - TimeUtil:getServerTime() <= 0 then
  166. self.icon_item:SetExpiredVisible(true)
  167. else
  168. self.icon_item:SetExpiredVisible(false)
  169. end
  170. end
  171. self:SetRedPoint()
  172. end
  173. end
  174. self.can_buy_obj:SetActive(false)
  175. if self.data then
  176. GoodsModel:getInstance():GetDynamic(self.data.goods_id, callback)
  177. end
  178. else
  179. self.need_refreshData = true
  180. end
  181. end
  182. --设置一生一世的信息
  183. function EquipItem:SetRingShow()
  184. if self.is_loaded then
  185. self.need_set_ring_show = false
  186. local goods_id = false
  187. local conf = false
  188. local data = false
  189. if GetModuleIsOpen(149) then
  190. data = MateModel:GetInstance():GetShipBasic()
  191. if not data or not data.stage then return end
  192. conf = MateModel:GetInstance():GetShipConf(data.stage, data.star)
  193. goods_id = conf and conf.goods_id
  194. end
  195. if goods_id and goods_id > 0 then
  196. --保存数据做tip显示用
  197. EquipModel:getInstance().mate_show_tool_tip_data = {stage = data.stage, star = data.star}
  198. self.ring_equip_id = goods_id
  199. self.icon_item:SetDataWithMapId(goods_id)
  200. self.icon_item:SetVisible(true)
  201. self.is_open_ring = true
  202. local function delay( )
  203. if self._use_delete_method then return end
  204. self.icon_item:SetRedDot(MateModel:GetInstance():GetShipRedDot(false))
  205. end
  206. setTimeout(delay,0.1)
  207. else
  208. self.icon_item:SetVisible(false)
  209. self.is_open_ring = false
  210. end
  211. else
  212. self.need_set_ring_show = true
  213. end
  214. end
  215. function EquipItem:SetRedPoint()
  216. if not self.dynamic or not self.data then
  217. local bool = GoodsModel:getInstance():GetQuickBuyEquipRedDot(self.series,self.pos_type)
  218. if self.red_dot then
  219. lua_resM:setImageSprite(self,self.can_buy_img,"bag_asset","bag_ui_29", false)
  220. self.can_buy_obj:SetActive(bool)
  221. end
  222. return
  223. end
  224. local bool = false
  225. local equip_cfg = EquipModel:getInstance():GetEquipmentCfg(self.dynamic.type_id)
  226. -- print("huangcong:EquipItem [start:165] :", equip_cfg)
  227. -- PrintTable(equip_cfg)
  228. -- print("huangcong:EquipItem [end]")
  229. --------现在背包中,升品,升星,精炼,不需要显示红点------
  230. if equip_cfg then
  231. --升品
  232. bool = EquipModel:getInstance():GetEquipCanUpQualityByPos(equip_cfg.series,equip_cfg.equip_type)
  233. if not bool and ComposeModel:getInstance():GetGuardOrOrnamentCanEvolution(equip_cfg)
  234. and (equip_cfg.equip_type <= EquipModel.EquipType.Guard and equip_cfg.equip_type >= EquipModel.EquipType.Necklace) then--可购买升品
  235. lua_resM:setImageSprite(self,self.can_buy_img,"bag_asset","bag_ui_31", false)
  236. self.can_buy_obj:SetActive(true)
  237. end
  238. -- if not bool then
  239. -- --升星
  240. -- bool = EquipModel:getInstance():EquipIsCanEvolution(equip_cfg.series,equip_cfg.equip_type,self.data)
  241. -- end
  242. -- if not bool then
  243. -- --精炼
  244. -- bool = EquipModel:getInstance():GetEquipCanStrengthByPos(equip_cfg.series,equip_cfg.equip_type)
  245. -- end
  246. end
  247. -- if self.red_dot then
  248. -- self.red_dot:SetActive(bool)
  249. -- end
  250. end
  251. --是否显示可精炼和镶嵌
  252. function EquipItem:ShowCanStrength(type_id)
  253. -- local bool = false
  254. -- local equip_cfg = EquipModel:getInstance():GetEquipmentCfg(type_id)
  255. -- -- print("huangcong:EquipItem [start:176] :", type_id)
  256. -- -- PrintTable(equip_cfg)
  257. -- -- print("huangcong:EquipItem [end]")
  258. -- if equip_cfg then
  259. -- bool = EquipModel:getInstance():GetEquipCanStrengthByPos(equip_cfg.series,equip_cfg.equip_type)
  260. -- end
  261. -- print("huangcong:EquipItem [start:180] :", bool)
  262. -- self.red_dot:SetActive(bool)
  263. -- self:showEffect(bool)
  264. end
  265. function EquipItem:SetDynamic(dynamic)
  266. if self.gameObject == nil then return end
  267. if dynamic.stren and dynamic.stren > 0 then
  268. self.stren.text = "+" .. dynamic.stren
  269. else
  270. self.stren.text = ""
  271. end
  272. end
  273. function EquipItem:SetEquipStyle(style)
  274. self.equip_style = style
  275. if self.is_loaded and style ~= nil then
  276. local str = WordManager:GetEquipStyleStr(style)
  277. self.stren.text = ""
  278. else
  279. self.style_cache = style
  280. end
  281. end
  282. function EquipItem:ClearData()
  283. self.data = nil
  284. if self.icon_item then
  285. self.icon_item:SetVisible(false, false)
  286. end
  287. if self.stren then
  288. self.stren.text = ""
  289. end
  290. if self.red_dot then
  291. self.red_dot:SetActive(false)
  292. end
  293. end
  294. function EquipItem:SetSelect(bool)
  295. self.selectBg:SetActive(bool)
  296. end
  297. function EquipItem:showEffect(bool)
  298. if bool then
  299. self.canStrenObj:SetActive(true)
  300. if self.is_bag then
  301. self:AddUIEffect("ui_effect_jineng_jiantou1", self.canStren, self.layer_name, nil, nil, true)
  302. else
  303. self:AddUIEffect("ui_effect_jineng_jiantou1", self.canStren, self.layer_name, nil, nil, true)
  304. end
  305. else
  306. self.canStrenObj:SetActive(false)
  307. self:ClearUIEffect(self.canStren)
  308. end
  309. end
  310. function EquipItem:__delete()
  311. if self.event_id then
  312. self.model:UnBind(self.event_id)
  313. self.event_id = nil
  314. end
  315. if self.dynamic_event_id then
  316. GlobalEventSystem:UnBind(self.dynamic_event_id)
  317. self.dynamic_event_id = nil
  318. end
  319. self:ClearUIEffect(self.canStren)
  320. if self.change_tong_id then
  321. self.mainVo:UnBind(self.change_tong_id)
  322. self.change_tong_id = nil
  323. end
  324. if self.icon_item then
  325. self.icon_item:DeleteMe()
  326. -- self.icon_item:ReleaseObj()
  327. self.icon_item = nil
  328. end
  329. self:ClearUIEffect(self.effect_con)
  330. end
  331. function EquipItem:SetPosType(pos, b, series, default_conta_show)
  332. self.pos_type = pos
  333. self.pos_type_visible = b
  334. self.series = series
  335. self.default_conta_show = default_conta_show
  336. if self.is_loaded then
  337. self.need_refreshData = false
  338. self.default_conta:SetActive(self.default_conta_show or (self.pos_type and ((self.pos_type == 11 and self.data == nil) or self.pos_type ~= 11)))
  339. if self.pos_type then
  340. lua_resM:setImageSprite(self,self.pos_type_img,"common_asset","com_equip_pos_".. self.pos_type, true)
  341. lua_resM:setImageSprite(self,self.default_conta_img,"common_asset","tyui_pz_8", true)
  342. end
  343. self.pos_type_img.gameObject:SetActive(self.pos_type_visible)
  344. self:SetRedPoint()
  345. if not self.init_guide_event and self.pos_type == EquipModel.EquipType.Weapon then
  346. self.init_guide_event = true
  347. local function onGuideTrigger()
  348. self:AddToStageHandler()
  349. end
  350. self:BindEvent(GlobalEventSystem, EventName.TRIGGER_GUIDE_TYPE, onGuideTrigger)
  351. end
  352. else
  353. self.need_refreshData = true
  354. end
  355. end
  356. function EquipItem:SetBgAlpha(alpha)
  357. self.bg_alpha = alpha
  358. if self.is_loaded then
  359. self.need_refreshData = false
  360. self.icon_item:SetAlpha(self.bg_alpha)
  361. else
  362. self.need_refreshData = true
  363. end
  364. end
  365. function EquipItem:GetPosType()
  366. return self.pos_type
  367. end
  368. function EquipItem:WillShowEffect(show)
  369. self.will_show_effect = show
  370. if self.is_loaded then
  371. if self.will_show_effect then
  372. self.will_show_effect = false
  373. self:AddEffect()
  374. end
  375. else
  376. self.need_refreshData = true
  377. end
  378. end
  379. function EquipItem:AddEffect()
  380. if not self.showing_effect then
  381. local function call_back( )
  382. self.showing_effect = false
  383. end
  384. self:ClearUIEffect(self.effect_con)
  385. self:AddUIEffect("ui_hunliqiudianliang", self.effect_con, "Activity", nil, 4, false, 0.6, nil, call_back)
  386. self.showing_effect = true
  387. end
  388. end
  389. function EquipItem:AddToStageHandler()
  390. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_SUIT_ACTIVE,4)
  391. if not helpVo then return end
  392. local help_type = helpVo.help_type
  393. local step = helpVo.step
  394. local button = false
  395. if (help_type == HelpType.TYPE_EQUIP_SUIT_ACTIVE) and step == 4 then
  396. button = self.effect_con.gameObject
  397. end
  398. if button then
  399. local function call_back()
  400. end
  401. GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW, button.transform, self.transform, call_back, helpVo, self.layout_file)
  402. end
  403. end