UIRuneShopCtr.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. local UIRuneShopCtr = class("UIRuneShopCtr", require("UICtrBase"))
  2. function UIRuneShopCtr:Init(view)
  3. self.view = view
  4. end
  5. ---@param data table|nil {[1] = Enum.RuneShopType, [2] = Enum.RuneShopSubType}, 默认值为{Enum.RuneShopType.MonthCard, Enum.RuneShopSubType.Daily}
  6. function UIRuneShopCtr:SetData(data)
  7. self.asyncIdx = 0
  8. self.data = data
  9. end
  10. function UIRuneShopCtr:GetAsyncIdx()
  11. self.asyncIdx = self.asyncIdx + 1
  12. return self.asyncIdx
  13. end
  14. function UIRuneShopCtr:GetData()
  15. return self.data
  16. end
  17. function UIRuneShopCtr:OnDispose()
  18. self.data = nil
  19. self.view = nil
  20. self.shopType = nil
  21. self.shopSubType = nil
  22. end
  23. function UIRuneShopCtr:InitData()
  24. local shopType = nil
  25. local shopSubType = nil
  26. if self.data then
  27. shopType = self.data[1]
  28. shopSubType = self.data[2]
  29. if self.data[4] then
  30. self:RefreshCurRewardsData()
  31. return
  32. end
  33. if shopType == Enum.RuneShopType.Gifts then
  34. if shopSubType ~= Enum.RuneShopSubType.Week
  35. and shopSubType ~= Enum.RuneShopSubType.Month
  36. and shopSubType ~= Enum.RuneShopSubType.Gold then
  37. shopSubType = Enum.RuneShopType.Daily
  38. end
  39. elseif shopType == Enum.RuneShopType.LimitTime then
  40. shopSubType = nil
  41. elseif shopType == Enum.RuneShopType.Rewards then
  42. shopSubType = nil
  43. else
  44. shopType = Enum.RuneShopType.MonthCard
  45. shopSubType = nil
  46. end
  47. else
  48. shopType = Enum.RuneShopType.MonthCard
  49. shopSubType = nil
  50. end
  51. self.shopType = shopType
  52. self.shopSubType = shopSubType
  53. self:RefreshCurShopData(true)
  54. end
  55. function UIRuneShopCtr:RefreshCurShopData(forceRefresh)
  56. self.isAirShip = false
  57. ManagerContainer.DataMgr.RuneShopDataMgr:RefreshShopData(self.shopType, self.shopSubType, forceRefresh)
  58. self.curShopData = ManagerContainer.DataMgr.RuneShopDataMgr:GetShopData(self.shopType, self.shopSubType)
  59. if self.curShopData then
  60. if not self.curShopData:IsValidShow() then
  61. self.curShopData:RefreshShowGoodsDatas()
  62. end
  63. end
  64. end
  65. function UIRuneShopCtr:RefreshCurRewardsData()
  66. self.isAirShip = true
  67. ManagerContainer.DataMgr.RuneShopDataMgr:RefreshRewardData()
  68. self.curRewardsData = ManagerContainer.DataMgr.RuneShopDataMgr:GetRewardsData()
  69. end
  70. function UIRuneShopCtr:GetShopType()
  71. return self.shopType
  72. end
  73. function UIRuneShopCtr:ChangeShopType(shopType)
  74. if self.shopType == shopType then
  75. return false
  76. end
  77. self.shopType = shopType
  78. if shopType == Enum.RuneShopType.Gifts then
  79. self.shopSubType = Enum.RuneShopSubType.Daily
  80. else
  81. self.shopSubType = nil
  82. end
  83. if self.shopType then
  84. self:RefreshCurShopData(true)
  85. else
  86. self:RefreshCurRewardsData()
  87. end
  88. return true
  89. end
  90. function UIRuneShopCtr:GetShopSubType()
  91. return self.shopSubType
  92. end
  93. function UIRuneShopCtr:ChangeShopSubType(shopSubType)
  94. if self.shopSubType == shopSubType then
  95. return false
  96. end
  97. self.shopSubType = shopSubType
  98. self:RefreshCurShopData(true)
  99. return true
  100. end
  101. function UIRuneShopCtr:GetCurVipLv()
  102. return ManagerContainer.DataMgr.UserData:GetVipLv()
  103. end
  104. function UIRuneShopCtr:GetOwnResCountByItemId(cfgId)
  105. return CommonUtil.GetOwnResCountByItemId(cfgId)
  106. end
  107. function UIRuneShopCtr:GetShowGoodsDatas()
  108. return self.curShopData and self.curShopData:GetShowGoodsDatas() or nil
  109. end
  110. function UIRuneShopCtr:GetRemainTime()
  111. return self.curShopData and self.curShopData:RefreshRemainTime() or nil
  112. end
  113. function UIRuneShopCtr:GetRewardsRemainTime()
  114. return self.curRewardsData and self.curRewardsData:RefreshRewaradsRemainTime() or nil
  115. end
  116. function UIRuneShopCtr:GetShowGoodsDataByIdx(idx)
  117. if self.curShopData then
  118. local showGoodsDatas = self.curShopData:GetShowGoodsDatas()
  119. if showGoodsDatas then
  120. return showGoodsDatas[idx]
  121. end
  122. end
  123. return nil
  124. end
  125. function UIRuneShopCtr:GetShowRewardsDataByIdx(idx)
  126. return self.curRewardsData and self.curRewardsData:GetGoodsDataByIdx(idx) or nil
  127. end
  128. --战令悬赏数据
  129. function UIRuneShopCtr:GetShowRewardsData()
  130. return self.curRewardsData:GetShowRewardsData()
  131. end
  132. function UIRuneShopCtr:GetRewardsBaseData()
  133. return ManagerContainer.DataMgr.RuneShopDataMgr:GetRewardsData() --self.curRewardsData
  134. end
  135. function UIRuneShopCtr:GetShowReardsNearMinCashReward(min)
  136. return self.curRewardsData and self.curRewardsData:GetShowReardsNearMinCashReward(min) or nil
  137. end
  138. function UIRuneShopCtr:GetShowReardsNearMaxCashReward(max)
  139. return self.curRewardsData and self.curRewardsData:GetShowReardsNearMaxCashReward(max) or nil
  140. end
  141. function UIRuneShopCtr:SendPay(goodsId)
  142. local errorCode = ManagerContainer.PayMgr:RuneShopPay(self.shopType, self.shopSubType, goodsId)
  143. local errorCodeKey = ManagerContainer.PayMgr:GetInitPayErrorCodeLangKey(errorCode)
  144. return errorCodeKey
  145. end
  146. return UIRuneShopCtr