抽卡动画添加战令宝箱部分

This commit is contained in:
CloudJ 2023-06-03 22:42:09 +08:00
parent 0fc3edfe24
commit a48651b348
2 changed files with 40 additions and 16 deletions

View File

@ -1,5 +1,19 @@
local BoxOpenUI = class("BoxOpenUI", BaseUI)
local SPINE_OPEN_TIME = 1.4
local DEFAULT_SPINE_NAME = "ui_shop_box_1" -- 默认的展示动画
local SUMMON_SPINE_NAME = {
[1] = "ui_shop_box_1",
[2] = "ui_shop_box_2",
[3] = "ui_shop_box_3",
}
local BOUNTY_SPINE_NAME = {
[8] = "ui_bounty_chestopen_1",
[9] = "ui_bounty_chestopen_2",
[11] = "ui_bounty_chestopen_3",
[18] = "ui_bounty_chestopen_4",
[10] = "ui_bounty_chestopen_5",
}
function BoxOpenUI:ctor(params)
self.params = params or {} -- 将信息传递给下一个界面
@ -18,31 +32,32 @@ end
function BoxOpenUI:onLoadRootComplete()
self.uiMap = self.root:genAllChildren()
self.bg = self.uiMap["box_open_ui.bg"]
self.summonSpineList = {}
for i = 1, 3 do
table.insert(self.summonSpineList, self.uiMap["box_open_ui.ui_spine_obj_" .. i])
self.summonSpineList[i]:setVisible(false)
end
-- 奖励界面打开时 关闭此界面
self:addEventListener(EventManager.CUSTOM_EVENT.CLOSE_BOX_OPEN_UI, function()
self:closeUI()
end)
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CLOSE_BOX_HERO_UI)
-- 播放spine表现 播放完毕后打开奖励UI
local spineObj
self.spineObj = self.uiMap["box_open_ui.ui_spine_obj"]
local spineName
Logger.logHighlight("type:%s index:%s", self.type, self.index)
if self.type == GConst.ShopConst.BOX_REWARD_TYPE.SUMMON then
spineObj = self.summonSpineList[self.index]
spineName = SUMMON_SPINE_NAME[self.index]
elseif self.type == GConst.ShopConst.BOX_REWARD_TYPE.BOUNTY then
-- TODOJ
spineName = BOUNTY_SPINE_NAME[self.index]
end
if not spineObj then
spineObj = self.summonSpineList[1]
if not spineName then
spineName = DEFAULT_SPINE_NAME
end
spineObj:setVisible(true)
spineObj:playAnim("born", false, true)
self:performWithDelayGlobal(function()
ModuleManager.ShopManager:showBoxRewardUI(self.params)
end, SPINE_OPEN_TIME)
self.spineObj:loadAssetAsync(spineName, function()
self.spineObj:playAnim("born", false, true, true)
self.spineObj:getSkeletonGraphic().enabled = true
self:performWithDelayGlobal(function()
ModuleManager.ShopManager:showBoxRewardUI(self.params)
end, SPINE_OPEN_TIME)
end, false)
end
return BoxOpenUI

View File

@ -107,6 +107,7 @@ function BoxRewardUI:onLoadRootComplete()
self.rewardCells = self.rewardCells or {}
local contentTrans = self.scrollRectContent:getTransform()
local alreadyCellCount = contentTrans.childCount - 1
local rewardCount = #self.fragmentRewards
if alreadyCellCount > 0 then
for i = 1, alreadyCellCount do
local prefab = contentTrans:GetChild(i).gameObject
@ -114,10 +115,18 @@ function BoxRewardUI:onLoadRootComplete()
local prefabObject = UIPrefabObject:create()
prefabObject:initWithPrefab(GConst.EMPTY_STRING, prefab)
prefabObject:initPrefabHelper()
-- 设定位置
local index = i
local rowIdx = (index - 1) % CELL_NUM + 1 -- 横排位置 1-4
local cowIdx = (index - 1) // CELL_NUM + 1
if rewardCount <= CELL_NUM then -- 居中展示
prefabObject:setAnchoredPosition(POSITION_X_DATA[rewardCount][rowIdx], 0)
else
prefabObject:setAnchoredPosition(POSITION_X_DATA[4][rowIdx], -(cowIdx - 1) * REWARD_CELL_HEIGHT)
end
table.insert(self.rewardCells, CellManager:addCellComp(prefabObject, BOX_HERO_CELL))
end
end
local rewardCount = #self.fragmentRewards
local cellCount = #self.rewardCells
local needCreateCount = rewardCount - cellCount
-- 将cell扩充至与奖励等数量