UIErrorTipsView.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. local UIErrorTipsView = require("UIErrorTips/UIErrorTipsView_Generate")
  2. local interTime = 500
  3. local durationTime = 2.5
  4. local errorList = {}
  5. local errorItemName = "InfoItem"
  6. local timerId
  7. local erroring = false
  8. function UIErrorTipsView:OnAwake(data)
  9. self.controller = require("UIErrorTips/UIErrorTipsCtr"):new()
  10. self.controller:Init(self)
  11. self.controller:SetData(data)
  12. end
  13. function UIErrorTipsView:AddEventListener()
  14. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.ERROR_DESC_DISPLAY, function(data)
  15. local result = self:AddNewErrorInfo(data.errorId,data.params)
  16. if result and not erroring then
  17. self:ShowErrorTimer()
  18. return
  19. end
  20. if result and timerId ~= nil then
  21. ManagerContainer.LuaTimerMgr:ResumeTimer(timerId)
  22. end
  23. end)
  24. end
  25. function UIErrorTipsView:FillContent(data, uiBase)
  26. self.uiBase = uiBase
  27. local gameObject = self.uiBase:GetRoot()
  28. if gameObject ~= nil then
  29. self.gameObject = gameObject
  30. self.transform = gameObject.transform
  31. end
  32. self:InitGenerate(self.transform, data)
  33. self:Init()
  34. end
  35. function UIErrorTipsView:Init()
  36. local data = self.controller:GetData()
  37. local result = self:AddNewErrorInfo(data.errorId,data.params)
  38. if result then
  39. self:ShowErrorTimer()
  40. end
  41. timerId = ManagerContainer.LuaTimerMgr:AddTimer(interTime, -1, self, self.ShowErrorTimer, nil)
  42. end
  43. function UIErrorTipsView:ShowErrorTimer()
  44. if #errorList > 0 then
  45. erroring = true
  46. ManagerContainer.GoPoolMgr:SpawnPrefabGo(errorItemName, function (itemLua)
  47. local message = errorList[1]
  48. if message then
  49. itemLua.text.text.text = message
  50. itemLua.transform:SetParent(self.transform)
  51. itemLua.transform.localPosition = Vector3.zero
  52. itemLua.transform.localScale = Vector3.one
  53. itemLua.transform:DOScale(1, durationTime):OnComplete(function ()
  54. if #errorList == 0 then
  55. erroring = false
  56. if timerId then
  57. ManagerContainer.LuaTimerMgr:PauseTimer(timerId)
  58. end
  59. end
  60. ManagerContainer.GoPoolMgr:RecycleGo(itemLua)
  61. end)
  62. table.remove(errorList, 1)
  63. else
  64. ManagerContainer.GoPoolMgr:RecycleGo(itemLua)
  65. end
  66. end)
  67. end
  68. end
  69. function UIErrorTipsView:AddNewErrorInfo(id,params)
  70. local message = 0
  71. if params ~= nil then
  72. message = I18N.SetLanguageValue(id,unpack(params))
  73. else
  74. message = I18N.T(id)
  75. end
  76. if tonumber(message) == id or message == "" then return false end
  77. errorList[#errorList + 1] = message
  78. if #errorList > 3 then
  79. for i = #errorList - 3, 1, - 1 do
  80. table.remove(errorList, i)
  81. end
  82. end
  83. return true
  84. end
  85. function UIErrorTipsView:RemoveEventListener()
  86. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  87. end
  88. function UIErrorTipsView:AddUIEventListener()
  89. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  90. end
  91. function UIErrorTipsView:OnHide()
  92. end
  93. function UIErrorTipsView:OnShow(data)
  94. end
  95. function UIErrorTipsView:OnClose()
  96. end
  97. function UIErrorTipsView:OnDispose()
  98. if timerId ~= nil then
  99. ManagerContainer.LuaTimerMgr:RemoveTimer(timerId)
  100. timerId = nil
  101. end
  102. end
  103. return UIErrorTipsView