local BattleResultUI = class("BattleResultUI", BaseUI) local UNIT_RESULT_RERPORT_CELL = "app/ui/battle/cell/unit_result_report_cell" local MAX_SCROLL_SHOW_COUNT = 10 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.mysteryBoxIdx = params.mysteryBoxIdx or 0 self.battleType = params.battleType self.isTryShowGoldPig = false 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:onClose() if self.sliderSequence then self.sliderSequence:Kill() end if self.animUnit then self.animUnit:Kill() end if self.animPig then self.animPig:Kill() end if self.animRewards then for idx, anim in pairs(self.animRewards) do if anim then anim:Kill() end 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() self:initGoldPig() end function BattleResultUI:_addListeners() local uiMap = self.root:genAllChildren() uiMap["battle_result_ui.mask_v"]:addClickListener(function() if self.isTryShowGoldPig then ModuleManager.BattleManager:endBattleAndExit() else if not self:tryShowGoldPig() then ModuleManager.BattleManager:endBattleAndExit() end end end) uiMap["battle_result_ui.mask_d"]:addClickListener(function() if self.isTryShowGoldPig then ModuleManager.BattleManager:endBattleAndExit() else if not self:tryShowGoldPig() then ModuleManager.BattleManager:endBattleAndExit() end end end) end function BattleResultUI:refreshFixedInfo() local uiMap = self.root:genAllChildren() local icon = uiMap["battle_result_ui.unit_node.icon"] local desc1 = uiMap["battle_result_ui.unit_node.desc_1"] local desc2 = uiMap["battle_result_ui.unit_node.desc_2"] local desc3 = uiMap["battle_result_ui.unit_node.desc_3"] local rewardTitle = uiMap["battle_result_ui.reward_node.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.victory_node.unit_node.report_img_v"]:setVisible(true) uiMap["battle_result_ui.defeat_node.unit_node.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", false, true, function() uiMap["battle_result_ui.victory_node.ui_spine_obj"]:playAnim("idle", true, true) end) self:refreshUnitNodeAnim(uiMap["battle_result_ui.victory_node.unit_node"]) 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.victory_node.unit_node.report_img_v"]:setVisible(false) uiMap["battle_result_ui.defeat_node.unit_node.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"]:playAnimComplete("born", false, true, function() uiMap["battle_result_ui.defeat_node.ui_spine_obj"]:playAnim("idle", true, true) end) self:refreshUnitNodeAnim(uiMap["battle_result_ui.defeat_node.unit_node"]) end function BattleResultUI:refreshUnitNodeAnim(parent) local uiMap = self.root:genAllChildren() uiMap["battle_result_ui.unit_node"]:setParent(parent, true) local canvasNodeUnit = parent:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP) self.animUnit = self.root:createBindTweenSequence() self.animUnit:Insert(0, canvasNodeUnit:DOFade(0, 0)) self.animUnit:Insert(0.1, canvasNodeUnit:DOFade(1, 0)) self.animUnit:Insert(0, parent:getTransform():DOScale(0, 0)) self.animUnit:Insert(0.1, parent:getTransform():DOScale(0.35, 0)) self.animUnit:Insert(0.13, parent:getTransform():DOScale(1.1, 0.16)) self.animUnit:Insert(0.26, parent:getTransform():DOScale(1, 0.14)) self.animUnit:OnComplete(function() self.animUnit = nil end) end function BattleResultUI:refreshRewards() if self.scrollRectComp then self.scrollRectComp:updateAllCell() return end self.animRewards = {} local uiMap = self.root:genAllChildren() self.rewardNode = uiMap["battle_result_ui.reward_node"] self.rewardNode:setVisible(true) local scrollRect = uiMap["battle_result_ui.reward_node.scroll_rect"] self.scrollRectComp = scrollRect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) self.scrollRectComp:addInitCallback(function() return GConst.TYPEOF_LUA_CLASS.REWARD_CELL end) self.scrollRectComp:addRefreshCallback(function(index, cell) cell:refresh(self.rewards[index]) if index <= MAX_SCROLL_SHOW_COUNT and self.animRewards[index] == nil then self.animRewards[index] = self:showRewardAppearAnim(index, cell) end cell:showRightUpIcon(index <= self.mysteryBoxIdx, GConst.ATLAS_PATH.COMMON, "common_chest_1") end) self.scrollRectComp:setFadeArgs(0.05, 0.3) self.scrollRectComp:clearCells() local rewardCount = #self.rewards if rewardCount > MAX_SCROLL_SHOW_COUNT then local comp = scrollRect:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_SCROLL_RECT) comp.movementType = CS.UnityEngine.UI.ScrollRect.MovementType.Elastic self.scrollRectComp:setPerLineNum(5) scrollRect:setSizeDeltaX(560) else local comp = scrollRect:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_SCROLL_RECT) comp.movementType = CS.UnityEngine.UI.ScrollRect.MovementType.Clamped if rewardCount >= 5 then self.scrollRectComp:setPerLineNum(5) scrollRect:setSizeDeltaX(560) elseif rewardCount <= 0 then self.scrollRectComp:setPerLineNum(1) scrollRect:setSizeDeltaX(560) else self.scrollRectComp:setPerLineNum(rewardCount) scrollRect:setSizeDeltaX(112*rewardCount) end end self.scrollRectComp:refillCells(rewardCount) 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_node.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 function BattleResultUI:initGoldPig() local uiMap = self.root:genAllChildren() self.goldPigRoot = uiMap["battle_result_ui.gold_pig"] self.goldPigRoot:setVisible(false) self.goldPigGem = uiMap["battle_result_ui.gold_pig.gem_bg"] self.goldPigGemTx = uiMap["battle_result_ui.gold_pig.gem_bg.gem_tx"] self.goldPigGemImg = uiMap["battle_result_ui.gold_pig.gem_bg.gem_img"] self.goldPigGemSliderComp = uiMap["battle_result_ui.gold_pig.slider_bg.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) self.goldPigGemSliderTx = uiMap["battle_result_ui.gold_pig.slider_bg.text"] self.goldPigSpine = uiMap["battle_result_ui.gold_pig.spine_pig"] self.canvasGroupPigGem = self.goldPigGem:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP) end function BattleResultUI:tryShowGoldPig() self.isTryShowGoldPig = true if self.battleType ~= GConst.BattleConst.BATTLE_TYPE.STAGE then return false end if not DataManager.GoldPigData:getIsOpen() then return false end self.rewardNode:setVisible(false) self.goldPigRoot:setVisible(true) local lastGemCount = DataManager.GoldPigData:getLastCount() local currGemCount = DataManager.GoldPigData:getCount() local maxGemCount = DataManager.GoldPigData:getMaxCount() if lastGemCount > currGemCount then lastGemCount = currGemCount end self.animPig = self.root:createBindTweenSequence() self.animPig:Insert(0, self.canvasGroupPigGem:DOFade(0, 0)) self.animPig:Insert(1.5, self.canvasGroupPigGem:DOFade(1, 0.3)) self.animPig:SetAutoKill(false) self.animPig:OnComplete(function() self.animPig = nil end) self.goldPigSpine:playAnimComplete("idle1", false, false, function() self.goldPigSpine:playAnim("idle2", true, false) end) self.goldPigGemTx:setText("+" .. currGemCount - lastGemCount) GFunc.centerImgAndTx(self.goldPigGemImg, self.goldPigGemTx, 0, -4) if currGemCount > lastGemCount then self.sliderSequence = DOTweenManager:createSeqWithIntId() local curProgress = 0 local remain = currGemCount - lastGemCount local startPercent = lastGemCount / maxGemCount local remainPercent = currGemCount / maxGemCount - startPercent self.goldPigGemSliderComp.value = startPercent self.goldPigGemSliderTx:setText(lastGemCount .. "/" .. currGemCount) local tween = DOTweenManager:createDOTweenTo( function() return curProgress end, function(value) curProgress = value self.goldPigGemSliderComp.value = startPercent + remainPercent*curProgress self.goldPigGemSliderTx:setText(lastGemCount + math.floor(remain*curProgress) .. "/" .. maxGemCount) end, 1, 1) self.sliderSequence:Append(tween) self.sliderSequence:AppendCallback(function() self.sliderSequence = nil end) else -- 相等就不跑动画了 self.goldPigGemSliderComp.value = currGemCount / maxGemCount self.goldPigGemSliderTx:setText(currGemCount .. "/" .. maxGemCount) end return true end -- 展示结算奖励的出现动画 function BattleResultUI:showRewardAppearAnim(idx, cell) local canvasGroup = cell.baseObject:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP) local selfObj = cell.baseObject local delay = (idx - 1) * 0.05 local scaleX = selfObj:fastGetLocalScale() local animRewardAppear = selfObj:createBindTweenSequence() animRewardAppear:Insert(0, canvasGroup:DOFade(0, 0)) animRewardAppear:Insert(0, selfObj:getTransform():DOScale(scaleX * 0.6, 0)) animRewardAppear:Insert(0.3 + delay, selfObj:getTransform():DOScale(scaleX * 1.1, 0.1)) animRewardAppear:Insert(0.3 + delay, canvasGroup:DOFade(1, 0.1)) animRewardAppear:Insert(0.4 + delay, selfObj:getTransform():DOScale(scaleX * 1, 0.13)) animRewardAppear:OnComplete(function() animRewardAppear = nil end) return animRewardAppear end return BattleResultUI