UIREShopCtr.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. local UIREShopCtr = class("UIREShopCtr", require("UICtrBase"))
  2. local reShopTypeId = 50
  3. function UIREShopCtr:Init(view)
  4. self.view = view
  5. end
  6. function UIREShopCtr:SetData(data)
  7. self.asyncIdx = 0
  8. self.data = data
  9. self.isResetSelect = true
  10. end
  11. function UIREShopCtr:GetAsyncIdx()
  12. self.asyncIdx = self.asyncIdx + 1
  13. return self.asyncIdx
  14. end
  15. function UIREShopCtr:GetData()
  16. return self.data
  17. end
  18. function UIREShopCtr:OnDispose()
  19. self.data = nil
  20. self.view = nil
  21. self.isResetSelect = false
  22. self.nearestRemainTime = nil
  23. self.shopLs = nil
  24. self.shopEndTimes = nil
  25. self.curSelectIdx = nil
  26. self.curShopCfgData = nil
  27. self.curShopData = nil
  28. end
  29. function UIREShopCtr:InitData()
  30. local shopLs = {}
  31. local cfgDatas
  32. local shopEndTimes = {}
  33. local nearestRemainTime = nil
  34. local remainTime = nil
  35. cfgDatas = ManagerContainer.CfgMgr:GetShopTypeCfgById(reShopTypeId)
  36. shopLs[#shopLs+1] = cfgDatas
  37. --local actItem = ManagerContainer.DataMgr.ActsDataMgr:GetActivityItemById(reShopTypeId)
  38. --if actItem and actItem.type == Enum.ActivityType.ACTIVITY_TYPE_SHOP then
  39. -- if actItem:IsUnlocked() and actItem:IsOpened() then
  40. -- if actItem.actShopIds then
  41. -- for _, actShopId in pairs(actItem.actShopIds) do
  42. -- cfgDatas = ManagerContainer.CfgMgr:GetShopTypeCfgById(actShopId)
  43. -- if cfgDatas then
  44. -- if actItem:IsLimited() then
  45. -- if not actItem:IsOutofDate() then
  46. -- remainTime = actItem:LeftTime()
  47. -- shopEndTimes[actShopId] = actItem.endTime
  48. -- if not nearestRemainTime or nearestRemainTime > remainTime then
  49. -- nearestRemainTime = remainTime
  50. -- end
  51. -- shopLs[#shopLs+1] = cfgDatas
  52. -- end
  53. -- else
  54. -- shopLs[#shopLs+1] = cfgDatas
  55. -- end
  56. -- end
  57. -- end
  58. -- end
  59. -- end
  60. --end
  61. self.nearestRemainTime = nearestRemainTime
  62. self.shopEndTimes = shopEndTimes
  63. table.sort(shopLs, function(a, b)
  64. return a.SortId < b.SortId
  65. end)
  66. self.shopLs = shopLs
  67. self.curSelectIdx = 1
  68. end
  69. function UIREShopCtr:RefreshCurShopData(forceRefresh)
  70. self.curShopCfgData = self.shopLs[self.curSelectIdx]
  71. if self.curShopCfgData then
  72. self.curShopData = ManagerContainer.DataMgr.ShopDataMgr:GetShopData(self.curShopCfgData.Id, forceRefresh)
  73. else
  74. self.curShopData = nil
  75. end
  76. if self.curShopData then
  77. if ManagerContainer.LuaTimerMgr:GetRemainSeconds(self.curShopData:GetNeedRefreshTime()) <= 0 then
  78. self.curShopData:RefreshShowGoodsDatas()
  79. end
  80. end
  81. end
  82. function UIREShopCtr:GetNearestRemainTime()
  83. return self.nearestRemainTime
  84. end
  85. function UIREShopCtr:GeCurEndTime()
  86. if self.shopLs then
  87. local cfgData = self.shopLs[self.curSelectIdx]
  88. if cfgData then
  89. return self.shopEndTimes and self.shopEndTimes[cfgData.Id] or nil
  90. end
  91. end
  92. return nil
  93. end
  94. function UIREShopCtr:GetShopLs()
  95. return self.shopLs
  96. end
  97. function UIREShopCtr:GetShopByIdx(idx)
  98. return self.shopLs and self.shopLs[idx] or nil
  99. end
  100. function UIREShopCtr:GetCurSelectIdx()
  101. return self.curSelectIdx
  102. end
  103. function UIREShopCtr:SetCurSelectIdx(newIdx)
  104. if self.curSelectIdx == newIdx then
  105. return false
  106. end
  107. self.curSelectIdx = newIdx
  108. self:RefreshCurShopData(true)
  109. return true
  110. end
  111. function UIREShopCtr:GetCurShopCfgData()
  112. return self.curShopCfgData
  113. end
  114. function UIREShopCtr:GetCurShopData()
  115. return self.curShopData
  116. end
  117. function UIREShopCtr:GetRefreshCostInfo()
  118. local costNum, costCfgId
  119. if self.curShopData and self.curShopCfgData then
  120. local payForRefreshs = self.curShopCfgData.PayForRefresh
  121. local refreshNum = self.curShopData:GetRefreshCount() or 0
  122. if payForRefreshs and #payForRefreshs > 0 then
  123. refreshNum = Mathf.Clamp(refreshNum+1, 1, #payForRefreshs)
  124. local payForRefresh = payForRefreshs[refreshNum]
  125. if payForRefresh then
  126. costCfgId = payForRefresh[1]
  127. costNum = payForRefresh[2]
  128. end
  129. end
  130. end
  131. return costNum, costCfgId
  132. end
  133. function UIREShopCtr:SendShopInfoReq()
  134. if not self.curShopData then
  135. return 398
  136. end
  137. if not ManagerContainer.DataMgr.ShopDataMgr:SendShopInfoReq(self.curShopData.shopId) then
  138. return 100007
  139. end
  140. return 0
  141. end
  142. function UIREShopCtr:SendRefreshShopReq()
  143. if not self.curShopCfgData or not self.curShopData then
  144. return 398
  145. end
  146. -- if self.curShopCfgData.ShopType ~= 2 then
  147. -- return 397
  148. -- end
  149. -- local refreshNum = self.curShopData:GetRefreshCount() or 0
  150. -- local refreshMaxNum = self.curShopCfgData.RefreshNum or 0
  151. -- if (refreshMaxNum - refreshNum) <= 0 then
  152. -- return 395
  153. -- end
  154. -- local costNum, costCfgId = self:GetRefreshCostInfo()
  155. -- local ownNum = CommonUtil.GetOwnResCountByItemId(costCfgId)
  156. -- if ownNum < costNum then
  157. -- return 396, costCfgId
  158. -- end
  159. if not ManagerContainer.DataMgr.ShopDataMgr:SendRefreshShopReq(self.curShopData.shopId) then
  160. return 100007
  161. end
  162. return 0
  163. end
  164. function UIREShopCtr:SetCurGoodsData(goodsData)
  165. self.curGoodsData = goodsData
  166. end
  167. function UIREShopCtr:GetOwnResCountByItemId(cfgId)
  168. return CommonUtil.GetOwnResCountByItemId(cfgId)
  169. end
  170. function UIREShopCtr:SendShopBuyItemReq()
  171. if not self.curGoodsData then
  172. return 390
  173. end
  174. local price = self.curGoodsData.curPrice
  175. local goodsCfgData = self.curGoodsData:GetGoodsCfgData()
  176. local ownCount = self:GetOwnResCountByItemId(goodsCfgData.PayForType)
  177. if ownCount < price then
  178. return 391, goodsCfgData.PayForType
  179. end
  180. if not ManagerContainer.DataMgr.ShopDataMgr:SendShopBuyItemReq(self.curShopData.shopId, self.curGoodsData.id, 1) then
  181. return 100007
  182. end
  183. return 0
  184. end
  185. return UIREShopCtr