miduo_client/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitPanel.lua

331 lines
15 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
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)
2020-05-25 19:16:23 +08:00
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting)
local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
2021-06-30 10:23:57 +08:00
local specialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig)
2020-05-09 13:31:21 +08:00
local orginLayer = 0
2020-05-25 19:16:23 +08:00
--抽卡类型
local rType={
Normal=1,--普通
Friend=2,--友情
Hero=3--神将
}
--按钮类型
local bType={
Btn1=1,
Btn10=2
}
--抽卡配置
local preConfigure={
2021-01-26 17:08:39 +08:00
[rType.Normal]={bgAtlas="c_chouka_putong_zh",
2020-05-25 19:16:23 +08:00
privilegeId=38,
2021-03-02 16:53:12 +08:00
btn={[bType.Btn1]={name="Btn1",isInfo=Language[10478],type=RecruitType.NormalSingle},--按钮配置 若有字段 则显示组件并显示内容
[bType.Btn10]={name="Btn10",isInfo=Language[10647],type=RecruitType.NormalTen}
2020-05-25 19:16:23 +08:00
},
},
2021-01-26 17:08:39 +08:00
[rType.Friend]={bgAtlas="c_chouka_youqing_zh",
2021-03-02 16:53:12 +08:00
btn={[bType.Btn1]={name="Btn1",isInfo=Language[10478],type=RecruitType.FriendSingle},
[bType.Btn10]={name="Btn10",isInfo=Language[10647],type=RecruitType.FriendTen}
2020-05-25 19:16:23 +08:00
},
},
2021-01-26 17:08:39 +08:00
[rType.Hero]={bgAtlas="c_chouka_shenjiang_zh",
2020-05-25 19:16:23 +08:00
privilegeId=14,
2021-03-02 16:53:12 +08:00
btn={[bType.Btn1]={name="Btn1",isInfo=Language[10478],type=RecruitType.Single},
[bType.Btn10]={name="Btn10",isInfo=Language[10647],type=RecruitType.Ten}
2020-05-25 19:16:23 +08:00
},
}
}
--预设容器
local preList={}
--倒计时容器
local timeList={}
2020-05-09 13:31:21 +08:00
function RecruitPanel:InitComponent()
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2020-05-25 19:16:23 +08:00
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")
2020-06-28 17:48:49 +08:00
this.sliderText = Util.GetGameObject(self.transform, "Text"):GetComponent("Text")
2020-05-09 13:31:21 +08:00
2020-05-25 19:16:23 +08:00
this.tenTip = Util.GetGameObject(this.gameObject, "TenTip")
this.tenTipText = Util.GetGameObject(this.gameObject, "TenTip/Text"):GetComponent("Text")
2020-05-25 19:16:23 +08:00
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"))
2020-05-09 13:31:21 +08:00
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")
2020-05-25 19:16:23 +08:00
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")--召唤上限
2021-06-29 11:30:26 +08:00
this.wishBtn = Util.GetGameObject(this.gameObject,"wishBtn")
2022-04-25 11:31:32 +08:00
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")
2021-06-30 13:51:47 +08:00
this.helpBtn = Util.GetGameObject(this.gameObject, "helpBtn")
this.helpPosition = this.helpBtn:GetComponent("RectTransform").localPosition
2020-05-09 13:31:21 +08:00
end
function RecruitPanel:BindEvent()
2020-05-25 19:16:23 +08:00
Util.AddClick(this.backBtn, function()
2020-05-09 13:31:21 +08:00
self:ClosePanel()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
end)
2021-06-30 13:51:47 +08:00
--帮助按钮
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.WishCard,this.helpPosition.x,this.helpPosition.y)
end)
2020-05-25 19:16:23 +08:00
--宝箱按钮
Util.AddClick(this.boxBtn,function()
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitBox)
2020-05-09 13:31:21 +08:00
Util.GetGameObject(self.transform, "rewardBox/content/boxIcon"):GetComponent("Animator").enabled = false
2020-05-25 19:16:23 +08:00
this.UI_effect_RecruitPanel_box_normal:SetActive(true)
2020-05-09 13:31:21 +08:00
end)
2020-05-25 19:16:23 +08:00
--奖池预览按钮
Util.AddClick(this.previewBtn, function()
UIManager.OpenPanel(UIName.HeroPreviewPanel,true)
2021-06-29 11:30:26 +08:00
end)
--心愿抽卡界面
Util.AddClick(this.wishBtn, function()
2021-06-30 10:23:57 +08:00
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
2023-12-07 01:11:27 +08:00
PopupTipPanel.ShowTip(string.format("%s次英雄召唤后开启心愿抽卡",data - RecruitManager.drawTimes[1]))
end
2021-06-30 10:23:57 +08:00
else
2023-12-07 01:11:27 +08:00
PopupTipPanel.ShowTip(string.format("%s次英雄召唤后开启心愿抽卡",data))
2021-06-30 10:23:57 +08:00
end
2020-05-09 13:31:21 +08:00
end)
end
function RecruitPanel:AddListener()
2020-05-25 19:16:23 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Recruit.OnRecruitRefreshData, this.UpdatePanelData)
2020-05-09 13:31:21 +08:00
end
function RecruitPanel:RemoveListener()
2020-05-25 19:16:23 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Recruit.OnRecruitRefreshData, this.UpdatePanelData)
2020-05-09 13:31:21 +08:00
end
function RecruitPanel:OnSortingOrderChange()
2020-05-25 19:16:23 +08:00
Util.AddParticleSortLayer(this.UI_effect_RecruitPanel_box_normal, self.sortingOrder - orginLayer)
2020-05-09 13:31:21 +08:00
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
2020-05-25 19:16:23 +08:00
2020-05-09 13:31:21 +08:00
function RecruitPanel:OnShow(...)
2020-05-25 19:16:23 +08:00
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
2020-05-09 13:31:21 +08:00
SoundManager.PlayMusic(SoundConfig.BGM_Recruit)
2020-05-25 19:16:23 +08:00
if this.liveNode then
poolManager:UnLoadLive("live2d_npc_chouka", this.liveNode)
2020-05-09 13:31:21 +08:00
end
2020-05-25 19:16:23 +08:00
this.liveNode = poolManager:LoadLive("live2d_npc_chouka", this.mask.transform, Vector3.one *0.45, Vector3.New(253,-586,0))
2020-05-09 13:31:21 +08:00
end
2020-05-25 19:16:23 +08:00
function RecruitPanel:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
2020-05-09 13:31:21 +08:00
end
end
2020-05-25 19:16:23 +08:00
function RecruitPanel:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2020-05-25 19:16:23 +08:00
SubUIManager.Close(this.upView)
preList={}
timeList={}
if this.liveNode then
poolManager:UnLoadLive("live2d_npc_chouka", this.liveNode)
2020-05-09 13:31:21 +08:00
end
end
2020-05-25 19:16:23 +08:00
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")
2021-04-21 13:12:04 +08:00
bg.sprite=this.spLoader:LoadSprite(v.bgAtlas)
2020-05-25 19:16:23 +08:00
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)
2021-06-01 19:47:54 +08:00
local redPoint = false
if v.privilegeId then
redPoint = RecruitManager.GetRecruitBtnRedpoint(m.type,v.privilegeId)
else
redPoint = RecruitManager.GetRecruitBtnRedpoint(m.type)
end
redPot:SetActive(redPoint)
2020-05-25 19:16:23 +08:00
if isFree then --若1按钮有免费次数 后面逻辑不走了
2021-03-02 16:53:12 +08:00
info.text=Language[10489]
2020-05-25 19:16:23 +08:00
else
itemId=d[1]
itemNum=d[2]
2021-04-21 13:12:04 +08:00
icon.sprite=this.spLoader:LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
2020-05-25 19:16:23 +08:00
num.text= "×"..itemNum
end
Util.AddOnceClick(btn,function()
if not isFree then
if BagManager.GetItemCountById(itemId)<d[2] then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name)..Language[10486])
2020-05-25 19:16:23 +08:00
return
end
end
2020-07-28 15:24:11 +08:00
local state = PlayerPrefs.GetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.Ten)
2020-05-25 19:16:23 +08:00
if n==bType.Btn1 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId)+1>privilegeConfig[maxTimesId].Condition[1][2] then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[10485])
2020-05-25 19:16:23 +08:00
return
end
2020-07-28 15:24:11 +08:00
--抽卡
local recruitOne = function()
RecruitManager.RecruitRequest(m.type, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId,1)--记录抽卡次数
2021-06-19 15:00:37 +08:00
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero[1],m.type,bType.Btn1,{v.btn[bType.Btn1].type,v.btn[bType.Btn10].type})
2020-07-28 15:24:11 +08:00
end,v.privilegeId)
end
2020-07-28 17:25:50 +08:00
if state==0 and d[1] ==16 and not isFree then
2020-07-28 15:24:11 +08:00
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitConfirm,RecruitType.Single,recruitOne)
else
recruitOne()
end
2020-05-25 19:16:23 +08:00
elseif n==bType.Btn10 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId)+10>privilegeConfig[maxTimesId].Condition[1][2] then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[10485])
2020-05-25 19:16:23 +08:00
return
end
2020-07-28 15:24:11 +08:00
--抽卡
local recruitTen = function()
RecruitManager.RecruitRequest(m.type, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId,10)--记录抽卡次数
2021-06-19 15:00:37 +08:00
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero, m.type,bType.Btn10,{v.btn[bType.Btn10].type,v.btn[bType.Btn10].type})
2020-07-28 15:24:11 +08:00
if m.type == 11 then
RecruitManager.isTenRecruit = 1
end
end,v.privilegeId)
end
2020-07-28 17:25:50 +08:00
if state==0 and d[1] ==16 and not isFree then
2020-07-28 15:24:11 +08:00
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitConfirm,RecruitType.Ten,recruitTen)
else
recruitTen()
end
2020-05-25 19:16:23 +08:00
end
end)
end
end
2020-09-25 14:11:05 +08:00
this.TimeCountDown()
2020-05-25 19:16:23 +08:00
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[11708]
else
2023-12-07 01:11:27 +08:00
this.tenTipText.text = string.format("剩余%s次必得五星英雄",RecruitManager.GetRecruit3MustCount())
end
2021-07-09 14:08:17 +08:00
this.upper.text="今日召唤上限:".. PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId).."/"..privilegeConfig[maxTimesId].Condition[1][2]--特权上限
2020-05-09 13:31:21 +08:00
end
2020-05-25 19:16:23 +08:00
function this.TimeCountDown()
if this.timer then
this.timer:Stop()
this.timer = nil
end
local timeDown=CalculateSecondsNowTo_N_OClock(0)
2021-03-02 16:53:12 +08:00
timeList[1].timeObj.text = Language[10023]..TimeToHMS(timeDown)
timeList[2].timeObj.text=Language[10023]..TimeToHMS(timeDown)
2020-05-25 19:16:23 +08:00
this.timer = Timer.New(function()
if timeDown < 1 then
this.timer:Stop()
this.timer = nil
--结束逻辑
2020-05-09 13:31:21 +08:00
2020-05-25 19:16:23 +08:00
return
end
timeDown = timeDown - 1
2021-03-02 16:53:12 +08:00
timeList[1].timeObj.text = Language[10023]..TimeToHMS(timeDown)
timeList[2].timeObj.text=Language[10023]..TimeToHMS(timeDown)
2020-05-25 19:16:23 +08:00
end, 1, -1, true)
this.timer:Start()
2020-05-09 13:31:21 +08:00
end
2020-06-23 18:36:24 +08:00
return RecruitPanel