UICardListCtr.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. local UICardListCtr = class("UICardListCtr", require("UICtrBase"))
  2. local curEleIndex = 0
  3. local cardDatas
  4. local costCardLogicDatas = {nil,nil,nil}
  5. function UICardListCtr:Init(view)
  6. self.view = view
  7. end
  8. function UICardListCtr:SetData(data)
  9. self.asyncIdx = 0
  10. if data == nil then return end
  11. self.data = data
  12. end
  13. function UICardListCtr:GetAsyncIdx()
  14. self.asyncIdx = self.asyncIdx + 1
  15. return self.asyncIdx
  16. end
  17. function UICardListCtr:GetData()
  18. return self.data
  19. end
  20. function UICardListCtr:GetEleIndex()
  21. return curEleIndex
  22. end
  23. function UICardListCtr:SetEleIndex(index)
  24. curEleIndex = index
  25. end
  26. function UICardListCtr:NilCostCards()
  27. costCardLogicDatas = {nil,nil,nil}
  28. end
  29. function UICardListCtr:GetCostCard(idx)
  30. return costCardLogicDatas[idx]
  31. end
  32. function UICardListCtr:AddCostCard(idx, logicData)
  33. costCardLogicDatas[idx] = logicData
  34. end
  35. function UICardListCtr:RemoveCostCard(idx)
  36. costCardLogicDatas[idx] = nil
  37. end
  38. function UICardListCtr:RefreshMvpCradList()
  39. local cardDatasSource = ManagerContainer.DataMgr.CardData:GetAllCardDataMap()
  40. local ls = {}
  41. for _,v in pairs(cardDatasSource) do
  42. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(v.cfgId)
  43. if itemCfgData.Quality == 4 then
  44. local composition = itemCfgData.Composition
  45. local num = v.num
  46. while (num > composition) do
  47. local data = {cfgId = v.cfgId, num = composition, isSelect = false,level = v.CardLevel}
  48. table.insert(ls, data)
  49. num = num - composition
  50. end
  51. -- 最后还需要把剩余的单独占格
  52. if num > 0 then
  53. local data = {cfgId = v.cfgId, num = num, isSelect = false,level = v.CardLevel}
  54. table.insert(ls, data)
  55. end
  56. end
  57. end
  58. if ls ~= nil then
  59. CommonUtil.ArraySortSelections(ls, Enum.TableSortRule.Down, "CardLevel","cfgId")
  60. end
  61. -- if ls == nil then
  62. -- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NoCardTips3")
  63. -- end
  64. self.MvpCardList = ls
  65. return self.MvpCardList
  66. end
  67. function UICardListCtr:GetMvpCardList()
  68. return self.MvpCardList
  69. end
  70. function UICardListCtr:GetTransferSlotIdx()
  71. return self.leftSlotIdx,self.rightSlotIdx
  72. end
  73. function UICardListCtr:ClearLeftSlotIdx()
  74. if self.leftSlotIdx then
  75. local oldData = self:GetShowData(self.leftSlotIdx - 1)
  76. if oldData then
  77. oldData.isSelect = false
  78. end
  79. end
  80. self.leftSlotIdx = nil
  81. end
  82. function UICardListCtr:ClearRightSlotIdx()
  83. if self.rightSlotIdx then
  84. local oldData = self:GetShowData(self.rightSlotIdx - 1)
  85. if oldData then
  86. oldData.isSelect = false
  87. end
  88. end
  89. self.rightSlotIdx = nil
  90. end
  91. function UICardListCtr:GetShowData(idx)
  92. return self.MvpCardList and self.MvpCardList[idx + 1] or nil
  93. end
  94. function UICardListCtr:SendTransReq()
  95. local leftData = self:GetShowData(self.leftSlotIdx - 1)
  96. local rightData = self:GetShowData(self.rightSlotIdx - 1)
  97. ManagerContainer.DataMgr.CardData:SendMvpCardTransReq(leftData.cfgId, rightData.cfgId)
  98. end
  99. function UICardListCtr:CheckTransError(leftIdx,rightIdx)
  100. if not leftIdx or not rightIdx then return 0 end
  101. local leftData = self:GetShowData(leftIdx - 1)
  102. local rightData = self:GetShowData(rightIdx - 1)
  103. if leftData.level == rightData.level then
  104. return 1
  105. elseif self:CheckCardEqual(leftData.cfgId,rightData.cfgId) then
  106. return 2
  107. else
  108. return 0
  109. end
  110. end
  111. function UICardListCtr:CheckCardEqual(leftId,rightId)
  112. if leftId and rightId then
  113. local w = math.floor(leftId / 10000)
  114. local q = math.floor(leftId / 1000 % 10)
  115. local s = math.floor(leftId / 10 % 10)
  116. local g = math.floor(leftId % 10)
  117. for i = 1, 5 do
  118. local v = w * 10000 + q * 1000 + i * 100 + s * 10 + g
  119. if v == rightId then
  120. return true
  121. end
  122. end
  123. end
  124. return false
  125. end
  126. function UICardListCtr:SetTransSlotIdx(idx)
  127. local oldIdx, newIdx
  128. if self.leftSlotIdx == idx then
  129. oldIdx = self.leftSlotIdx
  130. if oldIdx then
  131. local oldData = self:GetShowData(oldIdx - 1)
  132. if oldData then
  133. oldData.isSelect = false
  134. end
  135. end
  136. self.leftSlotIdx = nil
  137. return 0, oldIdx, newIdx
  138. elseif self.rightSlotIdx == idx then
  139. oldIdx = self.rightSlotIdx
  140. if oldIdx then
  141. local oldData = self:GetShowData(oldIdx - 1)
  142. if oldData then
  143. oldData.isSelect = false
  144. end
  145. end
  146. self.rightSlotIdx = nil
  147. return 0, oldIdx, newIdx
  148. end
  149. if (self.leftSlotIdx and self.leftSlotIdx == idx) or not self.leftSlotIdx then
  150. local checkCode = self:CheckTransError(idx, self.rightSlotIdx)
  151. if checkCode > 0 then
  152. return checkCode
  153. end
  154. oldIdx = self.leftSlotIdx
  155. if oldIdx then
  156. local oldData = self:GetShowData(oldIdx - 1)
  157. if oldData then
  158. oldData.isSelect = false
  159. end
  160. end
  161. if idx == oldIdx then idx = nil end
  162. if idx then
  163. local oldData = self:GetShowData(idx - 1)
  164. if oldData then
  165. oldData.isSelect = true
  166. end
  167. end
  168. self.leftSlotIdx = idx
  169. return 0, oldIdx, newIdx
  170. end
  171. if (self.rightSlotIdx and self.rightSlotIdx == idx) or not self.rightSlotIdx then
  172. local checkCode = self:CheckTransError(self.leftSlotIdx, idx)
  173. if checkCode > 0 then
  174. return checkCode
  175. end
  176. oldIdx = self.rightSlotIdx
  177. if oldIdx then
  178. local oldData = self:GetShowData(oldIdx - 1)
  179. if oldData then
  180. oldData.isSelect = false
  181. end
  182. end
  183. if idx == oldIdx then idx = nil end
  184. if idx then
  185. local oldData = self:GetShowData(idx - 1)
  186. if oldData then
  187. oldData.isSelect = true
  188. end
  189. end
  190. self.rightSlotIdx = idx
  191. return 0, oldIdx, newIdx
  192. end
  193. if self.leftSlotIdx ~= idx and self.rightSlotIdx ~= idx then return 4 end
  194. end
  195. function UICardListCtr:CanCostMore()
  196. for i = 1, 3 do
  197. if costCardLogicDatas[i] == nil then
  198. return true
  199. end
  200. end
  201. return false
  202. end
  203. function UICardListCtr:CanComposeMore()
  204. for i = 1, 3 do
  205. if costCardLogicDatas[i] ~= nil then
  206. return false
  207. end
  208. end
  209. return true
  210. end
  211. function UICardListCtr:AutoAddCostCard(logicData)
  212. for i = 1, 3 do
  213. if costCardLogicDatas[i] == nil then
  214. costCardLogicDatas[i] = logicData
  215. return i
  216. end
  217. end
  218. return 0
  219. end
  220. function UICardListCtr:AutoRemoveCostCard(logicData)
  221. for i = 1, 3 do
  222. if costCardLogicDatas[i] ~= nil and costCardLogicDatas[i].cfgId == logicData.cfgId then
  223. costCardLogicDatas[i] = nil
  224. return i
  225. end
  226. end
  227. return 0
  228. end
  229. function UICardListCtr:GetCardDatas(ele)
  230. cardDatas = {}
  231. local datas = ManagerContainer.DataMgr.CardData:GetAllCardDataMap()
  232. for _,v in pairs(datas) do
  233. if v.num > 0 then
  234. if ele == 0 then
  235. table.insert(cardDatas, CommonUtil.TableClone(v))
  236. else
  237. local cardCfgData = ManagerContainer.CfgMgr:GetCardDataById(v.cfgId)
  238. if cardCfgData.CardType == ele then
  239. table.insert(cardDatas, CommonUtil.TableClone(v))
  240. end
  241. end
  242. end
  243. end
  244. CommonUtil.ArraySortSelections(cardDatas, Enum.TableSortRule.Down, "CardType", "CardLevel", "cfgId")
  245. return cardDatas
  246. end
  247. function UICardListCtr:GetComposeCardDatas(ele, canCompose)
  248. cardDatas = {}
  249. local datas = ManagerContainer.DataMgr.CardData:GetAllCardDataMap()
  250. for _,v in pairs(datas) do
  251. if v.num > 0 then
  252. local cardCfgData = ManagerContainer.CfgMgr:GetCardDataById(v.cfgId)
  253. local nextCardCfgData = ManagerContainer.CfgMgr:GetCardDataById(v.cfgId + 100)
  254. if ele == 0 then
  255. if nextCardCfgData and ((canCompose and v.num >= 3) or (not canCompose and v.num > 0)) then
  256. table.insert(cardDatas, CommonUtil.TableClone(v))
  257. end
  258. else
  259. if cardCfgData.CardType == ele and nextCardCfgData and ((canCompose and v.num >= 3) or (not canCompose and v.num > 0)) then
  260. table.insert(cardDatas, CommonUtil.TableClone(v))
  261. end
  262. end
  263. end
  264. end
  265. CommonUtil.ArraySortListSelections(cardDatas, {Enum.TableSortRule.Down, Enum.TableSortRule.Up, Enum.TableSortRule.Down}, {"CardType", "CardLevel", "cfgId"})
  266. return cardDatas
  267. end
  268. function UICardListCtr:RecreateNeedNotice()
  269. for _, v in pairs(costCardLogicDatas) do
  270. if v ~= nil then
  271. local cardData = ManagerContainer.CfgMgr:GetCardDataById(v.cfgId)
  272. if cardData.CardType > Enum.CardType.NORMAL then
  273. return true
  274. end
  275. end
  276. end
  277. return false
  278. end
  279. function UICardListCtr:SendCardReceate()
  280. local data = {}
  281. for _,v in pairs(costCardLogicDatas) do
  282. if v ~= nil then
  283. data[#data + 1] = v.cfgId
  284. end
  285. end
  286. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CARD_COMPOSE_REQ, {card_list = data})
  287. end
  288. function UICardListCtr:SendCardCompose(nextCardIds, counts)
  289. local cfgIds = {}
  290. for k,v in pairs(nextCardIds) do
  291. if v ~= nil then
  292. cfgIds[#cfgIds + 1] = {key = v - 100, value = counts[v] * 3}
  293. end
  294. end
  295. if #cfgIds == 0 then return end
  296. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CARD_UP_GRADE_REQ, {config_ids = cfgIds})
  297. end
  298. function UICardListCtr:OnDispose()
  299. self.data = nil
  300. self.view = nil
  301. self:ClearLeftSlotIdx()
  302. self:ClearRightSlotIdx()
  303. self.MvpCardList = nil
  304. end
  305. function UICardListCtr:IsProduceFree()
  306. local vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  307. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  308. local boliShooLv = ManagerContainer.DataMgr.BoliShopData:GetCurLv()
  309. local boliShopCfg = ManagerContainer.CfgMgr:GetBoLiVipCfgById(boliShooLv)
  310. return vipCfg and vipCfg.CardReset >= 1 or boliShopCfg and boliShopCfg.CardReset >= 1
  311. end
  312. return UICardListCtr