| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- local UISummonCtr = class("UISummonCtr", require("UICtrBase"))
- function UISummonCtr:Init(view)
- self.view = view
- end
- ---@param data integer 默认进入的页面Id,参考SummonCfg配置
- function UISummonCtr:SetData(data)
- self.asyncIdx = 0
- self.data = data
- if self.data and type(self.data) == "table" and self.data.actId then
- self.isFromActivity = true
- if not self.activityData then
- self.activityData = ManagerContainer.DataMgr.ActsDataMgr:GetActivityItemById(self.data.actId)
- end
- end
- self:InitData()
- end
- function UISummonCtr:GetAsyncIdx()
- self.asyncIdx = self.asyncIdx + 1
- return self.asyncIdx
- end
- function UISummonCtr:GetData()
- return self.data
- end
- function UISummonCtr:GetActivityId()
- return self.data and type(self.data) == "table" and self.data.actId or nil
- end
- function UISummonCtr:GetEnterType()
- return self.isFromActivity
- end
- function UISummonCtr:GetRemainTime()
- if self.activityData then
- return self.activityData:LeftTime()
- end
- return 0
- end
- function UISummonCtr:OnDispose()
- self.data = nil
- self.view = nil
- self.listIdx = nil
- self.selectIdx = nil
- self.cfgs = nil
- self.cfgLength = nil
- end
- function UISummonCtr:InitData()
- local cfgs = {}
- local cfgSource = ManagerContainer.CfgMgr:GetAllSummonCfg()
- for id, cfg in pairs(cfgSource) do
- if self.isFromActivity then
- if cfg.ActivitiesId and cfg.ActivitiesId == self.data.actId then
- cfgs[#cfgs+1] = cfg
- end
- else
- if not (cfg.ActivitiesId and cfg.ActivitiesId > 0) then
- cfgs[#cfgs+1] = cfg
- end
- end
- end
- table.sort(cfgs, function(a, b)
- return a.SortId < b.SortId
- end)
- local idx = nil
- if self.data then
- for i = 1, #cfgs do
- if cfgs[i].Id == self.data then
- idx = i
- end
- end
- end
- if not idx then
- idx = 1
- end
- self.selectIdx = idx
- self.listIdx = idx - 1
- self.cfgs = cfgs
- self.cfgLength = #cfgs
- end
- function UISummonCtr:GetListIdx()
- return self.listIdx
- end
- function UISummonCtr:SetListIdx(listIdx)
- if self.listIdx == listIdx then return false end
- self.listIdx = listIdx
- self.selectIdx = self:GetSelectIdxByListIdx(listIdx)
- return true
- end
- function UISummonCtr:GetSelectIdxByListIdx(listIdx)
- if listIdx >= 0 then
- return listIdx % self.cfgLength + 1
- else
- return self.cfgLength - Mathf.Abs(listIdx + 1) % self.cfgLength
- end
- end
- function UISummonCtr:GetSelectIdx()
- return self.selectIdx
- end
- function UISummonCtr:GetCfgByIdx(idx)
- return self.cfgs[idx]
- end
- function UISummonCtr:GetCfgLength()
- return self.cfgLength
- end
- function UISummonCtr:GetSummonNumByIdx(idx)
- local cfg = self:GetCfgByIdx(idx)
- return ManagerContainer.DataMgr.SummonDataMgr:GetSummonNum(cfg.Id)
- end
- function UISummonCtr:GetOwnResCountByItemId(cfgId)
- return CommonUtil.GetOwnResCountByItemId(cfgId)
- end
- function UISummonCtr:GetSendSummonReqErrorCode(idx)
- local selectIdx = self:GetSelectIdx()
- local cfg = self:GetCfgByIdx(selectIdx)
- return ManagerContainer.DataMgr.SummonDataMgr:GetSendSummonReqErrorCode(cfg.Id, idx)
- end
- function UISummonCtr:ReadyData()
- ManagerContainer.DataMgr.SummonDataMgr:ClearSummonData()
- ManagerContainer.DataMgr.SummonDataMgr:ClearRedPoint()
- end
- function UISummonCtr:SendSummonReq(summonNum)
- local selectIdx = self:GetSelectIdx()
- local cfg = self:GetCfgByIdx(selectIdx)
- local IsFromActivity = self:GetEnterType()
- if IsFromActivity then
- if not ManagerContainer.DataMgr.SummonDataMgr:SendActivitySummonReq(cfg.ActivitiesId,summonNum) then
- return 100007
- end
- else
- if not ManagerContainer.DataMgr.SummonDataMgr:SendSummonReq(cfg.Id,summonNum) then
- return 100007
- end
- end
- return 0
- end
- return UISummonCtr
|