UILuckyEggAnimView.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. local UILuckyEggAnimView = require("UILuckyEgg/UILuckyEggAnimView_Generate")
  2. function UILuckyEggAnimView:OnAwake(data)
  3. self.controller = require("UILuckyEgg/UILuckyEggAnimCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UILuckyEggAnimView:AddEventListener()
  8. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_CLOSE_COMPELETED, self, self.OnUICloseCompleted)
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_PAGE_OUT_END_NTF, self, self.OnUIViewCloseAnimEnd)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.LUCKYEGG_AGAIN_DATA_CHANGED, self, self.OnLuckyAnimAgainDataChanged)
  11. end
  12. function UILuckyEggAnimView:FillContent(data, uiBase)
  13. self.uiBase = uiBase
  14. local gameObject = self.uiBase:GetRoot()
  15. if gameObject ~= nil then
  16. self.gameObject = gameObject
  17. self.transform = gameObject.transform
  18. end
  19. self:InitGenerate(self.transform, data)
  20. self:Init()
  21. end
  22. function UILuckyEggAnimView:Init()
  23. self.againData = nil
  24. self.white:SetActive(false)
  25. self.guide:SetActive(false)
  26. if self.controller:HasNeedShowItem() then
  27. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggShow, nil, self.uiData.id)
  28. else
  29. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggResult)
  30. end
  31. end
  32. function UILuckyEggAnimView:RemoveEventListener()
  33. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  34. end
  35. function UILuckyEggAnimView:AddUIEventListener()
  36. end
  37. function UILuckyEggAnimView:OnHide()
  38. end
  39. function UILuckyEggAnimView:OnShow(data)
  40. self.controller:SetData(data)
  41. end
  42. function UILuckyEggAnimView:OnClose()
  43. end
  44. function UILuckyEggAnimView:OnDispose()
  45. self.againData = nil
  46. if self.timer then
  47. self.timer:Stop()
  48. self.timer = nil
  49. end
  50. if self.openDelayTimer then
  51. self.openDelayTimer:Stop()
  52. self.openDelayTimer = nil
  53. end
  54. self.controller:OnDispose()
  55. end
  56. function UILuckyEggAnimView:OnUICloseCompleted(owner)
  57. end
  58. function UILuckyEggAnimView:OnUIViewCloseAnimEnd(id)
  59. if id == Enum.UIPageName.UILuckyEggResult then
  60. if self.againData then
  61. if not self.openDelayTimer then
  62. self.openDelayTimer = FrameTimer.New(slot(self.Init, self), 1)
  63. else
  64. self.openDelayTimer.count = Time.frameCount + 1
  65. end
  66. if not self.openDelayTimer.running then
  67. self.openDelayTimer:Start()
  68. end
  69. self.againData = false
  70. end
  71. end
  72. end
  73. function UILuckyEggAnimView:OnLuckyAnimAgainDataChanged()
  74. self.againData = true
  75. end
  76. function UILuckyEggAnimView:OnBeginDragDrawRect()
  77. if self.eventDataHashCode then return end
  78. local currentEventData = self.drawRect.uIEventTriggerListener.currentEventData
  79. if not currentEventData then return end
  80. self.eventDataHashCode = currentEventData:GetHashCode()
  81. if self.timer.state == 2 then
  82. self.timer:Stop()
  83. end
  84. self.guide:SetActive(false)
  85. end
  86. function UILuckyEggAnimView:OnEndDragDrawRect()
  87. if not self.eventDataHashCode then return end
  88. local currentEventData = self.drawRect.uIEventTriggerListener.currentEventData
  89. if not currentEventData then return end
  90. if self.eventDataHashCode ~= currentEventData:GetHashCode() then
  91. return
  92. end
  93. self.eventDataHashCode = nil
  94. local deltaPos = currentEventData.position - currentEventData.pressPosition
  95. if Mathf.Approximately(deltaPos.y, 0) then
  96. if self.timer.state == 2 then
  97. self.timer.time = 5
  98. self.timer.duration = 5
  99. if not self.timer.running then
  100. self.timer:Start()
  101. end
  102. end
  103. return
  104. end
  105. self.white:SetActive(true)
  106. self.white.image:DOFade(1, 1)
  107. self.timer.state = 3
  108. self.timer.time = 1
  109. self.timer.duration = 1
  110. if not self.timer.running then
  111. self.timer:Start()
  112. end
  113. end
  114. function UILuckyEggAnimView:LoadComplete()
  115. self.white:SetActive(true)
  116. self.white.image:DOFade(0, 1)
  117. self.timer.state = 1
  118. self.timer.time = 1
  119. self.timer.duration = 1
  120. if not self.timer.running then
  121. self.timer:Start()
  122. end
  123. end
  124. function UILuckyEggAnimView:TimerEnd()
  125. if self.timer.state == 1 then
  126. self.white:SetActive(false)
  127. self.timer.state = 2
  128. self.timer.time = 0
  129. self.timer.duration = 5
  130. if not self.timer.running then
  131. self.timer:Start()
  132. end
  133. elseif self.timer.state == 2 then
  134. self.guide:SetActive(true)
  135. self.timer:Stop()
  136. elseif self.timer.state == 3 then
  137. self.timer:Stop()
  138. if self.controller:HasNeedShowItem() then
  139. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggShow, nil, self.uiData.id)
  140. else
  141. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UILuckyEggResult)
  142. end
  143. end
  144. end
  145. return UILuckyEggAnimView