require("Base/BasePanel") RecruitPanel = Inherit(BasePanel) local this = RecruitPanel --local preList local i = 0 local canDrag = true local gameSetting = ConfigManager.GetConfig(ConfigName.GameSetting) local AllActSetConfig = ConfigManager.GetConfig(ConfigName.GlobalSystemConfig) local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig) local artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting) local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig) local orginLayer = 0 --抽卡类型 local rType={ Normal=1,--普通 Friend=2,--友情 Hero=3--神将 } --按钮类型 local bType={ Btn1=1, Btn10=2 } --抽卡配置 local preConfigure={ [rType.Normal]={bgAtlas="c_chouka_putong", privilegeId=38, btn={[bType.Btn1]={name="Btn1",isInfo=Language[10644],type=RecruitType.NormalSingle},--按钮配置 若有字段 则显示组件并显示内容 [bType.Btn10]={name="Btn10",isInfo=Language[10645],type=RecruitType.NormalTen} }, }, [rType.Friend]={bgAtlas="c_chouka_youqing", btn={[bType.Btn1]={name="Btn1",isInfo=Language[10644],type=RecruitType.FriendSingle}, [bType.Btn10]={name="Btn10",isInfo=Language[10645],type=RecruitType.FriendTen} }, }, [rType.Hero]={bgAtlas="c_chouka_shenjiang", privilegeId=14, btn={[bType.Btn1]={name="Btn1",isInfo=Language[10644],type=RecruitType.Single}, [bType.Btn10]={name="Btn10",isInfo=Language[10645],type=RecruitType.Ten} }, } } --预设容器 local preList={} --倒计时容器 local timeList={} function RecruitPanel:InitComponent() this.mask=Util.GetGameObject(self.transform,"Bg/Mask") this.backBtn = Util.GetGameObject(self.transform, "BackBtn/Btn") this.upView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft, panelType = PanelType.Recruit }) this.slider = Util.GetGameObject(self.transform, "rewardBox/content/Slider"):GetComponent("Image") this.sliderText = Util.GetGameObject(self.transform, "Text"):GetComponent("Text") this.tenTip = Util.GetGameObject(this.gameObject, "TenTip") this.previewBtn = Util.GetGameObject(this.gameObject, "PreviewBtn") this.UI_effect_RecruitPanel_box_normal = Util.GetGameObject(self.transform, "rewardBox/content/UI_effect_RecruitPanel_box_normal") effectAdapte(Util.GetGameObject(this.UI_effect_RecruitPanel_box_normal, "quan01")) self.UI_effect_RecruitPanel_box_open = Util.GetGameObject(self.transform, "rewardBox/content/UI_effect_RecruitPanel_box_open") effectAdapte(Util.GetGameObject(self.UI_effect_RecruitPanel_box_open, "quan01")) effectAdapte(Util.GetGameObject(self.UI_effect_RecruitPanel_box_open, "quan02")) self.UI_effect_RecruitPanel_particle = Util.GetGameObject(self.transform, "UI_effect_RecruitPanel_particle") this.panel=Util.GetGameObject(this.gameObject,"Panel") this.content=Util.GetGameObject(this.panel,"Content")--抽卡父节点 this.pre=Util.GetGameObject(this.content,"Pre")--抽卡预设 this.boxBtn=Util.GetGameObject(this.gameObject,"rewardBox/content/boxIcon/Btn") this.upper=Util.GetGameObject(this.gameObject,"Upper/Num"):GetComponent("Text")--召唤上限 end function RecruitPanel:BindEvent() Util.AddClick(this.backBtn, function() self:ClosePanel() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) end) --宝箱按钮 Util.AddClick(this.boxBtn,function() UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitBox) Util.GetGameObject(self.transform, "rewardBox/content/boxIcon"):GetComponent("Animator").enabled = false this.UI_effect_RecruitPanel_box_normal:SetActive(true) end) --奖池预览按钮 Util.AddClick(this.previewBtn, function() UIManager.OpenPanel(UIName.HeroPreviewPanel,true) end) end function RecruitPanel:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Recruit.OnRecruitRefreshData, this.UpdatePanelData) end function RecruitPanel:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Recruit.OnRecruitRefreshData, this.UpdatePanelData) end function RecruitPanel:OnSortingOrderChange() Util.AddParticleSortLayer(this.UI_effect_RecruitPanel_box_normal, self.sortingOrder - orginLayer) Util.AddParticleSortLayer(self.UI_effect_RecruitPanel_box_open, self.sortingOrder - orginLayer) Util.AddParticleSortLayer(self.UI_effect_RecruitPanel_particle, self.sortingOrder - orginLayer) orginLayer = self.sortingOrder end function RecruitPanel:OnShow(...) this.upView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Recruit }) this.UpdatePanelData() SoundManager.PlayMusic(SoundConfig.BGM_Recruit) if this.liveNode then poolManager:UnLoadLive("live2d_npc_chouka", this.liveNode) end this.liveNode = poolManager:LoadLive("live2d_npc_chouka", this.mask.transform, Vector3.one *0.45, Vector3.New(253,-586,0)) end function RecruitPanel:OnClose() if this.timer then this.timer:Stop() this.timer = nil end end function RecruitPanel:OnDestroy() SubUIManager.Close(this.upView) preList={} timeList={} if this.liveNode then poolManager:UnLoadLive("live2d_npc_chouka", this.liveNode) end end function this.UpdatePanelData() local maxTimesId=lotterySetting[1].MaxTimes --特权上限ID --初始化组件 for i, v in ipairs(preConfigure) do local o=preList[i] if not o then o=newObjToParent(this.pre,this.content) o.name="Pre"..i preList[i]=o end local bg=Util.GetGameObject(preList[i],"Bg"):GetComponent("Image") local time=Util.GetGameObject(preList[i],"Time"):GetComponent("Text") bg.sprite=Util.LoadSprite(v.bgAtlas) local freeTime= 0 if v.privilegeId then freeTime= PrivilegeManager.GetPrivilegeRemainValue(v.privilegeId) RecruitManager.freeUseTimeList[v.privilegeId]=freeTime--特权免费次数赋值 table.insert(timeList,{timeObj=time}) --将倒计时预设存入 end time.gameObject:SetActive((not freeTime or freeTime<=0) and i~=rType.Friend) --若不存在数据 或没免费次数 显示倒计时 --按钮赋值 for n, m in ipairs(v.btn) do local btn=Util.GetGameObject(o,m.name) local tip=Util.GetGameObject(o,m.name.."/Tip"):GetComponent("Text") local redPot=Util.GetGameObject(o,m.name.."/RedPoint") local info=Util.GetGameObject(o,m.name.."/Content/Info"):GetComponent("Text") local icon=Util.GetGameObject(o,m.name.."/Content/Icon"):GetComponent("Image") local num=Util.GetGameObject(o,m.name.."/Content/Num"):GetComponent("Text") --组件的显示 若上方有配置就显示 没配置不显示 tip.gameObject:SetActive(not not m.isTip) --若不存在m.isTip 返回true not true为false info.gameObject:SetActive(not not m.isInfo) --存在免费次数 并且 免费>=1 并且是1按钮 local isFree=freeTime and freeTime >= 1 and n==bType.Btn1 icon.gameObject:SetActive(not isFree or n==bType.Btn10 or i==rType.Friend) num.gameObject:SetActive(not isFree or n==bType.Btn10 or i==rType.Friend) tip.text= m.isTip and m.isTip or "" info.text= m.isInfo and m.isInfo or "" local itemId=0 local itemNum=0 local d=RecruitManager.GetExpendData(m.type) redPot:SetActive(isFree) if isFree then --若1按钮有免费次数 后面逻辑不走了 info.text=Language[11759] else itemId=d[1] itemNum=d[2] icon.sprite=Util.LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name) num.text= "×"..itemNum end Util.AddOnceClick(btn,function() if not isFree then if BagManager.GetItemCountById(itemId)privilegeConfig[maxTimesId].Condition[1][2] then PopupTipPanel.ShowTip(Language[11760]) return end RecruitManager.RecruitRequest(m.type, function(msg) PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId,1)--记录抽卡次数 UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero[1],m.type,bType.Btn1) end,v.privilegeId) elseif n==bType.Btn10 then if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId)+10>privilegeConfig[maxTimesId].Condition[1][2] then PopupTipPanel.ShowTip(Language[11760]) return end RecruitManager.RecruitRequest(m.type, function(msg) PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId,10)--记录抽卡次数 UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero, m.type,bType.Btn10) end,v.privilegeId) end end) end end this.TimeCountDown() local num=BagManager.GetItemCountById(lotterySetting[RecruitType.RecruitBox].CostItem[1][1]) RecruitManager.isCanOpenBox=num>=lotterySetting[RecruitType.RecruitBox].CostItem[1][2] this.slider.fillAmount =num/lotterySetting[RecruitType.RecruitBox].CostItem[1][2] this.sliderText.text = string.format("%s/%s", num, lotterySetting[RecruitType.RecruitBox].CostItem[1][2]) Util.GetGameObject(this.transform, "rewardBox/content/boxIcon"):GetComponent("Animator").enabled = RecruitManager.isCanOpenBox this.UI_effect_RecruitPanel_box_normal:SetActive(not RecruitManager.isCanOpenBox) this.tenTip:SetActive(RecruitManager.isTenRecruit == 0) this.upper.text=PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId).."/"..privilegeConfig[maxTimesId].Condition[1][2]--特权上限 end function this.TimeCountDown() if this.timer then this.timer:Stop() this.timer = nil end local timeDown=CalculateSecondsNowTo_N_OClock(5) timeList[1].timeObj.text = Language[10028]..TimeToHMS(timeDown) timeList[2].timeObj.text=Language[10028]..TimeToHMS(timeDown) this.timer = Timer.New(function() if timeDown < 1 then this.timer:Stop() this.timer = nil --结束逻辑 return end timeDown = timeDown - 1 timeList[1].timeObj.text = Language[10028]..TimeToHMS(timeDown) timeList[2].timeObj.text=Language[10028]..TimeToHMS(timeDown) end, 1, -1, true) this.timer:Start() end return RecruitPanel