local QianKunBox = {} 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 artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local lotterySpecialConfig = ConfigManager.GetConfig(ConfigName.LotterySpecialConfig) local wishSoulData function QianKunBox:New(gameObject) local b = {} b.gameObject = gameObject b.transform = gameObject.transform setmetatable(b, { __index = QianKunBox }) return b end --初始化组件(用于子类重写) function QianKunBox: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") --midDown self.midDown = Util.GetGameObject(self.gameObject,"midDown") self.midDowntips1 = Util.GetGameObject(self.midDown,"Text"):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.zhenqibaogeBtn:SetActive(false) self.zqbgEffect = Util.GetGameObject(self.zhenqibaogeBtn,"Fx_Circle 1") 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 --center self.center = Util.GetGameObject(self.gameObject,"center") self.icons = {} for i = 1 , 5 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,"icon"):GetComponent("Image") self.icons[i].kuang = Util.GetGameObject(self.icons[i].go,"kuang"):GetComponent("Image") if i<4 then self.icons[i].effect=Util.GetGameObject(self.icons[i].go,"UI_effect_RecruitPanel_box_open") self.icons[i].add=Util.GetGameObject(self.icons[i].go,"Image") end end self.btnTime = Util.GetGameObject(self.gameObject,"di1/time"):GetComponent("Text") self.btnTimes= Util.GetGameObject(self.gameObject,"di2/scroll/grid/time"):GetComponent("Text") self.effect = Util.GetGameObject(self.gameObject, "Effect_UI_changjing_qiankuanbaoguo") -- up soul self.btn_soul = Util.GetGameObject(self.gameObject, "rightUp/btn_hero") self.upSoulImg= Util.GetGameObject(self.gameObject, "rightUp/btn_hero/Icon"):GetComponent("Image") Util.GetGameObject(self.gameObject, "rightUp/btn_hero/InfoImg"):GetComponent("Image").sprite = self.spLoader:LoadSprite("q_qiankun__icondi_ghwj_zh") Util.GetGameObject(self.gameObject, "rightUp/btn_hero/InfoImg2"):GetComponent("Image").sprite = self.spLoader:LoadSprite("x_xinjiangzhaohuan_gailv_zh") end --绑定事件(用于子类重写) function QianKunBox:BindEvent() -- Util.AddOnceClick(self.zhenqibaogeBtn, function() -- JumpManager.GoJump(40011) -- 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.LOTTERY_SOUL_UP,PRE_REWARD_POOL_TYPE.LOTTERY_SOUL) end) Util.AddOnceClick(self.btnStore, function() JumpManager.GoJump(40017) end) Util.AddOnceClick(self.btn_soul, function() local data=RecruitManager.GetWishEquipData() UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.ChooseUpSoul,self.actId,wishSoulData) end) end --添加事件监听(用于子类重写) function QianKunBox:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Activity.TimeLimitUpHeroChange,self.OnUPEquipChange,self) end --移除事件监听(用于子类重写) function QianKunBox:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Activity.TimeLimitUpHeroChange,self.OnUPEquipChange,self) end --up的魂印改变 function QianKunBox:OnUPEquipChange(id) self:contentShow() end --界面打开时调用(用于子类重写) function QianKunBox:OnOpen(_activityConfig,_index,parent) self.actConfig = _activityConfig self.pageIndex = _index self.parent = parent end function QianKunBox:OnSortingOrderChange(_sortingOrder) sortingOrder = _sortingOrder or 0 Util.SetParticleSortLayer(self.effect, sortingOrder+1) 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 QianKunBox:OnShow(_sortingOrder) self.gameObject:SetActive(true) sortingOrder = _sortingOrder Util.SetParticleSortLayer(self.effect, sortingOrder+1) 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:TimeCountDown() end function QianKunBox:refreshMagicNum() local actData = ActivityGiftManager.GetActivityTypeInfo(self.actType) local d = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySpecialConfig,"Type",self.singleRecruit.MergePool) self.midDowntips1.text = string.format("%s%s%s",Language[10495],d[1].Count-math.floor(actData.value/1000),Language[10496]) self.btnTimes.text = string.format("%s次",tostring(d[2].Count - actData.value%1000)).."内必得金色及以上魂印" end function QianKunBox:refreshBtnShow() local curTimes = PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId) self.limit.text ="今日召唤上限:"..curTimes.."/"..privilegeConfig[self.maxtimesId].Condition[1][2] self.btnTime.gameObject:SetActive(true) 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(artResourcesConfig[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 state = PlayerPrefs.GetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.QianKunBoxTen) 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 if state==0 and itemId == 16 and not isFree then UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitConfirm,recrutId,function() self:Recruit(recrutNum,recrutId,uiName) end) else self:Recruit(recrutNum,recrutId,uiName) end end) end end function QianKunBox: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.QianKunBox) end,self.freeTimesId) end --五个魂印头像 function QianKunBox:contentShow() wishSoulData =RecruitManager.GetWishEquipData() local iconsData = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotteryRewardConfig,"Pool",self.singleRecruit.DiamondBoxContain[1][1]) LogRed("lotteryRewardConfig pool=="..self.singleRecruit.DiamondBoxContain[1][1]) local num=1 --如果没有默认数值,默认的就是表里面的请三个魂印 if wishSoulData and #wishSoulData~=0 then for i = 1, 3 do if i<=#wishSoulData then self.icons[i].icon.gameObject:SetActive(true) self.icons[i].kuang.gameObject:SetActive(true) local id=wishSoulData[i] self.icons[i].icon.sprite = self.spLoader:LoadSprite(artConfig[itemConfig[id].ResourceID].Name) self.icons[i].kuang.sprite = self.spLoader:LoadSprite(SoulPrintSpriteByQuantity[itemConfig[wishSoulData[i]].Quantity].circle) --点击能查看魂印信息 Util.AddOnceClick(self.icons[i].kuang.gameObject,function () UIManager.OpenPanel(UIName.SoulPrintPopUp,nil,nil,id,nil,nil) end) else self.icons[i].icon.gameObject:SetActive(false) self.icons[i].kuang.gameObject:SetActive(false) end Util.SetParticleSortLayer(self.icons[i].effect, sortingOrder+1) Util.AddOnceClick(self.icons[i].add.gameObject,function () local data=RecruitManager.GetWishEquipData() UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.ChooseUpSoul,self.actId,wishSoulData) end) end num=4 end for i = num, 5 do self.icons[i].icon.sprite = self.spLoader:LoadSprite(artConfig[itemConfig[iconsData[i].Reward[1]].ResourceID].Name) if i<4 then table.insert(wishSoulData,iconsData[i].Reward[1]) Util.SetParticleSortLayer(self.icons[i].effect, sortingOrder+1) Util.AddOnceClick(self.icons[i].add.gameObject,function () local data=RecruitManager.GetWishEquipData() UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.ChooseUpSoul,self.actId,wishSoulData) end) end self.icons[i].kuang.sprite = self.spLoader:LoadSprite(SoulPrintSpriteByQuantity[itemConfig[iconsData[i].Reward[1]].Quantity].circle) --点击能查看魂印信息 Util.AddOnceClick(self.icons[i].kuang.gameObject,function () UIManager.OpenPanel(UIName.SoulPrintPopUp,nil,nil,iconsData[i].Reward[1],nil,nil) end) end --初始设置库里面前三个为默认数据 if num==1 then RecruitManager.SetAllWishEquipData(wishSoulData) end self.upSoulImg.sprite=self.spLoader:LoadSprite(artConfig[itemConfig[wishSoulData[1]].ResourceID].Name) end --刷新时间 function QianKunBox:TimeCountDown() if self.timer then self.timer:Stop() self.timer = nil end local timeDown=CalculateSecondsNowTo_N_OClock(0) self.btnTime.text = TimeToHMS(timeDown).."后刷新" self.timer = Timer.New(function() self.btnTime.text = TimeToHMS(timeDown).."后刷新" if timeDown < 1 then self:refreshBtnShow() return end timeDown = timeDown - 1 end, 1, -1, true) self.timer:Start() end --- 将一段时间转换为天时分秒 function QianKunBox: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 QianKunBox: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 end --界面销毁时调用(用于子类重写) function QianKunBox:OnDestroy() self.btns = {} if self.shopView then SubUIManager.Close(self.shopView) end self.shopView = nil end return QianKunBox