c1_lua/lua/app/ui/battle/battle_result_ui.lua
2023-04-26 16:01:25 +08:00

128 lines
4.7 KiB
Lua

local BattleResultUI = class("BattleResultUI", BaseUI)
local UNIT_RESULT_RERPORT_CELL = "app/ui/battle/cell/unit_result_report_cell"
function BattleResultUI:getPrefabPath()
return "assets/prefabs/ui/battle/battle_result_ui.prefab"
end
function BattleResultUI:ctor(params)
self.rewards = params.rewards
self.combatReport = params.combatReport
self.totalDmg = 0
if self.combatReport.atkReport then
for _, info in ipairs(self.combatReport.atkReport) do
self.totalDmg = self.totalDmg + info.dmg
end
end
end
function BattleResultUI:onLoadRootComplete()
self:_display()
self:_addListeners()
end
function BattleResultUI:_display()
if self.combatReport.victory then
self:refreshVictoryNode()
AudioManager:playEffect(AudioManager.EFFECT_ID.BATTLE_VICTORY)
else
self:refreshDefeatNode()
AudioManager:playEffect(AudioManager.EFFECT_ID.BATTLE_DEFEAT)
end
self:refreshFixedInfo()
self:refreshRewards()
self:refreshUnitInfo()
end
function BattleResultUI:_addListeners()
local uiMap = self.root:genAllChildren()
uiMap["battle_result_ui.mask_v"]:addClickListener(function()
ModuleManager.BattleManager:endBattleAndExit()
end)
uiMap["battle_result_ui.mask_d"]:addClickListener(function()
ModuleManager.BattleManager:endBattleAndExit()
end)
end
function BattleResultUI:refreshFixedInfo()
local uiMap = self.root:genAllChildren()
local icon = uiMap["battle_result_ui.icon"]
local desc1 = uiMap["battle_result_ui.desc_1"]
local desc2 = uiMap["battle_result_ui.desc_2"]
local desc3 = uiMap["battle_result_ui.desc_3"]
local rewardTitle = uiMap["battle_result_ui.reward_title"]
local continue = uiMap["battle_result_ui.continue"]
desc1:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_4))
desc2:setText(self.combatReport.wave)
desc3:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_7, GFunc.num2Str(self.totalDmg)))
rewardTitle:setText(I18N:getGlobalText(I18N.GlobalConst.REWARD_DESC))
continue:setText(I18N:getGlobalText(I18N.GlobalConst.CONTINUE_DESC))
GFunc.centerImgAndTx(icon, desc2, 7)
end
function BattleResultUI:refreshVictoryNode()
local uiMap = self.root:genAllChildren()
uiMap["battle_result_ui.mask_v"]:setVisible(true)
uiMap["battle_result_ui.mask_d"]:setVisible(false)
uiMap["battle_result_ui.defeat_node"]:setVisible(false)
uiMap["battle_result_ui.victory_node"]:setVisible(true)
uiMap["battle_result_ui.report_img_v"]:setVisible(true)
uiMap["battle_result_ui.report_img_d"]:setVisible(false)
uiMap["battle_result_ui.victory_node.title_bg.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_5))
uiMap["battle_result_ui.victory_node.ui_spine_obj"]:playAnimComplete("born", true, true, function()
uiMap["battle_result_ui.victory_node.ui_spine_obj"]:playAnim("idle", true, true)
end)
end
function BattleResultUI:refreshDefeatNode()
local uiMap = self.root:genAllChildren()
uiMap["battle_result_ui.mask_v"]:setVisible(false)
uiMap["battle_result_ui.mask_d"]:setVisible(true)
uiMap["battle_result_ui.defeat_node"]:setVisible(true)
uiMap["battle_result_ui.victory_node"]:setVisible(false)
uiMap["battle_result_ui.report_img_v"]:setVisible(false)
uiMap["battle_result_ui.report_img_d"]:setVisible(true)
uiMap["battle_result_ui.defeat_node.title_bg.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_6))
uiMap["battle_result_ui.defeat_node.ui_spine_obj"]:playAnim("idle", false, true)
end
function BattleResultUI:refreshRewards()
if self.scrollRect then
self.scrollRect:updateAllCell()
return
end
local uiMap = self.root:genAllChildren()
self.scrollRect = uiMap["battle_result_ui.scroll_rect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
self.scrollRect:addInitCallback(function()
return GConst.TYPEOF_LUA_CLASS.REWARD_CELL
end)
self.scrollRect:addRefreshCallback(function(index, cell)
cell:refresh(self.rewards[index])
end)
self.scrollRect:clearCells()
self.scrollRect:refillCells(#self.rewards)
end
function BattleResultUI:refreshUnitInfo()
local uiMap = self.root:genAllChildren()
if not self.unitResultReportCells then
self.unitResultReportCells = {}
for index = 1, 5 do
self.unitResultReportCells[index] = CellManager:addCellComp(uiMap["battle_result_ui.unit_result_report_cell_" .. index], UNIT_RESULT_RERPORT_CELL)
end
end
for index, cell in ipairs(self.unitResultReportCells) do
local info = self.combatReport.atkReport[index]
cell:getBaseObject():setVisible(info ~= nil)
if info then
cell:refresh(info, self.totalDmg)
end
end
end
return BattleResultUI