PopGotMgr.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. --[[
  2. 道具变化协议 (包含道具增加)
  3. 装备变化协议 (包含装备增加))
  4. 由于是分两条协议下发,所以当功能会同时增加两种时,需要合并到一个数据中,给显示获得道具的界面
  5. ]]
  6. local PopGotMgr = class("PopGotMgr")
  7. local ShowPopType = {
  8. EquipAndItem = 1,
  9. Fashion = 2,
  10. EquipAndItemList = 3,
  11. SkillEquipList = 4,
  12. }
  13. local DeltaTime = 100
  14. -- 获得道具的显示页面中 道具的排序规则
  15. local EquipAndItemSortRule = function(a, b)
  16. local cfgIdA = a.cfgId
  17. local cfgIdB = b.cfgId
  18. local itemCfgA = ManagerContainer.CfgMgr:GetItemById(cfgIdA)
  19. local itemCfgB = ManagerContainer.CfgMgr:GetItemById(cfgIdB)
  20. local qualityA = itemCfgA.Quality
  21. local qualityB = itemCfgB.Quality
  22. local qualityLvA = 0
  23. local qualityLvB = 0
  24. if itemCfgA.ResType == Enum.ItemType.Equip then
  25. qualityA, qualityLvA = CommonUtil.GetEquipItemQuality(cfgIdA)
  26. end
  27. if itemCfgB.ResType == Enum.ItemType.Equip then
  28. qualityB, qualityLvB = CommonUtil.GetEquipItemQuality(cfgIdB)
  29. end
  30. if qualityA == qualityB then
  31. if qualityLvA == qualityLvB then
  32. return cfgIdA > cfgIdB
  33. else
  34. return qualityLvA > qualityLvB
  35. end
  36. else
  37. return qualityA > qualityB
  38. end
  39. end
  40. function PopGotMgr:ctor()
  41. self:ClearData()
  42. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.__cname, UIEventNames.EID_EQUIP_AND_ITEM_ADD, self, self.UpdatePopGot)
  43. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.__cname, UIEventNames.EID_EQUIP_AND_ITEM_ADD_LIST, self, self.UpdatePopGotList)
  44. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.__cname, UIEventNames.EID_FASHION_ADD, self, self.UpdateFashionGot)
  45. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.__cname, UIEventNames.EID_SKILL_EQUIP_ADD_LIST, self, self.UpdateSkillEquipList)
  46. end
  47. function PopGotMgr:Destroy()
  48. ManagerContainer.LuaEventMgr:Unregister(self.__cname)
  49. self:ClearData()
  50. end
  51. function PopGotMgr:UpdatePopGot(addItemMap)
  52. if self.isKeep then
  53. return
  54. end
  55. if self.addItemMap == nil then
  56. self.addItemMap = {}
  57. end
  58. local num = 0
  59. for key, value in pairs(addItemMap) do
  60. local count = 0
  61. local vip = 0
  62. if type(value) == "table" then
  63. count = value[1]
  64. vip = value[2]
  65. else
  66. count = value
  67. end
  68. if self.addItemMap[key] then
  69. self.addItemMap[key] = {self.addItemMap[key][1] + count, vip}
  70. else
  71. self.addItemMap[key] = {count, vip}
  72. num = num + 1
  73. end
  74. end
  75. if num <= 0 then
  76. return
  77. end
  78. if not self.showPopType then
  79. self.showPopType = ShowPopType.EquipAndItem
  80. end
  81. if self.timeId == nil then
  82. self.timeId = ManagerContainer.LuaTimerMgr:AddTimer(DeltaTime, 1, self, self.ShowView, nil)
  83. end
  84. end
  85. function PopGotMgr:UpdatePopGotList(addItemMap)
  86. if self.isKeep then
  87. return
  88. end
  89. if self.addItemMap == nil then
  90. self.addItemMap = {}
  91. end
  92. local num = 0
  93. for _, value in pairs(addItemMap) do
  94. local count = value[2]
  95. local vip = value[3]
  96. local key = value[1]
  97. self.addItemMap[#self.addItemMap + 1] = {key, count, vip}
  98. num = num + 1
  99. end
  100. if num <= 0 then
  101. return
  102. end
  103. if not self.showPopType then
  104. self.showPopType = ShowPopType.EquipAndItemList
  105. end
  106. if self.timeId == nil then
  107. self.timeId = ManagerContainer.LuaTimerMgr:AddTimer(DeltaTime, 1, self, self.ShowView, nil)
  108. end
  109. end
  110. function PopGotMgr:UpdateSkillEquipList(addItemMap)
  111. if self.isKeep then
  112. return
  113. end
  114. if self.addSkillEquipMap == nil then
  115. self.addSkillEquipMap = {}
  116. end
  117. local num = 0
  118. for _, value in pairs(addItemMap) do
  119. local count = value[2]
  120. local starLv = value[3]
  121. local key = value[1]
  122. self.addSkillEquipMap[#self.addSkillEquipMap + 1] = {key, count, starLv}
  123. num = num + 1
  124. end
  125. if num <= 0 then
  126. return
  127. end
  128. if not self.showPopType then
  129. self.showPopType = ShowPopType.SkillEquipList
  130. end
  131. if self.timeId == nil then
  132. self.timeId = ManagerContainer.LuaTimerMgr:AddTimer(DeltaTime, 1, self, self.ShowView, nil)
  133. end
  134. end
  135. function PopGotMgr:UpdateFashionGot(addFashionMap)
  136. if self.isKeep then
  137. return
  138. end
  139. if self.addFashionMap == nil then
  140. self.addFashionMap = {}
  141. end
  142. local num = 0
  143. for key, value in pairs(addFashionMap) do
  144. if self.addFashionMap[key] then
  145. self.addFashionMap[key] = self.addFashionMap[key] + value
  146. else
  147. self.addFashionMap[key] = value
  148. num = num + 1
  149. end
  150. end
  151. if num <= 0 then
  152. return
  153. end
  154. if not self.showPopType then
  155. self.showPopType = ShowPopType.Fashion
  156. end
  157. if self.timeId == nil then
  158. self.timeId = ManagerContainer.LuaTimerMgr:AddTimer(DeltaTime, 1, self, self.ShowView, nil)
  159. end
  160. end
  161. function PopGotMgr:ShowView()
  162. if self.showPopType == ShowPopType.EquipAndItem then
  163. local addItems = {}
  164. for key, value in pairs(self.addItemMap) do
  165. table.insert(addItems, {cfgId = key, num = value[1], vip = value[2]})
  166. end
  167. table.sort(addItems, EquipAndItemSortRule)
  168. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIPOPGot) then
  169. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = addItems} )
  170. self:PageViewKeep(true)
  171. end
  172. elseif self.showPopType == ShowPopType.EquipAndItemList then
  173. local addItems = {}
  174. for _, value in pairs(self.addItemMap) do
  175. table.insert(addItems, {cfgId = value[1], num = value[2], vip = value[3]})
  176. end
  177. table.sort(addItems, EquipAndItemSortRule)
  178. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIPOPGot) then
  179. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = addItems} )
  180. self:PageViewKeep(true)
  181. end
  182. elseif self.showPopType == ShowPopType.Fashion then
  183. local addFashions = {}
  184. for key, _ in pairs(self.addFashionMap) do
  185. table.insert(addFashions, {cfgId = key})
  186. end
  187. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIFashionGot) then
  188. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIFashionGot, addFashions)
  189. self:PageViewKeep(true)
  190. end
  191. elseif self.showPopType == ShowPopType.SkillEquipList then
  192. local addSkillEquip = {}
  193. for _, value in pairs(self.addSkillEquipMap) do
  194. table.insert(addSkillEquip, {cfgId = value[1], num = value[2], starLv = value[3]})
  195. end
  196. table.sort(addSkillEquip, EquipAndItemSortRule)
  197. if not ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIPOPGot) then
  198. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot, {rewards = addSkillEquip})
  199. self:PageViewKeep(true)
  200. end
  201. end
  202. end
  203. function PopGotMgr:PageViewKeep(isKeep)
  204. self.isKeep = isKeep or false
  205. if not self.isKeep then
  206. self:ClearData()
  207. end
  208. end
  209. function PopGotMgr:ClearData()
  210. self.addItemMap = nil
  211. self.addFashionMap = nil
  212. self.addSkillEquipMap = nil
  213. if self.timeId then
  214. ManagerContainer.LuaTimerMgr:RemoveTimer(self.timeId)
  215. self.timeId = nil
  216. end
  217. self.timeId = nil
  218. self.showPopType = nil
  219. self.isKeep = false
  220. end
  221. return PopGotMgr