UICardDecomposeTipsCtr.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. local UICardDecomposeTipsCtr = class("UICardDecomposeTipsCtr", require("UICtrBase"))
  2. local decomposeList
  3. local selectionList
  4. function UICardDecomposeTipsCtr:Init(view)
  5. self.view = view
  6. end
  7. function UICardDecomposeTipsCtr:SetData(data)
  8. self.asyncIdx = 0
  9. if data == nil then return end
  10. self.data = data
  11. end
  12. function UICardDecomposeTipsCtr:GetAsyncIdx()
  13. self.asyncIdx = self.asyncIdx + 1
  14. return self.asyncIdx
  15. end
  16. function UICardDecomposeTipsCtr:GetData()
  17. return self.data
  18. end
  19. function UICardDecomposeTipsCtr:GetDecomposeCardCount(type)
  20. if decomposeList == nil then
  21. decomposeList = {}
  22. end
  23. decomposeList[type] = {}
  24. local num = 0
  25. for _,v in pairs(self.data[1]) do
  26. if v.CardType == type then
  27. decomposeList[type][#decomposeList[type] + 1] = v
  28. num = num + v.decompose
  29. end
  30. end
  31. return num
  32. end
  33. function UICardDecomposeTipsCtr:IsOneKeyDecompose()
  34. return self.data[2]
  35. end
  36. function UICardDecomposeTipsCtr:GetDecomposeAwards()
  37. local type = self:GetSelectionList()
  38. local list = {}
  39. if type ~= 0 then
  40. for k2,v2 in pairs(type) do
  41. if v2 then
  42. for _,v in pairs(decomposeList[k2]) do
  43. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(v.cfgId)
  44. local award = CommonUtil.DeserializeCfgItemList(itemCfgData.Resolve)
  45. for _,v1 in pairs(award) do
  46. if list[v1[1]] == nil then
  47. list[v1[1]] = 0
  48. end
  49. list[v1[1]] = list[v1[1]] + (v1[2] * v.decompose)
  50. end
  51. end
  52. end
  53. end
  54. end
  55. local list1 = {}
  56. for k,v in pairs(list) do
  57. list1[#list1 + 1] = {k, v}
  58. end
  59. return list1
  60. end
  61. function UICardDecomposeTipsCtr:ResetSelectionList()
  62. selectionList = nil
  63. end
  64. function UICardDecomposeTipsCtr:SetSelectionList(type)
  65. if selectionList == nil then
  66. selectionList = {}
  67. end
  68. if selectionList[type] == nil then
  69. selectionList[type] = false
  70. end
  71. selectionList[type] = not selectionList[type]
  72. return selectionList[type]
  73. end
  74. function UICardDecomposeTipsCtr:GetSelectionList()
  75. if selectionList == nil then
  76. selectionList = {}
  77. end
  78. local noSelection = true
  79. for k, v in pairs(selectionList) do
  80. if v then
  81. noSelection = false
  82. end
  83. end
  84. return noSelection and 0 or selectionList
  85. end
  86. function UICardDecomposeTipsCtr:SendDecompose()
  87. local type = self:GetSelectionList()
  88. if type == 0 then
  89. return
  90. end
  91. local list = {}
  92. if type ~= 0 then
  93. for k2,v2 in pairs(type) do
  94. if v2 then
  95. for _,v in pairs(decomposeList[k2]) do
  96. local data = {key = v.cfgId, value = v.decompose}
  97. list[#list + 1] = data
  98. end
  99. end
  100. end
  101. end
  102. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_CARD_DECOMPOSE_REQ, {card_list = list})
  103. end
  104. function UICardDecomposeTipsCtr:OnDispose()
  105. self.data = nil
  106. self.view = nil
  107. decomposeList = nil
  108. selectionList = nil
  109. end
  110. return UICardDecomposeTipsCtr