UIPetBattleCtr.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. local UIPetBattleCtr = class("UIPetBattleCtr", require("UICtrBase"))
  2. local lockIds = {42,43,44,45,46,47}
  3. function UIPetBattleCtr:Init(view)
  4. self.view = view
  5. end
  6. function UIPetBattleCtr:SetData(data)
  7. if self.filterData == nil then
  8. self.filterData = {}
  9. self.filterData.raritySelections = {}
  10. self.filterData.attrSelections = {}
  11. self.filterData.typeSelections = {}
  12. self.isFilter = false
  13. end
  14. self:InitHeroBattleDatas()
  15. self.asyncIdx = 0
  16. if data == nil then return end
  17. self.data = data
  18. end
  19. function UIPetBattleCtr:GetAsyncIdx()
  20. self.asyncIdx = self.asyncIdx + 1
  21. return self.asyncIdx
  22. end
  23. function UIPetBattleCtr:GetData()
  24. return self.data
  25. end
  26. function UIPetBattleCtr:GetList()
  27. if not self.data then
  28. return nil
  29. end
  30. return self.data.list
  31. end
  32. function UIPetBattleCtr:GetCurSelectedId()
  33. if not self.data then
  34. return nil
  35. end
  36. return self.data.curId
  37. end
  38. function UIPetBattleCtr:InitCurSelectedData()
  39. local curId = self:GetCurSelectedId()
  40. if not curId then return false end
  41. return self:GetPetDataById(curId)
  42. end
  43. function UIPetBattleCtr:SetChildController(ctr)
  44. self.childCtr = ctr
  45. end
  46. function UIPetBattleCtr:InitHeroBattleDatas()
  47. self.heroBattleDatas = {}
  48. self.heroBattlePetIds = {}
  49. for i = 1, 6 do
  50. local heroData = CommonUtil.GetHeroLogicDataByUid(i)
  51. self.heroBattleDatas[i] = heroData
  52. self.heroBattlePetIds[i] = heroData.battlePetId
  53. end
  54. end
  55. function UIPetBattleCtr:GetBattlePetCount()
  56. local length = 0
  57. for _,v in pairs(self.heroBattlePetIds) do
  58. if v > 0 then
  59. length = length + 1
  60. end
  61. end
  62. return length
  63. end
  64. function UIPetBattleCtr:GetHeroDataByUid(id)
  65. if not self.heroBattleDatas then return end
  66. return self.heroBattleDatas[id]
  67. end
  68. function UIPetBattleCtr:GetSlotUnLockState(idx)
  69. return ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(lockIds[idx])
  70. end
  71. function UIPetBattleCtr:RefreshCurPetBattleLock()
  72. self.unlockCount = 0
  73. for i = 1,#lockIds do
  74. local unLockState, val, content = ManagerContainer.UIFuncUnlockMgr:GetFuncLockStatusById(lockIds[i])
  75. if unLockState then
  76. self.unlockCount = self.unlockCount + 1
  77. else
  78. self.curLockContent = content
  79. break
  80. end
  81. end
  82. self.lockCount = #lockIds - self.unlockCount
  83. end
  84. function UIPetBattleCtr:GetUnlockCount()
  85. return self.unlockCount
  86. end
  87. function UIPetBattleCtr:GetLockCount()
  88. return self.lockCount
  89. end
  90. function UIPetBattleCtr:GetLockContent()
  91. return self.curLockContent
  92. end
  93. function UIPetBattleCtr:RefreshPetDatas()
  94. local petDatasSource = ManagerContainer.DataMgr.PetDataMgr:GetPetDatas()
  95. local petDatas = petDatasSource
  96. if self.isFilter then
  97. petDatas = CommonUtil.ArrayFilterSelections(petDatasSource, Enum.FilterType.AND, {"quality", "Attribute", "natureType"}, {self.filterData.raritySelections, self.filterData.attrSelections, self.filterData.typeSelections})
  98. end
  99. if petDatas ~= nil then
  100. petDatas = CommonUtil.ArrayFilterSelections(petDatas, Enum.FilterType.AND, {"qiyueHeroId"}, {0})
  101. CommonUtil.ArraySortSelections(petDatas, Enum.TableSortRule.Down, "isBattle", "quality", "advanceLevel", "level", "isRelevant", "isSupport", "totalFightPower", "cfgId")
  102. --for _, v in pairs(petDatas) do
  103. -- if v.heroId > 0 then
  104. -- v.selected = 1
  105. -- end
  106. --end
  107. end
  108. if petDatas == nil then
  109. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NoCardTips3")
  110. end
  111. return petDatas
  112. end
  113. function UIPetBattleCtr:SetCurSelectedPetData(data)
  114. if self.lastSelectedData then
  115. self.lastSelectedData.selected = 0
  116. end
  117. if data then
  118. data.selected = 1
  119. end
  120. self.curSelectedData = data
  121. self.lastSelectedData = self.curSelectedData
  122. return data and self:GetPetDataIdxById(data.id) or nil
  123. end
  124. function UIPetBattleCtr:GetPetDataIdxById(id)
  125. if self.childCtr then
  126. local data,idx = self.childCtr:GetPetDataById(id)
  127. return idx
  128. end
  129. return nil
  130. end
  131. function UIPetBattleCtr:GetCurSelectedPetData()
  132. return self.curSelectedData
  133. end
  134. function UIPetBattleCtr:GetLastSelectedPetData()
  135. return self.lastSelectedData
  136. end
  137. function UIPetBattleCtr:GetPetDataById(id)
  138. if self.childCtr then
  139. return self.childCtr:GetPetDataById(id)
  140. end
  141. return nil
  142. end
  143. function UIPetBattleCtr:SetPetBattlePetId(idx, id)
  144. self.heroBattlePetIds[idx] = id or 0
  145. end
  146. function UIPetBattleCtr:GetPetBattlePetId(idx)
  147. return self.heroBattlePetIds[idx]
  148. end
  149. function UIPetBattleCtr:HasSamePetInBattle(id, idx)
  150. local petData = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(id)
  151. for k,v in pairs(self.heroBattlePetIds) do
  152. if v ~= 0 then
  153. local petData1 = ManagerContainer.DataMgr.PetDataMgr:GetPetDataById(v)
  154. if petData.cfgId == petData1.cfgId then
  155. if idx ~= k then
  156. return id ~= v
  157. end
  158. end
  159. end
  160. end
  161. return false
  162. end
  163. function UIPetBattleCtr:SendPetBattle(oneKeyDown)
  164. self:ClearSelectedInfo()
  165. local map = {}
  166. if not oneKeyDown then
  167. for k,v in pairs(self.heroBattlePetIds) do
  168. local heroData = self:GetHeroDataByUid(k)
  169. if k == 1 or heroData.owned then
  170. map[#map + 1] = {key = heroData.id, value = v}
  171. end
  172. end
  173. else
  174. for i = 1, 6 do
  175. local heroData = self:GetHeroDataByUid(i)
  176. if heroData and (heroData.id == 1 or heroData.owned) and heroData.battlePetId > 0 then
  177. map[#map + 1] = {key = heroData.id, value = 0}
  178. end
  179. end
  180. end
  181. if #map > 0 then
  182. ManagerContainer.DataMgr.PetDataMgr:SendPetBattle(map)
  183. end
  184. end
  185. function UIPetBattleCtr:ClearSelectedInfo()
  186. if self.curSelectedData then
  187. self.curSelectedData.selected = 0
  188. end
  189. if self.lastSelectedData then
  190. self.lastSelectedData.selected = 0
  191. end
  192. self.curSelectedData = nil
  193. self.lastSelectedData = nil
  194. end
  195. function UIPetBattleCtr:SetFilterData(data, isFilter)
  196. self.filterData = data
  197. self.isFilter = isFilter
  198. end
  199. function UIPetBattleCtr:GetFilterData()
  200. return self.filterData
  201. end
  202. function UIPetBattleCtr:GetIsFilter()
  203. return self.isFilter
  204. end
  205. function UIPetBattleCtr:GetShowDataLength()
  206. if self.childCtr then
  207. return self.childCtr:GetShowDataLength()
  208. end
  209. return 0
  210. end
  211. function UIPetBattleCtr:OnDispose()
  212. self.childCtr = nil
  213. self.heroBattlePetIds = nil
  214. self.heroBattleDatas = nil
  215. self.curSelectedData = nil
  216. self.lastSelectedData = nil
  217. self.filterData = nil
  218. self.isFilter = nil
  219. self.data = nil
  220. self.view = nil
  221. end
  222. return UIPetBattleCtr