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.combatReport = { -- battleType = GConst.BattleConst.BATTLE_TYPE.STAGE, -- victory = false, -- wave = 3, -- atkReport = { -- { -- heroId = 12001, -- dmg = 237800, -- }, -- { -- heroId = 12001, -- dmg = 23700, -- } -- } -- } 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() local uiMap = self.root:genAllChildren() if self.combatReport.victory then self:refreshVictoryNode() else self:refreshDefeatNode() 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"]:setActive(true) uiMap["battle_result_ui.mask_d"]:setActive(false) uiMap["battle_result_ui.defeat_node"]:setActive(false) uiMap["battle_result_ui.victory_node"]:setActive(true) uiMap["battle_result_ui.victory_node.title_bg.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_6)) end function BattleResultUI:refreshDefeatNode() local uiMap = self.root:genAllChildren() uiMap["battle_result_ui.mask_v"]:setActive(true) uiMap["battle_result_ui.mask_d"]:setActive(false) uiMap["battle_result_ui.defeat_node"]:setActive(true) uiMap["battle_result_ui.victory_node"]:setActive(false) uiMap["battle_result_ui.defeat_node.title_bg.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_6)) 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:refreshByConfig(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