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

530 lines
22 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
SingleRecruitPanel = Inherit(BasePanel)
local this=SingleRecruitPanel
local heroConfigData = ConfigManager.GetConfig(ConfigName.HeroConfig)
local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
local passiveSkillConfig=ConfigManager.GetConfig(ConfigName.PassiveSkillConfig)
local passiveSkillLogicConfig=ConfigManager.GetConfig(ConfigName.PassiveSkillLogicConfig)
local heroRankupConfig=ConfigManager.GetConfig(ConfigName.HeroRankupConfig)
local wishSettingConfig=ConfigManager.GetConfig(ConfigName.WishActivitySetting)
local isFirst=true--是否为第一次进入界面
local timeNum--第一个特效等待播放的时间
local timeNum2--第二个特效等待播放的时间
local timeNum3--第三个特效等待播放的时间
local heroData--展示界面需要的单个英雄数据
local type--抽卡类型
local recruitType={}--前端显示用 抽卡类型
local state --1单抽 2多抽
local index=0 --十连抽索引
local orginLayer
local heroStaticData
local testLiveGO
local maxTimesId--特权id上限今日召唤上限
local _heroTable={} --符合4、5星的英雄容器
local func=nil
this.time = Timer.New()
this.time2 = Timer.New()
this.time3 = Timer.New()
local Sound_Recruit2
local Sound_Recruit3
local Sound_Recruit4
local isJump = 0
--初始化组件(用于子类重写)
function SingleRecruitPanel:InitComponent()
this.spLoader = SpriteLoader.New()
orginLayer = 0
self.live2dRoot = Util.GetGameObject(self.gameObject, "rolePanel/live2dRoot")
self.bg = Util.GetGameObject(self.gameObject, "bg")
screenAdapte(self.bg)
self.heroName = Util.GetGameObject(self.transform, "rolePanel/rolePanel1/Panel/name/heroName"):GetComponent("Text")
self.proImage = Util.GetGameObject(self.transform, "rolePanel/rolePanel1/Panel/name/proImage/proImage/proImage"):GetComponent("Image")
self.starGrid = Util.GetGameObject(self.transform, "rolePanel/rolePanel1/Panel/star")
self.goBtn=Util.GetGameObject(self.transform,"rolePanel/rolePanel2/goBtn")
self.sureBtn = Util.GetGameObject(self.transform, "rolePanel/rolePanel2/sureBtn")
self.againBtn = Util.GetGameObject(self.transform, "rolePanel/rolePanel2/againBtn")
self.againIcon=Util.GetGameObject(self.againBtn,"Tip/juan"):GetComponent("Image")
self.againNum=Util.GetGameObject(self.againBtn,"Tip/Text"):GetComponent("Text")
self.dragView = SubUIManager.Open(SubUIConfig.DragView, self.gameObject.transform)
self.dragView.transform:SetSiblingIndex(1)
this.rolePanel = Util.GetGameObject(self.transform, "rolePanel")
this.jumpPanel = Util.GetGameObject(self.transform, "jumpPanel")
this.UI_Effect_open = Util.GetGameObject(self.transform, "bg/UI_Effect_open") --开门特效
this.UI_Effect_appear = Util.GetGameObject(self.transform, "bg/UI_Effect_appear")
this.UI_Effect_choukaSSR = Util.GetGameObject(self.transform, "bg/UI_Effect_chouka_SSR")
this.UI_Effect_choukaSR = Util.GetGameObject(self.transform, "bg/UI_Effect_chouka_SR")
this.UI_Effect_choukaR = Util.GetGameObject(self.transform, "bg/UI_Effect_chouka_R")
this.jumpBtn = Util.GetGameObject(this.jumpPanel.transform, "btnContinue/jumpBtn")
this.jumpBtnGo = Util.GetGameObject(this.jumpPanel.transform, "btnContinue")
self.posImage=Util.GetGameObject(self.transform,"Pos/PosImage"):GetComponent("Image")
self.posText=Util.GetGameObject(self.transform,"Pos/PosText"):GetComponent("Text")
this.info=Util.GetGameObject(self.gameObject,"rolePanel/rolePanel1/Panel/Info")
this.infoTitleBg=Util.GetGameObject(this.info,"TitleBg")
this.infoTitle=Util.GetGameObject(this.infoTitleBg,"Title"):GetComponent("Text")
this.infoBody=Util.GetGameObject(this.info,"BodyBg/Viewport/Body"):GetComponent("Text")
this.infoBodyGo=Util.GetGameObject(this.info,"BodyBg")
end
--绑定事件(用于子类重写)
function SingleRecruitPanel:BindEvent()
Util.AddClick(self.sureBtn, function()
isFirst=true
if lotterySetting[type] and lotterySetting[type].LotteryType == 11 then
isFirst=false
end
self:ClosePanel()
if PlayerManager.IsGetFiveStarHero then--and OperatingManager.IsShowFiveStarPatch then
Game.GlobalEvent:DispatchEvent(GameEvent.PatFace.PatFaceSend, FacePanelType.GrowGift, 5)
PlayerManager.IsGetFiveStarHero = false
end
end)
Util.AddClick(self.againBtn, function()
if recruitType and recruitType[1]==RecruitType.PrayerSingle then
if func then
self:ClosePanel()
func()
end
return
end
local d=RecruitManager.GetExpendData(type)
if BagManager.GetItemCountById(d[1])<d[2] then
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[d[1]].Name)..Language[10486])
return
end
if PrivilegeManager.GetPrivilegeUsedTimes(maxTimesId)+1>privilegeConfig[maxTimesId].Condition[1][2] then
PopupTipPanel.ShowTip(Language[10485])
return
end
if d[1] == 16 then
if lotterySetting[type].MoneyTimes and lotterySetting[type].MoneyTimes > 0 and PrivilegeManager.GetPrivilegeRemainValue(lotterySetting[type].MoneyTimes) < 1 then
PopupTipPanel.ShowTip(Language[11423])
return
end
end
local recruitOne = function()
RecruitManager.RecruitRequest(type,function(msg)
if d[1] == 16 and lotterySetting[type].MoneyTimes and lotterySetting[type].MoneyTimes > 0 then
PrivilegeManager.RefreshPrivilegeUsedTimes(lotterySetting[type].MoneyTimes,1)--记录妖晶限购抽卡次数
end
PrivilegeManager.RefreshPrivilegeUsedTimes(maxTimesId,1)--记录抽卡次数
for i=1, #msg.drop.Hero do
heroData = msg.drop.Hero[i]
self:UpdataPanelData(heroData)
end
end,maxTimesId)
end
local state = PlayerPrefs.GetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..recruitType[2])
if state==0 and d[1] == 16 then
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.RecruitConfirm,type,recruitOne)
else
recruitOne()
end
end)
Util.AddClick(this.dragView.gameObject, function ()
if not IsNull(testLiveGO) then
local SkeletonGraphic = testLiveGO:GetComponent("SkeletonGraphic")
SkeletonGraphic.AnimationState:SetAnimation(0, "touch", false)
end
end)
--十连跳过按钮 直接打开十连抽展示界面
Util.AddClick(this.jumpBtn, function()
isJump = 1
Game.GlobalEvent:DispatchEvent(GameEvent.UI.OnBtnClicked, self.uiConfig.id,this.jumpBtn.name)
isFirst=true
this.CloseAllTimer()
if state==1 then --单抽
this.UI_Effect_open:SetActive(false)
self:UpdataPanelData(heroData)
--如果不是在强制引导,就,,, by:王振兴 2021/04/15 适配新手引导跳过
if not GuideManager.IsInMainGuide() then
this.goBtn:SetActive(false)
this.againBtn:SetActive(true)
this.sureBtn:SetActive(true)
this.info:SetActive(false)
end
else
-- if lotterySetting[type].LotteryType == 11 then
-- isFirst=false
-- end
isFirst=false
local tempHeroTable = {}
for i = index,#_heroTable do
if heroConfigData[_heroTable[i].heroId].Star == 5 then
table.insert(tempHeroTable,_heroTable[i])
end
end
_heroTable = tempHeroTable
index = 0
if LengthOfTable(_heroTable)>0 then
this.CloseAllTimer()
self:TenOpenPanel()
else
self:ClosePanel()
UIManager.OpenPanel(UIName.TenRecruitPanel,heroData,type,recruitType)
end
-- self:ClosePanel()
-- UIManager.OpenPanel(UIName.TenRecruitPanel,heroData,type,recruitType)
end
this.jumpPanel:SetActive(false)
this.StopPanelSound()
end)
--确定按钮
Util.AddClick(self.goBtn,function()
if recruitType and recruitType[1]==RecruitType.PrayerSingle then
self:ClosePanel()
return
end
if state==1 then
this.goBtn:SetActive(false)
this.againBtn:SetActive(true)
if recruitType and recruitType[1]==RecruitType.PrayerSingle then
this.againBtn:SetActive(false)
end
this.sureBtn:SetActive(true)
this.info:SetActive(false)
elseif state==2 then
if index>=LengthOfTable(_heroTable) then
isFirst=true
if lotterySetting[type] and lotterySetting[type].LotteryType == 11 then
isFirst=false
end
self:ClosePanel()
UIManager.OpenPanel(UIName.TenRecruitPanel,heroData,type,recruitType)
else
self:TenOpenPanel(heroData)
end
end
end)
end
--添加事件监听(用于子类重写)
function SingleRecruitPanel:AddListener()
end
--移除事件监听(用于子类重写)
function SingleRecruitPanel:RemoveListener()
end
function SingleRecruitPanel:OnSortingOrderChange()
Util.AddParticleSortLayer(self.bg, self.sortingOrder - orginLayer)
this.rolePanel:GetComponent("Canvas").sortingOrder = self.sortingOrder + 5
this.jumpPanel:GetComponent("Canvas").sortingOrder = self.sortingOrder + 10
orginLayer = self.sortingOrder
end
--界面打开时调用(用于子类重写)
function SingleRecruitPanel:OnOpen(...)
isJump = 0
this.UI_Effect_open:SetActive(true)
Sound_Recruit4 = SoundManager.PlaySound(SoundConfig.Sound_Recruit4)
this.UI_Effect_choukaSSR:SetActive(false)
this.UI_Effect_choukaSR:SetActive(false)
this.UI_Effect_choukaR:SetActive(false)
this.UI_Effect_appear:SetActive(false)
this.rolePanel:SetActive(false)
this.jumpPanel:SetActive(false)
local data={...}
heroData=data[1]
type=data[2]
state=data[3]
recruitType=data[4]
if not func then
func=data[5]
end
end
function SingleRecruitPanel:OnShow()
isFirst=true
if lotterySetting[type] then
maxTimesId=lotterySetting[type].MaxTimes --特权上限ID
else
local wishConfig=ConfigManager.GetConfigData(ConfigName.WishActivitySetting,1)
if wishConfig then
maxTimesId=wishConfig.MaxTimes
end
end
index=0
if recruitType[1] == RecruitType.XiangYaoSingle or recruitType[1] == RecruitType.XiangYaoTen then
this.jumpPanel:SetActive(false)
else
this.jumpPanel:SetActive(true)
end
if state==1 then --单抽
if lotterySetting[type] and lotterySetting[type].LotteryType == 11 then
isFirst=false
else
local config=ConfigManager.TryGetConfigDataByKey(ConfigName.WishActivityUp,"ActivityId",type)
if config then
isFirst=false
end
end
self:TenOpenPanel()
elseif state==2 then
isFirst=true
if lotterySetting[type] and lotterySetting[type].LotteryType == 11 then
isFirst=false
else
local config=ConfigManager.TryGetConfigDataByKey(ConfigName.WishActivityUp,"ActivityId",type)
if config then
isFirst=false
end
end
_heroTable={}
--将符合条件的英雄插入容器中
for k, v in ipairs(heroData) do
if heroConfigData[v.heroId].Star==4 or heroConfigData[v.heroId].Star==5 then
-- LogBlue(heroConfigData[v.heroId].ReadingName)
table.insert(_heroTable,v)
end
end
-- --LogGreen("符合条件的英雄数量"..LengthOfTable(_heroTable))
self:TenOpenPanel()
end
end
local time--十连抽每次展示特效time
function SingleRecruitPanel:TenOpenPanel()
if isFirst then --第一次进来
this.UI_Effect_open:SetActive(true)
index=1
timeNum3=0
timeNum=1.3
timeNum2=4.3
else--以后每次进来
this.UI_Effect_open:SetActive(false)
index=index+1
timeNum3=2
timeNum=0
timeNum2=0
end
this.CloseAllTimer()
--当单抽 或者是 十连抽第一次的时候
if state==1 or isFirst then
this.rolePanel:SetActive(false)
this.time = Timer.New(function ()
this.UI_Effect_choukaSSR:SetActive(false)
this.UI_Effect_choukaSR:SetActive(false)
this.UI_Effect_choukaR:SetActive(false)
this.UI_Effect_appear:SetActive(true)
Sound_Recruit2 = SoundManager.PlaySound(SoundConfig.Sound_Recruit2)
end, timeNum)
this.time:Start()
this.time3 = Timer.New(function ()
this.UI_Effect_open:SetActive(false)
end, 4)
this.time3:Start()
elseif state==2 then-- 十连抽
timeNum2=0
--this.UI_Effect_choukaSSR:SetActive(false)
--this.UI_Effect_choukaSR:SetActive(false)
--this.UI_Effect_choukaR:SetActive(false)
end
this.time2 = Timer.New(function ()
if state==1 then
self:UpdataPanelData(heroData)
else
if LengthOfTable(_heroTable)>0 then
self:UpdataPanelData(_heroTable[index])
else
self:ClosePanel()
UIManager.OpenPanel(UIName.TenRecruitPanel,heroData,type,recruitType)
end
end
end, timeNum2)
this.time2:Start()
end
function SingleRecruitPanel:UpdataPanelData(_heroData)
--赋值展示界面数据
-- local time2 = Timer.New(function ()
this.CloseAllTimer()
Game.GlobalEvent:DispatchEvent(GameEvent.UI.OnUpdateData, self.uiConfig.id)
this.jumpPanel:SetActive(false)
this.UI_Effect_appear:SetActive(false)
Sound_Recruit3 = SoundManager.PlaySound(SoundConfig.Sound_Recruit3)
if heroStaticData and testLiveGO then
poolManager:UnLoadLive(GetResourcePath(heroStaticData.Live), testLiveGO)
heroStaticData, testLiveGO = nil, nil
end
heroStaticData = heroConfigData[_heroData.heroId]
-- Log("heroStaticData.Live:"..heroStaticData.Live)
--不同星级开启不同特效
this.UI_Effect_choukaSSR:SetActive(heroStaticData.Star == 5)
this.UI_Effect_choukaSR:SetActive(heroStaticData.Star == 4)
this.UI_Effect_choukaR:SetActive(heroStaticData.Star == 3 or heroStaticData.Star == 2 or heroStaticData.Star == 1)
--指定星级开启info
this.info:SetActive(heroStaticData.Star == 5 or heroStaticData.Star == 4)
this.infoBodyGo:SetActive(heroStaticData.Star == 5)
this.infoTitle.text=GetLanguageStrById(heroStaticData.HeroLocationDesc1)
if heroStaticData.Star == 5 then
local t={}
local upStarSkillDataList={} --数据容器
--获取几星激活数据
for i = 1, #heroStaticData.OpenPassiveSkillRules do
if heroStaticData.OpenPassiveSkillRules[i][1] == 2 then
local passiveSkillConfig = passiveSkillConfig[heroStaticData.OpenPassiveSkillRules[i][3]]
if passiveSkillConfig and passiveSkillLogicConfig[passiveSkillConfig.Id].Judge == 1 and string.len(passiveSkillConfig.Desc) > 1 then
local d = {}
d.passiveSkillConfig = passiveSkillConfig
d.OpenPassiveSkillRules = heroStaticData.OpenPassiveSkillRules[i]
d.titleStr = "<size=34><color=#5AC383>"..NumToSimplenessFont[heroRankupConfig[heroStaticData.OpenPassiveSkillRules[i][2]].Phase[2]] .. Language[11718]
table.insert(upStarSkillDataList,d)
end
end
end
--数据插入t
for j = 1, #upStarSkillDataList do
if passiveSkillLogicConfig[upStarSkillDataList[j].passiveSkillConfig.Id].Judge == 1 then
table.insert(t,upStarSkillDataList[j].titleStr..GetLanguageStrById(upStarSkillDataList[j].passiveSkillConfig.Desc).."\n")
end
end
--获取法宝数据
local dTalis = ConfigManager.GetConfigData(ConfigName.HeroConfig,heroStaticData.Id).EquipTalismana--当前法宝数据 data[1]星级 data[2]法宝ID
local dowerAllData= ConfigManager.GetAllConfigsDataByKey(ConfigName.EquipTalismana,"TalismanaId",dTalis[2])--当前法宝全部天赋数据(天赋可能为空)
local dowerData={}--当前法宝全部技能数据(天赋不为空)
for k=1,#dowerAllData do
if dowerAllData[k].OpenSkillRules then
table.insert(dowerData, dowerAllData[k])
end
end
--数据插入t,保证在星数据后
for n=1,#dowerData do
if dowerData[n].Level==25 then
table.insert(t,Language[11719]..GetLanguageStrById(passiveSkillConfig[dowerData[n].OpenSkillRules[1]].Desc).."\n")
end
end
local s=table.concat(t)--将表里字符串拼接
--看这下面 是全角空格哦~
-- this.infoBody.text=string.sub(string.gsub(s," "," "),1,-2)--去除最后\n
this.infoBody.text=string.sub(s,1,-2)--去除最后\n
end
--TODO:动态加载立绘
testLiveGO = poolManager:LoadLive(GetResourcePath(heroStaticData.Live), self.live2dRoot.transform,
Vector3.one * heroStaticData.Scale, Vector3.New(heroStaticData.Position[1],heroStaticData.Position[2],0))
local SkeletonGraphic = testLiveGO:GetComponent("SkeletonGraphic")
local idle = function() SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true) end
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete + idle
poolManager:SetLiveClearCall(GetResourcePath(heroStaticData.Live), testLiveGO, function ()
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete - idle
end)
self.dragView:SetDragGO(testLiveGO)
SetHeroStars(this.spLoader, self.starGrid, _heroData.star,1,Vector2.New(52,52),-2,Vector2.New(0.5,0.5))
-- self.profession.sprite = this.spLoader:LoadSprite(GetJobSpriteStrByJobNum(heroStaticData.Profession))
self.proImage.sprite =this.spLoader:LoadSprite(GetProStrImageByProNum(heroStaticData.PropertyName))
self.heroName.text =GetLanguageStrById(heroStaticData.ReadingName) --string.format("lv.%s", heroData.lv)
Util.GetGameObject(self.transform,"Pos"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetHeroPosBgStr(heroStaticData.Profession))
self.posImage.sprite=this.spLoader:LoadSprite(GetHeroPosStr(heroStaticData.Profession))
self.posText.text=GetLanguageStrById(heroStaticData.HeroLocation)
SetTextVerTial(self.posText.gameObject,Vector3.New(63.76,1.5,0),"MiddleLeft")
local d=nil
if recruitType and recruitType[1]==RecruitType.PrayerSingle then
local num=PrivilegeManager.GetPrivilegeRemainValue(wishSettingConfig[1].DiamondMaxTimes)
d=RecruitManager.GetExpendDataByCostItem(wishSettingConfig[1].CostItemSingle,1,num)
else
d=RecruitManager.GetExpendData(type)
end
self.againIcon.sprite=this.spLoader:LoadSprite(artResourcesConfig[itemConfig[d[1]].ResourceID].Name)
self.againNum.text="×"..d[2]
this.rolePanel:SetActive(true)
PlayUIAnim(self.transform)
isFirst=false
--10连
if state == 2 then
Util.GetGameObject(self.transform, "rolePanel/rolePanel2"):SetActive(true)
this.sureBtn:SetActive(false)
this.againBtn:SetActive(false)
this.goBtn:SetActive(true)
else
this.goBtn:SetActive(heroStaticData.Star == 5 or heroStaticData.Star == 4)
this.sureBtn:SetActive(heroStaticData.Star ~= 5 and heroStaticData.Star ~= 4)
this.againBtn:SetActive(heroStaticData.Star ~= 5 and heroStaticData.Star ~= 4)
if recruitType and recruitType[1]==RecruitType.PrayerSingle then
this.againBtn:SetActive(false)
end
Util.GetGameObject(self.transform, "rolePanel/rolePanel2"):SetActive(true)
if heroStaticData.Quality == 5 and heroStaticData.Natural >= 13 then
HeroManager.DetectionOpenFiveStarActivity(heroStaticData.Star)
end
end
end
function SingleRecruitPanel:OnClose()
_heroTable={}
index=0
this.CloseAllTimer()
if heroStaticData then
poolManager:UnLoadLive(GetResourcePath(heroStaticData.Live), testLiveGO)
end
heroStaticData, testLiveGO = nil, nil
this.StopPanelSound()
end
function this.StopPanelSound()
if Sound_Recruit2 then
SoundManager.StopSound(Sound_Recruit2)
Sound_Recruit2 = nil
end
if Sound_Recruit3 then
SoundManager.StopSound(Sound_Recruit3)
Sound_Recruit3 = nil
end
if Sound_Recruit4 then
SoundManager.StopSound(Sound_Recruit4)
Sound_Recruit4 = nil
end
end
function SingleRecruitPanel:GetProStr(index)
local proStr=""
if index==1 then
proStr=Language[11720]
elseif index==2 then
proStr=Language[11721]
elseif index==3 then
proStr=Language[11722]
elseif index==4 then
proStr=Language[11723]
elseif index==5 then
proStr=Language[11724]
elseif index==6 then
proStr=Language[11725]
end
return proStr
end
function SingleRecruitPanel:OnDestroy()
this.spLoader:Destroy()
if func then
func=nil
end
end
function this.CloseAllTimer()
if this.time then
this.time:Stop()
this.time = nil
end
if this.time2 then
this.time2:Stop()
this.time2 = nil
end
if this.time3 then
this.time3:Stop()
this.time3 = nil
end
end
return SingleRecruitPanel