# Conflicts:
#	lua/app/config/strings/cn/buff.lua.meta
This commit is contained in:
xiekaidong 2023-04-20 15:17:23 +08:00
commit 3c896cf339
4 changed files with 142 additions and 5 deletions

View File

@ -191,6 +191,22 @@ function BattleController:clearBuff(side)
self.battleUI:clearBuff(side)
end
function BattleController:showBuffTips(side)
if side == BattleConst.SIDE_ATK then
local buffList = self.atkTeam:getBuffList()
if #buffList <= 0 then
return
end
self.battleUI:showLeftBuffTips(buffList)
else
local buffList = self.defTeam:getBuffList()
if #buffList <= 0 then
return
end
self.battleUI:showRightBuffTips(buffList)
end
end
function BattleController:prepareFight()
local count = 0
local totalCount = 3

View File

@ -28,6 +28,10 @@ function BattleTeam:prepare()
end
end
function BattleTeam:getBuffList()
return self.buffList
end
function BattleTeam:getMainUnit()
return self.mainUnit
end

View File

@ -1,3 +1,5 @@
local UIPrefabObject = require "app/bf/unity/uiprefab_object"
local BattleUI = class("BattleUI", BaseUI)
local GRID_CELL = "app/ui/battle/cell/grid_cell"
local GRID_CELL_PATH = "assets/prefabs/ui/battle/cell/grid_cell.prefab"
@ -103,6 +105,7 @@ function BattleUI:initSkill()
end
function BattleUI:initBuff()
-- buff icon
self.atkBuffIconList = {
self.uiMap["battle_ui.top_node.buff_l.buff_1"],
self.uiMap["battle_ui.top_node.buff_l.buff_2"],
@ -111,6 +114,9 @@ function BattleUI:initBuff()
self.uiMap["battle_ui.top_node.buff_l.buff_5"],
}
for k, v in ipairs(self.atkBuffIconList) do
v:addClickListener(function()
self.battleController:showBuffTips(1)
end)
v:setLocalScale(0, 0, 0)
end
self.atkBuffTextList = {
@ -130,7 +136,10 @@ function BattleUI:initBuff()
self.uiMap["battle_ui.top_node.buff_r.buff_4"],
self.uiMap["battle_ui.top_node.buff_r.buff_5"],
}
for k, v in ipairs(self.atkBuffIconList) do
for k, v in ipairs(self.defBuffIconList) do
v:addClickListener(function()
self.battleController:showBuffTips(2)
end)
v:setLocalScale(0, 0, 0)
end
self.defBuffTextList = {
@ -143,6 +152,22 @@ function BattleUI:initBuff()
for k, v in ipairs(self.defBuffTextList) do
v:setText(GConst.EMPTY_STRING)
end
-- buff的tips
self.battleBuffTipsRoot = self.uiMap["battle_ui.battle_buff_tips"]
self.battleBuffTipsRoot:setLocalScale(0, 0, 0)
local battleBuffTipsMask = self.uiMap["battle_ui.battle_buff_tips.mask"]
battleBuffTipsMask:addClickListener(function()
self.battleBuffTipsRoot:setLocalScale(0, 0, 0)
end)
self.battleBuffTipsBg = self.uiMap["battle_ui.battle_buff_tips.bg"]
self.battleBuffTipsBuff = self.uiMap["battle_ui.battle_buff_tips.bg.buff"]
self.battleBuffTipsBuffList = {}
local children = self.battleBuffTipsBg:getChildList()
if children then
for k, v in ipairs(children) do
table.insert(self.battleBuffTipsBuffList, v)
end
end
end
function BattleUI:refreshBuff(side, buffList)
@ -157,8 +182,13 @@ function BattleUI:refreshBuff(side, buffList)
local icon = self.atkBuffIconList[index]
local text = self.atkBuffTextList[index]
icon:setLocalScale(1, 1, 1)
icon:setTexture(GConst.ATLAS_PATH.ICON_BUFF, buffObj.buff:getIcon())
text:setText(buffObj.round)
icon:setSprite(GConst.ATLAS_PATH.ICON_BUFF, buffObj.buff:getIcon())
local round = buffObj.round
if round <= 1 or round > 9 then
text:setText(GConst.EMPTY_STRING)
else
text:setText(tostring(round))
end
index = index + 1
if index > buffIconCount then
break
@ -180,8 +210,13 @@ function BattleUI:refreshBuff(side, buffList)
local icon = self.defBuffIconList[index]
local text = self.defBuffTextList[index]
icon:setLocalScale(1, 1, 1)
icon:setTexture(GConst.ATLAS_PATH.ICON_BUFF, buffObj.buff:getIcon())
text:setText(buffObj.round)
icon:setSprite(GConst.ATLAS_PATH.ICON_BUFF, buffObj.buff:getIcon())
local round = buffObj.round
if round <= 1 or round > 9 then
text:setText(GConst.EMPTY_STRING)
else
text:setText(tostring(round))
end
index = index + 1
if index > buffIconCount then
break
@ -213,6 +248,76 @@ function BattleUI:clearBuff(side)
end
end
function BattleUI:showLeftBuffTips(buffList)
local x = self.battleBuffTipsBg:fastGetAnchoredPosition()
if x > 0 then
self.battleBuffTipsBg:setAnchoredPositionX(-x)
end
self:showBuffTips(buffList)
end
function BattleUI:showRightBuffTips(buffList)
local x = self.battleBuffTipsBg:fastGetAnchoredPosition()
if x < 0 then
self.battleBuffTipsBg:setAnchoredPositionX(-x)
end
self:showBuffTips(buffList)
end
function BattleUI:showBuffTips(buffList)
if #buffList <= 0 then
return
end
self.battleBuffTipsRoot:setLocalScale(1, 1, 1)
local buffObj = nil
local count = #buffList
local index = 1
local addY = 0
for i = 1, count do
buffObj = buffList[i]
if buffObj and buffObj.buff:getIcon() then
local buffTipsObj = self:getBattleBuffTipsObj(index)
buffTipsObj:setLocalScale(1, 1, 1)
buffTipsObj:setAnchoredPositionY(-addY)
local buffTipsObjMap = buffTipsObj:genAllChildren()
buffTipsObjMap["buff.icon"]:setSprite(GConst.ATLAS_PATH.ICON_BUFF, buffObj.buff:getIcon())
local round = buffObj.round
if round <= 1 or round > 9 then
buffTipsObjMap["buff.round"]:setText(GConst.EMPTY_STRING)
else
buffTipsObjMap["buff.round"]:setText(tostring(round))
end
local descTx = buffTipsObjMap["buff.desc"]
descTx:setText(buffObj.buff:getDesc())
descTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO):ForceMeshUpdate()
local height = descTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).renderedHeight
if height > 30 then
addY = addY + 46 + height - 30
else
addY = addY + 46
end
index = index + 1
end
end
for i = index, #self.battleBuffTipsBuffList do
self.battleBuffTipsBuffList[i]:setLocalScale(0, 0, 0)
end
self.battleBuffTipsBg:setSizeDeltaY(addY + 20)
end
function BattleUI:getBattleBuffTipsObj(index)
if self.battleBuffTipsBuffList[index] then
return self.battleBuffTipsBuffList[index]
end
local prefab = CS.UnityEngine.Object.Instantiate(self.battleBuffTipsBuff:getGameObject())
local prefabObject = UIPrefabObject:create()
prefabObject:initWithPrefab(self.battleBuffTipsBuff:getAssetPath(), prefab)
prefabObject:initPrefabHelper()
prefabObject:setParent(self.battleBuffTipsBg, false)
table.insert(self.battleBuffTipsBuffList, prefabObject)
return prefabObject
end
function BattleUI:initBattlefield()
self.battleNode = self.uiMap["battle_ui.battle_node"]
end

View File

@ -22,6 +22,18 @@ function BattleBuffEntity:getName()
return self.name
end
function BattleBuffEntity:getDesc()
if self.desc == nil then
local buff18NInfo = I18N:getConfigWithOtherKey("buff", "name")[self.name]
if buff18NInfo then
self.desc = buff18NInfo.desc or GConst.EMPTY_STRING
else
self.desc = GConst.EMPTY_STRING
end
end
return self.desc
end
function BattleBuffEntity:getBuffType()
return self.buffType
end