RedPointSimpleMgr.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. local RedPointSimpleMgr = class("RedPointSimpleMgr")
  2. local rpTree = {}
  3. local TypeGroup = {}
  4. local SameTargetGroup = {}
  5. local upLimit = 3
  6. local curUpCount = 0
  7. function RedPointSimpleMgr:ctor()
  8. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UI_FILLCONTENT_COMPELETED, self, self.FillContentCompeleted)
  9. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UI_CLOSE_COMPELETED, self, self.UICloseCompeleted)
  10. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.RED_POINT_MGR_NOTICE, self, self.RPNotify)
  11. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.RED_POINT_UNLOCK_NTF, self, self.UnlockRefreshRP)
  12. self:InitTree()
  13. end
  14. function RedPointSimpleMgr:InitTree()
  15. local redPointCfgDatas = ManagerContainer.CfgMgr:GetUIRedPointCfgDatas()
  16. for k,v in pairs(redPointCfgDatas) do
  17. if Constant.OpenPay or not v.NoPay then
  18. if rpTree[v.Id] == nil then
  19. rpTree[v.Id] = {}
  20. end
  21. local treeNode = rpTree[v.Id]
  22. treeNode.data = v
  23. treeNode.state = false
  24. local key = v.UIId..v.FuncEnterPath
  25. if SameTargetGroup[key] == nil then
  26. SameTargetGroup[key] = {}
  27. end
  28. SameTargetGroup[key][v.Priority] = treeNode
  29. if v.RPNotifyType and v.RPNotifyType ~= Enum.RPNotifyType.None then
  30. if TypeGroup[v.RPNotifyType] == nil then
  31. TypeGroup[v.RPNotifyType] = {}
  32. end
  33. TypeGroup[v.RPNotifyType][v.Id] = treeNode
  34. end
  35. treeNode.sameGroup = SameTargetGroup[key]
  36. end
  37. end
  38. for k,v in pairs(redPointCfgDatas) do
  39. if Constant.OpenPay or not v.NoPay then
  40. local treeNode = rpTree[v.Id]
  41. if treeNode and treeNode.data.UpNode then
  42. if treeNode.upNodes == nil then
  43. treeNode.upNodes = {}
  44. end
  45. for _,v1 in pairs(treeNode.data.UpNode) do
  46. treeNode.upNodes[#treeNode.upNodes + 1]= rpTree[v1]
  47. if rpTree[v1].downNodes == nil then
  48. rpTree[v1].downNodes = {}
  49. end
  50. rpTree[v1].downNodes[#rpTree[v1].downNodes + 1] = treeNode
  51. end
  52. end
  53. end
  54. end
  55. end
  56. function RedPointSimpleMgr:RPNotify(rpType, result, param)
  57. curUpCount = 0
  58. if type(result) ~= "boolean" then
  59. result = result > 0
  60. end
  61. local treeNode = TypeGroup[rpType]
  62. if treeNode then
  63. for _,v in pairs(treeNode) do
  64. --local unlockState = true
  65. --if v.data.FuncLock > 0 then
  66. -- unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(v.data.FuncLock)
  67. --end
  68. --if unlockState then
  69. if param ~= nil then
  70. if v.stateGroup == nil then
  71. v.stateGroup = {}
  72. end
  73. v.stateGroup[param] = result
  74. local state1 = false
  75. for _,v1 in pairs(v.stateGroup) do
  76. if v1 then
  77. state1 = true
  78. end
  79. end
  80. v.state = state1
  81. else
  82. v.state = result
  83. end
  84. self:RefreshRedPointDisplayPriority(v, true)
  85. if v.upNodes then
  86. for _,v1 in pairs(v.upNodes) do
  87. self:RefreshUpNodeState(v1)
  88. end
  89. end
  90. --end
  91. end
  92. end
  93. end
  94. function RedPointSimpleMgr:CheckRPStateByType(rpType)
  95. local treeNode = TypeGroup[rpType]
  96. local state = false
  97. if not treeNode then return state end
  98. for _,v in pairs(treeNode) do
  99. if v.stateGroup then
  100. local state1 = false
  101. for _,v1 in pairs(v.stateGroup) do
  102. if v1 then
  103. state1 = true
  104. end
  105. end
  106. state = state1
  107. else
  108. state = v.state
  109. end
  110. break
  111. end
  112. return state
  113. end
  114. function RedPointSimpleMgr:RefreshUpNodeState(treeNode)
  115. curUpCount = curUpCount + 1
  116. if curUpCount > 3 then
  117. LogError(treeNode.data.Id.." redpoint recursive error")
  118. return
  119. end
  120. if treeNode.downNodes then
  121. local state = false
  122. for _,v in pairs(treeNode.downNodes) do
  123. if v.state then
  124. state = true
  125. break
  126. end
  127. end
  128. treeNode.state = state
  129. self:RefreshRedPointDisplayPriority(treeNode, true)
  130. end
  131. if treeNode.upNodes then
  132. for _,v1 in pairs(treeNode.upNodes) do
  133. self:RefreshUpNodeState(v1)
  134. end
  135. end
  136. end
  137. function RedPointSimpleMgr:CheckRPState(treeNode)
  138. if treeNode.stateGroup then
  139. for _,v1 in pairs(treeNode.stateGroup) do
  140. if v1 then
  141. return true
  142. end
  143. end
  144. else
  145. return treeNode.state
  146. end
  147. end
  148. function RedPointSimpleMgr:CheckRPLockState(treeNode)
  149. local unlockState = true
  150. if treeNode.data.FuncLock > 0 then
  151. unlockState = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(treeNode.data.FuncLock)
  152. end
  153. return unlockState
  154. end
  155. function RedPointSimpleMgr:RefreshRedPointDisplayPriority(treeNode, needCheckLock)
  156. if needCheckLock then
  157. local unlockState = self:CheckRPLockState(treeNode)
  158. if not unlockState then
  159. return
  160. end
  161. end
  162. local state = false
  163. if #treeNode.sameGroup == 0 then
  164. if treeNode.target == nil then
  165. return
  166. end
  167. local state1 = false
  168. if treeNode.stateGroup then
  169. for _,v1 in pairs(treeNode.stateGroup) do
  170. if v1 then
  171. state1 = true
  172. end
  173. end
  174. else
  175. state1 = treeNode.state
  176. end
  177. treeNode.target:SetActive(state1)
  178. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_PAGE_REDPOINT_NTF,treeNode.data.Id,state1)
  179. return
  180. end
  181. local hasDisplay = false
  182. for i = 1, #treeNode.sameGroup do
  183. local v = treeNode.sameGroup[i]
  184. if v then
  185. local state1 = false
  186. if not state then
  187. if v.stateGroup then
  188. for _,v1 in pairs(v.stateGroup) do
  189. if v1 then
  190. state1 = true
  191. end
  192. end
  193. else
  194. state1 = v.state
  195. end
  196. if state1 then
  197. state = true
  198. end
  199. else
  200. state1 = v.state
  201. end
  202. if v.target then
  203. if state1 and needCheckLock then
  204. local unlockState = self:CheckRPLockState(v)
  205. if unlockState and not hasDisplay then
  206. hasDisplay = true
  207. else
  208. state1 = false
  209. end
  210. v.target:SetActive(state1)
  211. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_PAGE_REDPOINT_NTF,treeNode.data.Id,state1)
  212. else
  213. if state1 and not hasDisplay then
  214. hasDisplay = true
  215. else
  216. state1 = false
  217. end
  218. v.target:SetActive(state1)
  219. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_PAGE_REDPOINT_NTF,treeNode.data.Id,state1)
  220. end
  221. end
  222. end
  223. end
  224. end
  225. function RedPointSimpleMgr:FillContentCompeleted(wnd)
  226. local list = ManagerContainer.CfgMgr:GetUIRedPointCfgDataByUIId(wnd.uiData.id)
  227. for k,v in pairs(list) do
  228. if Constant.OpenPay or not v.NoPay then
  229. local treeNode = rpTree[v.Id]
  230. if treeNode then
  231. local data = treeNode.data
  232. local target = CommonUtil.ParseUITargetPath(wnd, data.FuncEnterPath)
  233. if target then
  234. local redPointGo = target.transform:Find("redPoint"..data.Id)
  235. if not redPointGo then
  236. redPointGo = ManagerContainer.ResMgr:GetGoFromPool(Constants.UICommonPath, Enum.RPPrefab[data.RPType])
  237. else
  238. redPointGo = redPointGo.gameObject
  239. end
  240. if redPointGo then
  241. redPointGo.name = "redPoint"..data.Id
  242. redPointGo.transform:SetParent(target.transform)
  243. local rectTrans = redPointGo:GetComponent(Enum.TypeInfo.RectTransform)
  244. rectTrans.anchoredPosition3D = Vector3(data.Position[1], data.Position[2], 0)
  245. redPointGo.transform.localScale = Vector3.one
  246. treeNode.target = redPointGo
  247. if data.UIId == Enum.UIPageName.UIPrivateChatBtn then
  248. redPointGo.transform:SetAsFirstSibling()
  249. end
  250. redPointGo:SetActive(false)
  251. self:RefreshRedPointDisplayPriority(treeNode, true)
  252. end
  253. end
  254. end
  255. end
  256. end
  257. end
  258. function RedPointSimpleMgr:UICloseCompeleted(wnd)
  259. local list = ManagerContainer.CfgMgr:GetUIRedPointCfgDataByUIId(wnd.uiData.id)
  260. for k,v in pairs(list) do
  261. if Constant.OpenPay or not v.NoPay then
  262. local treeNode = rpTree[v.Id]
  263. if treeNode then
  264. ManagerContainer.ResMgr:RecycleGO(Constants.UICommonPath, Enum.RPPrefab[treeNode.data.RPType], treeNode.target)
  265. treeNode.target = nil
  266. end
  267. end
  268. end
  269. end
  270. function RedPointSimpleMgr:UnlockRefreshRP(ids)
  271. local treeNode
  272. for k,v in pairs(ids) do
  273. local funcCfgData = ManagerContainer.CfgMgr:GetUIFuncUnLockCfgDataById(v)
  274. if funcCfgData.RefreshRP ~= nil then
  275. for _,v1 in pairs(funcCfgData.RefreshRP) do
  276. treeNode = rpTree[v1]
  277. if treeNode then
  278. self:RefreshRedPointDisplayPriority(treeNode, true)
  279. end
  280. end
  281. end
  282. end
  283. end
  284. function RedPointSimpleMgr:CheckRPStateById(id)
  285. if not rpTree[id] then return false end
  286. return rpTree[id].state
  287. end
  288. function RedPointSimpleMgr:Destroy()
  289. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UI_FILLCONTENT_COMPELETED, self, self.FillContentCompeleted)
  290. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UI_CLOSE_COMPELETED, self, self.UICloseCompeleted)
  291. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.RED_POINT_MGR_NOTICE, self, self.RPNotify)
  292. rpTree = nil
  293. TypeGroup = nil
  294. SameTargetGroup = nil
  295. end
  296. return RedPointSimpleMgr