LoadStatusLoopListCtr.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. local LoadStatusLoopListCtr = class('LoadStatusLoopListCtr')
  2. function LoadStatusLoopListCtr:ctor(owner, loopListView, defaultDataLength, maxDataLength,
  3. hasBegin, beginPrefabName, beginLoadStatus,
  4. hasEnd, endPrefabName, endLoadStatus,
  5. getItemByIndexCB, updateLoadItemCB, beginLoadCB, cbOwner)
  6. self.owner = owner
  7. self.loopListView = loopListView
  8. self.listNum = defaultDataLength
  9. self.listMaxNum = maxDataLength
  10. self.curLoadStatus1 = beginLoadStatus or Enum.ListLoadingStatus.None
  11. self.curLoadStatus2 = endLoadStatus or Enum.ListLoadingStatus.None
  12. self.hasBegin = hasBegin
  13. self.beginPrefabName = beginPrefabName
  14. self.hasEnd = hasEnd
  15. self.endPrefabName = endPrefabName
  16. self.getItemByIndexCB = getItemByIndexCB
  17. self.updateLoadItemCB = updateLoadItemCB
  18. self.beginLoadCB = beginLoadCB
  19. self.cbOwner = cbOwner
  20. if hasBegin then self.listNum = self.listNum + 1 end
  21. if hasEnd then self.listNum = self.listNum + 1 end
  22. loopListView:InitListView(self.listNum, function(loopListView, idx)
  23. return self:GetItemByIndex(loopListView, idx)
  24. end)
  25. if hasBegin or hasEnd then
  26. loopListView.mOnDragingAction = function()
  27. self:OnDraging()
  28. end
  29. loopListView.mOnEndDragAction = function()
  30. self:OnEndDrag()
  31. end
  32. end
  33. end
  34. function LoadStatusLoopListCtr:Dispose()
  35. if self.delayTimer then
  36. self.delayTimer:Stop()
  37. self.delayTimer = nil
  38. end
  39. self.loopListView.mOnDragingAction = nil
  40. self.loopListView.mOnEndDragAction = nil
  41. self.loopListView:Dispose()
  42. self.owner = nil
  43. self.loopListView = nil
  44. self.listNum = nil
  45. self.listMaxNum = nil
  46. self.curLoadStatus1 = nil
  47. self.curLoadStatus2 = nil
  48. self.hasBegin = nil
  49. self.beginPrefabName = nil
  50. self.hasEnd = nil
  51. self.endPrefabName = nil
  52. self.getItemByIndexCB = nil
  53. self.updateLoadItemCB = nil
  54. self.beginLoadCB = nil
  55. end
  56. function LoadStatusLoopListCtr:OnAllLoaded()
  57. self:OnLoaded1()
  58. self:OnLoaded2()
  59. end
  60. function LoadStatusLoopListCtr:RefreshDataLength(length, resetPos)
  61. self.listNum = length
  62. if self.hasBegin then self.listNum = self.listNum + 1 end
  63. if self.hasEnd then self.listNum = self.listNum + 1 end
  64. self.loopListView:SetListItemCount(self.listNum, resetPos or false)
  65. self.loopListView:RefreshAllShownItem()
  66. end
  67. function LoadStatusLoopListCtr:RefreshMaxDataLength(length)
  68. self.listMaxNum = length
  69. if self.hasBegin then self.listMaxNum = self.listMaxNum + 1 end
  70. if self.hasEnd then self.listMaxNum = self.listMaxNum + 1 end
  71. end
  72. function LoadStatusLoopListCtr:OnLoaded1()
  73. if not self.hasBegin then return end
  74. if self.curLoadStatus1 == Enum.ListLoadingStatus.WaitLoad then
  75. self.curLoadStatus1 = Enum.ListLoadingStatus.Loaded
  76. if self.delayTimer then
  77. self.delayTimer.time = self.delayTimer.duration
  78. else
  79. self.delayTimer = Timer.New(function()
  80. self:OnLoaded1Complete()
  81. end, 1, 1)
  82. end
  83. if not self.delayTimer.running then
  84. self.delayTimer:Start()
  85. end
  86. local item = self.loopListView:GetShownItemByItemIndex(0)
  87. if not item then return end
  88. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self.owner, self.beginPrefabName, item.gameObject)
  89. if not itemlua then return end
  90. self:UpdateLoadingItem1(itemlua)
  91. end
  92. end
  93. function LoadStatusLoopListCtr:OnLoaded1Complete()
  94. if self.curLoadStatus1 == Enum.ListLoadingStatus.Loaded then
  95. self.curLoadStatus1 = Enum.ListLoadingStatus.None
  96. local item = self.loopListView:GetShownItemByItemIndex(0)
  97. if not item then return end
  98. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self.owner, self.beginPrefabName, item.gameObject)
  99. if not itemlua then return end
  100. self:UpdateLoadingItem1(itemlua)
  101. itemlua.rectTransform.anchoredPosition3D = Vector3(0, -itemlua.layoutElement.preferredHeight, 0)
  102. self.loopListView:OnItemSizeChanged(0)
  103. end
  104. end
  105. function LoadStatusLoopListCtr:OnLoaded2()
  106. if not self.hasEnd then return end
  107. if self.curLoadStatus2 == Enum.ListLoadingStatus.WaitLoad then
  108. self.curLoadStatus2 = Enum.ListLoadingStatus.None
  109. end
  110. end
  111. function LoadStatusLoopListCtr:SetHasBegin(status)
  112. self.hasBegin = status
  113. end
  114. function LoadStatusLoopListCtr:SetHasEnd(status)
  115. self.hasEnd = status
  116. end
  117. function LoadStatusLoopListCtr:GetItemByIndex(loopListView, idx)
  118. if idx < 0 then return nil end
  119. if self.hasBegin then
  120. if idx == 0 then
  121. local item = loopListView:NewListViewItem(self.beginPrefabName)
  122. local itemlua = CommonUtil.BindGridViewItem2Lua(self.owner, self.beginPrefabName, item.gameObject)
  123. self:UpdateLoadingItem1(itemlua)
  124. return item
  125. end
  126. end
  127. if self.hasEnd then
  128. if idx == self.listNum - 1 then
  129. local item = loopListView:NewListViewItem(self.endPrefabName)
  130. local itemlua = CommonUtil.BindGridViewItem2Lua(self.owner, self.endPrefabName, item.gameObject)
  131. self:UpdateLoadingItem2(itemlua)
  132. return item
  133. end
  134. end
  135. if self.getItemByIndexCB then
  136. return self.getItemByIndexCB(self.cbOwner or self.owner, loopListView, idx, (self.hasBegin and (idx - 1) or idx))
  137. end
  138. return nil
  139. end
  140. function LoadStatusLoopListCtr:OnDraging()
  141. if self.hasBegin then
  142. self:OnDraging1()
  143. end
  144. if self.hasEnd then
  145. if self.listNum < self.listMaxNum then
  146. self:OnDraging2()
  147. end
  148. end
  149. end
  150. function LoadStatusLoopListCtr:OnEndDrag()
  151. if self.hasBegin then
  152. self:OnEndDrag1()
  153. end
  154. if self.hasEnd then
  155. if self.listNum < self.listMaxNum then
  156. self:OnEndDrag2()
  157. end
  158. end
  159. end
  160. function LoadStatusLoopListCtr:OnDraging1()
  161. if self.loopListView.ShownItemCount == 0 then return end
  162. if self.curLoadStatus1 ~= Enum.ListLoadingStatus.None
  163. and self.curLoadStatus1 ~= Enum.ListLoadingStatus.WaitRelease then
  164. return
  165. end
  166. local item = self.loopListView:GetShownItemByItemIndex(0)
  167. if not item then return end
  168. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self.owner, self.beginPrefabName, item.gameObject)
  169. if not itemlua then return end
  170. local sr = self.loopListView.ScrollRect
  171. local pos = sr.content.anchoredPosition3D
  172. local height = itemlua.layoutElement.preferredHeight
  173. if pos.y < -height then
  174. if self.curLoadStatus1 ~= Enum.ListLoadingStatus.None then
  175. return
  176. end
  177. self.curLoadStatus1 = Enum.ListLoadingStatus.WaitRelease
  178. self:UpdateLoadingItem1(itemlua)
  179. itemlua.rectTransform.anchoredPosition3D = Vector3(0, height, 0)
  180. else
  181. if self.curLoadStatus1 ~= Enum.ListLoadingStatus.WaitRelease then
  182. return
  183. end
  184. self.curLoadStatus1 = Enum.ListLoadingStatus.None
  185. self:UpdateLoadingItem1(itemlua)
  186. itemlua.rectTransform.anchoredPosition3D = Vector3.zero
  187. end
  188. end
  189. function LoadStatusLoopListCtr:OnDraging2()
  190. if self.loopListView.ShownItemCount == 0 then return end
  191. if self.curLoadStatus2 ~= Enum.ListLoadingStatus.None
  192. and self.curLoadStatus2 ~= Enum.ListLoadingStatus.WaitRelease then
  193. return
  194. end
  195. local item = self.loopListView:GetShownItemByItemIndex(self.listNum - 1)
  196. if not item then return end
  197. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self.owner, self.endPrefabName, item.gameObject)
  198. if not itemlua then return end
  199. local item1 = self.loopListView:GetShownItemByItemIndex(self.listNum - 2)
  200. if not item1 then return end
  201. local min = item1.CachedRectTransform.rect.min
  202. local pos = item1.CachedRectTransform:TransformPoint(min)
  203. pos = self.loopListView.ScrollRect.viewport:InverseTransformPoint(pos)
  204. local height = itemlua.layoutElement.preferredHeight
  205. if pos.y + self.loopListView.ViewPortSize >= height then
  206. if self.curLoadStatus2 == Enum.ListLoadingStatus.None then
  207. self.curLoadStatus2 = Enum.ListLoadingStatus.WaitRelease
  208. self:UpdateLoadingItem2(itemlua)
  209. end
  210. else
  211. if self.curLoadStatus2 == Enum.ListLoadingStatus.WaitRelease then
  212. self.curLoadStatus2 = Enum.ListLoadingStatus.None
  213. self:UpdateLoadingItem2(itemlua)
  214. end
  215. end
  216. end
  217. function LoadStatusLoopListCtr:OnEndDrag1()
  218. if self.loopListView.ShownItemCount == 0 then return end
  219. if self.curLoadStatus1 ~= Enum.ListLoadingStatus.None
  220. and self.curLoadStatus1 ~= Enum.ListLoadingStatus.WaitRelease then
  221. return
  222. end
  223. local item = self.loopListView:GetShownItemByItemIndex(0)
  224. if not item then return end
  225. self.loopListView:OnItemSizeChanged(item.ItemIndex)
  226. if self.curLoadStatus1 ~= Enum.ListLoadingStatus.WaitRelease then
  227. return
  228. end
  229. self.curLoadStatus1 = Enum.ListLoadingStatus.WaitLoad
  230. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self.owner, self.beginPrefabName, item.gameObject)
  231. if not itemlua then return end
  232. self:UpdateLoadingItem1(itemlua)
  233. if self.beginLoadCB then
  234. self.beginLoadCB(self.cbOwner or self.owner, true)
  235. end
  236. end
  237. function LoadStatusLoopListCtr:OnEndDrag2()
  238. if self.loopListView.ShownItemCount == 0 then return end
  239. if self.curLoadStatus2 ~= Enum.ListLoadingStatus.None and self.curLoadStatus2 ~= Enum.ListLoadingStatus.WaitRelease then
  240. return
  241. end
  242. local item = self.loopListView:GetShownItemByItemIndex(self.listNum - 1)
  243. if not item then return end
  244. self.loopListView:OnItemSizeChanged(item.ItemIndex)
  245. if self.curLoadStatus2 ~= Enum.ListLoadingStatus.WaitRelease then
  246. return
  247. end
  248. self.curLoadStatus2 = Enum.ListLoadingStatus.WaitLoad
  249. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self.owner, self.endPrefabName, item.gameObject)
  250. if not itemlua then return end
  251. self:UpdateLoadingItem2(itemlua)
  252. if self.beginLoadCB then
  253. self.beginLoadCB(self.cbOwner or self.owner, false)
  254. end
  255. end
  256. function LoadStatusLoopListCtr:UpdateLoadingItem1(itemlua)
  257. if self.updateLoadItemCB then
  258. self.updateLoadItemCB(self.owner, itemlua, self.curLoadStatus1, true)
  259. return
  260. end
  261. if self.curLoadStatus1 == Enum.ListLoadingStatus.None then
  262. itemlua.root:SetActive(false)
  263. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, 0)
  264. elseif self.curLoadStatus1 == Enum.ListLoadingStatus.WaitContinureDrag then
  265. itemlua.root:SetActive(true)
  266. itemlua.wait:SetActive(false)
  267. itemlua.desTxt.text.text = string.formatbykey('GuildTips_039')
  268. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, itemlua.layoutElement.preferredHeight)
  269. elseif self.curLoadStatus1 == Enum.ListLoadingStatus.WaitRelease then
  270. itemlua.root:SetActive(true)
  271. itemlua.wait:SetActive(false)
  272. itemlua.desTxt.text.text = string.formatbykey('GuildTips_039')
  273. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, itemlua.layoutElement.preferredHeight)
  274. elseif self.curLoadStatus1 == Enum.ListLoadingStatus.WaitLoad then
  275. itemlua.root:SetActive(true)
  276. itemlua.wait:SetActive(true)
  277. itemlua.desTxt.text.text = string.formatbykey('GuildTips_038')
  278. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, itemlua.layoutElement.preferredHeight)
  279. elseif self.curLoadStatus1 == Enum.ListLoadingStatus.Loaded then
  280. itemlua.root:SetActive(true)
  281. itemlua.wait:SetActive(false)
  282. itemlua.desTxt.text.text = string.formatbykey('GuildTips_042')
  283. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, itemlua.layoutElement.preferredHeight)
  284. end
  285. end
  286. function LoadStatusLoopListCtr:UpdateLoadingItem2(itemlua)
  287. if self.updateLoadItemCB then
  288. self.updateLoadItemCB(self.owner, itemlua, self.curLoadStatus2, false)
  289. return
  290. end
  291. if self.curLoadStatus2 == Enum.ListLoadingStatus.None then
  292. itemlua.root:SetActive(false)
  293. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, 0)
  294. elseif self.curLoadStatus2 == Enum.ListLoadingStatus.WaitRelease then
  295. itemlua.root:SetActive(true)
  296. itemlua.wait:SetActive(false)
  297. itemlua.desTxt.text.text = string.formatbykey('GuildTips_041')
  298. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, itemlua.layoutElement.preferredHeight)
  299. elseif self.curLoadStatus2 == Enum.ListLoadingStatus.WaitLoad then
  300. itemlua.root:SetActive(true)
  301. itemlua.wait:SetActive(true)
  302. itemlua.desTxt.text.text = string.formatbykey('GuildTips_038')
  303. itemlua.rectTransform:SetSizeWithCurrentAnchors(UnityEngine.RectTransform.Axis.Vertical, itemlua.layoutElement.preferredHeight)
  304. end
  305. end
  306. return LoadStatusLoopListCtr