miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/View/DamageResultPanel.lua

412 lines
15 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Modules.Battle.Config.PokemonEffectConfig")
require("Base/BasePanel")
local SpiritAnimal = ConfigManager.GetConfig(ConfigName.SpiritAnimal)
local DamageResultPanel = Inherit(BasePanel)
local this = DamageResultPanel
-- Tab管理器
local TabBox = require("Modules/Common/TabBox")
local _TabFontColor = { default = Color.New(168 / 255, 168 / 255, 167 / 255, 1),
select = Color.New(250 / 255, 227 / 255, 175 / 255, 1) }
local _TabData = {
[1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[10271] },
[2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[10272] },
[3] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "特殊" },
[4] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "灵兽" },
}
-- 最大层数
local _MaxOrder = 0
-- 最大数值,以最大数值为比计算其他数值的比例
local _MaxDamageValue = 0
local _MaxTreatValue = 0
-- 节点保存
local _LeftItemPool = {}
local _RightItemPool = {}
local LEFT_CAMP = 0
local RIGHT_CAMP = 1
-- 数据重构
local _NormalMonsterList = {}
local _DiffMonsterList = {}
--初始化组件(用于子类重写)
function DamageResultPanel:InitComponent()
this.BtnBack = Util.GetGameObject(this.transform, "btnBack")
this.leftResult = Util.GetGameObject(this.transform, "left/result"):GetComponent("Image")
this.leftName = Util.GetGameObject(this.transform, "left/name"):GetComponent("Text")
this.leftItem = Util.GetGameObject(this.transform, "left/item")
this.leftGrid = Util.GetGameObject(this.transform, "left/scrollRect/grid")
this.rightResult = Util.GetGameObject(this.transform, "right/result"):GetComponent("Image")
this.rightName = Util.GetGameObject(this.transform, "right/name"):GetComponent("Text")
this.rightItem = Util.GetGameObject(this.transform, "right/item")
this.rightGrid = Util.GetGameObject(this.transform, "right/scrollRect/grid")
-- 初始化Tab管理器
this.tabbox = Util.GetGameObject(this.transform, "top")
this.TabCtrl = TabBox.New()
this.TabCtrl:SetTabAdapter(this.TabAdapter)
this.TabCtrl:SetChangeTabCallBack(this.OnTabChange)
this.TabCtrl:Init(this.tabbox, _TabData)
end
--绑定事件(用于子类重写)
function DamageResultPanel:BindEvent()
Util.AddClick(this.BtnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function DamageResultPanel:AddListener()
end
--移除事件监听(用于子类重写)
function DamageResultPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function DamageResultPanel:OnOpen(result)
this.leftResult.sprite = Util.LoadSprite(result == 1 and "UI_effect_JJC_JieSuan_ShengLi_png" or "UI_effect_JJC_JieSuan_ShiBai_png")
this.rightResult.sprite = Util.LoadSprite(result == 0 and "UI_effect_JJC_JieSuan_ShengLi_png" or "UI_effect_JJC_JieSuan_ShiBai_png")
local nameStr = BattleRecordManager.GetBattleBothNameStr()
if nameStr then
local namelist = string.split(nameStr, "|")
this.leftName.text = namelist[1]
this.rightName.text = namelist[2]
else
this.leftName.text = Language[10273]
this.rightName.text = Language[10274]
end
-- 数据
this.battleRecord = BattleRecordManager.GetBattleRecord()
if not this.battleRecord then return end
-- 计算最大数据
_MaxDamageValue = 0
_MaxTreatValue = 0
if this.battleRecord.data then
for _, role in pairs(this.battleRecord.data) do
-- 计算最大值
if role.damage and role.damage > _MaxDamageValue then _MaxDamageValue = role.damage end
if role.treat and role.treat > _MaxTreatValue then _MaxTreatValue = role.treat end
end
end
-- tab节点管理
if this.TabCtrl then
this.TabCtrl:Init(this.tabbox, _TabData)
end
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function DamageResultPanel:OnShow()end
function this.isTabShow(index)
if not this.battleRecord then
return false
end
local list
if index == 1 or index == 2 then
return true
elseif index == 3 then
list = this.battleRecord.data
elseif index == 4 then
list = this.battleRecord.mdata
end
--
if list and table.nums(list) ~= 0 then
for _, role in pairs(list) do
-- 还有除info, damage, treat之外的其他属性
if table.nums(role) > 3 then
return true
end
end
end
return false
end
-- tab节点显示自定义
function this.TabAdapter(tab, index, status)
local tabLab = Util.GetGameObject(tab, "Text")
Util.GetGameObject(tab,"Img"):GetComponent("Image").sprite = Util.LoadSprite(_TabData[index][status])
tabLab:GetComponent("Text").text = _TabData[index].name
tabLab:GetComponent("Text").color = _TabFontColor[status]
tab.gameObject:SetActive(this.isTabShow(index))
end
-- tab改变回调事件
function this.OnTabChange(index, lastIndex)
local showType = index -- 1 伤害 2 治疗 3 特殊 4 灵兽
-- 关闭显示
for _, item in pairs(_LeftItemPool) do
item:SetActive(false)
end
for _, item in pairs(_RightItemPool) do
item:SetActive(false)
end
-- 数据匹配
if not this.battleRecord then return end
local leftIndex, rightIndex = 0, 0
local function CreateMonsterItem(data)
local pool, item, grid, index
if data.info.camp == LEFT_CAMP then
leftIndex = leftIndex + 1
pool, item, grid, index = _LeftItemPool, this.leftItem, this.leftGrid, leftIndex
elseif data.info.camp == RIGHT_CAMP then
rightIndex = rightIndex + 1
pool, item, grid, index = _RightItemPool, this.rightItem, this.rightGrid, rightIndex
end
if not pool[index] then
pool[index] = newObjToParent(item, grid)
end
pool[index]:SetActive(true)
this.ItemAdapter(pool[index], data, showType)
end
-- 创建
local showList = this.battleRecord.data
if showType == 4 then
showList = this.battleRecord.mdata
end
for _, data in pairs(showList) do
CreateMonsterItem(data)
end
-- 播放动画
this.StartPlayAnim(showType)
end
-- 开始播放动画
function this.StartPlayAnim(showType)
if showType > 2 then
return
end
-- 根据showType播放动画
DoTween.To(
DG.Tweening.Core.DOGetter_float( function () return 0 end),
DG.Tweening.Core.DOSetter_float(
function (progress)
local leftIndex, rightIndex = 0, 0
local function _Play(data)
local pool, index, drt
if data.info.camp == LEFT_CAMP then
leftIndex = leftIndex + 1
pool, index = _LeftItemPool, leftIndex
drt = 1
elseif data.info.camp == RIGHT_CAMP then
rightIndex = rightIndex + 1
pool, index = _RightItemPool, rightIndex
drt = -1
end
if pool[index] then
local _progress = Util.GetGameObject(pool[index], "progress")
local value = 0
if showType == 1 then
if _MaxDamageValue ~= 0 then
value = (data.damage or 0)/_MaxDamageValue
end
else
if _MaxTreatValue ~= 0 then
value = (data.treat or 0)/_MaxTreatValue
end
end
_progress.transform.localScale = Vector3(value * progress * drt, 1, 1)
end
end
-- 创建
for _, data in pairs(this.battleRecord.data) do
_Play(data)
end
end),
1, 1)
:SetEase(Ease.OutQuad)
end
-- 数据匹配
function this.ItemAdapter(item, data, showType)
local head = Util.GetGameObject(item, "headpos/head")
this.HeadAdapter(head, data.info, showType)
local damage = Util.GetGameObject(item, "damage"):GetComponent("Text")
local progress = Util.GetGameObject(item, "progress")
local scroll = Util.GetGameObject(item, "scroll")
local content = Util.GetGameObject(item, "scroll/Viewport/Content"):GetComponent("Text")
-- 显隐
damage.gameObject:SetActive(showType <= 2)
progress.gameObject:SetActive(showType <= 2)
scroll:SetActive(showType > 2)
--
if showType == 1 then
damage.text = data.damage or 0
progress:GetComponent("Image").sprite = Util.LoadSprite("r_guaji_zhandoutongjitiao_01")
progress.transform.localScale = Vector3(0, 1, 1)
elseif showType == 2 then
damage.text = data.treat or 0
progress:GetComponent("Image").sprite = Util.LoadSprite("r_guaji_zhandoutongjitiao_02")
progress.transform.localScale = Vector3(0, 1, 1)
elseif showType == 3 or showType == 4 then
local txt = ""
for key, value in pairs(data) do
local s = this.GetSpecialText(key, value)
if s and s ~= "" then
if txt ~= "" then
txt = txt.."\n"
end
txt = txt..s
end
end
-- 没有显示则不显示
if txt == "" then
item.gameObject:SetActive(false)
else
content.text = txt
end
end
end
function this.GetSpecialText(key, value)
if key == "buff" then
local s = ""
for id, v in pairs(value) do
local type = math.floor(id/100)
local subType = id%100
print(id, type, subType)
local config = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.BuffEffectConfig, "Type", type, "CType", subType)
if config then
if s ~= "" then
s = s.."\n"
end
local color = UIColorStr.RED
if type == BuffName.Shield then
color = UIColorStr.GREEN
end
s = s .. string.format("%s<color=%s>%s</color>次", config.Describe, color, v)
end
end
return s
elseif key == "addRage" then
return string.format("回怒:<color=%s>%s</color>点", UIColorStr.GREEN, value)
elseif key == "subRage" then
return string.format("减怒:<color=%s>%s</color>点", UIColorStr.RED, value)
elseif key == "transRage" then
return string.format("借怒:<color=%s>%s</color>点", UIColorStr.GREEN, value)
elseif key == "secKill" then
return string.format("斩杀:<color=%s>%s</color>次", UIColorStr.RED, value)
end
end
-- 头像数据匹配
function this.HeadAdapter(head, data)
local frame = Util.GetGameObject(head, "frame"):GetComponent("Image")
local icon = Util.GetGameObject(head, "icon"):GetComponent("Image")
local prefess = Util.GetGameObject(head, "pro")
prefess:SetActive(false)
local prefessIcon = Util.GetGameObject(head, "pro/icon"):GetComponent("Image")
local proto = Util.GetGameObject(head, "prott")
local protoIcon = Util.GetGameObject(head, "prott/Image"):GetComponent("Image")
local lv = Util.GetGameObject(head, "lv")
local lvText = Util.GetGameObject(head, "lv/Text"):GetComponent("Text")
local starRoot = Util.GetGameObject(head, "star")
if data.type == BattleUnitType.Role then
local roleId = data.roleData.monsterId or data.roleData.roleId
local roleLv = data:GetRoleData(RoleDataName.Level)
local skinId = data.roleData.skinId
local star = data.star
local config = {}
if roleId > 10100 then
local MonsterConfig = ConfigManager.GetConfigData(ConfigName.MonsterConfig, roleId)
config.Quality = MonsterConfig.Quality
config.lv = MonsterConfig.Level
if MonsterConfig.MonsterId > 10000 then
local heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, MonsterConfig.MonsterId)
config.Icon = heroConfig.Icon
config.Profession = heroConfig.Profession
config.PropertyName = heroConfig.PropertyName
else
local monsterViewInfo = ConfigManager.GetConfigData(ConfigName.MonsterViewConfig, MonsterConfig.MonsterId)
config.Icon = monsterViewInfo.MonsterIcon
end
else
local heroConfig = ConfigManager.GetConfigData(ConfigName.HeroConfig, roleId)
config.Quality = heroConfig.Quality
config.Icon = heroConfig.Icon
config.Profession = heroConfig.Profession
config.PropertyName = heroConfig.PropertyName
config.lv = roleLv
end
-- 头像
frame.sprite = Util.LoadSprite(GetHeroQuantityImageByquality(config.Quality))
local aa=config.Icon
if data.skinId and data.skinId>0 then
local skinConfig=ConfigManager.GetConfigDataByKey(ConfigName.HeroSkin,"Type",data.skinId)
if skinConfig then
aa=skinConfig.Icon
end
end
icon.sprite = Util.LoadSprite(GetResourcePath(aa))
-- 等级
lv:SetActive(true)
lvText.text = config.lv
-- 星级
SetHeroStars(starRoot, star)
-- 职业
prefess:SetActive(false)
-- 属性
proto:SetActive(false)
if config.PropertyName then
protoIcon.sprite = Util.LoadSprite(GetProStrImageByProNum(config.PropertyName))
proto:SetActive(true)
end
elseif data.type == BattleUnitType.Monster then
local id = data.uid
local roleLv = data:GetRoleData(RoleDataName.Level)
local star = data.star
prefess:SetActive(false)
proto:SetActive(false)
-- 等级
lv:SetActive(true)
lvText.text = roleLv
-- 星级
SetHeroStars(starRoot, star)
-- 头像
frame.sprite = Util.LoadSprite(GetHeroQuantityImageByquality(SpiritAnimal[id].Quality))
icon:GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(SpiritAnimal[id].Icon))
end
end
--界面关闭时调用(用于子类重写)
function DamageResultPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function DamageResultPanel:OnDestroy()
_LeftItemPool = {}
_RightItemPool = {}
_MaxDamageValue = 0
_MaxTreatValue = 0
end
return DamageResultPanel