UILoadingView.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. local UILoadingView = require("UILoading/UILoadingView_Generate")
  2. local _timeLimit = 3000; --超过3秒就替换新的小提示
  3. local _timerId; --timer计时器id
  4. function UILoadingView:OnAwake(data)
  5. self.controller = require("UILoading/UILoadingCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UILoadingView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Loading_Begin, self, self.OnLoadingBegin)
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Loading_Progress, self, self.OnLoadingProgress)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Loading_Complete, self, self.OnLoadingComplete)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Loading_Close, self, self.OnLoadingClose)
  14. --打开初始化完毕后的 回调开始加载
  15. if nil ~= self.controller.data and nil ~= self.controller.data.FucOpenFinishedcb then
  16. self.controller.data.FucOpenFinishedcb()
  17. end
  18. end
  19. function UILoadingView: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. self:OnLoadingBegin()
  29. -- LogError("-----------------------")
  30. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loaded_Page_OK)
  31. end
  32. function UILoadingView:Init()
  33. self:SetTip();
  34. _timerId = ManagerContainer.LuaTimerMgr:AddTimer(_timeLimit, -1, self, self.SetTip, nil)
  35. local loadingBg = self.controller:GetBgName();
  36. CommonUtil.LoadIcon(self, loadingBg, function (sprite)
  37. self.loadingBg.image.sprite = sprite
  38. end)
  39. end
  40. --设置小提示的显示
  41. function UILoadingView:SetTip()
  42. local _tip = self.controller:GetTipString();
  43. self.tip.text.text = _tip;
  44. end
  45. function UILoadingView:RemoveEventListener()
  46. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  47. end
  48. function UILoadingView:AddUIEventListener()
  49. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  50. end
  51. function UILoadingView:OnLoadingBegin()
  52. self.scrollbar.scrollbar.size = 0
  53. self.numberText.text.text = "0%"
  54. end
  55. function UILoadingView:OnLoadingProgress(progress)
  56. self.scrollbar.scrollbar.size = progress
  57. if progress > 1 then
  58. progress = 1
  59. end
  60. self.numberText.text.text = math.floor(progress*100).."%"
  61. end
  62. function UILoadingView:OnLoadingComplete()
  63. self.scrollbar.scrollbar.size = 1
  64. self.numberText.text.text = "100%"
  65. self.transform:DOScale(1, 1):OnComplete(function ()
  66. self:ClosePage()
  67. end)
  68. end
  69. function UILoadingView:OnLoadingClose()
  70. self:ClosePage()
  71. end
  72. function UILoadingView:OnHide()
  73. end
  74. function UILoadingView:OnShow(data)
  75. end
  76. function UILoadingView:OnClose()
  77. if _timerId ~= nil then
  78. ManagerContainer.LuaTimerMgr:RemoveTimer(_timerId);
  79. _timerId = nil;
  80. end
  81. end
  82. function UILoadingView:OnDispose()
  83. ManagerContainer.LuaGameMgr:CloseLoading()
  84. end
  85. function UILoadingView:ClosePage()
  86. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UILoading)
  87. end
  88. return UILoadingView