UIWishPOPGotView.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. local UIWishPOPGotView = require("UIPOPGot/UIWishPOPGotView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. function UIWishPOPGotView:OnAwake(data)
  4. self.controller = require("UIPOPGot/UIWishPOPGotCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIWishPOPGotView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  10. end
  11. function UIWishPOPGotView:FillContent(data, uiBase)
  12. self.uiBase = uiBase
  13. local gameObject = self.uiBase:GetRoot()
  14. if gameObject ~= nil then
  15. self.gameObject = gameObject
  16. self.transform = gameObject.transform
  17. end
  18. self:InitGenerate(self.transform, data)
  19. self:Init()
  20. end
  21. function UIWishPOPGotView:Init()
  22. self.scrollView.scrollRect.enabled = false
  23. self.rewardData = self.controller:GetData()
  24. local len = self.rewardData and #self.rewardData or 0
  25. self.isCanClose = len < 2
  26. if len >= 2 then
  27. if not self.timer then
  28. self.timer = Timer.New(function()
  29. self.isCanClose = true
  30. end,1.5,1)
  31. self.timer:Start()
  32. end
  33. end
  34. self.scrollView.loopGridView:InitGridView(0, function(gridView, itemIndex, row, column)
  35. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  36. end, nil)
  37. self.scrollView.loopGridView:RefreshListByIndex(len, 0)
  38. end
  39. function UIWishPOPGotView:OnPageInEnd()
  40. self.super.OnPageInEnd(self)
  41. self.scrollView.scrollRect.enabled = true
  42. end
  43. function UIWishPOPGotView:GetItemByRowColumn(gridView, itemIndex, row, column)
  44. local rewardData = self.rewardData[itemIndex + 1]
  45. local item
  46. local itemlua
  47. if rewardData.lucky then
  48. item = gridView:NewListViewItem('WishLuckyItem')
  49. itemlua = CommonUtil.BindGridViewItem2Lua(self, 'WishLuckyItem', item.gameObject)
  50. local data = {cfgId = rewardData.cfgId,num = rewardData.num}
  51. IconItemCtr:SetData(self, itemlua.iconItem, data,nil,self,self.OnItemClick)
  52. else
  53. item = gridView:NewListViewItem('IconItem')
  54. itemlua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', item.gameObject)
  55. local data = {cfgId = rewardData.cfgId,num = rewardData.num}
  56. IconItemCtr:SetData(self, itemlua, data,nil,self,self.OnItemClick)
  57. end
  58. return item
  59. end
  60. function UIWishPOPGotView:OnItemClick(button, params)
  61. local data = params[0]
  62. ManagerContainer.LuaUIMgr:OpenTips(data)
  63. end
  64. function UIWishPOPGotView:RemoveEventListener()
  65. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  66. end
  67. function UIWishPOPGotView:AddUIEventListener()
  68. self.uiBase:AddButtonEventListener(self.AnyBtn.button, function()
  69. if self.isCanClose then
  70. self:UIClose()
  71. end
  72. end)
  73. end
  74. function UIWishPOPGotView:OnHide()
  75. end
  76. function UIWishPOPGotView:OnShow(data)
  77. self.controller:SetData(data)
  78. end
  79. function UIWishPOPGotView:OnClose()
  80. end
  81. function UIWishPOPGotView:OnDispose()
  82. self.controller:OnDispose()
  83. if self.timer then
  84. self.timer:Stop()
  85. end
  86. self.timer = nil
  87. self.scrollView.loopGridView:Dispose()
  88. end
  89. return UIWishPOPGotView