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 specialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig) 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_zh", privilegeId = 38, btn = { [bType.Btn1] = { name = "Btn1", isInfo = Language[10577], type = RecruitType.NormalSingle }, --按钮配置 若有字段 则显示组件并显示内容 [bType.Btn10] = { name = "Btn10", isInfo = Language[10833], type = RecruitType.NormalTen } }, }, [rType.Friend] = { bgAtlas = "c_chouka_youqing_zh", btn = { [bType.Btn1] = { name = "Btn1", isInfo = Language[10577], type = RecruitType.FriendSingle }, [bType.Btn10] = { name = "Btn10", isInfo = Language[10833], type = RecruitType.FriendTen } }, }, [rType.Hero] = { bgAtlas = "c_chouka_shenjiang_zh", privilegeId = 14, btn = { [bType.Btn1] = { name = "Btn1", isInfo = Language[10577], type = RecruitType.Single }, [bType.Btn10] = { name = "Btn10", isInfo = Language[10833], type = RecruitType.Ten } }, } } --预设容器 local preList = {} --倒计时容器 local timeList = {} function RecruitPanel:InitComponent() this.spLoader = SpriteLoader.New() 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.tenTipText = Util.GetGameObject(this.gameObject, "TenTip/Text"):GetComponent("Text") 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") --召唤上限 this.wishBtn = Util.GetGameObject(this.gameObject, "wishBtn") this.wishBtn:SetActive(false) this.wishImg = Util.GetGameObject(this.wishBtn, "Img") this.wishTextImg = Util.GetGameObject(this.wishBtn, "ImgText") this.wishText = Util.GetGameObject(this.wishTextImg, "Text"):GetComponent("Text") this.helpBtn = Util.GetGameObject(this.gameObject, "helpBtn") this.helpPosition = this.helpBtn:GetComponent("RectTransform").localPosition end function RecruitPanel:BindEvent() Util.AddClick(this.backBtn, function() self:ClosePanel() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) end) --帮助按钮 Util.AddClick(this.helpBtn, function() UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.WishCard, this.helpPosition.x, this.helpPosition.y) 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) --心愿抽卡界面 Util.AddClick(this.wishBtn, function() local data = tonumber(specialConfig[119].Value) if RecruitManager.drawTimes[1] then if RecruitManager.drawTimes[1] >= data then UIManager.OpenPanel(UIName.GeneralBigPopup, GENERAL_POPUP_TYPE.WishDraw) else PopupTipPanel.ShowTip(string.format(Language[12583], data - RecruitManager.drawTimes[1])) end else PopupTipPanel.ShowTip(string.format(Language[12583], data)) end 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() --如果没有达到150抽按钮置灰 local data = tonumber(specialConfig[119].Value) if RecruitManager.drawTimes[1] then if RecruitManager.drawTimes[1] < data then Util.SetGray(this.wishImg, true) this.wishTextImg:SetActive(true) this.wishText.text = string.format("%s/%s", RecruitManager.drawTimes[1], data) else Util.SetGray(this.wishImg, false) this.wishTextImg:SetActive(false) end else this.wishTextImg:SetActive(true) Util.SetGray(this.wishImg, true) this.wishText.text = string.format("%s/%s", 0, data) end 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() this.spLoader:Destroy() 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 = this.spLoader: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) local redPoint = false if v.privilegeId then redPoint = RecruitManager.GetRecruitBtnRedpoint(m.type, v.privilegeId) else redPoint = RecruitManager.GetRecruitBtnRedpoint(m.type) end redPot:SetActive(redPoint) if isFree then --若1按钮有免费次数 后面逻辑不走了 info.text = Language[10588] else itemId = d[1] itemNum = d[2] icon.sprite = this.spLoader:LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name) num.text = "×" .. itemNum end Util.AddOnceClick(btn, function() if not isFree then if BagManager.GetItemCountById(itemId) < d[2] then PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name) .. Language[10584]) return end end local state = PlayerPrefs.GetInt(PlayerManager.uid .. "GeneralPopup_RecruitConfirm" .. RecruitType.Ten) if n == bType.Btn1 then if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId) + 1 > privilegeConfig[maxTimesId].Condition[1][2] then PopupTipPanel.ShowTip(Language[10587]) return end --抽卡 local recruitOne = function() RecruitManager.RecruitRequest(m.type, function(msg) PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId, 1) --记录抽卡次数 UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero[1], m.type, bType.Btn1, { v.btn[bType.Btn1].type, v.btn[bType.Btn10].type }) end, v.privilegeId) end if state == 0 and d[1] == 16 and not isFree then UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitConfirm, RecruitType.Single, recruitOne) else recruitOne() end elseif n == bType.Btn10 then if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId) + 10 > privilegeConfig[maxTimesId].Condition[1][2] then PopupTipPanel.ShowTip(Language[10587]) return end --抽卡 local recruitTen = function() RecruitManager.RecruitRequest(m.type, function(msg) PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId, 10) --记录抽卡次数 UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero, m.type, bType.Btn10, { v.btn[bType.Btn10].type, v.btn[bType.Btn10].type }) if m.type == 11 then RecruitManager.isTenRecruit = 1 end end, v.privilegeId) end if state == 0 and d[1] == 16 and not isFree then UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitConfirm, RecruitType.Ten, recruitTen) else recruitTen() end 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(true) if RecruitManager.isTenRecruit == 0 then this.tenTipText.text = Language[12585] else this.tenTipText.text = string.format(Language[12586], RecruitManager.GetRecruit3MustCount()) end this.upper.text = Language[10596] .. 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(0) timeList[1].timeObj.text = Language[10026] .. TimeToHMS(timeDown) timeList[2].timeObj.text = Language[10026] .. 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[10026] .. TimeToHMS(timeDown) timeList[2].timeObj.text = Language[10026] .. TimeToHMS(timeDown) end, 1, -1, true) this.timer:Start() end return RecruitPanel