UISummonCtr.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. local UISummonCtr = class("UISummonCtr", require("UICtrBase"))
  2. function UISummonCtr:Init(view)
  3. self.view = view
  4. end
  5. ---@param data integer 默认进入的页面Id,参考SummonCfg配置
  6. function UISummonCtr:SetData(data)
  7. self.asyncIdx = 0
  8. self.data = data
  9. if self.data and type(self.data) == "table" and self.data.actId then
  10. self.isFromActivity = true
  11. if not self.activityData then
  12. self.activityData = ManagerContainer.DataMgr.ActsDataMgr:GetActivityItemById(self.data.actId)
  13. end
  14. end
  15. self:InitData()
  16. end
  17. function UISummonCtr:GetAsyncIdx()
  18. self.asyncIdx = self.asyncIdx + 1
  19. return self.asyncIdx
  20. end
  21. function UISummonCtr:GetData()
  22. return self.data
  23. end
  24. function UISummonCtr:GetActivityId()
  25. return self.data and type(self.data) == "table" and self.data.actId or nil
  26. end
  27. function UISummonCtr:GetEnterType()
  28. return self.isFromActivity
  29. end
  30. function UISummonCtr:GetRemainTime()
  31. if self.activityData then
  32. return self.activityData:LeftTime()
  33. end
  34. return 0
  35. end
  36. function UISummonCtr:OnDispose()
  37. self.data = nil
  38. self.view = nil
  39. self.listIdx = nil
  40. self.selectIdx = nil
  41. self.cfgs = nil
  42. self.cfgLength = nil
  43. end
  44. function UISummonCtr:InitData()
  45. local cfgs = {}
  46. local cfgSource = ManagerContainer.CfgMgr:GetAllSummonCfg()
  47. for id, cfg in pairs(cfgSource) do
  48. if self.isFromActivity then
  49. if cfg.ActivitiesId and cfg.ActivitiesId == self.data.actId then
  50. cfgs[#cfgs+1] = cfg
  51. end
  52. else
  53. if not (cfg.ActivitiesId and cfg.ActivitiesId > 0) then
  54. cfgs[#cfgs+1] = cfg
  55. end
  56. end
  57. end
  58. table.sort(cfgs, function(a, b)
  59. return a.SortId < b.SortId
  60. end)
  61. local idx = nil
  62. if self.data then
  63. for i = 1, #cfgs do
  64. if cfgs[i].Id == self.data then
  65. idx = i
  66. end
  67. end
  68. end
  69. if not idx then
  70. idx = 1
  71. end
  72. self.selectIdx = idx
  73. self.listIdx = idx - 1
  74. self.cfgs = cfgs
  75. self.cfgLength = #cfgs
  76. end
  77. function UISummonCtr:GetListIdx()
  78. return self.listIdx
  79. end
  80. function UISummonCtr:SetListIdx(listIdx)
  81. if self.listIdx == listIdx then return false end
  82. self.listIdx = listIdx
  83. self.selectIdx = self:GetSelectIdxByListIdx(listIdx)
  84. return true
  85. end
  86. function UISummonCtr:GetSelectIdxByListIdx(listIdx)
  87. if listIdx >= 0 then
  88. return listIdx % self.cfgLength + 1
  89. else
  90. return self.cfgLength - Mathf.Abs(listIdx + 1) % self.cfgLength
  91. end
  92. end
  93. function UISummonCtr:GetSelectIdx()
  94. return self.selectIdx
  95. end
  96. function UISummonCtr:GetCfgByIdx(idx)
  97. return self.cfgs[idx]
  98. end
  99. function UISummonCtr:GetCfgLength()
  100. return self.cfgLength
  101. end
  102. function UISummonCtr:GetSummonNumByIdx(idx)
  103. local cfg = self:GetCfgByIdx(idx)
  104. return ManagerContainer.DataMgr.SummonDataMgr:GetSummonNum(cfg.Id)
  105. end
  106. function UISummonCtr:GetOwnResCountByItemId(cfgId)
  107. return CommonUtil.GetOwnResCountByItemId(cfgId)
  108. end
  109. function UISummonCtr:GetSendSummonReqErrorCode(idx)
  110. local selectIdx = self:GetSelectIdx()
  111. local cfg = self:GetCfgByIdx(selectIdx)
  112. return ManagerContainer.DataMgr.SummonDataMgr:GetSendSummonReqErrorCode(cfg.Id, idx)
  113. end
  114. function UISummonCtr:ReadyData()
  115. ManagerContainer.DataMgr.SummonDataMgr:ClearSummonData()
  116. ManagerContainer.DataMgr.SummonDataMgr:ClearRedPoint()
  117. end
  118. function UISummonCtr:SendSummonReq(summonNum)
  119. local selectIdx = self:GetSelectIdx()
  120. local cfg = self:GetCfgByIdx(selectIdx)
  121. local IsFromActivity = self:GetEnterType()
  122. if IsFromActivity then
  123. if not ManagerContainer.DataMgr.SummonDataMgr:SendActivitySummonReq(cfg.ActivitiesId,summonNum) then
  124. return 100007
  125. end
  126. else
  127. if not ManagerContainer.DataMgr.SummonDataMgr:SendSummonReq(cfg.Id,summonNum) then
  128. return 100007
  129. end
  130. end
  131. return 0
  132. end
  133. return UISummonCtr