miduo_client/Assets/ManagedResources/~Lua/Modules/Popup/View/GeneralPopup_LingShouBaoGe.lua

139 lines
4.2 KiB
Lua

----- 灵兽宝阁选择神兽 -----
local this = {}
--传入父脚本模块
local parent
--传入特效层级
local SpiritAnimalSummonConfig = ConfigManager.GetConfig(ConfigName.SpiritAnimalSummon)
local sortingOrder = 0
local itemsGrid = {} --item重复利用
local itemViewGrid = {}
local itemGoGrid = {}
local ActData = nil
local curMonsterId = nil
local oldMonsterId = nil
local curIndex = nil
function this:InitComponent(gameObject)
this.spLoader = SpriteLoader.New()
this.titleText = Util.GetGameObject(gameObject, "TitleText"):GetComponent("Text")
this.tip = Util.GetGameObject(gameObject, "tip"):GetComponent("Text")
this.root = Util.GetGameObject(gameObject, "Root")
this.itemPre = Util.GetGameObject(gameObject, "itemPre")
this.confirm = Util.GetGameObject(gameObject, "ConfirmBtn")
this.cancel = Util.GetGameObject(gameObject, "CancelBtn")
end
function this:BindEvent()
Util.AddClick(this.confirm, function()
if curMonsterId == oldMonsterId then
parent:ClosePanel()
return
end
NetManager.ChengeMonsterChooseRequest(ActData.activityId, curMonsterId, function()
local selectId = ConfigManager.GetConfigDataByDoubleKey(ConfigName.SpiritAnimalSummon, "ActivityID",
ActData.activityId, "FocusID", curMonsterId).Id
ActivityGiftManager.ChangeLingShouBaoGeSelectId(ActData.activityId, selectId)
Game.GlobalEvent:DispatchEvent(GameEvent.Activity.UpMonsterChange)
parent:ClosePanel()
end)
end)
Util.AddClick(this.cancel, function()
parent:ClosePanel()
end)
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:OnShow(_parent, ...)
parent = _parent
sortingOrder = _parent.sortingOrder
--不定参中包含的不定参 _args[1]为面板类型 _args[2]之后(包括)为打开面板后传入的不定参
local _args = { ... }
ActData = _args[1]
oldMonsterId = _args[2]
curMonsterId = _args[2]
this.titleText.text = Language[12327]
this.tip.text = Language[12328]
local monsterData = ConfigManager.GetAllConfigsDataByKey(ConfigName.SpiritAnimalSummon, "ActivityID",
ActData.activityId)
if not itemsGrid then
itemsGrid = {}
itemViewGrid = {}
itemGoGrid = {}
end
for k, v in ipairs(itemsGrid) do
v.gameObject:SetActive(false)
end
for k, v in ipairs(itemViewGrid) do
v.gameObject:SetActive(false)
end
for i = 1, #monsterData do
local item = itemsGrid[i]
if not item then
item = newObject(this.itemPre)
item.name = "itemPre_" .. i
item.transform:SetParent(this.root.transform)
item.transform.localScale = Vector3.one
item.transform.localPosition = Vector3.zero
itemsGrid[i] = item
end
item.gameObject:SetActive(true)
this:SetSingleMonster(item, i, monsterData[i])
end
end
function this:SetSingleMonster(item, i, data)
local icon = Util.GetGameObject(item, "icon")
local btn = Util.GetGameObject(item, "btn")
local btnGo = Util.GetGameObject(item, "btn/Go")
itemGoGrid[i] = btnGo
if not itemViewGrid[i] then
itemViewGrid[i] = SubUIManager.Open(SubUIConfig.ItemView, icon.transform)
end
itemViewGrid[i].gameObject:SetActive(true)
itemViewGrid[i]:OnOpen(false, { data.FocusID, 0 }, 1, false, false, false, sortingOrder)
if curMonsterId == data.FocusID then
btnGo:SetActive(true)
curIndex = i
else
btnGo:SetActive(false)
end
Util.AddOnceClick(btn, function()
for i = 1, #itemGoGrid do
if itemGoGrid[i].activeSelf then
itemGoGrid[i]:SetActive(false)
end
end
curIndex = i
curMonsterId = data.FocusID
btnGo:SetActive(true)
end)
LogYellow("data.FocusID:" .. tostring(data.FocusID))
Util.AddLongPressClick(btn, function()
itemViewGrid[i]:OnBtnCkickEvent(data.FocusID)
end, 0.5)
end
function this:OnClose()
end
function this:OnDestroy()
this.spLoader:Destroy()
itemsGrid = {} --item重复利用
itemViewGrid = {}
itemGoGrid = {}
sortingOrder = 0
end
return this