UIActivityTowerCtr.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. local UIActivityTowerCtr = class("UIActivityTowerCtr", require("UICtrBase"))
  2. local PetDataCountPerPage = 10
  3. function UIActivityTowerCtr:Init(view)
  4. self.view = view
  5. end
  6. function UIActivityTowerCtr:SetData(data)
  7. self.asyncIdx = 0
  8. if data == nil then return end
  9. self.data = data
  10. self.curPetPage = 0
  11. self.minIdx = 0
  12. self.maxIdx = 9
  13. end
  14. function UIActivityTowerCtr:GetAsyncIdx()
  15. self.asyncIdx = self.asyncIdx + 1
  16. return self.asyncIdx
  17. end
  18. function UIActivityTowerCtr:GetData()
  19. return self.data
  20. end
  21. function UIActivityTowerCtr:OnDispose()
  22. self.data = nil
  23. self.view = nil
  24. self.shopType = nil
  25. self.shopSubType = nil
  26. self.type = nil
  27. self.idx = nil
  28. end
  29. function UIActivityTowerCtr:InitData()
  30. self.type = self.data
  31. self.idx = ManagerContainer.DataMgr.RankActivitiesMgr:GetCurRankActivityIdx(self.type)
  32. if not self.type or not self.idx then return end
  33. if self.type == Enum.RankActivitiesType.ClimbingTower then
  34. self.shopType = Enum.RuneShopType.RushTower
  35. elseif self.type == Enum.RankActivitiesType.Dojo then
  36. self.shopType = Enum.RuneShopType.RushArena
  37. elseif self.type == Enum.RankActivitiesType.MapProgress then
  38. self.shopType = Enum.RuneShopType.RushMap
  39. elseif self.type == Enum.RankActivitiesType.Pet then
  40. self.shopType = Enum.RuneShopType.RushPet
  41. elseif self.type == Enum.RankActivitiesType.Skill then
  42. self.shopType = Enum.RuneShopType.RushSkill
  43. end
  44. self:RefreshCurShopData(true)
  45. end
  46. function UIActivityTowerCtr:GetType()
  47. return self.type
  48. end
  49. function UIActivityTowerCtr:GetIdx()
  50. return self.idx
  51. end
  52. function UIActivityTowerCtr:RefreshCurShopData(forceRefresh)
  53. ManagerContainer.DataMgr.RuneShopDataMgr:RefreshShopData(self.shopType, self.shopSubType, forceRefresh)
  54. self.curShopData = ManagerContainer.DataMgr.RuneShopDataMgr:GetShopData(self.shopType, self.shopSubType)
  55. if self.curShopData then
  56. if not self.curShopData:IsValidShow() then
  57. self.curShopData:RefreshShowGoodsDatas()
  58. end
  59. return true
  60. end
  61. return false
  62. end
  63. function UIActivityTowerCtr:GetShopType()
  64. return self.shopType
  65. end
  66. function UIActivityTowerCtr:GetShowGoodsDatas()
  67. if not self.curShopData then
  68. self.curShopData = ManagerContainer.DataMgr.RuneShopDataMgr:GetShopData(self.shopType, self.shopSubType)
  69. if self.curShopData then
  70. if not self.curShopData:IsValidShow() then
  71. self.curShopData:RefreshShowGoodsDatas()
  72. end
  73. end
  74. end
  75. local datas = self.curShopData and self.curShopData:GetShowGoodsDatas() or nil
  76. if not datas then
  77. return
  78. else
  79. self.curShopData:RefreshShowGoodsDatas()
  80. end
  81. --table.sort(datas, ShowDataSort)
  82. return datas
  83. end
  84. function UIActivityTowerCtr:SendPay(goodsId)
  85. local errorCode = ManagerContainer.PayMgr:RuneShopPay(self.shopType, self.shopSubType, goodsId)
  86. local errorCodeKey = ManagerContainer.PayMgr:GetInitPayErrorCodeLangKey(errorCode)
  87. return errorCodeKey
  88. end
  89. function UIActivityTowerCtr:SendRewardReq(rewardType)
  90. ManagerContainer.DataMgr.RankActivitiesMgr:SendRewardReq(self.type, rewardType)
  91. end
  92. function UIActivityTowerCtr:SetCurPetPage(idx)
  93. local maxChange = idx > self.maxIdx
  94. if maxChange then
  95. self.maxIdx = idx
  96. self.minIdx = self.maxIdx - 5
  97. end
  98. local minChange = false
  99. if not maxChange then
  100. minChange = idx < self.minIdx
  101. if minChange then
  102. self.minIdx = idx
  103. self.maxIdx = self.minIdx + 5
  104. end
  105. end
  106. local newPage = math.floor(idx/PetDataCountPerPage)
  107. if newPage == self.curPetPage then
  108. return
  109. end
  110. if minChange or maxChange then
  111. -- LogHRWarning("query pet data +++++++++++++++++++++++++++++++++++++++++++++++++++++++ "..newPage)
  112. self.curPetPage = newPage
  113. ManagerContainer.DataMgr.RankActivitiesMgr:QueryRankActivityData(self.type, newPage)
  114. end
  115. end
  116. return UIActivityTowerCtr