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

310 lines
14 KiB
Lua

ElementDrawCardPanelNew = {}
local isPlayAnim = true
local isSubPlayAnim = true
function ElementDrawCardPanelNew:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = ElementDrawCardPanelNew })
return b
end
local Pos = {
[1] = { ori = Vector3.New(0, 277, 0), tar = Vector3.New(-0, -174.83, 0), },
[2] = { ori = Vector3.New(0, -186.4, 0), tar = Vector3.New(-0, -186.4, 0), },
[3] = { ori = Vector3.New(0, -256.2, 0), tar = Vector3.New(-0, -256.2, 0), },
[4] = { ori = Vector3.New(0, 371.8, 0), tar = Vector3.New(-0, -205, 0), },
}
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
function ElementDrawCardPanelNew:InitComponent()
self.spLoader = SpriteLoader.New()
self.getCardPanel = Util.GetGameObject(self.transform, "getCardPanel")
self.getCardPanel.gameObject:SetActive(false)
self.getCardPanelCanvas = self.getCardPanel:GetComponent("Canvas")
self.root = Util.GetGameObject(self.getCardPanel, "root")
self.content2 = Util.GetGameObject(self.getCardPanel, "content2")
self.buyOneBtn = Util.GetGameObject(self.getCardPanel, "content2/btn1")
self.content1 = Util.GetGameObject(self.getCardPanel, "content1")
self.content3 = Util.GetGameObject(self.getCardPanel, "content3")
self.buyTenBtn = Util.GetGameObject(self.getCardPanel, "content3/btn1")
self.titleImageText = Util.GetGameObject(self.getCardPanel, "content1/titleImage/Text"):GetComponent("Text")
self.Image2Text = Util.GetGameObject(self.getCardPanel, "content1/Image/Image2/Text"):GetComponent("Text")
self.Image3 = Util.GetGameObject(self.getCardPanel, "content1/Image/Image3"):GetComponent("Image")
self.detailText1 = Util.GetGameObject(self.getCardPanel, "content1/Image2/detailText1"):GetComponent("Text")
self.detailText2 = Util.GetGameObject(self.getCardPanel, "content1/Image2/detailText2"):GetComponent("Text")
self.btnBack = Util.GetGameObject(self.getCardPanel, "btnBack")
self.itemPosCom = Util.GetGameObject(self.transform, "enterCardPanel/itemPos"):GetComponent("HorizontalLayoutGroup")
self.itemPos = {}
for i = 1, 4 do
self.itemPos[i] = {}
self.itemPos[i].pos = Util.GetGameObject(self.transform, "enterCardPanel/itemPos/itemPre" .. i)
self.itemPos[i].btn = Util.GetGameObject(self.itemPos[i].pos, "Button")
self.itemPos[i].codeLayer = Util.GetGameObject(self.itemPos[i].pos, "Image"):GetComponent("Canvas")
self.itemPos[i].effect = Util.GetGameObject(self.itemPos[i].pos, "effect")
end
self.effect = Util.GetGameObject(self.transform, "effect")
self.UI_effect_RecruitPanel_particle = Util.GetGameObject(self.effect, "UI_effect_RecruitPanel_particle")
self.fx_shiyuanzheng_diban = Util.GetGameObject(self.transform, "fx_shiyuanzheng_diban")
self.qianghua = Util.GetGameObject(self.effect, "qianghua")
self.bgImage = Util.GetGameObject(self.transform, "bgImage")
self.previewBtn = Util.GetGameObject(self.transform, "enterCardPanel/previewBtn")
self.shopBtn = Util.GetGameObject(self.transform, "enterCardPanel/shopBtn")
self.helpBtn = Util.GetGameObject(self.transform, "enterCardPanel/helpBtn")
self.exchangeBtn = Util.GetGameObject(self.transform, "enterCardPanel/exchangeBtn")
screenAdapte(self.bgImage)
self.liveNode = nil
end
--绑定事件(用于子类重写)
function ElementDrawCardPanelNew:BindEvent()
Util.AddClick(self.buyOneBtn, function()
local index = self.index > 0 and self.index or RecruitManager.recruitSubIndex
local singleConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.LotterySetting, "LotteryType",
TableRecruitType.Siyuanzhen, "PropertyType", self.index, "PerCount", 1)
local costnum = singleConfig.CostItem[1][2]
local costId = singleConfig.CostItem[1][1]
if BagManager.GetItemCountById(costId) < costnum then
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[costId].Name) .. Language[10584])
return
end
RecruitManager.RecruitRequest(singleConfig.Id, function(msg)
UIManager.OpenPanel(UIName.SecretBoxBuyOnePanel, msg.drop, singleConfig.Id)
Game.GlobalEvent:DispatchEvent(GameEvent.Bag.BagGold)
end)
end)
Util.AddClick(self.buyTenBtn, function()
local index = self.index > 0 and self.index or RecruitManager.recruitSubIndex
local tenConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.LotterySetting, "LotteryType",
TableRecruitType.Siyuanzhen, "PropertyType", self.index, "PerCount", 10)
local costnum = tenConfig.CostItem[1][2]
local costId = tenConfig.CostItem[1][1]
if BagManager.GetItemCountById(costId) < costnum then
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[costId].Name) .. Language[10584])
return
end
RecruitManager.RecruitRequest(tenConfig.Id, function(msg)
UIManager.OpenPanel(UIName.SecretBoxBuyTenPanel, msg.drop, tenConfig.Id)
Game.GlobalEvent:DispatchEvent(GameEvent.Bag.BagGold)
end)
end)
Util.AddClick(self.btnBack, function()
if self.liveNode then
poolManager:UnLoadLive(self.liveNode.name, self.liveNode)
self.liveNode = nil
end
self.getCardPanel:SetActive(false)
self.parent.AddTrigger()
self.qianghua:SetActive(false)
self.UI_effect_RecruitPanel_particle:SetActive(true)
SoundManager.PlayMusic(SoundConfig.BGM_Main)
RecruitManager.recruitSubIndex = 0
self.parent.tabbox.gameObject:SetActive(true)
self.parent.btnBack.gameObject:SetActive(true)
isSubPlayAnim = true
end)
Util.AddClick(self.previewBtn, function()
UIManager.OpenPanel(UIName.HeroPreviewPanel, false)
end)
Util.AddClick(self.shopBtn, function()
JumpManager.GoJump(20008)
end)
Util.AddClick(self.helpBtn, function()
local pos = self.helpBtn.transform.localPosition
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.ElementDraw, pos.x, pos.y)
end)
Util.AddClick(self.exchangeBtn, function()
UIManager.OpenPanel(UIName.CompoundHeroPanel, 2)
end)
for i = 1, #self.itemPos do
Util.AddClick(self.itemPos[i].btn, function()
self.index = i
RecruitManager.recruitSubIndex = i
self:BtnAction(i)
end)
end
end
function ElementDrawCardPanelNew:BtnAction(index)
--LogGreen("index:"..index)
if not index or index < 1 or index > 4 then
return
end
self.parent.btnBack.gameObject:SetActive(false)
self.parent.tabbox.gameObject:SetActive(false)
if self.liveNode then
poolManager:UnLoadLive(self.liveNode.name, self.liveNode)
self.liveNode = nil
end
--Vector3.one *heroConfig.Scale
self.root.gameObject:SetActive(false)
local heroConfig
local SkeletonGraphic
if self.config.ShopData[2][index] and self.config.ShopData[2][index] > 0 then
heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, self.config.ShopData[2][index])
local name = GetResourcePath(heroConfig.Live)
self.liveNode = poolManager:LoadLive(name, self.root.transform, Vector3.one * heroConfig.Scale,
Vector3.New(heroConfig.Position[1], heroConfig.Position[2], 0))
self.liveNode.name = name
SkeletonGraphic = self.liveNode:GetComponent("SkeletonGraphic")
SetHEeroLiveToward(self.liveNode, heroConfig.Toward)
local idle = function() SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true) end
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete + idle
poolManager:SetLiveClearCall(name, self.liveNode, function()
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete - idle
end)
end
self.getCardPanel.gameObject:SetActive(true)
if isSubPlayAnim then
self.content1.gameObject:SetActive(false)
self.content2.gameObject:SetActive(false)
self.content3.gameObject:SetActive(false)
LogGreen("开始播放人物动画")
self.liveNode.gameObject.transform:DOScale(Vector3.zero, 0)
self.root.gameObject:SetActive(true)
self.liveNode.gameObject.transform:DOScale(Vector3.one * heroConfig.Scale, 0.3):SetEase(Ease.Linear):OnStart(function()
self.root.gameObject.transform:DOLocalMove(Pos[index].ori, 0)
self.root.gameObject.transform:DOLocalMove(Pos[index].tar, 0.3, false):SetEase(Ease.Linear):OnStart(function() end)
:OnUpdate(function() --TODO:测试速度
end):OnComplete(function()
end)
-- SkeletonGraphic:DOColor(Color.New(1,1,1,0),0)
-- SkeletonGraphic:DOColor(Color.New(1,1,1,1),0.5):SetEase(Ease.Linear):OnStart(function() end):OnUpdate(function() --TODO:测试速度
-- end):OnComplete(function ()
-- end)
end):OnUpdate(function() --TODO:测试速度
end):OnComplete(function()
end)
Timer.New(function()
self.content1.gameObject:SetActive(true)
self.content2.gameObject:SetActive(true)
self.content3.gameObject:SetActive(true)
PlayUIAnim(self.getCardPanel)
end, 0.2):Start()
isSubPlayAnim = false
else
self.root.gameObject:SetActive(true)
end
self.parent.RemoveTrigger()
self.qianghua:SetActive(true)
self.UI_effect_RecruitPanel_particle:SetActive(false)
self.Image2Text.text = string.format(Language[12574], PropertyType[index])
SetTextVerTial(self.Image2Text, Vector3.New(134.88, -5.9, 0), "MiddleLeft")
self.Image3.sprite = self.spLoader:LoadSprite(PropertyTypeImageBySiYuan[index].image3)
self.titleImageText.text = string.format(Language[12575], PropertyTypeImageBySiYuan[index].property)
self.detailText1.text = string.format(Language[12576], PropertyType[index])
end
--添加事件监听(用于子类重写)
function ElementDrawCardPanelNew:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.SecretBox.OnOpenOneReward, self.OpenOneRewardPanel)
Game.GlobalEvent:AddEvent(GameEvent.SecretBox.OnOpenTenReward, self.OpenTenRewardPanel)
end
--移除事件监听(用于子类重写)
function ElementDrawCardPanelNew:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.SecretBox.OnOpenOneReward, self.OpenOneRewardPanel)
Game.GlobalEvent:RemoveEvent(GameEvent.SecretBox.OnOpenTenReward, self.OpenTenRewardPanel)
end
function ElementDrawCardPanelNew.OpenOneRewardPanel(drop)
UIManager.OpenPanel(UIName.SecretBoxBuyOnePanel, drop)
end
function ElementDrawCardPanelNew.OpenTenRewardPanel(drop)
UIManager.OpenPanel(UIName.SecretBoxBuyTenPanel, drop)
end
function ElementDrawCardPanelNew:OnSortingOrderChange(sortingOrder)
self.sortingOrder = sortingOrder
Util.SetParticleSortLayer(self.UI_effect_RecruitPanel_particle, self.sortingOrder + 1)
Util.SetParticleSortLayer(self.qianghua, self.sortingOrder + 4)
Util.SetParticleSortLayer(self.fx_shiyuanzheng_diban, self.sortingOrder + 1)
self.getCardPanelCanvas.overrideSorting = true
self.getCardPanelCanvas.sortingOrder = self.sortingOrder + 3
for i = 1, 4 do
self.itemPos[i].codeLayer.overrideSorting = true
self.itemPos[i].codeLayer.sortingOrder = self.sortingOrder + 2
Util.SetParticleSortLayer(self.itemPos[i].effect, self.sortingOrder + 1)
end
end
--界面打开时调用(用于子类重写)
function ElementDrawCardPanelNew:OnOpen(_Config, _index, parent)
self.config = _Config
self.parent = parent
isPlayAnim = true
isSubPlayAnim = true
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function ElementDrawCardPanelNew:OnShow(orginLayer)
self.sortingOrder = orginLayer
self.gameObject:SetActive(true)
self.qianghua:SetActive(false)
self.UI_effect_RecruitPanel_particle:SetActive(true)
self.index = RecruitManager.recruitSubIndex
self:BtnAction(self.index)
self.parent.mask2.sprite = self.spLoader:LoadSprite(self.config.Icon[3])
self.parent.mask1.sprite = self.spLoader:LoadSprite(self.config.Icon[3])
Util.SetParticleSortLayer(self.UI_effect_RecruitPanel_particle, self.sortingOrder + 1)
Util.SetParticleSortLayer(self.fx_shiyuanzheng_diban, self.sortingOrder + 1)
Util.SetParticleSortLayer(self.qianghua, self.sortingOrder + 4)
self.getCardPanelCanvas.overrideSorting = true
self.getCardPanelCanvas.sortingOrder = self.sortingOrder + 3
for i = 1, 4 do
self.itemPos[i].codeLayer.overrideSorting = true
self.itemPos[i].codeLayer.sortingOrder = self.sortingOrder + 2
Util.SetParticleSortLayer(self.itemPos[i].effect, self.sortingOrder + 1)
end
self.itemPosCom.enabled = true
ForceRebuildLayout(self.itemPosCom.transform)
-- self.itemPosCom.enabled = false
-- if isPlayAnim then
-- isPlayAnim = false
-- local anims = self.gameObject:GetComponentsInChildren(typeof(PlayFlyAnim))
-- if anims.Length > 0 then
-- for i = 0, anims.Length - 1 do
-- local anim = anims[i]
-- if anim.isPlayOnOpen then
-- anim:PlayAnim(false,function()
-- self.itemPosCom.enabled = true
-- end)
-- end
-- end
-- end
-- end
-- Timer.New(function()
-- self.itemPosCom.enabled = true
-- end,0.5):Start()
end
--界面关闭时调用(用于子类重写)
function ElementDrawCardPanelNew:OnClose()
isPlayAnim = true
isSubPlayAnim = true
self.gameObject:SetActive(false)
if self.liveNode then
poolManager:UnLoadLive(self.liveNode.name, self.liveNode)
self.liveNode = nil
end
end
--界面销毁时调用(用于子类重写)
function ElementDrawCardPanelNew:OnDestroy()
self.spLoader:Destroy()
end
return ElementDrawCardPanelNew