UIBuyTimesCtr.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. local UIBuyTimesCtr = class("UIBuyTimesCtr", require("UICtrBase"))
  2. function UIBuyTimesCtr:Init(view)
  3. self.view = view
  4. end
  5. function UIBuyTimesCtr:SetData(data)
  6. self.asyncIdx = 0
  7. if data == nil then return end
  8. self.data = data
  9. end
  10. function UIBuyTimesCtr:GetAsyncIdx()
  11. self.asyncIdx = self.asyncIdx + 1
  12. return self.asyncIdx
  13. end
  14. function UIBuyTimesCtr:GetCostNum()
  15. if self.data then
  16. return self.data[1] or 0
  17. end
  18. return 0
  19. end
  20. function UIBuyTimesCtr:GetCostNumByGuildDemon(BuyCount)
  21. local cost = 0
  22. if self.data and self.data[1] and #self.data[1] > 0 then
  23. local costs = self.data[1]
  24. local maxBuyCount = self:GetChallengeTimesFromGuildDemon()
  25. local remainCount = self:GetRemainCount()
  26. local specialCount = maxBuyCount - remainCount
  27. if specialCount + 1 <= #costs then
  28. local count = 0
  29. for i = specialCount + 1, specialCount + BuyCount do
  30. if costs[i] then
  31. cost = cost + costs[i][2]
  32. count = count + 1
  33. end
  34. end
  35. if BuyCount + specialCount > #costs then
  36. cost = cost + (BuyCount - count) * costs[#costs][2]
  37. end
  38. else
  39. cost = BuyCount * costs[#costs][2]
  40. end
  41. end
  42. return cost
  43. end
  44. function UIBuyTimesCtr:GetChallengeTimesFromGuildDemon()
  45. return self.data and self.data[5] or 0
  46. end
  47. function UIBuyTimesCtr:IsGuildDemon()
  48. return self.data and self.data[5]
  49. end
  50. function UIBuyTimesCtr:GetRemainCount()
  51. if self.data then
  52. return self.data[2]
  53. end
  54. return nil
  55. end
  56. --是否卖完
  57. function UIBuyTimesCtr:IsOver()
  58. local remainCount = self:GetRemainCount()
  59. if remainCount < 1 then
  60. return true
  61. end
  62. return false
  63. end
  64. --是否可以购买
  65. function UIBuyTimesCtr:IsCanBuy(count)
  66. if self.data then
  67. local cb = self.data[3]
  68. if cb then
  69. if not self:IsGuildDemon() then
  70. return cb(self:GetCostNum(),count)
  71. else
  72. return cb(self:GetCostNumByGuildDemon(count))
  73. end
  74. end
  75. end
  76. return false
  77. end
  78. function UIBuyTimesCtr:IsCanBuyByGuildDemon(cost)
  79. if self.data then
  80. local cb = self.data[3]
  81. if cb then
  82. return cb(cost)
  83. end
  84. end
  85. return false
  86. end
  87. function UIBuyTimesCtr:HandleCallback(count)
  88. if self.data then
  89. local cb = self.data[4]
  90. if cb then
  91. cb(count)
  92. end
  93. end
  94. end
  95. function UIBuyTimesCtr:GetData()
  96. return self.data
  97. end
  98. function UIBuyTimesCtr:OnDispose()
  99. self.data = nil
  100. self.view = nil
  101. end
  102. return UIBuyTimesCtr