local TailsmanSoulChipLottery = {} local sortingOrder = 0 local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local artConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting) local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig) local lotterySpecialConfig = ConfigManager.GetConfig(ConfigName.LotterySpecialConfig) local wishSoulData function TailsmanSoulChipLottery:New(gameObject) local b = {} b.gameObject = gameObject b.transform = gameObject.transform setmetatable(b, { __index = TailsmanSoulChipLottery }) return b end --初始化组件(用于子类重写) function TailsmanSoulChipLottery:InitComponent() self.spLoader = SpriteLoader.New() self.btnHelp= Util.GetGameObject(self.gameObject,"help") self.helpPosition=self.btnHelp:GetComponent("RectTransform").localPosition self.limit = Util.GetGameObject(self.gameObject,"limitdi/limit"):GetComponent("Text") --rightUp self.rightUp = Util.GetGameObject(self.gameObject,"rightUp") self.btnReward = Util.GetGameObject(self.rightUp,"reward") self.btnStore = Util.GetGameObject(self.rightUp,"store") self.zhenqibaogeBtn = Util.GetGameObject(self.rightUp,"zqbg") self.zqbgEffect = Util.GetGameObject(self.zhenqibaogeBtn,"Fx_Circle 1") self.btn_soul = Util.GetGameObject(self.rightUp, "btn_hero") self.upSoulImg= Util.GetGameObject(self.btn_soul, "Icon"):GetComponent("Image") self.btns = {} for i = 1 , 2 do self.btns[i] = {} self.btns[i].btn = Util.GetGameObject(self.rightUp,"btn"..i) self.btns[i].red = Util.GetGameObject(self.btns[i].btn.gameObject,"redPoint") self.btns[i].info = Util.GetGameObject(self.btns[i].btn.gameObject,"layout/Text"):GetComponent("Text") self.btns[i].icon = Util.GetGameObject(self.btns[i].btn.gameObject,"layout/icon"):GetComponent("Image") self.btns[i].num = Util.GetGameObject(self.btns[i].btn.gameObject,"layout/num"):GetComponent("Text") end self.btnTime = Util.GetGameObject(self.btns[1].btn,"di1/time"):GetComponent("Text") --center self.center = Util.GetGameObject(self.gameObject,"center") self.icons = {} for i = 1 , 4 do self.icons[i] = {} self.icons[i].go = Util.GetGameObject(self.center,"icons/icon"..i) self.icons[i].icon = Util.GetGameObject(self.icons[i].go,"frame/icon"):GetComponent("Image") self.icons[i].kuang = Util.GetGameObject(self.icons[i].go,"kuang") self.icons[i].effect=Util.GetGameObject(self.icons[i].go,"UI_effect_RecruitPanel_box_open") end self.updateTimes = Util.GetGameObject(self.gameObject,"updateTimes") self.updateTimesTip = Util.GetGameObject(self.updateTimes,"Text"):GetComponent("Text") self.updateTimesTip1 = Util.GetGameObject(self.updateTimes,"Text1"):GetComponent("Text") end --绑定事件(用于子类重写) function TailsmanSoulChipLottery:BindEvent() Util.AddOnceClick(self.zhenqibaogeBtn, function() JumpManager.GoJump(40050,nil,self.actId) end) Util.AddOnceClick(self.btnHelp, function() UIManager.OpenPanel(UIName.HelpPopup,self.actConfig.HelpId,self.helpPosition.x,self.helpPosition.y) end) Util.AddOnceClick(self.btnReward, function() UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.RecrutDetail,self.actConfig.HelpId,self.actType,PRE_REWARD_POOL_TYPE.TIANDIHONGLU_UP,PRE_REWARD_POOL_TYPE.TIANDIHONGLU) end) Util.AddOnceClick(self.btnStore, function() JumpManager.GoJump(40047) end) Util.AddOnceClick(self.btn_soul, function() UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.chooseTailsManSoul) end) end --添加事件监听(用于子类重写) function TailsmanSoulChipLottery:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Activity.TailsmanSoulChipChange,self.OnUPEquipChange,self) end --移除事件监听(用于子类重写) function TailsmanSoulChipLottery:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Activity.TailsmanSoulChipChange,self.OnUPEquipChange,self) end --up的魂印改变 function TailsmanSoulChipLottery:OnUPEquipChange(id) self:contentShow() end --界面打开时调用(用于子类重写) function TailsmanSoulChipLottery:OnOpen(_activityConfig,_index,parent) self.actConfig = _activityConfig self.pageIndex = _index self.parent = parent end function TailsmanSoulChipLottery:OnSortingOrderChange(_sortingOrder) sortingOrder = _sortingOrder or 0 Util.SetParticleSortLayer(self.zqbgEffect, sortingOrder+1) for i = 1, 5 do if self.icons[i] and self.icons[i].effect then Util.SetParticleSortLayer(self.icons[i].effect.gameObject, sortingOrder+1) end end end -- 打开,重新打开时回调 function TailsmanSoulChipLottery:OnShow(_sortingOrder) self.gameObject:SetActive(true) sortingOrder = _sortingOrder Util.SetParticleSortLayer(self.zqbgEffect, sortingOrder+1) self.actId = self.actConfig.ActId self.actType = self.actConfig.ActiveType > 0 and self.actConfig.ActiveType or self.actConfig.FunType if self.actConfig.IfBack == 1 then if self.actConfig.ActiveType > 0 then local id = ActivityGiftManager.IsActivityTypeOpen(self.actConfig.ActiveType) if id and id > 0 then self.actId = id local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType,"ActId",id) if config then self.actConfig = config end end end end local array = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySetting,"ActivityId",self.actId) self.singleRecruit = array[1] self.tenRecruit = array[2] self.freeTimesId=self.singleRecruit.FreeTimes self.maxtimesId=self.singleRecruit.MaxTimes self:refreshMagicNum() self:refreshBtnShow()--刷新按钮显示 self:contentShow() self:IconsPlayAnim() end function TailsmanSoulChipLottery:IconsPlayAnim() if self.IconsPlayAnimTimer then self.IconsPlayAnimTimer:Stop() self.IconsPlayAnimTimer = nil end self.coroutines = {} local playAnimFunc = function() for i = 1, #self.icons do self.coroutines[i] = coroutine.start(function() coroutine.wait(i/5) while(true) do local pos = self.icons[i].go.transform.localPosition local tw = self.icons[i].go.transform:DOLocalMove(Vector3(pos.x, pos.y + 50, pos.z), 1.5 , false):OnStart(function () end):OnUpdate(function() end):OnComplete(function () pos = self.icons[i].go.transform.localPosition self.icons[i].go.transform:DOLocalMove(Vector3(pos.x, pos.y - 50, pos.z), 1.5 , false):OnStart(function () end):OnUpdate(function() end):OnComplete(function () end) end):SetEase(Ease.Linear) coroutine.wait(3) end end) end end playAnimFunc() -- self.IconsPlayAnimTimer = Timer.New(playAnimFunc,3,-1,false) -- self.IconsPlayAnimTimer:Start() end function TailsmanSoulChipLottery:refreshMagicNum() self.actData = ActivityGiftManager.GetActivityTypeInfo(self.actType) CommonActPageManager.ShowIcon(self.zhenqibaogeBtn,self.actId) local d = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySpecialConfig,"Type",self.singleRecruit.MergePool) self.updateTimesTip.text = string.format("召唤%s次必得红色碎片","ff850c",d[1].Count - self.actData.value) local endTime = ActivityGiftManager.GetTaskEndTime(self.actType) - PlayerManager.serverTime self.updateTimesTip1.text = string.format("活动剩余时间:%s",self:TimeToDHMS(endTime)) local timeDown=CalculateSecondsNowTo_N_OClock(0) self.timer = Timer.New(function() if timeDown < 1 then self:RefreshGetHeroTimes() return else self.btnTime.text = TimeToHMS(timeDown).."后刷新" end if endTime < 1 then self.timer:Stop() self.timer = nil self:OnShow(sortingOrder) return else self.updateTimesTip1.text = string.format("活动剩余时间:%s",self:TimeToDHMS(endTime)) end endTime = endTime - 1 timeDown = timeDown - 1 end, 1, -1, true) self.timer:Start() end function TailsmanSoulChipLottery:refreshBtnShow() local curTimes = PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId) self.limit.text ="今日召唤上限:"..curTimes.."/"..privilegeConfig[self.maxtimesId].Condition[1][2] self.btnTime.gameObject:SetActive(false) local freeTime = 0 if self.freeTimesId and self.freeTimesId > 0 then freeTime = PrivilegeManager.GetPrivilegeRemainValue(self.freeTimesId) RecruitManager.freeUseTimeList[self.freeTimesId]=freeTime end --按钮赋值 for n, m in ipairs(self.btns) do --存在免费次数 并且 免费>=1 并且是1按钮 local isFree = freeTime >= 1 and n == 1 m.red.gameObject:SetActive(isFree) m.icon.gameObject:SetActive(not isFree) m.num.gameObject:SetActive(not isFree) local itemId=0 local itemNum=0 local type = 0 if n == 1 then type = self.singleRecruit.Id m.info.text = "1次" else type = self.tenRecruit.Id m.info.text = "10次" end local d = {} if (isFree) then self.btnTime.gameObject:SetActive(false) m.info.text="免费抽取" else local d = RecruitManager.GetExpendData(type) itemId=d[1] itemNum=d[2] m.icon.sprite = self.spLoader:LoadSprite(artConfig[itemConfig[itemId].ResourceID].Name) m.num.text= tostring(itemNum) end Util.AddOnceClick(m.btn,function() if not isFree then if BagManager.GetItemCountById(itemId) < itemNum then PopupTipPanel.ShowTip(itemConfig[itemId].Name.."数量不足!") return end end local recrutId = n == 1 and self.singleRecruit.Id or self.tenRecruit.Id local recrutNum = n == 1 and 1 or 10 local uiName = n == 1 and UIName.QianKunBoxBuyOnePanel or UIName.QianKunBoxBuyTenPanel self:Recruit(recrutNum,recrutId,uiName) end) end end function TailsmanSoulChipLottery:Recruit(recrutType,recrutId,uiName) if PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId)+recrutType>privilegeConfig[self.maxtimesId].Condition[1][2] then PopupTipPanel.ShowTip("无法超出每日召唤次数上限!") return end RecruitManager.RecruitRequest(recrutId, function(msg) PrivilegeManager.RefreshPrivilegeUsedTimes(self.maxtimesId,recrutType)--记录抽卡次数 UIManager.OpenPanel(uiName, msg.drop,recrutId,{RecruitType.QianKunBoxTen,RecruitType.QianKunBoxTen}) CheckRedPointStatus(RedPointType.TailsmanSoulChipLottery) end,self.freeTimesId) end --五个魂印头像 function TailsmanSoulChipLottery:contentShow() wishSoulData = RecruitManager.GetWishTailsManSoulChips() local iconsData = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotteryRewardConfig,"Pool",self.singleRecruit.DiamondBoxContain[1][1]) if wishSoulData and #wishSoulData > 0 then else local li = {} for i = 1,4 do table.insert(li,iconsData[i].Reward[1]) end RecruitManager.SetWishTailsManSoulChips(li) wishSoulData = RecruitManager.GetWishTailsManSoulChips() end --如果没有默认数值,默认的就是表里面的请三个魂印 if wishSoulData and #wishSoulData > 0 then for i = 1, #self.icons do if i <= #wishSoulData then self.icons[i].icon.gameObject:SetActive(true) local id = wishSoulData[i] self.icons[i].icon.sprite = self.spLoader:LoadSprite(artConfig[itemConfig[id].ResourceID].Name) --点击能查看魂印信息 Util.AddOnceClick(self.icons[i].kuang.gameObject,function () UIManager.OpenPanel(UIName.RewardItemSingleShowPopup,id,nil,nil) end) end Util.SetParticleSortLayer(self.icons[i].effect, sortingOrder+1) end end self.upSoulImg.sprite=self.spLoader:LoadSprite(artConfig[itemConfig[wishSoulData[1]].ResourceID].Name) end --- 将一段时间转换为天时分秒 function TailsmanSoulChipLottery:TimeToDHMS(second) local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = math.floor(second % 60) local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) if day <= 0 and hour <= 0 then return string.format("%s分%s秒",minute, sec) else return string.format("%s天%s小时",day, hour) end end --界面关闭时调用(用于子类重写) function TailsmanSoulChipLottery:OnClose() self.gameObject:SetActive(false) if self.timer then self.timer:Stop() self.timer = nil end if self.shopView then SubUIManager.Close(self.shopView) end self.shopView = nil for i = 1, #self.icons do coroutine.stop(self.coroutines[i]) end end --界面销毁时调用(用于子类重写) function TailsmanSoulChipLottery:OnDestroy() self.btns = {} if self.shopView then SubUIManager.Close(self.shopView) end self.shopView = nil end return TailsmanSoulChipLottery