源战役客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

782 řádky
27 KiB

před 4 týdny
  1. ItemUseView = ItemUseView or BaseClass(BaseView)
  2. ItemUseView.UIStyle =
  3. {
  4. Normal = 1, --正常装备,单个道具使用
  5. BatUse = 2, --多个道具,批量使用
  6. Auction = 3, --便捷上架拍卖
  7. Designation = 4, --称号快捷穿戴
  8. }
  9. ItemUseView.ViewDepth = 750
  10. function ItemUseView:__init()
  11. self.base_file = "itemUse"
  12. self.layout_file = "ItemUseView"
  13. self.layer_name = "Activity"
  14. self.destroy_imm = false
  15. self.is_delay_callback = false
  16. self.open_wnd_anim = 0
  17. self.is_set_zdepth = true
  18. self.mask_open_sound = true
  19. self.mask_close_sound = true
  20. self.close_mode = CloseMode.CloseDestroy
  21. self.force_no_ctl_queue = true
  22. -- self.change_scene_close = true
  23. self.model = ItemUseModel:getInstance()
  24. self.goods_model = GoodsModel:getInstance()
  25. self.mainVo = RoleManager.Instance.mainRoleInfo
  26. self.transform_x = ScreenWidth/2-377--377是对右边的值
  27. self.transform_y = -ScreenHeight/2+177--177是对下边的值
  28. self.ui_style = ItemUseView.UIStyle.Normal
  29. self.is_in_anim = false
  30. self.cur_use = 0
  31. self.max_use = 0
  32. self.load_callback = function ()
  33. self:LoadSuccess()
  34. self:InitEvent()
  35. UIDepth.SetUIDepth(self.gameObject,true,ItemUseView.ViewDepth) --强制设置层级
  36. end
  37. self.open_callback = function ()
  38. self:LayoutUI()
  39. self:ResetCloseTimer()
  40. GlobalEventSystem:Fire(EventName.SET_LOCAK_VIEW_LAYER)
  41. end
  42. self.close_callback = function ()
  43. self:ClearCloseTimer()
  44. -- self.item_icon:clearResRef()
  45. self:ClearTimer()
  46. if self.need_fire_auto then
  47. local need_do_task = self.close_by_hand == true and true or false
  48. GuideModel:getInstance():BeginTask(self.layout_file,need_do_task)
  49. self.need_fire_auto = false
  50. end
  51. end
  52. self.destroy_callback = function ()
  53. self:Clear()
  54. end
  55. end
  56. function ItemUseView:ResetCloseTimer( )
  57. self:ClearCloseTimer()
  58. -- self:StartCloseTimer()
  59. end
  60. function ItemUseView:Open(vo,forceAutoSec)
  61. self.vo = vo
  62. self.forceAutoSec = forceAutoSec
  63. if self.vo then
  64. self.type_id = self.vo.type_id
  65. self.goods_id = self.vo.goods_id
  66. self.num = self.model:GetGoodsNumById(self.goods_id)
  67. self.goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.vo.type_id)
  68. end
  69. BaseView.Open(self)
  70. end
  71. function ItemUseView:Clear()
  72. if self.dynamic_event_id then
  73. GlobalEventSystem:UnBind(self.dynamic_event_id)
  74. self.dynamic_event_id = nil
  75. end
  76. if self.item_icon then
  77. self.item_icon:ReleaseObj()
  78. self.item_icon = nil
  79. end
  80. if self.refresh_item_id then
  81. GoodsModel:getInstance():UnBind(self.refresh_item_id)
  82. self.refresh_item_id = nil
  83. end
  84. if self.scale_anim_id then
  85. TweenLite.Stop(self.scale_anim_id)
  86. self.scale_anim_id = nil
  87. end
  88. if self.mark_goods_update_id then
  89. MarketModel:getInstance():UnBind(self.mark_goods_update_id)
  90. end
  91. self:ClearTimer()
  92. self:ClearCloseTimer()
  93. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
  94. end
  95. function ItemUseView:LayoutUI()
  96. if self.vo then
  97. self:AddToStageHandler()
  98. SetLocalScale(self.gameObject.transform, 1, 1,1)
  99. self:ClearTimer()
  100. local type_id = self.vo.type_id
  101. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  102. local num = self.model:GetGoodsNumById(self.goods_id)
  103. self.max_use = 0
  104. self.cur_use = 0
  105. self.close_btn:SetActive(true)
  106. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
  107. if goods_basic then
  108. local nameStr = GoodsModel.GetRealGoodsName(goods_basic)
  109. if utf8len(nameStr) > 8 then
  110. nameStr = SubStringUTF8(nameStr, 1, 7) .. "..."
  111. end
  112. self.name.text = HtmlColorTxt(nameStr, WordManager.GetGoodsColor(goods_basic.color))
  113. if self.item_icon then
  114. if goods_basic.type == GoodsModel.TYPE.EQUIP then
  115. local stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.vo)
  116. stren_data.equip_key = "EquipView"
  117. stren_data.key_value = "show_bag_view"
  118. self.stren_data = stren_data
  119. self.item_icon:SetData(type_id,num,self.vo.color,stren_data)
  120. else
  121. self.item_icon:SetData(type_id,num,self.vo.color)
  122. end
  123. self.item_icon:SetVisible(true)
  124. end
  125. if self:IsBatchUseGoods(goods_basic, num) then
  126. self.ui_style = ItemUseView.UIStyle.BatUse
  127. elseif self:IsActionEquip(self.vo, goods_basic) then
  128. self.ui_style = ItemUseView.UIStyle.Auction
  129. elseif self:IsDesignationGoods(goods_basic) then
  130. self.ui_style = ItemUseView.UIStyle.Designation
  131. else
  132. self.ui_style = ItemUseView.UIStyle.Normal
  133. end
  134. if self.ui_style == ItemUseView.UIStyle.Auction then
  135. self.auction_group:SetActive(true)
  136. self.base_group:SetActive(false)
  137. self.designation_group_obj:SetActive(false)
  138. SetAnchoredPosition(self.item_parent.transform , 71, 167)
  139. SetAnchoredPosition(self.name.transform, 60, 116)
  140. SetAnchoredPosition(self.effect_con.transform, 64.5, 162)
  141. self.base_price_txt.text = tostring(goods_basic.trade_price or 0)
  142. self.fixed_price_txt.text = tostring(goods_basic.buyout_price or 0)
  143. SetAnchoredPosition(self.transform, self.transform_x-123, self.transform_y+31)--这里的123是因为变宽了向右移,31是多了一个栏 用右下角对齐 需要往上移动
  144. elseif self.ui_style == ItemUseView.UIStyle.Designation then
  145. self.auction_group:SetActive(false)
  146. self.designation_group_obj:SetActive(true)
  147. self.base_group:SetActive(false)
  148. self.item_icon:SetVisible(false)
  149. local cfg = Config.Dsgt
  150. local designation_id = DesignationModel:GetInstance():GetDesignationIdByGoodsId(type_id)
  151. cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
  152. if cfg[designation_id].type == 1 then--文字称号(文字称号也用图片了)
  153. lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetDesignImage(cfg[designation_id].id), true)
  154. self.designation_image_obj:SetActive(true)
  155. elseif cfg[designation_id].type == 2 then--图片称号
  156. lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetDesignImage(cfg[designation_id].id), true)
  157. self.designation_image_obj:SetActive(true)
  158. elseif cfg[designation_id].type == 3 then--特效称号
  159. if not self.dynamic_image_obj then
  160. self.dynamic_image_obj = UiFactory.createChild(self.designation_image, UIType.Image, "dynamic_image")
  161. self.dynamic_image_img = self.dynamic_image_obj:GetComponent("Image")
  162. self.dynamic_image = self.dynamic_image_obj.transform
  163. SetAnchoredPosition(self.dynamic_image,0,0)
  164. else
  165. self.dynamic_image_obj:SetActive(true)
  166. end
  167. self.designation_image_obj:SetActive(true)
  168. local data = DesignationModel:GetInstance():GetDynamicDesignationCFG(designation_id)
  169. local res = Split(data[1].res,"_")--分割出来配置 然后取文字
  170. local font_res = res[1] or ""
  171. lua_resM:setImageSprite(self, self.dynamic_image_img, data[1].ab, font_res.."_font", true)
  172. local action = cc.Animation.New(data,0.15)
  173. cc.ActionManager:getInstance():addAction(cc.RepeatForever.New(action),self.designation_image.transform)
  174. end
  175. self.designation_tip_text_tmp.text = cfg[designation_id].description
  176. self.name.text = ""
  177. SetAnchoredPosition(self.transform, self.transform_x-80, self.transform_y+90)--这里的123是因为变宽了向右移,60是变高了 用右下角对齐 需要往上移动
  178. self:CheckShowEffectAndAutoUse()
  179. else
  180. self.auction_group:SetActive(false)
  181. self.designation_group_obj:SetActive(false)
  182. self.base_group:SetActive(true)
  183. SetAnchoredPosition(self.item_parent.transform , 9.5, 51.5)
  184. SetAnchoredPosition(self.name.transform, -1, 1)
  185. SetAnchoredPosition(self.effect_con.transform, 3, 61.5)
  186. if goods_basic.type == GoodsModel.TYPE.EQUIP then --10是装备
  187. if self:IsAutoEquip() then
  188. self.use_btn_text.text = "装备"
  189. self.close_btn:SetActive(false)
  190. else
  191. self.use_btn_text.text = "查看"
  192. end
  193. self:ChangeState()
  194. else
  195. self.use_btn_text.text = "使用"
  196. end
  197. if self.ui_style == ItemUseView.UIStyle.BatUse then
  198. self.addNumCon.gameObject:SetActive(true)
  199. SetAnchoredPositionY(self.use_btn.transform, -80)
  200. self.cur_use = num
  201. self.max_use = num
  202. self:ChangeCountNum()
  203. SetAnchoredPosition(self.transform, self.transform_x, self.transform_y+14)--这里的14是因为多了一个栏 用右下角对齐 需要往上移动
  204. else
  205. self.addNumCon.gameObject:SetActive(false)
  206. if self:IsShowAutoUse() then
  207. SetAnchoredPositionY(self.use_btn.transform, -52)
  208. else
  209. SetAnchoredPositionY(self.use_btn.transform, -64)
  210. end
  211. SetAnchoredPosition(self.transform, self.transform_x, self.transform_y)
  212. end
  213. self:CheckShowEffectAndAutoUse()
  214. end
  215. end
  216. end
  217. end
  218. function ItemUseView:LoadSuccess()
  219. self.use_btn = self:GetChild("contain/base_group/UseBtn").gameObject
  220. self.close_btn = self:GetChild("contain/base_group/CloseBtn").gameObject
  221. self.use_btn_text = self:GetChild("contain/base_group/UseBtn/Text"):GetComponent("TextMeshProUGUI")
  222. self.name = self:GetChild("contain/item_name"):GetComponent("TextMeshProUGUI")
  223. self.item_parent = self:GetChild("contain/ItemParent")
  224. -- self.item_icon = AwardItem.New(self.item_parent, nil, "Top")
  225. self.item_icon = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_parent)
  226. self.item_icon:SetItemSize(78, 78)
  227. self.transform.localPosition = Vector3(ScreenWidth/2 - 490,-ScreenHeight/2 + 160,0)
  228. self.tip_text = self:GetChild("contain/base_group/Tip"):GetComponent("TextMeshProUGUI")
  229. self.tip_obj = self:GetChild("contain/base_group/Tip").gameObject
  230. self.effect_con = self:GetChild("contain/EffectCon").gameObject
  231. self.Border_img = self:GetChild("contain/base_group/Border"):GetComponent("Image")
  232. self.addNumCon = self:GetChild("contain/base_group/addNumCon")
  233. self.del_btn_obj = self:GetChild("contain/base_group/addNumCon/del_btn").gameObject
  234. self.add_btn_obj = self:GetChild("contain/base_group/addNumCon/add_btn").gameObject
  235. self.count_btn_obj = self:GetChild("contain/base_group/addNumCon/count_btn").gameObject
  236. self.count_num_txt = self:GetChild("contain/base_group/addNumCon/count_num"):GetComponent("TextMeshProUGUI")
  237. self.base_group = self:GetChild("contain/base_group").gameObject
  238. self.auction_group = self:GetChild("contain/auction_group").gameObject
  239. self.base_price_txt = self:GetChild("contain/auction_group/base_price"):GetComponent("TextMeshProUGUI")
  240. self.fixed_price_txt = self:GetChild("contain/auction_group/fixed_price"):GetComponent("TextMeshProUGUI")
  241. self.close_btn_2 = self:GetChild("contain/auction_group/CloseBtn2").gameObject
  242. self.auction_btn = self:GetChild("contain/auction_group/auctionBtn").gameObject
  243. --称号快捷使用
  244. self.nodes = {
  245. "contain/designation_group:obj", "contain/designation_group/designation_btn:obj", "contain/designation_group/CloseBtn3:obj",
  246. "contain/designation_group/designation_time_text:tmp", "contain/designation_group/designation_tip_text:tmp",
  247. "contain/designation_group/designation_name_text:tmp", "contain/designation_group/designation_image:img:obj",
  248. "contain:obj"
  249. }
  250. self:GetChildren(self.nodes)
  251. GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW_SUCCESS, ItemUseView.ViewDepth)
  252. self.transform:SetAsLastSibling()
  253. end
  254. function ItemUseView:InitEvent()
  255. local function onBtnClickHandler(target, x, y)
  256. if target == self.use_btn then
  257. self:CloseGuide()
  258. self:UseCall()
  259. self:NextItemUse(true)
  260. elseif target == self.auction_btn then
  261. self:AuctionCall()
  262. self:NextItemUse(true)
  263. elseif target == self.close_btn then
  264. self:CloseGuide()
  265. self:NextItemUse(true)
  266. elseif target == self.close_btn_2 then
  267. self:NextItemUse(true)
  268. elseif target == self.CloseBtn3_obj then
  269. self:NextItemUse(true)
  270. elseif target == self.del_btn_obj then
  271. self.cur_use = self.cur_use - 1
  272. self:ChangeCountNum()
  273. elseif target == self.add_btn_obj then
  274. self.cur_use = self.cur_use + 1
  275. self:ChangeCountNum()
  276. elseif target == self.count_btn_obj then
  277. local function call_back(final_number)
  278. self.cur_use = final_number
  279. self:ChangeCountNum()
  280. end
  281. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_CALCULATOR_VIEW,self.max_use,call_back, Vector3(x, y, 0), 9)
  282. elseif target == self.designation_btn_obj then
  283. self:UseCall()
  284. self:NextItemUse(true)
  285. end
  286. end
  287. AddClickEventHz(0.5,self.use_btn,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
  288. AddClickEventHz(0.5,self.designation_btn_obj,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
  289. AddClickEventHz(0.5,self.auction_btn,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
  290. AddClickEventHz(0.5,self.close_btn,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
  291. AddClickEventHz(0.5,self.close_btn_2,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
  292. AddClickEventHz(0.5,self.CloseBtn3_obj,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
  293. AddClickEvent(self.del_btn_obj,onBtnClickHandler)
  294. AddClickEvent(self.add_btn_obj,onBtnClickHandler)
  295. AddClickEvent(self.count_btn_obj,onBtnClickHandler)
  296. local change_dynamic = function (goods_id)
  297. self:ChangeState()
  298. end
  299. self.dynamic_event_id = GlobalEventSystem:Bind(GoodsModel.CHANGE_GOODS_DYNAMIC,change_dynamic)
  300. local function onRefreshItemNum()
  301. if self.vo then
  302. local goods_id = self.vo.goods_id
  303. local num = self.model:GetGoodsNumById(goods_id)
  304. if self.num ~= num and num > 0 then
  305. self.num = num
  306. if self.item_icon then
  307. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.vo.type_id)
  308. if goods_basic.type == GoodsModel.TYPE.EQUIP then
  309. local stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.vo)
  310. stren_data.equip_key = "EquipView"
  311. stren_data.key_value = "show_bag_view"
  312. self.stren_data = stren_data
  313. self.item_icon:SetData(self.vo.type_id,num,self.vo.color,stren_data)
  314. local can_tip, flag = EquipModel:getInstance():EquipCanShowGoodsTip(self.vo)
  315. self.item_icon:ChangeEquipState(flag)
  316. else
  317. self.item_icon:SetData(self.vo.type_id,num,self.vo.color)
  318. if self:IsBatchUseGoods(goods_basic, num) then
  319. self.max_use = num
  320. self.cur_use = num
  321. self.count_num_txt.text = tostring(self.cur_use)
  322. end
  323. end
  324. end
  325. end
  326. end
  327. end
  328. self.refresh_item_id = GoodsModel:getInstance():Bind(GoodsModel.CHANGE_BAGLIST,onRefreshItemNum)
  329. local function item_click_func(target,target2,x,y)
  330. if self.vo then
  331. local type_id = self.vo.type_id
  332. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  333. if goods_basic then
  334. if goods_basic.type == GoodsModel.TYPE.EQUIP then --装备
  335. if goods_basic.subtype == 12 then --时装物品
  336. UIToolTipMgr:getInstance():AppendGoodsTips(goods_basic.type_id, x, y,self.vo)
  337. else
  338. self.stren_data.key_value = "show_bag_view"
  339. UIToolTipMgr:getInstance():AppendEquipTips(goods_basic.type_id, x, y,self.vo,nil,true,nil,self.stren_data and self.stren_data.key_value)
  340. end
  341. else --普通物品
  342. UIToolTipMgr:getInstance():AppendGoodsTips(goods_basic.type_id, x, y, self.vo)
  343. end
  344. end
  345. end
  346. end
  347. if self.item_icon then
  348. self.item_icon.ClickCallFun = item_click_func
  349. end
  350. --监听别的itemuseview打开了
  351. local function onOpenItemUseViewSuccess(layer_count)
  352. if self.is_in_anim then
  353. self:ResetViewUIZDepth(layer_count)
  354. end
  355. end
  356. self:BindEvent(GlobalEventSystem, EventName.OPEN_ITEM_USE_VIEW_SUCCESS, onOpenItemUseViewSuccess)
  357. local function onSceneStartHandler()
  358. self:ChangeSceneHandle()
  359. end
  360. self:ChangeSceneHandle()
  361. self:BindEvent(GlobalEventSystem, EventName.SCENE_LOAD_VIEW_COMPLETE, onSceneStartHandler)
  362. local function onGuideTrigger()
  363. self:AddToStageHandler()
  364. end
  365. self:BindEvent(GlobalEventSystem, EventName.TRIGGER_GUIDE_TYPE, onGuideTrigger)
  366. local function onLittleMove(is_out)
  367. if not is_out then
  368. self:ResetViewUIZDepth(ItemUseView.ViewDepth)
  369. end
  370. end
  371. self:BindEvent(GlobalEventSystem, EventName.PLAY_MAINUI_MOVIE_EVENT, onLittleMove)
  372. local function onMarkGoodsUpdate( )
  373. if MarketModel:getInstance():IsMaxMarketGoods() then
  374. if self.ui_style == ItemUseView.UIStyle.Auction then
  375. self:NextItemUse(true)
  376. end
  377. end
  378. end
  379. self.mark_goods_update_id = MarketModel:getInstance():BindOne("goods_shelves_list", onMarkGoodsUpdate)
  380. end
  381. function ItemUseView:OnCLickUseBtn( )
  382. if self.vo then
  383. if self:IsEquipNormalType() then
  384. --如果数 可自动穿戴的装备,直接穿
  385. if self:IsAutoEquip() then
  386. EquipModel:getInstance():WearEquip( self.vo, true )
  387. else
  388. --如果该部位有装备,则打开装备对比,并且打开背包
  389. local serires, pos = self:GetEquipSeriesAndPos()
  390. local equip = GoodsModel.getInstance():GetTargetSeriesTargetPosEquip(serires, pos)
  391. if equip then
  392. GlobalEventSystem:Fire(EventName.ITEM_USE_DELAY_OPEN_EQUIP_TOOL, self.vo)
  393. end
  394. GoodsModel.getInstance():SetBagEquipChooseIndex(serires)
  395. GlobalEventSystem:Fire(EventName.OPEN_BAG_VIEW_IF_NOT, 1)
  396. --OpenFun.Open(150,1)
  397. end
  398. self:CustomClose()
  399. else
  400. local use_args = {}
  401. local type_id = self.vo.type_id
  402. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  403. if self:IsBatchUseGoods(goods_basic, self.vo.goods_num) then
  404. use_args.force_batch_use = true
  405. use_args.use_num = self.cur_use > 0 and self.cur_use or 1
  406. end
  407. GoodsModel:getInstance():Fire(GoodsModel.TRY_TO_USE_GOODS, self.vo, nil, use_args)
  408. self:CustomClose()
  409. end
  410. end
  411. end
  412. function ItemUseView:NextItemUse(force_oepn)
  413. local goods_id = self.vo.goods_id
  414. self.model:ClearIdData(goods_id)
  415. local vo = self.model:GetItemShowVo()
  416. if vo then
  417. local function call_back()
  418. self:Close()
  419. --GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, nil, force_oepn)
  420. end
  421. self:DoViewAnim(false, call_back)
  422. GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, nil, force_oepn, true)
  423. else
  424. self:CustomClose()
  425. end
  426. end
  427. function ItemUseView:CustomClose()
  428. local function call_back()
  429. self:Close()
  430. end
  431. self:DoViewAnim(false, call_back)
  432. end
  433. function ItemUseView:IsEquipNormalType()
  434. if self.vo then
  435. local type_id = self.vo.type_id
  436. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  437. if goods_basic then
  438. return goods_basic.type == GoodsModel.TYPE.EQUIP
  439. end
  440. end
  441. return false
  442. end
  443. function ItemUseView:IsItemType()
  444. if self.vo then
  445. local type_id = self.vo.type_id
  446. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  447. if goods_basic then
  448. return goods_basic.type ~= GoodsModel.TYPE.God and goods_basic.type ~= GoodsModel.TYPE.DESIGNATION
  449. end
  450. end
  451. return false
  452. end
  453. function ItemUseView:Show()
  454. self.gameObject:SetActive(true)
  455. end
  456. function ItemUseView:Hide()
  457. self.gameObject:SetActive(false)
  458. end
  459. function ItemUseView:IsShowEffect()
  460. return false
  461. end
  462. function ItemUseView:GetGoodsId()
  463. if self.vo then
  464. return self.vo.goods_id
  465. end
  466. return nil
  467. end
  468. function ItemUseView:GetTypeId()
  469. if self.vo then
  470. return self.vo.type_id
  471. end
  472. return nil
  473. end
  474. function ItemUseView:ShowTipText()
  475. if self:IsEquipNormalType() or self.model:IsEquipSpecialType(self.vo.type_id) then
  476. self.tip_text.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动装备"
  477. elseif self:IsItemType() then
  478. self.tip_text.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动使用"
  479. elseif self:IsDesignationGoods() then
  480. self.designation_time_text_tmp.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动穿戴"
  481. else
  482. self.tip_text.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动装备"
  483. end
  484. end
  485. function ItemUseView:CheckShowEffectAndAutoUse()
  486. if self:IsShowEffect() then
  487. self.effect_con:SetActive(true)
  488. local function load_end_func( )
  489. local renders = self.effect_con:GetComponentsInChildren(typeof(UnityEngine.Renderer))
  490. if renders then
  491. for i = 0, renders.Length - 1 do
  492. local render = renders[i]
  493. render.sortingOrder = 111
  494. end
  495. end
  496. end
  497. self:AddUIEffect("ui_effect_yindao_biankuang", self.effect_con.transform, self.layer_name, nil, nil, true, nil, nil,nil,load_end_func)
  498. else
  499. self.effect_con:SetActive(false)
  500. end
  501. if self:IsShowAutoUse() or self.forceAutoSec then
  502. self:ClearTimer()
  503. self.tip_obj:SetActive(true)
  504. self.sec = self.forceAutoSec or 5
  505. self:ShowTipText()
  506. local function onTimer()
  507. self.sec = self.sec - 1
  508. if self.sec < 1 then
  509. self:OnCLickUseBtn()
  510. self:ClearTimer()
  511. self:NextItemUse(true)
  512. else
  513. self:ShowTipText()
  514. end
  515. end
  516. self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer,1,-1)
  517. else
  518. self.tip_obj:SetActive(false)
  519. end
  520. end
  521. function ItemUseView:ClearTimer()
  522. if self.timer_id then
  523. GlobalTimerQuest:CancelQuest(self.timer_id)
  524. self.timer_id = nil
  525. end
  526. end
  527. function ItemUseView:ChangeState( )
  528. self.item_icon:ChangeEquipState(nil)
  529. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.type_id)
  530. if basic == nil then
  531. return
  532. end
  533. if self.vo.type == GoodsModel.TYPE.EQUIP and self.vo.goods_num > 0 then
  534. local can_tip, flag = EquipModel:getInstance():EquipCanShowGoodsTip(self.vo)
  535. self.item_icon:ChangeEquipState(flag)
  536. end
  537. end
  538. --5秒后自动关闭,并清除所有数据
  539. function ItemUseView:StartCloseTimer( )
  540. local time = 5
  541. local function onTimer()
  542. time = time -1
  543. if time< 0 then
  544. --清除数据
  545. local goods_id = self.vo.goods_id
  546. self.model:ClearIdData(goods_id)
  547. local vo = self.model:GetItemShowVo()
  548. if vo then
  549. local function call_back()
  550. self:Close()
  551. --GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
  552. end
  553. self:DoViewAnim(false, call_back)
  554. GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
  555. else
  556. self:CustomClose()
  557. end
  558. end
  559. end
  560. self.close_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer,1,-1)
  561. end
  562. function ItemUseView:ClearCloseTimer()
  563. if self.close_timer_id then
  564. GlobalTimerQuest:CancelQuest(self.close_timer_id)
  565. self.close_timer_id = nil
  566. end
  567. end
  568. --是否显示自动使用提示
  569. function ItemUseView:IsShowAutoUse( )
  570. if (self:IsEquipNormalType() and self:IsAutoEquip())
  571. then
  572. return true
  573. end
  574. -- if ((self:IsEquipNormalType() and self:IsAutoEquip()) or self.model:IsEquipSpecialType(self.vo.type_id) or self:IsDesignationGoods())
  575. -- and RoleManager.Instance.mainRoleInfo.level < 150 then
  576. -- return true
  577. -- end
  578. end
  579. function ItemUseView:UseCall( )
  580. self:ResetCloseTimer()
  581. self:OnCLickUseBtn()
  582. end
  583. function ItemUseView:AuctionCall( )
  584. self:ResetCloseTimer()
  585. GlobalEventSystem:Fire(EventName.OPEN_MARKET_VIEW, MarketConst.TabId.SalesHall)
  586. end
  587. --是否可以批量批量使用
  588. function ItemUseView:IsBatchUseGoods( goods_basic, num )
  589. return goods_basic and goods_basic.type ~= GoodsModel.TYPE.EQUIP and goods_basic.batch_use == 1 and num > 1
  590. end
  591. --是否可以上架(可以上架,并且不是本职业使用,的装备)
  592. function ItemUseView:IsActionEquip(goods_vo, goods_basic )
  593. local bool = GetModuleOpenLevel(155)--得市场开了才能弹出
  594. return bool and not MarketModel:getInstance():IsMaxMarketGoods() and self.goods_model:IsEquipCanAuctionButNoUse(goods_vo, goods_basic)
  595. end
  596. function ItemUseView:IsDesignationGoods( goods_basic )
  597. if goods_basic then
  598. return goods_basic.type == GoodsModel.TYPE.DESIGNATION
  599. end
  600. if self.vo then
  601. local type_id = self.vo.type_id
  602. local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
  603. if goods_basic then
  604. return goods_basic.type == GoodsModel.TYPE.DESIGNATION
  605. end
  606. end
  607. return false
  608. end
  609. function ItemUseView:ChangeCountNum()
  610. if self.max_use == 0 then return end
  611. self.cur_use = self.cur_use < 1 and 1 or self.cur_use
  612. self.cur_use = self.cur_use > self.max_use and self.max_use or self.cur_use
  613. self.count_num_txt.text = tostring(self.cur_use)
  614. end
  615. function ItemUseView:DoViewAnim(show, call_back)
  616. if not ClientConfig.view_scale_ani_mode then
  617. if call_back then
  618. call_back()
  619. end
  620. return
  621. end
  622. if not self.gameObject then return end
  623. self.is_in_anim = true
  624. local tween_type = show and TweenFunc.EASE_OUT_BACK or TweenFunc.EASE_IN_BACK
  625. local cfg = show and BaseView.OpenCloseScaleCfg[1] or BaseView.OpenCloseScaleCfg[2]
  626. local cur_scale = Vector3.New(cfg.start_scale, cfg.start_scale, cfg.start_scale)
  627. local target_scale = Vector3.New(cfg.end_scale, cfg.end_scale, cfg.end_scale)
  628. --local target_scale = Vector3.New(3,3, 3)
  629. local time = cfg.time
  630. SetLocalScale(self.gameObject.transform, cur_scale.x, cur_scale.y, cur_scale.z)
  631. if self.scale_anim_id then
  632. TweenLite.Stop(self.scale_anim_id)
  633. self.scale_anim_id = nil
  634. end
  635. self:ResetUIZDepth()
  636. self.scale_anim_id = TweenLite.to(self, self.gameObject.transform, TweenLite.UiAnimationType.SCALE, target_scale, time, call_back, tween_type)
  637. end
  638. function ItemUseView:ResetViewUIZDepth(layer_count)
  639. UIDepth.SetUIDepth(self.gameObject,true, layer_count + 10)
  640. end
  641. function ItemUseView:ChangeSceneHandle()
  642. local is_hide = SceneManager.Instance:IsJumpOneScene() or SceneManager.Instance:IsMirrorPkRankScene()
  643. self.contain_obj:SetActive(not is_hide)
  644. end
  645. --是否是可以自动传的装备(1代装备)
  646. function ItemUseView:IsAutoEquip()
  647. if not self.vo or not self.vo.type_id then return false end
  648. --105级之前自动穿戴
  649. if RoleManager.Instance.mainRoleInfo.level <= 105 then
  650. return true
  651. end
  652. local cfg = Config.Equipment[self.vo.type_id]
  653. --1代装备,绿色品质,普通装备(不包括首饰和守护)
  654. return cfg and cfg.series == 1 and self.vo.color <= 1 and cfg.equip_type < EquipModel.EquipType.Necklace
  655. end
  656. --当前装备的代数和部位
  657. function ItemUseView:GetEquipSeriesAndPos()
  658. local cfg = Config.Equipment[self.vo.type_id]
  659. if cfg then
  660. return cfg.series, cfg.equip_type
  661. end
  662. end
  663. function ItemUseView:AddToStageHandler()
  664. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_ONE,1)
  665. or GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_TWO,1)
  666. if not helpVo then return end
  667. local help_type = helpVo.help_type
  668. if help_type == HelpType.TYPE_EQUIP_COLLECT_ONE or help_type == HelpType.TYPE_EQUIP_COLLECT_TWO then
  669. local step = helpVo.step
  670. local button = false
  671. if (help_type == HelpType.TYPE_EQUIP_COLLECT_ONE and step == 1) or (help_type == HelpType.TYPE_EQUIP_COLLECT_TWO and step == 1) then
  672. button = self.use_btn
  673. end
  674. if button then
  675. local function call_back()
  676. end
  677. GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW, button.transform, button.transform.parent.transform, call_back, helpVo, self.layout_file)
  678. end
  679. GlobalEventSystem:Fire(EventName.STOP_AUTO_DO_TASK)
  680. GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
  681. else
  682. GlobalEventSystem:Fire(EventName.CLOSE_GUIDE_PROMPT_VIEW)
  683. end
  684. end
  685. function ItemUseView:Close()
  686. self:CloseGuide()
  687. BaseView.Close(self)
  688. end
  689. function ItemUseView:CloseGuide()
  690. local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_ONE,1)
  691. or GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_TWO,1)
  692. if helpVo then
  693. GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
  694. end
  695. end