UICollectView.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. local UICollectView = require("UICollect/UICollectView_Generate")
  2. local CardBook = require("UICollect/CardBook")
  3. local PetBook = require("UICollect/PetBook")
  4. local KeepSakeBook = require("UICollect/KeepSakeBook")
  5. function UICollectView:OnAwake(data)
  6. self.controller = require("UICollect/UICollectCtr"):new()
  7. self.controller:Init(self)
  8. self.controller:SetData(data)
  9. end
  10. function UICollectView:AddEventListener()
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.KEEPSAKE_LEVEL_UP_SUCCESS_NTF, function()
  13. if self.keepSakeBookLua then
  14. self.numexchage.text.text = CommonUtil.GetOwnResCountByItemId(Enum.ItemIds.KeepSakeExchange)
  15. self.keepSakeBookLua:OnValueChangedToggle()
  16. end
  17. end)
  18. end
  19. function UICollectView:FillContent(data, uiBase)
  20. self.uiBase = uiBase
  21. local gameObject = self.uiBase:GetRoot()
  22. if gameObject ~= nil then
  23. self.gameObject = gameObject
  24. self.transform = gameObject.transform
  25. end
  26. self:InitGenerate(self.transform, data)
  27. self:Init()
  28. end
  29. function UICollectView:Init()
  30. self:RefreshPetEnterLock()
  31. self:RefreshCollectionEnterLock()
  32. self:InitSubGo()
  33. end
  34. function UICollectView:RefreshPetEnterLock()
  35. local unLockState, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(56, true)
  36. self.lockPet:SetActive(not unLockState)
  37. if not unLockState then
  38. self.lockPet.text.uILocalizeScript:SetContent(content)
  39. end
  40. end
  41. function UICollectView:RefreshCollectionEnterLock()
  42. local unLockState, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(65, true)
  43. self.lockCollection:SetActive(not unLockState)
  44. if not unLockState then
  45. self.lockCollection.text.uILocalizeScript:SetContent(content)
  46. end
  47. end
  48. function UICollectView:InitSubGo()
  49. if not self.cardBookLua then
  50. self.cardBookLua = CardBook:new()
  51. local go = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, "UICollect/BookItem")
  52. local trans = go.transform
  53. trans:SetParent(self.bookAnim.transform)
  54. trans:GetComponent(Enum.TypeInfo.RectTransform).anchoredPosition3D = Vector3.zero
  55. trans.localRotation = Quaternion.identity
  56. trans.localScale = Vector3.one
  57. trans:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta = Vector2.one
  58. trans.name = "CardBook"
  59. self.cardBookLua:InitGo(self, go)
  60. if self.cardBookLua then
  61. self.cardBookLua:AddEventListener()
  62. self.cardBookLua:AddUIEventListener()
  63. end
  64. end
  65. if not self.petBookLua then
  66. self.petBookLua = PetBook:new()
  67. local go = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, "UICollect/BookItem")
  68. local trans = go.transform
  69. trans:SetParent(self.bookAnim.transform)
  70. trans:GetComponent(Enum.TypeInfo.RectTransform).anchoredPosition3D = Vector3.zero
  71. trans.localRotation = Quaternion.identity
  72. trans.localScale = Vector3.one
  73. trans:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta = Vector2.one
  74. trans.name = "PetBook"
  75. self.petBookLua:InitGo(self, go)
  76. if self.petBookLua then
  77. self.petBookLua:AddEventListener()
  78. self.petBookLua:AddUIEventListener()
  79. end
  80. end
  81. if not self.keepSakeBookLua then
  82. self.keepSakeBookLua = KeepSakeBook:new()
  83. local go = ManagerContainer.ResMgr:GetGoFromPool(Constants.UIPath, "UICollect/BookItem")
  84. local trans = go.transform
  85. trans:SetParent(self.bookAnim.transform)
  86. trans:GetComponent(Enum.TypeInfo.RectTransform).anchoredPosition3D = Vector3.zero
  87. trans.localRotation = Quaternion.identity
  88. trans.localScale = Vector3.one
  89. trans:GetComponent(Enum.TypeInfo.RectTransform).sizeDelta = Vector2.one
  90. trans.name = "keepSakeBook"
  91. self.keepSakeBookLua:InitGo(self, go)
  92. if self.keepSakeBookLua then
  93. self.keepSakeBookLua:AddEventListener()
  94. self.keepSakeBookLua:AddUIEventListener()
  95. end
  96. end
  97. end
  98. function UICollectView:OnValueChangedToggle()
  99. self.myExchangeCards:SetActive(self.type == Enum.CollectType.KeepSake)
  100. if self.type == Enum.CollectType.Card then
  101. if self.cardBookLua and self.cardBookLua.OnValueChangedToggle then
  102. self.cardBookLua:OnValueChangedToggle()
  103. end
  104. elseif self.type == Enum.CollectType.Pet then
  105. if self.petBookLua and self.petBookLua.OnValueChangedToggle then
  106. self.petBookLua:OnValueChangedToggle()
  107. end
  108. elseif self.type == Enum.CollectType.KeepSake then
  109. self.numexchage.text.text = CommonUtil.GetOwnResCountByItemId(Enum.ItemIds.KeepSakeExchange)
  110. if self.keepSakeBookLua and self.keepSakeBookLua.OnValueChangedToggle then
  111. self.keepSakeBookLua:OnValueChangedToggle()
  112. end
  113. end
  114. end
  115. function UICollectView:RemoveEventListener()
  116. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  117. if self.cardBookLua then
  118. self.cardBookLua:RemoveEventListener()
  119. end
  120. if self.petBookLua then
  121. self.petBookLua:RemoveEventListener()
  122. end
  123. if self.keepSakeBookLua then
  124. self.keepSakeBookLua:RemoveEventListener()
  125. end
  126. end
  127. function UICollectView:AddUIEventListener()
  128. self.uiBase:AddButtonEventListener(self.btnCardBook.button, self, self.OnBtnCardBookClick)
  129. self.uiBase:AddButtonEventListener(self.btnPetBook.button, self, self.OnBtnPetBookClick)
  130. self.uiBase:AddButtonEventListener(self.btnCollectionBook.button, self, self.OnBtnKeepSakeBookClick)
  131. self.uiBase:AddButtonEventListener(self.btnClose.button, self, self.OnCloseClick)
  132. self.uiBase:AddButtonEventListener(self.btnPlayRule.button, self, self.OnClickPlayRuleBtn)
  133. end
  134. function UICollectView:OnClickPlayRuleBtn()
  135. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', 'CollectPlayExplain'})
  136. end
  137. function UICollectView:OnBtnCardBookClick(button, params)
  138. self.type = Enum.CollectType.Card
  139. self.window.animator:Play("Book")
  140. self.cardBookLua:Show()
  141. self.petBookLua:Hide()
  142. self.keepSakeBookLua:Hide()
  143. if self.cardBookLua and self.cardBookLua.SelectToggle then
  144. self.cardBookLua:SelectToggle()
  145. end
  146. end
  147. function UICollectView:OnBtnPetBookClick(button, params)
  148. self.type = Enum.CollectType.Pet
  149. self.window.animator:Play("Book")
  150. self.cardBookLua:Hide()
  151. self.petBookLua:Show()
  152. self.keepSakeBookLua:Hide()
  153. if self.petBookLua and self.petBookLua.SelectToggle then
  154. self.petBookLua:SelectToggle()
  155. end
  156. end
  157. function UICollectView:OnBtnKeepSakeBookClick(button, params)
  158. self.type = Enum.CollectType.KeepSake
  159. self.window.animator:Play("Book")
  160. self.cardBookLua:Hide()
  161. self.petBookLua:Hide()
  162. self.keepSakeBookLua:Show()
  163. if self.keepSakeBookLua and self.keepSakeBookLua.SelectToggle then
  164. self.keepSakeBookLua:SelectToggle()
  165. end
  166. end
  167. function UICollectView:BookBack()
  168. self.type = nil
  169. self.window.animator:Play("List")
  170. CommonUtil.CloseUIClearAsyncSeqIds(self)
  171. end
  172. function UICollectView:OnCloseClick()
  173. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  174. end
  175. function UICollectView:OnHide()
  176. end
  177. function UICollectView:OnShow(data)
  178. self.controller:SetData(data)
  179. end
  180. function UICollectView:OnClose()
  181. end
  182. function UICollectView:OnDispose()
  183. if self.cardBookLua then
  184. local go = self.cardBookLua.viewLua.gameObject
  185. self.cardBookLua:Dispose()
  186. self.cardBookLua = nil
  187. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, "UICollect/BookItem", go)
  188. end
  189. if self.petBookLua then
  190. local go = self.petBookLua.viewLua.gameObject
  191. self.petBookLua:Dispose()
  192. self.petBookLua = nil
  193. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, "UICollect/BookItem", go)
  194. end
  195. if self.keepSakeBookLua then
  196. local go = self.keepSakeBookLua.viewLua.gameObject
  197. self.keepSakeBookLua:Dispose()
  198. self.keepSakeBookLua = nil
  199. ManagerContainer.ResMgr:RecycleGO(Constants.UIPath, "UICollect/BookItem", go)
  200. end
  201. self.controller:OnDispose()
  202. end
  203. return UICollectView