UIBagView.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. local UIBagView = require("UIBag/UIBagView_Generate")
  2. local RectOffset = UnityEngine.RectOffset
  3. local IconItemCtr = require("Common/IconItemCtr")
  4. function UIBagView:OnAwake(data)
  5. self.controller = require("UIBag/UIBagCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UIBagView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EQUIP_CHANGE, self, self.RefreshEquipDatas)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ITEM_CHANGE, self, self.RefreshItemDatas)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.CARD_CHANGE, self, self.RefreshCardDatas)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WISHBOX_SLOT_CHANGE, self, self.RefreshWishSlotData)
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.FILTER_NTF, self, self.RefreshCardDatasByFilter)
  15. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.WISHBOX_SLOT_SHOWANIMATION, self, self.PlayWishSlotAnimation)
  16. end
  17. function UIBagView:FillContent(data, uiBase)
  18. self.uiBase = uiBase
  19. local gameObject = self.uiBase:GetRoot()
  20. if gameObject ~= nil then
  21. self.gameObject = gameObject
  22. self.transform = gameObject.transform
  23. end
  24. self:InitGenerate(self.transform, data)
  25. self:Init()
  26. end
  27. function UIBagView:Init()
  28. self.scrollView.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  29. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  30. end, nil)
  31. self.toggleGroup.toggleGroup:SetAllTogglesOff()
  32. local bagViewPageType = self.controller:GetBagViewPageType()
  33. self:SetToggleGroupStatus(bagViewPageType)
  34. -- self.isInit = false
  35. -- self.delayTimer = FrameTimer.New(function()
  36. -- self:InitData()
  37. -- end, 1)
  38. -- self.delayTimer:Start()
  39. self.controller:RefreshShowDataType()
  40. self:RefreshViewPage(true)
  41. self:RefreshWishSlotData()
  42. self:RefreshWishSlotAnim()
  43. self.delayTimer = FrameTimer.New(function()
  44. if bagViewPageType == Enum.BagViewPageType.Card then
  45. local lockStatus = ManagerContainer.UIFuncUnlockMgr:GetTargetFuncLockStatus(self, self.btnDecompose)
  46. if lockStatus then
  47. self.btnDecompose_lock:SetActive(lockStatus)
  48. end
  49. lockStatus = ManagerContainer.UIFuncUnlockMgr:GetTargetFuncLockStatus(self, self.btnProduce)
  50. if lockStatus then
  51. self.btnProduce_lock:SetActive(lockStatus)
  52. end
  53. else
  54. self.btnDecompose:SetActive(false)
  55. self.btnProduce:SetActive(false)
  56. self.btnDecompose_lock:SetActive(false)
  57. self.btnProduce_lock:SetActive(false)
  58. end
  59. end, 1)
  60. self.delayTimer:Start()
  61. end
  62. function UIBagView:RefreshWishSlotAnim()
  63. local wishSlotData = ManagerContainer.DataMgr.BagData:GetWishSlotData()
  64. if wishSlotData and #wishSlotData > 0 then
  65. for i = 1, #wishSlotData do
  66. local wishItem = self["wishSlot"..i]
  67. if wishItem then
  68. wishItem.wishShow:SetActive(true)
  69. wishItem.wishShow.animator:Play("WishShow",0,1.5)
  70. end
  71. end
  72. end
  73. end
  74. function UIBagView:RemoveEventListener()
  75. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  76. end
  77. function UIBagView:AddUIEventListener()
  78. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  79. self.uiBase:AddToggleEventListener(self.toggleEquip.toggle, self, self.OnValueChangedToggle, Enum.BagViewPageType.Equip)
  80. self.uiBase:AddToggleEventListener(self.toggleItems.toggle, self, self.OnValueChangedToggle, Enum.BagViewPageType.Item)
  81. self.uiBase:AddToggleEventListener(self.toggleCards.toggle, self, self.OnValueChangedToggle, Enum.BagViewPageType.Card)
  82. self.uiBase:AddToggleEventListener(self.toggleArtifact.toggle, self, self.OnValueChangedToggle, Enum.BagViewPageType.SkillEquip)
  83. self.uiBase:AddButtonEventListener(self.btnBack.button, self, self.OnClickBackBtn)
  84. self.uiBase:AddButtonEventListener(self.btnDecompose.button, self, self.OnClickDecomposeBtn)
  85. self.uiBase:AddButtonEventListener(self.btnProduce.button, self, self.OnClickProduceBtn)
  86. self.uiBase:AddButtonEventListener(self.btnArtifactDecompose.button, self, self.OnArtifactDecomposeClick)
  87. self.uiBase:AddButtonEventListener(self.btnArtifactReforge.button, self, self.OnArtifactReforgeClick)
  88. self.uiBase:AddButtonEventListener(self.btnFilter.button, self, self.OnFilterClick)
  89. end
  90. function UIBagView:OnHide()
  91. -- if self.delayTimer then
  92. -- self.delayTimer:Stop()
  93. -- end
  94. -- self.delayTimer = nil
  95. -- self.isInit = nil
  96. -- local loopGridView = self.scrollView.loopGridView
  97. -- if loopGridView and self.defaultRectOffset then
  98. -- loopGridView:SetPadding(self.defaultRectOffset)
  99. -- end
  100. -- self.defaultRectOffset = nil
  101. if self.delayTimer then
  102. self.delayTimer:Stop()
  103. end
  104. self.delayTimer = nil
  105. end
  106. function UIBagView:OnShow(data)
  107. self.controller:SetData(data)
  108. self.scrollView.loopGridView:SetListItemCount(0, true)
  109. self.toggleGroup.toggleGroup:SetAllTogglesOff()
  110. local bagViewPageType = self.controller:GetBagViewPageType()
  111. self:SetToggleGroupStatus(bagViewPageType)
  112. self.delayTimer = FrameTimer.New(function()
  113. if bagViewPageType == Enum.BagViewPageType.Card then
  114. local lockStatus = ManagerContainer.UIFuncUnlockMgr:GetTargetFuncLockStatus(self, self.btnDecompose)
  115. if lockStatus then
  116. self.btnDecompose_lock:SetActive(lockStatus)
  117. end
  118. lockStatus = ManagerContainer.UIFuncUnlockMgr:GetTargetFuncLockStatus(self, self.btnProduce)
  119. if lockStatus then
  120. self.btnProduce_lock:SetActive(lockStatus)
  121. end
  122. else
  123. self.btnDecompose:SetActive(false)
  124. self.btnProduce:SetActive(false)
  125. self.btnDecompose_lock:SetActive(false)
  126. self.btnProduce_lock:SetActive(false)
  127. end
  128. end, 1)
  129. self.delayTimer:Start()
  130. self.controller:RefreshShowDataType()
  131. self:RefreshViewPage(true)
  132. end
  133. function UIBagView:OnClose()
  134. self.scrollView.loopGridView:Dispose()
  135. end
  136. function UIBagView:PlayWishSlotAnimation(idx)
  137. local wishItem = self["wishSlot"..idx + 1]
  138. if wishItem then
  139. wishItem.wishShow.animator:Play("WishShow",0,0)
  140. end
  141. end
  142. function UIBagView:SetToggleGroupStatus(bagViewPageType)
  143. if bagViewPageType == Enum.BagViewPageType.Equip then
  144. self.toggleEquip.toggle.isOn = true
  145. elseif bagViewPageType == Enum.BagViewPageType.Item then
  146. self.toggleItems.toggle.isOn = true
  147. elseif bagViewPageType == Enum.BagViewPageType.Card then
  148. self.toggleCards.toggle.isOn = true
  149. elseif bagViewPageType == Enum.BagViewPageType.SkillEquip then
  150. self.toggleArtifact.toggle.isOn = true
  151. end
  152. end
  153. function UIBagView:RefreshWishSlotData()
  154. local wishSlotData = ManagerContainer.DataMgr.BagData:GetWishSlotData()
  155. if not wishSlotData then
  156. self:DisposeRefreshTimer()
  157. return
  158. end
  159. local isNeedTimer = false
  160. for i = 1, #wishSlotData do
  161. local wishItem = self["wishSlot"..i]
  162. local wishData = wishSlotData[i]
  163. local currTime = ManagerContainer.LuaTimerMgr:CurLuaServerTime()
  164. if wishItem then
  165. local currEndTime = wishData.end_time * 1000 - currTime
  166. --wishItem.wishShow:SetActive(false)
  167. wishItem.lock:SetActive(not wishData.isOpen)
  168. wishItem.luckyLabel:SetActive(wishData.luckyItem ~= nil)
  169. wishItem.lucky:SetActive(wishData.isLucky)
  170. wishItem.iconSmallItem.gameObject:SetActive(wishData.item ~= nil)
  171. wishItem.times:SetActive(currEndTime > 0)
  172. if wishData.end_time > 0 then
  173. isNeedTimer = true
  174. local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(wishData.end_time * 1000)
  175. if remainTime >= 0 then
  176. wishItem.times.text.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false)
  177. end
  178. end
  179. if wishData.item then
  180. local data = {cfgId = wishData.item.key,num = wishData.item.value}
  181. IconItemCtr:SetData(self, wishItem.iconSmallItem, data)
  182. end
  183. wishItem.iconSmallItem.redPoint:SetActive(wishData.end_time == 0 or currEndTime <= 0)
  184. self.uiBase:AddButtonUniqueEventListener(wishItem.button.button, self, self.OnWishSlotItemClick,i)
  185. end
  186. end
  187. if isNeedTimer then
  188. self:StartRefreshTimer()
  189. end
  190. end
  191. function UIBagView:GetShowItemByIdx(idx)
  192. local item = self.scrollView.loopGridView:GetShownItemByItemIndex(idx)
  193. if item then
  194. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self, "IconItem", item.gameObject)
  195. return itemlua
  196. end
  197. end
  198. function UIBagView:StartRefreshTimer()
  199. local timer = self.refreshTimer
  200. if not timer then
  201. timer = Timer.New(slot(self.RefreshTimer,self), 1, -1)
  202. self.refreshTimer = timer
  203. end
  204. if not timer.running then
  205. timer:Start()
  206. end
  207. end
  208. function UIBagView:DisposeRefreshTimer()
  209. self:StopRefreshTimer()
  210. self.refreshTimer = nil
  211. end
  212. function UIBagView:OnWishSlotItemClick(btn,param)
  213. local wishSlotData = ManagerContainer.DataMgr.BagData:GetWishSlotData()
  214. if not wishSlotData then
  215. return
  216. end
  217. local idx = param[0]
  218. local wishItem = self["wishSlot"..idx]
  219. local wishData = wishSlotData[idx]
  220. if wishData then
  221. if wishData.isOpen then
  222. if wishData.item then
  223. local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(wishData.end_time * 1000)
  224. if remainTime <= 0 then
  225. ManagerContainer.DataMgr.BagData:SendWishAccelerateReq(idx - 1)
  226. else
  227. if wishData.src_item then
  228. local wishcfg = ManagerContainer.CfgMgr:GetWishCfgById(wishData.src_item)
  229. if wishcfg then
  230. local cost = wishcfg.AccelerateCost
  231. local txt = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, true, false)
  232. local data = {cfgId = cost[1][1],needNum = cost[1][2],timeTxt = txt,idx = idx}
  233. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIGetNowPop,data)
  234. end
  235. end
  236. end
  237. else
  238. self:RefreshWishNoticeItem()
  239. end
  240. else
  241. local cfgdata = GlobalConfig.Instance:GetConfigStrValue(348)
  242. local costData = CommonUtil.DeserializeGlobalStrToNumberTable(cfgdata)
  243. local costNum = costData[1][2]
  244. ManagerContainer.LuaUIMgr:ShowMessageBox("WishSlotUnlockTips",{costNum},nil,self,self.WishSlotUnlockSure,nil)
  245. end
  246. end
  247. end
  248. function UIBagView:RefreshWishNoticeItem()
  249. if self.wishNoticetimer and self.wishNoticetimer.running then
  250. return
  251. end
  252. local showDatas = self.controller:GetAllShowDatas()
  253. if not self.NoticeItemList then
  254. self.NoticeItemList = {}
  255. end
  256. local refreshPos = nil
  257. local parentGo = self.noticeItemParent.transform
  258. if showDatas and #showDatas > 0 then
  259. for i = 1, #showDatas do
  260. local cfgData = ManagerContainer.CfgMgr:GetItemById(showDatas[i].cfgId)
  261. if cfgData then
  262. if cfgData.ResType == Enum.ItemType.WishBox or cfgData.ResType == Enum.ItemType.OptionalWishBox then
  263. if not refreshPos then
  264. refreshPos = true
  265. local loopGridView = self.scrollView.loopGridView
  266. local length = self.controller:GetShowDataLength()
  267. loopGridView:RefreshListByIndex(length, i)
  268. if not self.wishNoticetimer then
  269. self.wishNoticetimer = Timer.New(slot(self.RefreshWishNoticeTimer,self), 2.5, 1)
  270. self.wishNoticetimer:Start()
  271. end
  272. end
  273. local itemLua = self:GetShowItemByIdx(i - 1)
  274. if itemLua then
  275. local newGo = UnityEngine.GameObject.Instantiate(self.bagNoticeItem.gameObject)
  276. newGo:SetActive(true)
  277. newGo.transform:SetParent(parentGo)
  278. newGo.transform.localScale = Vector3.New(1,1,1)
  279. newGo.transform.position = itemLua.transform.position
  280. table.insert(self.NoticeItemList,newGo)
  281. end
  282. end
  283. end
  284. end
  285. end
  286. if not refreshPos then
  287. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NoWishBox")
  288. end
  289. end
  290. function UIBagView:RefreshWishNoticeTimer()
  291. if self.NoticeItemList then
  292. for i = 1, #self.NoticeItemList do
  293. local go = self.NoticeItemList[i]
  294. if go then
  295. CommonUtil.DestroyGO(go)
  296. end
  297. end
  298. self.NoticeItemList = nil
  299. end
  300. if self.wishNoticetimer then
  301. self.wishNoticetimer:Stop()
  302. end
  303. self.wishNoticetimer = nil
  304. end
  305. function UIBagView:WishSlotUnlockSure()
  306. --确认解锁数据是否足够
  307. local cfgdata = GlobalConfig.Instance:GetConfigStrValue(348)
  308. local costData = CommonUtil.DeserializeGlobalStrToNumberTable(cfgdata)
  309. local costId = costData[1][1]
  310. local costNum = costData[1][2]
  311. local hasNum = CommonUtil.GetOwnResCountByItemId(costId)
  312. if hasNum >= costNum then
  313. ManagerContainer.DataMgr.BagData:SendWishSlotUnlockReq()
  314. else
  315. CommonUtil.ItemNotEnoughHandle(costId)
  316. end
  317. end
  318. function UIBagView:RefreshTimer()
  319. local wishSlotData = ManagerContainer.DataMgr.BagData:GetWishSlotData()
  320. if not wishSlotData then
  321. self:DisposeRefreshTimer()
  322. return
  323. end
  324. local minEndTime = nil
  325. for i = 1, #wishSlotData do
  326. if not minEndTime then
  327. minEndTime = wishSlotData[1].end_time
  328. else
  329. if wishSlotData[i].end_time > 0 and minEndTime > wishSlotData[i].end_time then
  330. minEndTime = wishSlotData[i].end_time
  331. end
  332. end
  333. end
  334. for i = 1, #wishSlotData do
  335. local wishData = wishSlotData[i]
  336. local wishItem = self["wishSlot"..i]
  337. if wishItem then
  338. if wishData.end_time > 0 then
  339. local endTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(wishData.end_time * 1000)
  340. if endTime >= 0 then
  341. wishItem.times.text.text.text = DateTimeUtil.convertSeconds2TimeStr1(endTime, true, true, false)
  342. else
  343. wishItem.times:SetActive(false)
  344. end
  345. end
  346. end
  347. end
  348. if not minEndTime then
  349. return
  350. end
  351. local remainTime = ManagerContainer.LuaTimerMgr:GetRemainSecondsWithUInt64(minEndTime * 1000)
  352. if not remainTime or remainTime <= 0 then
  353. self:RefreshWishSlotData()
  354. else
  355. if self.refreshTimer then
  356. local validTime = nil
  357. if remainTime >= 86400 then
  358. validTime = remainTime % 3600
  359. if validTime == 0 then validTime = 3600 end
  360. elseif remainTime >= 3600 then
  361. validTime = remainTime % 60
  362. if validTime == 0 then validTime = 60 end
  363. else
  364. validTime = 1
  365. end
  366. if validTime then
  367. self.refreshTimer.duration = validTime
  368. else
  369. self:StopRefreshTimer()
  370. end
  371. end
  372. end
  373. end
  374. function UIBagView:StopRefreshTimer()
  375. if self.refreshTimer then
  376. self.refreshTimer:Stop()
  377. end
  378. end
  379. function UIBagView:OnDispose()
  380. -- if self.inited then
  381. -- if self.delayTimer then
  382. -- self.delayTimer:Stop()
  383. -- end
  384. -- self.delayTimer = nil
  385. -- self.isInit = nil
  386. -- local loopGridView = self.scrollView.loopGridView
  387. -- loopGridView:Dispose()
  388. -- if self.defaultRectOffset then
  389. -- loopGridView:SetPadding(self.defaultRectOffset)
  390. -- end
  391. -- self.defaultRectOffset = nil
  392. -- end
  393. -- self.scrollView.loopGridView:Dispose()
  394. if self.delayTimer then
  395. self.delayTimer:Stop()
  396. end
  397. self.delayTimer = nil
  398. if self.NoticeItemList then
  399. for i = 1, #self.NoticeItemList do
  400. local go = self.NoticeItemList[i]
  401. if go then
  402. CommonUtil.DestroyGO(go)
  403. end
  404. end
  405. self.NoticeItemList = nil
  406. end
  407. if self.wishNoticetimer then
  408. self.wishNoticetimer:Stop()
  409. end
  410. self.wishNoticetimer = nil
  411. if self.wishShowtimer then
  412. self.wishShowtimer:Stop()
  413. end
  414. self.wishShowtimer = nil
  415. self:DisposeRefreshTimer()
  416. end
  417. function UIBagView:GetItemByRowColumn(gridView, itemIndex, row, column)
  418. -- local length = self.controller:GetShowDataLength()
  419. -- if (itemIndex < 0 or itemIndex >= length) then
  420. -- return nil
  421. -- end
  422. local showData = self.controller:GetShowData(itemIndex)
  423. local item = nil
  424. if showData then
  425. item = gridView:NewListViewItem('IconItem')
  426. local itemlua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', item.gameObject)
  427. CommonUtil.UpdateItemPrefab(self, itemlua, showData, Enum.ItemIEnterType.Bag, self, self.ShowItemTips)
  428. else
  429. item = gridView:NewListViewItem('IconEmptyItem')
  430. end
  431. return item
  432. end
  433. function UIBagView:RefreshEquipDatas()
  434. self:RefreshDatas(Enum.BagViewPageType.Equip)
  435. end
  436. function UIBagView:RefreshItemDatas()
  437. self:RefreshDatas(Enum.BagViewPageType.Item)
  438. end
  439. function UIBagView:RefreshCardDatas()
  440. self:RefreshDatas(Enum.BagViewPageType.Card)
  441. end
  442. function UIBagView:RefreshCardDatasByFilter(uiId, data, isFilter)
  443. if uiId ~= self.uiData.id then return end
  444. self.controller:SetFilterData(data, isFilter)
  445. self:RefreshDatas(Enum.BagViewPageType.Card)
  446. end
  447. function UIBagView:RefreshDatas(bagViewPageType)
  448. self.controller:RefreshViewDatas(bagViewPageType)
  449. if self.controller:GetBagViewPageType() == bagViewPageType then
  450. self:RefreshViewPage()
  451. end
  452. end
  453. -- function UIBagView:InitData()
  454. -- local loopGridView = self.scrollView.loopGridView
  455. -- local itemSize = loopGridView.ItemSize
  456. -- local itemPadding = loopGridView.ItemPadding
  457. -- local padding = loopGridView.Padding
  458. -- local itemSizeWithPadding = itemPadding + itemSize
  459. -- local width = loopGridView.ViewPortWidth - padding.left - padding.right + itemPadding.x
  460. -- local height = loopGridView.ViewPortHeight - padding.top
  461. -- local row = Mathf.Floor(width / (itemSizeWithPadding.x))
  462. -- local column = Mathf.Ceil(height / (itemSizeWithPadding.y))
  463. -- local realWidth = row * itemSizeWithPadding.x
  464. -- local offset = width - realWidth
  465. -- if offset > 0 then
  466. -- offset = offset * 0.5
  467. -- local newPadding = RectOffset(offset + padding.left, offset + padding.right, padding.top, padding.bottom)
  468. -- loopGridView:SetPadding(newPadding)
  469. -- end
  470. -- loopGridView:SetGridFixedGroupCount(SuperScrollView.GridFixedType.ColumnCountFixed, row)
  471. -- self.defaultRectOffset = padding
  472. -- self.isInit = true
  473. -- self.controller:SetGridRowColumn(row, column)
  474. -- self.controller:RefreshShowDataType()
  475. -- self:RefreshViewPage(true)
  476. -- end
  477. function UIBagView:RefreshViewPage(resetPos)
  478. -- if not self.isInit then return end
  479. local bagViewPageType = self.controller:GetBagViewPageType()
  480. if self.NoticeItemList then
  481. for i = 1, #self.NoticeItemList do
  482. local go = self.NoticeItemList[i]
  483. if go then
  484. CommonUtil.DestroyGO(go)
  485. end
  486. end
  487. self.NoticeItemList = nil
  488. end
  489. self.btnFilter:SetActive(bagViewPageType == Enum.BagViewPageType.Card)
  490. self.btnArtifactDecompose:SetActive(bagViewPageType == Enum.BagViewPageType.SkillEquip)
  491. self.btnArtifactReforge:SetActive(bagViewPageType == Enum.BagViewPageType.SkillEquip)
  492. self.wishBox:SetActive(bagViewPageType == Enum.BagViewPageType.Item)
  493. if bagViewPageType == Enum.BagViewPageType.Equip then
  494. -- 装备
  495. self.btnDecompose:SetActive(false)
  496. self.btnProduce:SetActive(false)
  497. self.btnDecompose_lock:SetActive(false)
  498. self.btnProduce_lock:SetActive(false)
  499. elseif bagViewPageType == Enum.BagViewPageType.Item then
  500. -- 道具
  501. self:RefreshWishSlotAnim()
  502. self.btnDecompose:SetActive(false)
  503. self.btnProduce:SetActive(false)
  504. self.btnDecompose_lock:SetActive(false)
  505. self.btnProduce_lock:SetActive(false)
  506. elseif bagViewPageType == Enum.BagViewPageType.Card then
  507. -- 卡片
  508. local lockStatus = ManagerContainer.UIFuncUnlockMgr:GetTargetFuncLockStatus(self, self.btnDecompose)
  509. self.btnDecompose:SetActive(not lockStatus)
  510. if lockStatus then
  511. self.btnDecompose_lock:SetActive(lockStatus)
  512. end
  513. lockStatus = ManagerContainer.UIFuncUnlockMgr:GetTargetFuncLockStatus(self, self.btnProduce)
  514. self.btnProduce:SetActive(not lockStatus)
  515. if lockStatus then
  516. self.btnProduce_lock:SetActive(lockStatus)
  517. end
  518. elseif bagViewPageType == Enum.BagViewPageType.SkillEquip then
  519. -- 神器
  520. self.btnDecompose:SetActive(false)
  521. self.btnProduce:SetActive(false)
  522. self.btnDecompose_lock:SetActive(false)
  523. self.btnProduce_lock:SetActive(false)
  524. self.btnArtifactDecompose:SetActive(true)
  525. end
  526. local loopGridView = self.scrollView.loopGridView
  527. local length = self.controller:GetShowDataLength()
  528. if resetPos then
  529. loopGridView:RefreshListByIndex(length, 0)
  530. else
  531. loopGridView:RefreshListByIndex(length)
  532. end
  533. self.btnFilter.check:SetActive(self.controller:GetIsFilter())
  534. end
  535. function UIBagView:ShowItemTips(button, params)
  536. local bagViewPageType = self.controller:GetBagViewPageType()
  537. if bagViewPageType == Enum.BagViewPageType.SkillEquip then
  538. local data = params[0]
  539. local params = {{cfgId = data.cfgId, jobType = data.JobType, logicData = data}, Enum.ItemIEnterType.SkillEquip, self.uiData.id}
  540. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIArtifactTips, params)
  541. else
  542. local data = clone(params[0])
  543. data.displayBtn = true
  544. data.source = self.uiData.id
  545. local _extData = {_id = data.id, cfgId = data.cfgId}
  546. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(data.cfgId)
  547. if itemCfgData and itemCfgData.SkipInterface > 0 and itemCfgData.ResType ~= Enum.ItemType.Gift then
  548. if data.state == nil then data.state = 0 end
  549. data.state = Bit.bor(data.state, Bit.lshift(1, Enum.TipsEnterType.BtnGoto)) --data.state + CommonUtil.Get2Powers(Enum.TipsEnterType.BtnGoto)
  550. end
  551. ManagerContainer.LuaUIMgr:OpenTips(data, _extData)
  552. end
  553. end
  554. function UIBagView:OnValueChangedToggle(toggle, bagViewPageType, isOn)
  555. if not isOn then return end
  556. if self.controller:SetBagViewPageType(bagViewPageType) then
  557. self:RefreshViewPage(true)
  558. end
  559. end
  560. function UIBagView:OnClickBackBtn()
  561. -- 酒馆按钮打开的界面,不能直接关闭,暂时屏蔽关闭
  562. -- if ManagerContainer.FSMMgr:IsMainCityState() then
  563. -- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UIMAINVIEW_CHANGE_NOTICE, Enum.MainViewPageType.Town)
  564. -- else
  565. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UIMAINVIEW_CHANGE_NOTICE, Enum.MainViewPageType.Adventure)
  566. -- end
  567. end
  568. function UIBagView:OnClickDecomposeBtn()
  569. if self.controller:GetBagViewPageType() ~= Enum.BagViewPageType.Card then
  570. return
  571. end
  572. self:UIHide()
  573. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UICardList, Enum.CardFuncType.Compose)
  574. end
  575. function UIBagView:OnClickProduceBtn()
  576. if self.controller:GetBagViewPageType() ~= Enum.BagViewPageType.Card then
  577. return
  578. end
  579. self:UIHide()
  580. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UICardList, Enum.CardFuncType.Recreate)
  581. end
  582. function UIBagView:OnArtifactDecomposeClick()
  583. if self.controller:GetBagViewPageType() ~= Enum.BagViewPageType.SkillEquip then
  584. return
  585. end
  586. self:UIHide()
  587. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPetDecompose, 2, self.uiData.id)
  588. end
  589. function UIBagView:OnArtifactReforgeClick()
  590. if self.controller:GetBagViewPageType() ~= Enum.BagViewPageType.SkillEquip then
  591. return
  592. end
  593. self:UIHide()
  594. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIArtifactReforge, nil, self.uiData.id)
  595. end
  596. function UIBagView:OnFilterClick()
  597. local data = {uiId = self.uiData.id, enter = Enum.ItemIEnterType.Bag, filterData = self.controller:GetFilterData()}
  598. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFilter, data)
  599. end
  600. --强制引导
  601. function UIBagView:FindBagFirstCard(owner, ownerCB)
  602. local target
  603. local item = self.scrollView.loopGridView:GetShownItemByRowColumn(0, 0)
  604. if item.ItemPrefabName == "IconItem" then
  605. target = item.transform:Find("bg").gameObject
  606. end
  607. if target == nil then
  608. if owner and ownerCB then
  609. ownerCB(owner)
  610. return
  611. end
  612. end
  613. if owner and ownerCB then
  614. ownerCB(owner, target)
  615. return
  616. end
  617. end
  618. function UIBagView:FindBagFirstItem(itemId, owner, ownerCB)
  619. if not ownerCB then return end
  620. local target = nil
  621. if itemId then
  622. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(itemId)
  623. if itemCfgData then
  624. local bagViewPageType = self.controller:GetBagViewPageTypeByItemType(itemCfgData.ResType)
  625. self:SetToggleGroupStatus(bagViewPageType)
  626. local showDatas = self.controller:GetAllShowDatas()
  627. if showDatas then
  628. local length = self.controller:GetShowDataLength()
  629. for i = 1, length do
  630. if showDatas[i] and showDatas[i].cfgId == itemId then
  631. local loopGridView = self.scrollView.loopGridView
  632. local item = loopGridView:GetShownItemByItemIndex(i - 1)
  633. if not item then
  634. loopGridView:RefreshListByIndex(length, i - 1)
  635. item = loopGridView:GetShownItemByItemIndex(i - 1)
  636. end
  637. if item.ItemPrefabName == "IconItem" then
  638. target = item.transform:Find("bg").gameObject
  639. end
  640. break
  641. end
  642. end
  643. end
  644. end
  645. end
  646. if owner then
  647. ownerCB(owner, target)
  648. else
  649. ownerCB(target)
  650. end
  651. end
  652. return UIBagView