231 lines
8.9 KiB
Lua
231 lines
8.9 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.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
|
|
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.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_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.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.scrollRectComp then
|
|
self.scrollRectComp:updateAllCell()
|
|
return
|
|
end
|
|
|
|
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])
|
|
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 > 10 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, true)
|
|
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
|
|
|
|
function BattleResultUI:initGoldPig()
|
|
local uiMap = self.root:genAllChildren()
|
|
self.goldPigRoot = uiMap["battle_result_ui.gold_pig"]
|
|
self.goldPigRoot:setVisible(false)
|
|
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"]
|
|
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.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
|
|
|
|
return BattleResultUI |