| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- local UILuckyEggCtr = class("UILuckyEggCtr", require("UICtrBase"))
- function UILuckyEggCtr:Init(view)
- self.view = view
- end
- ---@param data integer 默认进入的页面Id,参考SummonCfg配置
- function UILuckyEggCtr:SetData(data)
- self.asyncIdx = 0
- self.data = data
- if self.data and type(self.data) == "table" and self.data.actId then
- if not self.activityData then
- self.activityData = ManagerContainer.DataMgr.ActsDataMgr:GetActivityItemById(self.data.actId)
- end
- end
- self:InitData()
- end
- function UILuckyEggCtr:GetAsyncIdx()
- self.asyncIdx = self.asyncIdx + 1
- return self.asyncIdx
- end
- function UILuckyEggCtr:GetData()
- return self.data
- end
- function UILuckyEggCtr:GetActivityId()
- return self.data and type(self.data) == "table" and self.data.actId or nil
- end
- function UILuckyEggCtr:OnDispose()
- self.data = nil
- self.view = nil
- self.listIdx = nil
- self.selectIdx = nil
- self.cfgs = nil
- self.cfgLength = nil
- end
- function UILuckyEggCtr:InitData()
- local cfgs = {}
- local cfgSource = ManagerContainer.CfgMgr:GetLuckyEggCfg()
- ManagerContainer.DataMgr.LuckyEggDataMgr.curActID = self.data.actId
- --LogError("--------------------self.data.actId-- "..Inspect(self.data.actId))
- for id, cfg in pairs(cfgSource) do
- --LogError("----------------------"..Inspect(cfg))
- if cfg.ActivitiesId == self.data.actId then
- --LogError("----------------------"..Inspect(cfg))
- cfgs[#cfgs+1] = cfg
- 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:CheckTotalRecharge()
- end
- function UILuckyEggCtr:GetListIdx()
- return self.listIdx
- end
- function UILuckyEggCtr:SetListIdx(listIdx)
- if self.listIdx == listIdx then return false end
- self.listIdx = listIdx
- self.selectIdx = self:GetSelectIdxByListIdx(listIdx)
- return true
- end
- function UILuckyEggCtr:GetSelectIdxByListIdx(listIdx)
- return listIdx % self.cfgLength + 1
- end
- function UILuckyEggCtr:GetSelectIdx()
- return self.selectIdx
- end
- function UILuckyEggCtr:GetCfgByIdx(idx)
- return self.cfgs[idx]
- end
- function UILuckyEggCtr:GetCfgLength()
- return self.cfgLength
- end
- function UILuckyEggCtr:GetCfgLength_cfg()
- return #self.cfgs
- end
- --- 获取额外奖励进度
- function UILuckyEggCtr:GetLuckyEggNumByIdx(idx)
- local cfg = self:GetCfgByIdx(idx)
- return ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggNum(cfg.Id)
- end
- function UILuckyEggCtr:GetOwnResCountByItemId(cfgId)
- return CommonUtil.GetOwnResCountByItemId(cfgId)
- end
- function UILuckyEggCtr:CheckTotalRecharge()
- local payNum = ManagerContainer.PayMgr:GetTotalRecharge() or 0
- --- 彩蛋开放最低儲值金额
- local needNum = 0
- if #self.cfgs == 1 then
- needNum = 0
- end
- self.eggActive = payNum >= needNum
- --- 彩蛋儲值金额需要满足条件才能激活
- self.cfgLength = self.eggActive and #self.cfgs or #self.cfgs - 1
- end
- --- 根据当前儲值金额判断是否激活彩蛋
- ---@return boolean
- function UILuckyEggCtr:GetEggActiveByPay()
- if #self.cfgs == 1 then
- return true
- end
- return self.eggActive
- end
- function UILuckyEggCtr:GetSendLuckyEggReqErrorCode(idx)
- local selectIdx = self:GetSelectIdx()
- local cfg = self:GetCfgByIdx(selectIdx)
- return ManagerContainer.DataMgr.LuckyEggDataMgr:GetSendLuckyEggReqErrorCode(cfg.Id, idx)
- end
- function UILuckyEggCtr:GetActivityData()
- local rank_list = {}
- local selectIdx = self:GetSelectIdx()
- local cfg = self:GetCfgByIdx(selectIdx)
- if cfg then
- rank_list = ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggMsgDataByType(cfg.Type) or {}
- end
- return rank_list
- end
- function UILuckyEggCtr:ReadyData()
- ManagerContainer.DataMgr.LuckyEggDataMgr:ClearLuckyEggData()
- ManagerContainer.DataMgr.LuckyEggDataMgr:ClearRedPoint()
- end
- function UILuckyEggCtr:HasNeedShowItem()
- local luckyData = ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggData()
- if luckyData then
- local luckyCfgData = ManagerContainer.CfgMgr:GetLuckyEggCfgByTypeAndActid(luckyData.luckyType,self.data.actId)
- if luckyCfgData and luckyCfgData.ShowItemType and #luckyCfgData.ShowItemType > 0 then
- if luckyData.rewards then
- for i = 1, #luckyData.rewards do
- local reward = luckyData.rewards[i]
- if reward then
- local itemCfgData = ManagerContainer.CfgMgr:GetItemById(reward.cfgId)
- if CommonUtil.EleInTable(itemCfgData.ResType, luckyCfgData.ShowItemType) then
- return true
- end
- end
- end
- end
- end
- end
- return false
- end
- function UILuckyEggCtr:SendLuckyEggReq(summonNum)
- local selectIdx = self:GetSelectIdx()
- local cfg = self:GetCfgByIdx(selectIdx)
- if not ManagerContainer.DataMgr.LuckyEggDataMgr:SendLuckyEggReq(cfg.ActivitiesId,summonNum,cfg.Type) then
- return 100007
- end
- return 0
- end
- function UILuckyEggCtr:SendLuckyEggRecordReq()
- local selectIdx = self:GetSelectIdx()
- local cfg = self:GetCfgByIdx(selectIdx)
- if cfg then
- ManagerContainer.DataMgr.LuckyEggDataMgr:SendLuckyEggRecordReq(cfg.ActivitiesId,cfg.Type)
- end
- return 0
- end
- return UILuckyEggCtr
|